A bunch of module bugfixes
This commit is contained in:
@ -15,31 +15,30 @@ priv_to_org.config = {
|
||||
}
|
||||
|
||||
--- (Required): initiate function
|
||||
-- Modules have access to the following instance variables:
|
||||
-- <li><code>self.org</code> (the org the module was called in),</li>
|
||||
-- <li><code>self.initiator</code> (the user that callced the module),</li>
|
||||
-- <li><code>self.id</code> (the process id of the module instance)</li>
|
||||
-- @param config (optional) If user wants to override fields in the config table
|
||||
-- @param result (optional) Callback if this module is embedded in other modules
|
||||
-- @function initiate
|
||||
function priv_to_org:initiate(config, result)
|
||||
function priv_to_org:initiate(result)
|
||||
local player_privs = minetest.get_player_privs(self.initiator)
|
||||
for i,v in ipairs(player_privs) do
|
||||
if not v then table.remove(player_privs,i) end
|
||||
-- construct table for display
|
||||
local player_privs_table = {"View..."}
|
||||
for k,v in pairs(player_privs) do
|
||||
if player_privs[k] then
|
||||
table.insert(player_privs_table,k)
|
||||
end
|
||||
end
|
||||
modpol.interactions.dropdown_query(
|
||||
self.initiator,
|
||||
"Which privilege do you want to share with members of "..self.org.name.."?",
|
||||
player_privs,
|
||||
player_privs_table,
|
||||
function(input)
|
||||
for member in self.org.members do
|
||||
local member_privs = minetest.get_player_privs(member.name)
|
||||
for i,member in ipairs(self.org.members) do
|
||||
local member_privs = minetest.get_player_privs(member)
|
||||
member_privs[input] = true
|
||||
minetest.set_player_privs(member.name, member_privs)
|
||||
minetest.set_player_privs(member, member_privs)
|
||||
end
|
||||
local message = self.initiator .. " has set " .. input ..
|
||||
local message = self.initiator .. " added " .. input ..
|
||||
" privilege to all members of " .. self.org.name
|
||||
modpol.interactions.message_org(self.initiator,self.org.id, message)
|
||||
modpol.interactions.message_org(self.initiator, self.org.id, message)
|
||||
end)
|
||||
-- call result function
|
||||
if result then result() end
|
||||
|
@ -223,8 +223,16 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
elseif fields.modules
|
||||
and fields.modules ~= "View..." then
|
||||
local module = fields.modules
|
||||
org:call_module(module, pname)
|
||||
modpol.interactions.org_dashboard(pname,org.name)
|
||||
modpol.interactions.binary_poll_user(
|
||||
pname,
|
||||
modpol.modules[module].name.."\n"..
|
||||
modpol.modules[module].desc.."\n"..
|
||||
"Proceed?",
|
||||
function(input)
|
||||
if input == "Yes" then
|
||||
org:call_module(module, pname)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Receiving actions
|
||||
elseif fields.actions
|
||||
@ -258,14 +266,16 @@ function modpol.interactions.policy_dashboard(
|
||||
end
|
||||
|
||||
|
||||
-- BASIC INTERACTION FUNCTIONS
|
||||
-- ===========================
|
||||
-- INTERACTION FUNCTIONS
|
||||
-- =====================
|
||||
|
||||
-- Function: modpol.interactions.message
|
||||
-- input: user (string), message (string)
|
||||
-- output: displays message to specified user
|
||||
function modpol.interactions.message(user, message)
|
||||
minetest.chat_send_player(user, message)
|
||||
if message then
|
||||
minetest.chat_send_player(user, message)
|
||||
end
|
||||
end
|
||||
|
||||
-- Function: modpol.interactions.text_query
|
||||
@ -331,11 +341,13 @@ end
|
||||
minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
if formname == "modpol:dropdown_query" then
|
||||
local pname = player:get_player_name()
|
||||
if fields.cancel ~= "cancel" then
|
||||
if fields.cancel == "cancel" then
|
||||
-- cancel, do nothing
|
||||
else
|
||||
local choice = fields.input
|
||||
local func = _contexts[pname]["dropdown_query_func"]
|
||||
if not choice then
|
||||
-- no choice, do nothing
|
||||
-- empty, do nothing
|
||||
elseif func then
|
||||
func(choice)
|
||||
else
|
||||
@ -355,10 +367,10 @@ function modpol.interactions.binary_poll_user(user, question, func)
|
||||
-- set up formspec
|
||||
local formspec = {
|
||||
"formspec_version[4]",
|
||||
"size[5,3]",
|
||||
"size[8,4]",
|
||||
"label[0.375,0.5;",minetest.formspec_escape(question), "]",
|
||||
"button[1,1.5;1,0.8;yes;Yes]",
|
||||
"button[2,1.5;1,0.8;no;No]",
|
||||
"button[1,2.5;1,0.8;yes;Yes]",
|
||||
"button[2,2.5;1,0.8;no;No]",
|
||||
--TODO can we enable text wrapping?
|
||||
--TODO we could use scroll boxes to contain the text
|
||||
}
|
||||
@ -377,7 +389,6 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
elseif fields.no then vote = fields.no
|
||||
end
|
||||
if vote then
|
||||
modpol.interactions.message(pname, "Responded " .. vote)
|
||||
local func = _contexts[pname]["binary_poll_func"]
|
||||
if func then func(vote) end
|
||||
end
|
||||
|
Reference in New Issue
Block a user