Began dashboard formspec in Minetest

This commit is contained in:
Nathan Schneider 2021-04-17 09:40:23 -06:00
parent 6bc5f4077e
commit a6cd6ebcfe
2 changed files with 31 additions and 10 deletions

View File

@ -21,8 +21,7 @@ regchat(
"dashboard", { "dashboard", {
privs = {}, privs = {},
func = function(user) func = function(user)
local result = modpol.dashboard(user) modpol.dashboard(user)
return true, result
end, end,
}) })

View File

@ -6,11 +6,27 @@
-- 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 -- TKTK currently a manually curated list---needs major improvement
modpol.dashboard = function(user) modpol.dashboard = function(user)
local output = "Command list:" -- prepare data
-- to add: my orgs, nested orgs map
local commands = "Command list: "
for key,value in pairs(command_list) do for key,value in pairs(command_list) do
output = output .. "/" .. value .. " " commands = commands .. "/" .. value .. " "
end end
return output local orgs = "Orgs: " .. modpol.orgs.list_all()
local users = "Players: "
.. table.concat(modpol.list_users(), ", ")
-- set up formspec
local formspec = {
"formspec_version[4]",
"size[10,8]",
"label[0.5,0.5;", minetest.formspec_escape(commands), "]",
"label[0.5,1.5;", minetest.formspec_escape(orgs), "]",
"label[0.5,2.5;", minetest.formspec_escape(users), "]",
"button[0.5,7;1,0.8;yes;Done]",
}
local formspec_string = table.concat(formspec, "")
-- present to player
minetest.show_formspec(user, "modpol:dashboard", formspec_string)
end end
-- =================================================================== -- ===================================================================
@ -33,11 +49,17 @@ modpol.binary_poll_user = function(user, question)
local formspec_string = table.concat(formspec, "") local formspec_string = table.concat(formspec, "")
-- present to player -- present to player
minetest.show_formspec(user, "modpol:binary_poll", formspec_string) minetest.show_formspec(user, "modpol:binary_poll", formspec_string)
end end
--what to do -- ===================================================================
minetest.register_on_player_receive_fields(function (player, formname, fields) -- Register input fields from forms
-- modpol:poll -- Minetest-specific; does not overwrite
-- separate this out into discrete functions?
-- how do we ensure this is maximally modular?
-- Perhaps create a table of possible formnames and their associated functions
-- Then we can easily add to the table of possible options
minetest.register_on_player_receive_fields(function (player, formname, fields)
-- modpol:binary_poll
if formname == "modpol:binary_poll" then if formname == "modpol:binary_poll" then
local pname = player:get_player_name() local pname = player:get_player_name()
local vote = nil local vote = nil