Implemented binary_poll_user and /pollself
This commit is contained in:
parent
e581b6a84f
commit
c8ca1d3d51
@ -1,6 +1,6 @@
|
||||
# modpol: Modular Politics for Minetest
|
||||
|
||||
A mod for [Minetest](https://minetest.net) that provides an API for diverse governance mechanisms according to the [Modular Politics](https://metagov.org/modpol) specification. Built in collaboration with the Minetest community—see the initial [forum post](https://forum.minetest.net/viewtopic.php?f=47&t=26037)!
|
||||
This is a mod for [Minetest](https://minetest.net) that provides an API for diverse governance mechanisms. It seeks to implement the [Modular Politics](https://metagov.org/modpol) proposal.
|
||||
|
||||
This mod produces an API that can serve as a dependency for other mods that add specific governance functionalities.
|
||||
|
||||
@ -16,7 +16,8 @@ Most of these commands will later be buried under other commands that do more pr
|
||||
* `/listplayers` - Lists all the players currently in the game
|
||||
* `/joinorg [orgname]` - Adds the user to the specified org
|
||||
* `/listmembers [orgname]` - Lists the players currently in the specified org
|
||||
* `/pollself [question]` - Asks the player a yes/no/abstain question
|
||||
|
||||
---
|
||||
|
||||
Initiated by [Nathan Schneider](https://nathanschneider.info) of the [Media Enterprise Design Lab](https://colorado.edu/lab/medlab) at the University of Colorado Boulder, as part of the [Metagovernance Project](https://metagov.org). Reach out if you'd like to contribute!
|
||||
Initiated by [Nathan Schneider](https://nathanschneider.info) of the [Media Enterprise Design Lab](https://colorado.edu/lab/medlab) at the University of Colorado Boulder, as part of the [Metagovernance Project](https://metagov.org), in collaboration with the Minetest community—see the initial [forum post](https://forum.minetest.net/viewtopic.php?f=47&t=26037). Contributions welcome.
|
||||
|
57
init.lua
57
init.lua
@ -217,13 +217,62 @@ function modpol.remove_privilege(org, privilege)
|
||||
-- remove privilege from all members of an org, unless they have it from other orgs
|
||||
end
|
||||
|
||||
-- POLLING FUNCTIONS
|
||||
--[[ USER INTERACTIONS ]]--
|
||||
|
||||
function modpol.poll_org(org, question)
|
||||
-- create formspec for all org members
|
||||
-- return their answers
|
||||
-- modpol.binary_poll_user(user, question)
|
||||
-- presents a yes/no/abstain poll to a user, returns answer
|
||||
function modpol.binary_poll_user(user, question)
|
||||
-- set up formspec
|
||||
local text = "Poll: " .. question
|
||||
local formspec = {
|
||||
"formspec_version[4]",
|
||||
"size[5,3]",
|
||||
"label[0.375,0.5;", minetest.formspec_escape(text), "]",
|
||||
"button[1,1.5;1,0.8;yes;Yes]",
|
||||
"button[2,1.5;1,0.8;no;No]",
|
||||
"button[3,1.5;1,0.8;abstain;Abstain]"
|
||||
--TKTK can we enable text wrapping?
|
||||
}
|
||||
local formspec_string = table.concat(formspec, "")
|
||||
-- present to player
|
||||
minetest.show_formspec(user, "modpol:binary_poll", formspec_string)
|
||||
end
|
||||
|
||||
-- Receiving fields
|
||||
minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
-- modpol:poll
|
||||
if formname == "modpol:binary_poll" then
|
||||
local pname = player:get_player_name()
|
||||
local vote = nil
|
||||
if fields.yes then vote = fields.yes
|
||||
elseif fields.no then vote = fields.no
|
||||
elseif fields.abstain then vote = fields.abstain
|
||||
end
|
||||
if vote then
|
||||
minetest.chat_send_all(pname .. " voted " .. vote)
|
||||
end
|
||||
minetest.close_formspec(pname, formname)
|
||||
return vote
|
||||
else -- if the form is not a recognized name
|
||||
return
|
||||
end
|
||||
end)
|
||||
|
||||
-- /pollself [question]
|
||||
-- asks the user a question
|
||||
minetest.register_chatcommand(
|
||||
"pollself", {
|
||||
privs = {},
|
||||
func = function(user, param)
|
||||
modpol.binary_poll_user(user, param)
|
||||
return true, result
|
||||
end,
|
||||
})
|
||||
|
||||
--[[ TKTK need to enable more complex ineractions
|
||||
- checkboxes, radio
|
||||
- write-in
|
||||
]]--
|
||||
|
||||
-- MESSAGE FUNCTIONS
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user