diff --git a/modpol/orgs/orgs.lua b/modpol/orgs/orgs.lua index d86342f..d8db2ad 100644 --- a/modpol/orgs/orgs.lua +++ b/modpol/orgs/orgs.lua @@ -38,6 +38,21 @@ function modpol.orgs.list_all() return org_table end +-- Function: modpol.orgs.user_orgs(user) +-- input: user (string) +-- output: table of strings of org names +function modpol.orgs.user_orgs(user) + local all_orgs = modpol.orgs.list_all() + local user_orgs = {} + for i,v in ipairs(all_orgs) do + local this_table = modpol.orgs.get_org(v) + if this_table:has_member(user) then + table.insert(user_orgs,v) + end + end + return user_orgs +end + -- =========================================== -- deletes all orgs except for the instance function modpol.orgs.reset() @@ -188,7 +203,7 @@ end -- adds a user to an org function modpol.orgs:add_member(user) -- trys to fill in empty spots first - empty_index = self:get_member_index('') + local empty_index = self:get_member_index('') if empty_index then self.members[empty_index] = user else diff --git a/modpol_minetest/overrides/interactions/interactions.lua b/modpol_minetest/overrides/interactions/interactions.lua index 71fcd51..67fe86c 100644 --- a/modpol_minetest/overrides/interactions/interactions.lua +++ b/modpol_minetest/overrides/interactions/interactions.lua @@ -1,5 +1,7 @@ --- =================================================================== +-- INTERACTIONS.LUA (for Minetest) + -- CONTEXTUAL STUFF +-- ================ -- First, set up contexts to enable passing across formspecs -- https://rubenwardy.com/minetest_modding_book/en/players/formspecs.html#contexts @@ -17,8 +19,26 @@ end) -- table of formspec field responses local formspec_fields = {} --- =================================================================== + +-- UTILITIES +-- ========= + +-- Function: formspec_list +-- for use generating option lists in formspecs from tables +-- input: table of strings +-- output: a formspec-ready list of the strings +local function formspec_list(array) + local escaped = {} + for i = 1, #array do + escaped[i] = minetest.formspec_escape(array[i]) + end + return table.concat(escaped,",") +end + + -- MAIN MODPOL DASHBOARD +-- ===================== + -- Function: modpol.interactions.dashboard(user) -- Params: user (string) -- Q: Should this return a menu of commands relevant to the specific user? @@ -31,17 +51,22 @@ function modpol.interactions.dashboard(user) for key,value in pairs(command_list) do commands = commands .. "/" .. value .. " " end - local orgs = "Orgs: " .. - table.concat(modpol.orgs.list_all(), ", ") - local users = "Players: " - .. table.concat(modpol.list_users(), ", ") + local all_orgs = modpol.orgs.list_all() + local user_orgs = modpol.orgs.user_orgs(user) + local all_users = modpol.list_users() -- set up formspec local formspec = { "formspec_version[4]", "size[10,8]", - "label[0.5,0.5;", minetest.formspec_escape(commands), "]", - "label[0.5,1.5;", minetest.formspec_escape(orgs), "]", - "label[0.5,2.5;", minetest.formspec_escape(users), "]", + "label[0.5,0.5;MODULAR POLITICS]", + "label[0.5,2;All orgs:]", + "dropdown[2,1.5;5,0.8;user_orgs;"..formspec_list(all_orgs)..";;]", + "label[0.5,3;Your orgs:]", + "dropdown[2,2.5;5,0.8;input;"..formspec_list(user_orgs)..";;]", + "label[0.5,4;All users:]", + "dropdown[2,3.5;5,0.8;input;"..formspec_list(all_users)..";;]", + "label[0.5,5;Processes:]", + "dropdown[2,4.5;5,0.8;input;TBA;;]", "button[0.5,7;1,0.8;test_poll;Test poll]", "button[2,7;1,0.8;add_org;Add org]", "button[3.5,7;1.5,0.8;remove_org;Remove org]", @@ -65,7 +90,9 @@ minetest.register_on_player_receive_fields(function (player, formname, fields) end end) --- BASIC INTERACTION FUNCTIONS -- + +-- BASIC INTERACTION FUNCTIONS +-- =========================== -- Function: modpol.interactions.message -- input: message (string) @@ -103,16 +130,16 @@ minetest.register_on_player_receive_fields(function (player, formname, fields) end end) + -- Function: dropdown_query -- input: user (string), label (string), options (table of strings) function modpol.interactions.dropdown_query(user, label, options) -- set up formspec - local options_string = table.concat(options,",") local formspec = { "formspec_version[4]", "size[10,4]", - "label[0.5,1;", minetest.formspec_escape(label), "]", - "dropdown[0.5,1.25;9,0.8;input;".. minetest.formspec_escape(options_string)..";;]", + "label[0.5,1;"..minetest.formspec_escape(label).."]", + "dropdown[0.5,1.25;9,0.8;input;"..formspec_list(options)..";;]", "button[0.5,2.5;1,0.8;yes;OK]", } local formspec_string = table.concat(formspec, "") @@ -190,7 +217,6 @@ function modpol.interactions.binary_poll_org(initiator, org) modpol.interactions.binary_poll_user(v, input) end _contexts[initiator] = nil - modpol.interactions.dashboard(initiator) end end