Getting the testing formspecs working with requests and nested functions, bugfixes like crazy
This commit is contained in:
		| @@ -280,18 +280,14 @@ function modpol.orgs:has_member(user) | ||||
| end | ||||
|  | ||||
| -- ================================== | ||||
| -- returns a list of users in an org | ||||
| function modpol.orgs:list_member() | ||||
|     local str | ||||
|     for k, v in ipairs(self.members) do | ||||
|         -- checking to see if member name is valid | ||||
|         if str and str ~= '' then  | ||||
|             str = str .. '\n' .. v | ||||
|         else  | ||||
|             str = v | ||||
|         end | ||||
|     end | ||||
|     return str | ||||
| -- Function: modpol.orgs:list_members() | ||||
| -- output: a table of the names (string) of members | ||||
| function modpol.orgs:list_members() | ||||
|    local members = {} | ||||
|    for k, v in ipairs(self.members) do | ||||
|       table.insert(members, v) | ||||
|    end | ||||
|    return members | ||||
| end | ||||
|  | ||||
| -- ============================== | ||||
|   | ||||
| @@ -122,6 +122,7 @@ function modpol.interactions.org_dashboard(user, org_name) | ||||
|       end | ||||
|       return toggle_code | ||||
|    end | ||||
|    -- identify parent TODO | ||||
|    -- prepare children menu | ||||
|    local children = {} | ||||
|    for k,v in ipairs(org.children) do | ||||
| @@ -140,11 +141,9 @@ function modpol.interactions.org_dashboard(user, org_name) | ||||
|                active = '*' | ||||
|             end | ||||
|          end | ||||
|          print(this_request.params) | ||||
|          print(this_request.type) | ||||
|          for k,v in pairs(this_request.params) do print(k, v) end  | ||||
|          for k,v in pairs(this_request.params[1]) do print(k,v) end  | ||||
|          local req_str = v.id .. " (" .. this_request.type .. " -> " .. this_request.params[1] .. ")" .. active | ||||
|          local req_str = "[" .. v.id .. "] " .. | ||||
|             this_request.type .. ": " .. | ||||
|             this_request.params[1] .. active | ||||
|          table.insert(processes, req_str) | ||||
|       end | ||||
|    end | ||||
| @@ -183,6 +182,13 @@ minetest.register_on_player_receive_fields(function (player, formname, fields) | ||||
|          local pname = player:get_player_name() | ||||
|          local org = modpol.orgs.get_org(_contexts[pname].current_org) | ||||
|          if nil then | ||||
|          elseif fields.processes then | ||||
|             local sel = | ||||
|                string.match(fields.processes,"%[(%d)%]") | ||||
|             local process = org.processes[tonumber(sel)] | ||||
|             if process then | ||||
|                process:interact(user) | ||||
|             end | ||||
|          elseif fields.join then | ||||
|             local new_request = { | ||||
|                user = pname, | ||||
| @@ -197,16 +203,16 @@ minetest.register_on_player_receive_fields(function (player, formname, fields) | ||||
|             modpol.interactions.dashboard(pname) | ||||
|          elseif fields.test_poll then | ||||
|             modpol.interactions.binary_poll_org( | ||||
|                pname, _contexts[pname].current_org.id, | ||||
|                "Poll question (yes/no):", | ||||
|                pname, org.id, | ||||
|                function(input) | ||||
|                   modpol.interactions.message_org( | ||||
|                      _contexts[pname].current_org.id, | ||||
|                      pname, | ||||
|                      org.id, | ||||
|                      pname .. " voted " .. input) | ||||
|             end) | ||||
|          elseif fields.add_child then | ||||
|             modpol.interactions.add_org( | ||||
|                pname, _contexts[pname].current_org.id) | ||||
|                pname, org.id) | ||||
|          elseif fields.remove_org then | ||||
|             modpol.interactions.remove_org(pname) | ||||
|          elseif fields.back then | ||||
| @@ -329,7 +335,6 @@ function modpol.interactions.binary_poll_user(user, question, func) | ||||
|    _contexts[user]["binary_poll_func"] = func | ||||
|    -- present to player | ||||
|    minetest.show_formspec(user, "modpol:binary_poll_user", formspec_string) | ||||
|    modpol.interactions.message(user,"should have showed formspec: " .. question) | ||||
| end | ||||
| minetest.register_on_player_receive_fields(function (player, formname, fields) | ||||
|       local pname = player:get_player_name() | ||||
| @@ -342,7 +347,7 @@ minetest.register_on_player_receive_fields(function (player, formname, fields) | ||||
|          if vote then | ||||
|             modpol.interactions.message(pname, "Voted " .. vote) | ||||
|             local func = _contexts[pname]["binary_poll_func"] | ||||
|             func(vote) | ||||
|             if func then func(vote) end | ||||
|          end | ||||
|          minetest.close_formspec(pname, formname) | ||||
|       end | ||||
| @@ -356,7 +361,7 @@ end) | ||||
| -- output: broadcasts message to all org members | ||||
| function modpol.interactions.message_org(initiator, org_id, message) | ||||
|    local org = modpol.orgs.get_org(org_id) | ||||
|    local users = org:list_member() | ||||
|    local users = org:list_members() | ||||
|    for k,v in ipairs(users) do | ||||
|       modpol.interactions.message(v, message) | ||||
|    end | ||||
| @@ -366,14 +371,15 @@ end | ||||
| -- Function: modpol.interactions.binary_poll_org | ||||
| -- input: initator (user string), org_id (number) | ||||
| -- output: gets question from initiator, asks all org members, broadcasts answers | ||||
| function modpol.interactions.binary_poll_org(initiator, org_id) | ||||
| -- TODO for testing. This should be implemented as a request. | ||||
| function modpol.interactions.binary_poll_org(initiator, org_id, func) | ||||
|    local org = modpol.orgs.get_org(org_id) | ||||
|    local users = org:list_member() | ||||
|    local users = org:list_members() | ||||
|    modpol.interactions.text_query( | ||||
|       initiator, "Yes/no poll question:", | ||||
|       function(input) | ||||
|          for k,v in ipairs(users) do | ||||
|             modpol.interactions.binary_poll_user(v, input) | ||||
|             modpol.interactions.binary_poll_user(v, input, func) | ||||
|          end | ||||
|    end) | ||||
| end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user