Have basic checkbox_query working in CLI core interactions, not yet attempted in Minetest
This commit is contained in:
@@ -30,3 +30,6 @@ dofile (localdir .. "/modules/remove_process.lua")
|
|||||||
dofile (localdir .. "/modules/rename_org_consent.lua")
|
dofile (localdir .. "/modules/rename_org_consent.lua")
|
||||||
dofile (localdir .. "/modules/send_token.lua")
|
dofile (localdir .. "/modules/send_token.lua")
|
||||||
dofile (localdir .. "/modules/tokenomics.lua")
|
dofile (localdir .. "/modules/tokenomics.lua")
|
||||||
|
|
||||||
|
|
||||||
|
dofile (localdir .. "/modules/checkbox_test.lua")
|
||||||
|
@@ -341,7 +341,54 @@ function modpol.interactions.dropdown_query(user, label, options, func)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function: modpol.binary_poll_user(user, question)
|
--- Function: modpol.interactions.checkbox_query
|
||||||
|
-- Allows user to select from a set of options
|
||||||
|
-- @param user Name of user (string)
|
||||||
|
-- @param label Query for user before options (string)
|
||||||
|
-- @param options table of options and their checked status in the form {{"option_1_string", true}, {"option_2_string", false}}
|
||||||
|
-- @param func function to be called with param "input", made up of the corrected table in the same format as the param options
|
||||||
|
function modpol.interactions.checkbox_query(
|
||||||
|
user, label, options, func)
|
||||||
|
-- set up options
|
||||||
|
local options_display = ""
|
||||||
|
local options_number = 0
|
||||||
|
for i,v in ipairs(options) do
|
||||||
|
local checked = false
|
||||||
|
if v[2] then checked = true end
|
||||||
|
if checked then
|
||||||
|
checked = "x"
|
||||||
|
else
|
||||||
|
checked = " "
|
||||||
|
end
|
||||||
|
options_display = options_display..i..". ["..
|
||||||
|
checked.."] "..v[1].."\n"
|
||||||
|
options_number = options_number + 1
|
||||||
|
end
|
||||||
|
if options_number == 0 then
|
||||||
|
print("Error: No options given for dropdown")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
options_display = options_display..
|
||||||
|
"List numbers to check (e.g., 1,2,5):"
|
||||||
|
-- begin displaying
|
||||||
|
print(user .. ": " .. label)
|
||||||
|
print(options_display)
|
||||||
|
-- read input and produce output
|
||||||
|
local answer = io.read()
|
||||||
|
local answer_table = {}
|
||||||
|
for match in (answer..","):gmatch("(.-)"..",") do
|
||||||
|
table.insert(answer_table, tonumber(match))
|
||||||
|
end
|
||||||
|
local result_table = modpol.util.copy_table(options)
|
||||||
|
for i,v in ipairs(answer_table) do
|
||||||
|
-- flip the boolean on selected options
|
||||||
|
result_table[v][2] = not result_table[v][2]
|
||||||
|
end
|
||||||
|
func(result_table)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Function: modpol.interactions.binary_poll_user
|
||||||
-- Params: user (string), question (string), func (function)
|
-- Params: user (string), question (string), func (function)
|
||||||
-- func input: user input (string: y/n)
|
-- func input: user input (string: y/n)
|
||||||
-- Output: Applies "func" to user input
|
-- Output: Applies "func" to user input
|
||||||
|
Reference in New Issue
Block a user