diff --git a/modpol/api.lua b/modpol/api.lua index cae289f..9565302 100644 --- a/modpol/api.lua +++ b/modpol/api.lua @@ -12,8 +12,5 @@ dofile (localdir .. "/orgs/requests.lua") --interactions dofile (localdir .. "/interactions/interactions.lua") --- messaging functions -dofile (localdir .. "/processes/processes.lua") - --modules -dofile (localdir .. "/modules/consent.lua") \ No newline at end of file +dofile (localdir .. "/modules/consent.lua") diff --git a/modpol/interactions/interactions.lua b/modpol/interactions/interactions.lua index 4eb9c26..e6ba855 100644 --- a/modpol/interactions/interactions.lua +++ b/modpol/interactions/interactions.lua @@ -5,7 +5,10 @@ modpol.interactions = {} --- =================================================================== + +-- DASHBOARDS +-- ========== + -- Function: modpol.dashboard(user) -- Params: user (string) -- Q: Should this return a menu of commands relevant to the specific user? @@ -16,8 +19,6 @@ function modpol.dashboard(user) -- Org status output = output .. "Orgs:\n" .. table.concat(modpol.orgs.list_all(),"\n") - -- Process status (ongoing processes) - output = output .. "\nProcesses:\n" .. table.concat(modpol.processes) -- Command list (should be redone to be org-specific) output = output .. "\nCommand list:\n" for key,value in pairs(modpol) do @@ -27,6 +28,43 @@ function modpol.dashboard(user) end +-- Function: modpol.interactions.org_dashboard +-- Params: user (string), org_name (string) +-- Output: Displays a menu of org-specific commands to the user +function modpol.interactions.org_dashboard(user, org_name) + local org = modpol.orgs.get_org(org_name) + if not org then return nil end + local is_member = org:has_member(user) + local membership_toggle = function() + local toggle_code = "" + if is_member then + toggle_code = "[Leave]" + else + toggle_code = "[Join]" + end + return toggle_code + end + local children = {} + for k,v in ipairs(org.children) do + local this_child = modpol.orgs.get_org(v) + table.insert(children, this_child.name) + end + -- set up output + local dashboard_table = { + "Org: " .. org_name, + membership_toggle(), + "Members: " .. table.concat(org.members, ", "), + "Children: " .. table.concat(children, ", "), + "Policies: " .. table.concat(org.policies, ", "), + "Processes: " .. table.concat(org.processes, ", "), + "[Add child]", + "[Remove org]", + "[Dashboard: modpol.dashboard()]" + } + -- present to player + print(table.concat(dashboard_table, "\n")) +end + -- =================================================================== -- Function: modpol.interactions.message -- input: user (string), message (string) diff --git a/modpol/processes/processes.lua b/modpol/processes/processes.lua deleted file mode 100644 index 8a6c699..0000000 --- a/modpol/processes/processes.lua +++ /dev/null @@ -1,106 +0,0 @@ --- =================================================================== --- /processes.lua --- Process-related functions for Modular Politics --- Called by modpol.lua - --- =================================================================== --- modpol.processes, a high-level table of active processes --- Process table structure: --- [name]: unique name --- [org]: org --- [update_functions]: table of available update functions --- [state]: table of relevant data on the state of the function - -modpol.processes = {} - --- =================================================================== --- Function: modpol.register_process --- Adds a process to modpol.processes - --- =================================================================== --- Function: modpol.delegate_process --- Delegates a process from one org to another - --- =================================================================== --- Function: modpol.begin_process --- Params: user (string), org (string), action (string) --- Outputs: Checks the org for any policies related to a given action; --- Calls the modpol.initiate.* function(org) based on policy --- Defaults to modpol.initiate.consent() -modpol.begin_process = function(user, org, action) - if modpol.orgs[org]["policies"] - and modpol.orgs[org]["policies"][routine] then - -- check user org membership is satisfied - -- register process - -- start the appropriate process - else - -- register process (or does .initiate.* do that?) - modpol.initiate.consent(org) - end -end - --- =================================================================== --- Function: modpol.update_process - --- =================================================================== --- Function: modpol.end_process - - - - - --- =================================================================== --- Basic decision functions --- =================================================================== - --- =================================================================== --- Function: modpol.consent --- Params: org (string), proposal (string) --- Outputs: boolean - true if consent achieved or false; nil on error --- Also includes a table of responses --- This is the default decision-making routine for Modular Politics --- Stops at the first "No" vote -modpol.consent = function(org, query) - -- Check that org exists - if modpol.orgs[org] == nil then - return nil, "Error: Org does not exist" - end - -- Poll all members - local responses = {} - for index, value in ipairs(modpol.orgs[org]["members"]) do - local response = modpol.binary_poll_user(value, query) - responses[value] = response - if response == "No" then - return false, responses - end - end - return true, responses -end - --- =================================================================== --- Function: modpol.approved --- A simple function for automatically approved processes --- Params: none --- Outputs: boolean - true -modpol.approved = function() - -- Check that org exists - if modpol.orgs[org] == nil then - return nil, "Error: Org does not exist" - end - return true -end - --- =================================================================== --- Experimental --- =================================================================== - --- =================================================================== --- TKTK exploring modpol.initiate functions, which have no args --- Need to properly document these -modpol.initiate = {} - -modpol.initiate.consent = function(org) - print("What is your query?") - local query = io.read() - return modpol.consent(org, query) -end diff --git a/modpol_minetest/overrides/interactions/interactions.lua b/modpol_minetest/overrides/interactions/interactions.lua index 30ec7f0..58316b2 100644 --- a/modpol_minetest/overrides/interactions/interactions.lua +++ b/modpol_minetest/overrides/interactions/interactions.lua @@ -64,8 +64,6 @@ function modpol.interactions.dashboard(user) "dropdown[2,2.5;5,0.8;user_orgs;"..formspec_list(user_orgs)..";;]", "label[0.5,4;All users:]", "dropdown[2,3.5;5,0.8;all_users;"..formspec_list(all_users)..";;]", - "label[0.5,5;Processes:]", - "dropdown[2,4.5;5,0.8;processes;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]", @@ -160,7 +158,13 @@ minetest.register_on_player_receive_fields(function (player, formname, fields) local org = modpol.orgs.get_org(_contexts[pname].current_org) if nil then elseif fields.join then - org:add_member(pname) + local new_request = { + user = player, + type = "add_member", + params = {player} + } + org:make_request(new_request) + --org:add_member(pname) modpol.interactions.org_dashboard(pname,org.name) elseif fields.leave then org:remove_member(pname)