mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-29 05:51:05 +01:00
Change API so most parameters are in a definition table, add /gamerule chatcommand, implement gamerule announceAdvancements
This commit is contained in:
parent
ee2c878160
commit
387101fc8e
2 changed files with 62 additions and 27 deletions
|
@ -4,7 +4,7 @@ local storage = minetest.get_mod_storage()
|
||||||
local mod = {}
|
local mod = {}
|
||||||
vl_tuning = mod
|
vl_tuning = mod
|
||||||
|
|
||||||
--
|
-- All registered tunable parameters
|
||||||
local tunables = {}
|
local tunables = {}
|
||||||
|
|
||||||
-- Supported variable types
|
-- Supported variable types
|
||||||
|
@ -45,29 +45,28 @@ function tunable_class:get_string()
|
||||||
return self.type.to_string(self[1])
|
return self.type.to_string(self[1])
|
||||||
end
|
end
|
||||||
|
|
||||||
function mod.get_server_setting(name, description, default, setting, setting_type, options )
|
function mod.setting(setting, setting_type, def )
|
||||||
local tunable = tunables[name]
|
-- return the existing setting if it was previously registered. Don't update the definition
|
||||||
|
local tunable = tunables[setting]
|
||||||
if tunable then return tunable end
|
if tunable then return tunable end
|
||||||
|
|
||||||
tunable = {
|
-- Setup the tunable data
|
||||||
name = name,
|
tunable = table.copy(def)
|
||||||
default = default,
|
tunable.setting = setting
|
||||||
setting = setting,
|
tunable.type = tunable_types[setting_type]
|
||||||
description = description,
|
tunable[1] = tunable.default
|
||||||
type = tunable_types[setting_type],
|
|
||||||
options = options,
|
|
||||||
}
|
|
||||||
tunable[1] = default
|
|
||||||
print(dump(tunable))
|
|
||||||
setmetatable(tunable, {__index=tunable_class})
|
setmetatable(tunable, {__index=tunable_class})
|
||||||
if setting then
|
|
||||||
|
-- Load the setting value from mod storage
|
||||||
local setting_value = storage:get_string(setting)
|
local setting_value = storage:get_string(setting)
|
||||||
if setting_value and setting_value ~= "" then
|
if setting_value and setting_value ~= "" then
|
||||||
tunable:set(setting_value)
|
tunable:set(setting_value)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
print(dump(tunable))
|
-- Add to the list of all available settings
|
||||||
tunables[name] = tunable
|
tunables[setting] = tunable
|
||||||
|
|
||||||
|
-- Provide it so that the current value in [1] can be accessed without having to call into this API again
|
||||||
return tunable
|
return tunable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -87,13 +86,13 @@ minetest.register_chatcommand("set_setting", {
|
||||||
end
|
end
|
||||||
|
|
||||||
local tunable = tunables[params[1]]
|
local tunable = tunables[params[1]]
|
||||||
if tunable then
|
if not tunable then
|
||||||
|
return false, S("Setting @1 doesn't exist", params[1])
|
||||||
|
end
|
||||||
|
|
||||||
minetest.log("action", "[vl_tuning] "..name.." set ".. params[1] .." to "..params[2])
|
minetest.log("action", "[vl_tuning] "..name.." set ".. params[1] .." to "..params[2])
|
||||||
tunable:set(params[2])
|
tunable:set(params[2])
|
||||||
return true
|
return true
|
||||||
else
|
|
||||||
return false, S("Setting @1 doesn't exist", params[1])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
minetest.register_chatcommand("get_setting", {
|
minetest.register_chatcommand("get_setting", {
|
||||||
|
@ -110,3 +109,34 @@ minetest.register_chatcommand("get_setting", {
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_chatcommand("gamerule", {
|
||||||
|
description = S("Display or set customizable options"),
|
||||||
|
params = S("<rule> [<value>]"),
|
||||||
|
privs = { server = true },
|
||||||
|
func = function(name, params_raw)
|
||||||
|
-- Split apart the params
|
||||||
|
local params = {}
|
||||||
|
for str in string.gmatch(params_raw, "([^ ]+)") do
|
||||||
|
params[#params + 1] = str
|
||||||
|
end
|
||||||
|
|
||||||
|
if #params < 1 or #params > 2 then
|
||||||
|
return false, S("Usage: /gamerule <rule> [<value>]")
|
||||||
|
end
|
||||||
|
|
||||||
|
local tunable = tunables["gamerule:"..params[1]]
|
||||||
|
if not tunable then
|
||||||
|
return false, S("Game rule @1 doesn't exist", params[1])
|
||||||
|
end
|
||||||
|
|
||||||
|
local value = params[2]
|
||||||
|
if value then
|
||||||
|
minetest.log("action", "[vl_tuning] Setting game rule "..params[1].." to "..params[2])
|
||||||
|
tunable:set(params[2])
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return true, tunable:get_string()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,12 @@ local modpath = minetest.get_modpath(modname)
|
||||||
local S = minetest.get_translator(modname)
|
local S = minetest.get_translator(modname)
|
||||||
|
|
||||||
-- Tunable parameters
|
-- Tunable parameters
|
||||||
local notif_delay = vl_tuning.get_server_setting("award_display_time", S("Amount of time award notification are displayed"), 3, "awards_notif_delay", "number", { min = 2, max = 10 })
|
local notif_delay = vl_tuning.setting("award_display_time", "number", {
|
||||||
|
description = S("Amount of time award notification are displayed"), default = 3, min = 2, max = 10
|
||||||
|
})
|
||||||
|
local announce_in_chat = vl_tuning.setting("gamerule:announceAdvancements", "bool", {
|
||||||
|
description = S("Whether advancements should be announced in chat"), default = true,
|
||||||
|
})
|
||||||
|
|
||||||
-- The global award namespace
|
-- The global award namespace
|
||||||
awards = {
|
awards = {
|
||||||
|
@ -220,7 +225,7 @@ function awards.unlock(name, award)
|
||||||
|
|
||||||
-- Get award
|
-- Get award
|
||||||
minetest.log("action", name.." has gotten award "..award)
|
minetest.log("action", name.." has gotten award "..award)
|
||||||
if minetest.settings:get_bool("mcl_showAdvancementMessages", true) then
|
if minetest.settings:get_bool("mcl_showAdvancementMessages", true) or announce_in_chat[1] then
|
||||||
minetest.chat_send_all(S("@1 has made the advancement @2", name, minetest.colorize(mcl_colors.GREEN, "[" .. (awdef.title or award) .. "]")))
|
minetest.chat_send_all(S("@1 has made the advancement @2", name, minetest.colorize(mcl_colors.GREEN, "[" .. (awdef.title or award) .. "]")))
|
||||||
end
|
end
|
||||||
data.unlocked[award] = award
|
data.unlocked[award] = award
|
||||||
|
|
Loading…
Reference in a new issue