Resolved merge conflicts with master
This commit is contained in:
@ -76,6 +76,8 @@ end
|
||||
--- Deletes all orgs except for the
|
||||
-- @function modpol.orgs.reset
|
||||
function modpol.orgs.reset()
|
||||
local instance_members =
|
||||
modpol.util.copy_table(modpol.instance.members)
|
||||
for id, org in ipairs(modpol.orgs.array) do
|
||||
if id > 1 then
|
||||
modpol.orgs.array[id] = "removed"
|
||||
@ -84,9 +86,9 @@ function modpol.orgs.reset()
|
||||
|
||||
modpol.orgs.array[1] = nil
|
||||
modpol.instance = modpol.orgs.init_instance()
|
||||
|
||||
modpol.instance.members = instance_members
|
||||
|
||||
modpol.ocutil.log('Reset all orgs')
|
||||
modpol.ocutil.log('All orgs reset')
|
||||
modpol.orgs:record('Resetting all orgs', 'org_reset')
|
||||
end
|
||||
|
||||
|
@ -7,33 +7,18 @@
|
||||
-- @param intiator Initiator for module
|
||||
-- @param config Config for module
|
||||
-- @param result
|
||||
function modpol.orgs:call_module(module_slug, initiator, config, result)
|
||||
function modpol.orgs:call_module(module_slug, initiator, config, result, parent_id)
|
||||
if not modpol.modules[module_slug] then
|
||||
modpol.ocutil.log('Error in ' .. self.name .. ':call_module -> module "' .. module_slug .. '" not found')
|
||||
return
|
||||
end
|
||||
|
||||
local empty_index = nil
|
||||
-- linear search for empty process slots (lazy deletion)
|
||||
for k, v in ipairs(self.processes) do
|
||||
if v == 'deleted' then
|
||||
empty_index = k
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
local index
|
||||
-- attempts to fill empty spots in list, otherwise appends to end
|
||||
if empty_index then
|
||||
index = empty_index
|
||||
else
|
||||
index = #self.processes + 1
|
||||
end
|
||||
local index = #self.processes + 1
|
||||
|
||||
local module = modpol.modules[module_slug]
|
||||
|
||||
-- sets default values for undeclared config variables
|
||||
if #module.config > 0 then
|
||||
if modpol.util.num_pairs(module.config) > 0 and config then
|
||||
for k, v in pairs(module.config) do
|
||||
if config[k] == nil then
|
||||
config[k] = v
|
||||
@ -47,24 +32,61 @@ function modpol.orgs:call_module(module_slug, initiator, config, result)
|
||||
initiator = initiator,
|
||||
org = self,
|
||||
id = index,
|
||||
parent_id = parent_id,
|
||||
children = {},
|
||||
config = config,
|
||||
data = module.data,
|
||||
data = modpol.util.copy_table(module.data),
|
||||
slug = module_slug
|
||||
}
|
||||
|
||||
-- call module wrapper for modules, passes its id to child process when called
|
||||
function new_process:call_module(module_slug, initiator, config, result)
|
||||
local child_id = self.org:call_module(module_slug, initiator, config, result, self.id)
|
||||
table.insert(self.children, child_id)
|
||||
end
|
||||
|
||||
setmetatable(new_process, new_process.metatable)
|
||||
|
||||
self.processes[index] = new_process
|
||||
self.processes[index]:initiate(result)
|
||||
local msg = "Initiating "..module_slug..
|
||||
" process id "..index.." in org "..self.name
|
||||
|
||||
return index
|
||||
end
|
||||
|
||||
--- Delete process by id
|
||||
-- @function modpol.orgs:delete_process
|
||||
-- @param id Id of process
|
||||
function modpol.orgs:delete_process(id)
|
||||
self.processes[id] = 'deleted'
|
||||
|
||||
function modpol.orgs:get_root_process(id)
|
||||
local process = self.processes[id]
|
||||
while (process.parent_id) do
|
||||
process = self.processes[process.parent_id]
|
||||
end
|
||||
return process
|
||||
end
|
||||
|
||||
function modpol.orgs:delete_process(id)
|
||||
local process = self.processes[id]
|
||||
if process and process ~= "deleted" then
|
||||
-- recursively deletes any children
|
||||
if #process.children > 0 then
|
||||
for i, child_id in pairs(process.children) do
|
||||
self:delete_process(child_id)
|
||||
end
|
||||
end
|
||||
local msg = "Deleting " .. self.processes[id].slug .. " process id "..id.." in org "..self.name
|
||||
modpol.ocutil.log(msg)
|
||||
self:record(msg, self.processes[id].slug)
|
||||
self:wipe_pending_actions(id)
|
||||
-- sets process to 'deleted' in process table
|
||||
self.processes[id] = 'deleted'
|
||||
end
|
||||
end
|
||||
|
||||
--- Delete process tree by id
|
||||
-- @function modpol.orgs:delete_process_tree
|
||||
-- @param id Id of process tree
|
||||
function modpol.orgs:delete_process_tree(id)
|
||||
self:delete_process(self:get_root_process(id).id)
|
||||
end
|
||||
|
||||
--- Add a new pending action
|
||||
@ -124,8 +146,15 @@ function modpol.orgs:interact(process_id, user)
|
||||
local process = self.processes[process_id]
|
||||
if self.pending[user] then
|
||||
local callback = self.pending[user][process_id]
|
||||
if callback then
|
||||
if callback and process ~= "deleted" then
|
||||
-- get data in case callback ends process
|
||||
local slug = self.processes[process_id].slug
|
||||
-- run callback
|
||||
process[callback](process, user)
|
||||
-- record org data
|
||||
local msg = "Updating "..slug..
|
||||
" process id "..process_id.." in org "..self.name
|
||||
self:record(msg, slug)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
27
modpol_core/orgs/users.lua
Normal file
27
modpol_core/orgs/users.lua
Normal file
@ -0,0 +1,27 @@
|
||||
-- /users.lua
|
||||
-- User-related functions for Modular Politics
|
||||
|
||||
-- ===================================================================
|
||||
-- Function: modpol.list_users
|
||||
-- Params: org
|
||||
-- Outputs: Table of user names
|
||||
--
|
||||
-- This may be overwritten by the platform-specific interface
|
||||
|
||||
modpol.list_users = function(org)
|
||||
local users = {}
|
||||
if (org == nil) then -- no specified org; all players
|
||||
if modpol.orgs["instance"]
|
||||
and modpol.orgs["instance"]["members"] then
|
||||
-- if instance exists and has membership
|
||||
users = modpol.orgs["instance"]["members"]
|
||||
else
|
||||
users = {}
|
||||
end
|
||||
else -- if an org is specified
|
||||
if (modpol.orgs[org] ~= nil) then -- org exists
|
||||
users = modpol.orgs[org]["members"]
|
||||
end
|
||||
end
|
||||
return users
|
||||
end
|
Reference in New Issue
Block a user