Merge branch 'master' into modules
This commit is contained in:
commit
6258855380
@ -8,10 +8,6 @@
|
|||||||
-- Main API table
|
-- Main API table
|
||||||
if not modpol then modpol = {} end
|
if not modpol then modpol = {} end
|
||||||
|
|
||||||
-- Table for modpol data
|
|
||||||
modpol.orgs = {
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Record of every state change should appear here
|
-- Record of every state change should appear here
|
||||||
modpol.ledger = {
|
modpol.ledger = {
|
||||||
}
|
}
|
||||||
@ -76,12 +72,14 @@ dofile (topdir .. "/api.lua")
|
|||||||
-- ===================================================================
|
-- ===================================================================
|
||||||
-- Final checks
|
-- Final checks
|
||||||
|
|
||||||
-- create instance if not present
|
for id, org in ipairs(modpol.orgs.array) do
|
||||||
if not modpol.orgs.get_org('instance') then
|
setmetatable(org, modpol.orgs)
|
||||||
modpol.orgs.init_instance()
|
|
||||||
modpol.instance = modpol.orgs.get_org('instance')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- create instance if not present
|
||||||
|
modpol.instance = modpol.orgs.array[1] or modpol.orgs.init_instance()
|
||||||
|
|
||||||
|
|
||||||
modpol.ocutil.log ("modpol loaded")
|
modpol.ocutil.log ("modpol loaded")
|
||||||
|
|
||||||
-- ===================================================================
|
-- ===================================================================
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
modpol.orgs =
|
modpol.orgs = modpol.orgs or
|
||||||
{
|
{
|
||||||
count = 1,
|
count = 1,
|
||||||
array = {}
|
array = {}
|
||||||
@ -82,6 +82,8 @@ function modpol.orgs.reset()
|
|||||||
modpol.orgs.array[id] = nil
|
modpol.orgs.array[id] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
modpol.orgs:record('Resetting all orgs', 'org_reset')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ===================================================
|
-- ===================================================
|
||||||
@ -103,6 +105,9 @@ function modpol.orgs.init_instance()
|
|||||||
|
|
||||||
-- adding instance to org list
|
-- adding instance to org list
|
||||||
modpol.orgs.array[1] = instance
|
modpol.orgs.array[1] = instance
|
||||||
|
|
||||||
|
modpol.orgs:record('Initialized the instance org', 'create_instance')
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -158,6 +163,12 @@ function modpol.orgs:add_org(name)
|
|||||||
return false, error_msg
|
return false, error_msg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if modpol.orgs.get_org(name) then
|
||||||
|
error_msg = 'Error: org name is already being used'
|
||||||
|
modpol.ocutil.log(error_msg)
|
||||||
|
return false, error_msg
|
||||||
|
end
|
||||||
|
|
||||||
-- creating the child sub org
|
-- creating the child sub org
|
||||||
modpol.orgs.count = modpol.orgs.count + 1
|
modpol.orgs.count = modpol.orgs.count + 1
|
||||||
local child_org = temp_org()
|
local child_org = temp_org()
|
||||||
@ -173,6 +184,7 @@ function modpol.orgs:add_org(name)
|
|||||||
-- adding child to org list
|
-- adding child to org list
|
||||||
modpol.orgs.array[child_org.id] = child_org
|
modpol.orgs.array[child_org.id] = child_org
|
||||||
|
|
||||||
|
self:record('created sub org ' .. name, 'add_org')
|
||||||
|
|
||||||
return child_org
|
return child_org
|
||||||
end
|
end
|
||||||
@ -197,6 +209,8 @@ function modpol.orgs:delete()
|
|||||||
modpol.orgs.array[self.id] = 'removed'
|
modpol.orgs.array[self.id] = 'removed'
|
||||||
print('Removed ' .. self.name .. ': ' .. self.id)
|
print('Removed ' .. self.name .. ': ' .. self.id)
|
||||||
|
|
||||||
|
self:record('Deleted ' .. self.name .. ' and all child orgs', 'del_org')
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -221,6 +235,7 @@ function modpol.orgs:add_member(user)
|
|||||||
-- adds to end if no empty spots
|
-- adds to end if no empty spots
|
||||||
table.insert(self.members, user)
|
table.insert(self.members, user)
|
||||||
end
|
end
|
||||||
|
self.record('Added member ' .. user, 'add_member')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- =======================================
|
-- =======================================
|
||||||
@ -232,6 +247,7 @@ function modpol.orgs:remove_member(user)
|
|||||||
if user_index then
|
if user_index then
|
||||||
self.members[user_index] = ''
|
self.members[user_index] = ''
|
||||||
end
|
end
|
||||||
|
self.record('Removed member ' .. user, 'del_member')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ===========================================
|
-- ===========================================
|
||||||
|
@ -49,7 +49,7 @@ local store_orgs = function()
|
|||||||
modpol.ocutil.fatal_error ("store_data: orgs")
|
modpol.ocutil.fatal_error ("store_data: orgs")
|
||||||
end
|
end
|
||||||
|
|
||||||
local nn = modpol.ocutil.table_length (modpol.orgs)
|
local nn = modpol.ocutil.table_length (modpol.orgs.array)
|
||||||
local str = "entries"
|
local str = "entries"
|
||||||
if nn == 1 then str = "entry" end
|
if nn == 1 then str = "entry" end
|
||||||
modpol.ocutil.log (nn .. " orgs stored to disk")
|
modpol.ocutil.log (nn .. " orgs stored to disk")
|
||||||
@ -80,7 +80,7 @@ end
|
|||||||
modpol.store_data = function()
|
modpol.store_data = function()
|
||||||
store_ledger()
|
store_ledger()
|
||||||
store_orgs()
|
store_orgs()
|
||||||
store_old_ledgers()
|
-- store_old_ledgers()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ===================================================================
|
-- ===================================================================
|
||||||
@ -116,7 +116,12 @@ local load_orgs = function()
|
|||||||
end
|
end
|
||||||
modpol.orgs = func()
|
modpol.orgs = func()
|
||||||
|
|
||||||
local nn = modpol.ocutil.table_length (modpol.orgs)
|
-- this block resets the metatable after being loaded in so that the class functions work
|
||||||
|
for id, org in ipairs(modpol.orgs.array) do
|
||||||
|
setmetatable(org, modpol.orgs)
|
||||||
|
end
|
||||||
|
|
||||||
|
local nn = modpol.ocutil.table_length (modpol.orgs.array)
|
||||||
local str = "entries"
|
local str = "entries"
|
||||||
if nn == 1 then str = "entry" end
|
if nn == 1 then str = "entry" end
|
||||||
modpol.ocutil.log (nn .. " orgs loaded from disk")
|
modpol.ocutil.log (nn .. " orgs loaded from disk")
|
||||||
@ -152,7 +157,7 @@ end
|
|||||||
modpol.load_storage = function()
|
modpol.load_storage = function()
|
||||||
load_ledger()
|
load_ledger()
|
||||||
load_orgs()
|
load_orgs()
|
||||||
load_old_ledgers()
|
-- load_old_ledgers()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ===================================================================
|
-- ===================================================================
|
||||||
|
@ -36,21 +36,17 @@ local function formspec_list(array)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- MAIN MODPOL DASHBOARD
|
-- DASHBOARDS
|
||||||
-- =====================
|
-- ==========
|
||||||
|
|
||||||
-- Function: modpol.interactions.dashboard(user)
|
-- Function: modpol.interactions.dashboard(user)
|
||||||
-- Params: user (string)
|
-- Params: user (string)
|
||||||
-- Q: Should this return a menu of commands relevant to the specific user?
|
-- Q: Should this return a menu of commands relevant to the specific user?
|
||||||
-- Output: Displays a menu of commands to the user
|
-- Output: Displays a menu of commands to the user
|
||||||
-- TKTK currently a manually curated list---needs major improvement
|
-- TODO currently a manually curated list---needs major improvement
|
||||||
function modpol.interactions.dashboard(user)
|
function modpol.interactions.dashboard(user)
|
||||||
-- prepare data
|
-- prepare data
|
||||||
-- to add: my orgs, nested orgs map
|
-- to add: nested orgs map
|
||||||
local commands = "Command list: "
|
|
||||||
for key,value in pairs(command_list) do
|
|
||||||
commands = commands .. "/" .. value .. " "
|
|
||||||
end
|
|
||||||
local all_orgs = modpol.orgs.list_all()
|
local all_orgs = modpol.orgs.list_all()
|
||||||
local user_orgs = modpol.orgs.user_orgs(user)
|
local user_orgs = modpol.orgs.user_orgs(user)
|
||||||
local all_users = modpol.list_users()
|
local all_users = modpol.list_users()
|
||||||
@ -60,13 +56,13 @@ function modpol.interactions.dashboard(user)
|
|||||||
"size[10,8]",
|
"size[10,8]",
|
||||||
"label[0.5,0.5;MODULAR POLITICS]",
|
"label[0.5,0.5;MODULAR POLITICS]",
|
||||||
"label[0.5,2;All orgs:]",
|
"label[0.5,2;All orgs:]",
|
||||||
"dropdown[2,1.5;5,0.8;user_orgs;"..formspec_list(all_orgs)..";;]",
|
"dropdown[2,1.5;5,0.8;all_orgs;"..formspec_list(all_orgs)..";;]",
|
||||||
"label[0.5,3;Your orgs:]",
|
"label[0.5,3;Your orgs:]",
|
||||||
"dropdown[2,2.5;5,0.8;input;"..formspec_list(user_orgs)..";;]",
|
"dropdown[2,2.5;5,0.8;user_orgs;"..formspec_list(user_orgs)..";;]",
|
||||||
"label[0.5,4;All users:]",
|
"label[0.5,4;All users:]",
|
||||||
"dropdown[2,3.5;5,0.8;input;"..formspec_list(all_users)..";;]",
|
"dropdown[2,3.5;5,0.8;all_users;"..formspec_list(all_users)..";;]",
|
||||||
"label[0.5,5;Processes:]",
|
"label[0.5,5;Processes:]",
|
||||||
"dropdown[2,4.5;5,0.8;input;TBA;;]",
|
"dropdown[2,4.5;5,0.8;processes;TBA;;]",
|
||||||
"button[0.5,7;1,0.8;test_poll;Test poll]",
|
"button[0.5,7;1,0.8;test_poll;Test poll]",
|
||||||
"button[2,7;1,0.8;add_org;Add org]",
|
"button[2,7;1,0.8;add_org;Add org]",
|
||||||
"button[3.5,7;1.5,0.8;remove_org;Remove org]",
|
"button[3.5,7;1.5,0.8;remove_org;Remove org]",
|
||||||
@ -91,6 +87,56 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
end)
|
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)
|
||||||
|
-- prepare data
|
||||||
|
local org = modpol.orgs.get_org(org_name)
|
||||||
|
if not org then return nil end
|
||||||
|
-- set player context
|
||||||
|
_contexts[user][current_org] = org
|
||||||
|
-- set up formspec
|
||||||
|
local formspec = {
|
||||||
|
"formspec_version[4]",
|
||||||
|
"size[10,8]",
|
||||||
|
"label[0.5,0.5;Org: "..
|
||||||
|
minetest.formspec_escape(org_name).."]",
|
||||||
|
"label[0.5,2;Members:]",
|
||||||
|
"dropdown[2,1.5;5,0.8;user_orgs;"..formspec_list(org.members)..";;]",
|
||||||
|
"label[0.5,3;Children:]",
|
||||||
|
"dropdown[2,2.5;5,0.8;children;"..formspec_list(org.children)..";;]",
|
||||||
|
"label[0.5,4;Policies:]",
|
||||||
|
"dropdown[2,3.5;5,0.8;policies;"..formspec_list(org.policies)..";;]",
|
||||||
|
"label[0.5,5;Processes:]",
|
||||||
|
"dropdown[2,4.5;5,0.8;processes;"..formspec_list(org.processes)..";;]",
|
||||||
|
"button[0.5,7;1,0.8;test_poll;Test poll]",
|
||||||
|
"button[2,7;1,0.8;add_org;Add child]",
|
||||||
|
"button[3.5,7;1.5,0.8;remove_org;Remove org]",
|
||||||
|
"button[8.5,7;1,0.8;back;Back]",
|
||||||
|
}
|
||||||
|
local formspec_string = table.concat(formspec, "")
|
||||||
|
-- present to player
|
||||||
|
minetest.show_formspec(user, "modpol:org_dashboard", formspec_string)
|
||||||
|
end
|
||||||
|
-- receive input
|
||||||
|
minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||||
|
if formname == "modpol:org_dashboard" then
|
||||||
|
local pname = player:get_player_name()
|
||||||
|
if fields.test_poll then
|
||||||
|
modpol.interactions.binary_poll_org(pname, _contexts.pname.current_org.id, "Poll question (yes/no):")
|
||||||
|
elseif fields.add_org then
|
||||||
|
modpol.interactions.add_org(pname, _contexts.pname.current_org.id)
|
||||||
|
elseif fields.remove_org then
|
||||||
|
modpol.interactions.remove_org(pname)
|
||||||
|
elseif fields.back then
|
||||||
|
modpol.interactions.dashboard(pname)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- BASIC INTERACTION FUNCTIONS
|
-- BASIC INTERACTION FUNCTIONS
|
||||||
-- ===========================
|
-- ===========================
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user