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