first pass of new process system
This commit is contained in:
parent
f381845d21
commit
1d45dc38b0
@ -5,12 +5,13 @@ JoinOrg = {}
|
|||||||
JoinOrg_mt = { __index = JoinOrg }
|
JoinOrg_mt = { __index = JoinOrg }
|
||||||
|
|
||||||
|
|
||||||
function JoinOrg.create(initiator, org)
|
function JoinOrg.create(initiator, org, id)
|
||||||
local inst = {
|
local inst = {
|
||||||
name = "Join an org",
|
name = "Join an org",
|
||||||
desc = "Initiator chooses an org to become a member of. Nothing happens if they are already in an org.",
|
desc = "Initiator chooses an org to become a member of. Nothing happens if they are already in an org.",
|
||||||
initiator = initiator,
|
initiator = initiator,
|
||||||
org = org
|
org = org,
|
||||||
|
id = id
|
||||||
}
|
}
|
||||||
setmetatable(inst, JoinOrg_mt)
|
setmetatable(inst, JoinOrg_mt)
|
||||||
return inst
|
return inst
|
||||||
@ -71,6 +72,7 @@ end
|
|||||||
|
|
||||||
function JoinOrg:on_success()
|
function JoinOrg:on_success()
|
||||||
self.org:add_member(self.initiator)
|
self.org:add_member(self.initiator)
|
||||||
|
self.org:delete_process(self.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ===================================
|
-- ===================================
|
||||||
|
@ -4,30 +4,72 @@ function modpol.orgs:call_module(module_name, initiator)
|
|||||||
return
|
return
|
||||||
end
|
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 module = modpol.modules[module_name]
|
local module = modpol.modules[module_name]
|
||||||
local new_process = module.create(initiator, self)
|
local new_process = module.create(initiator, self, index)
|
||||||
|
|
||||||
table.insert(self.processes, new_process)
|
self.processes[index] = new_process
|
||||||
|
|
||||||
return new_process
|
return index
|
||||||
end
|
end
|
||||||
|
|
||||||
function modpol.orgs:create_process()
|
function modpol.orgs:delete_process(id)
|
||||||
|
self.processes[id] = 'deleted'
|
||||||
end
|
end
|
||||||
|
|
||||||
function modpol.orgs:add_pending_action()
|
function modpol.orgs:add_pending_action(process_id, user, callback)
|
||||||
|
self.pending[user] = self.pending[user] or {}
|
||||||
|
self.pending[user][process_id] = callback
|
||||||
end
|
end
|
||||||
|
|
||||||
function mopdol.orgs:remove_pending_action()
|
function mopdol.orgs:remove_pending_action(process_id, user)
|
||||||
|
if self.pending[user] then
|
||||||
|
self.pending[user][process_id] = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function modpol.orgs:wipe_pending_actions()
|
function modpol.orgs:wipe_pending_actions(process_id)
|
||||||
|
for user in pairs(self.pending) do
|
||||||
|
self.pending[user][process_id] = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function modpol.orgs:has_pending_actions()
|
function modpol.orgs:has_pending_actions()
|
||||||
|
-- next() will return the next pair in a table
|
||||||
|
-- if next() returns nil, the table is empty
|
||||||
|
if not self.pending[user] then
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
if not next(self.pending[user]) then
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
process[callback](process)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
x
Reference in New Issue
Block a user