mirror of
https://github.com/Splizard/minetest-mod-snow.git
synced 2024-12-29 16:00:16 +01:00
Config menu with "snow" command.
This commit is contained in:
parent
639bda9402
commit
b472de8132
52
util.lua
52
util.lua
@ -69,8 +69,10 @@ minetest.register_on_shutdown(function() saveConfig(minetest.get_modpath("snow")
|
|||||||
local config = loadConfig(minetest.get_modpath("snow").."/config.txt")
|
local config = loadConfig(minetest.get_modpath("snow").."/config.txt")
|
||||||
if config then
|
if config then
|
||||||
for i,v in pairs(config) do
|
for i,v in pairs(config) do
|
||||||
|
if type(snow[i]) == type(v) then
|
||||||
snow[i] = v
|
snow[i] = v
|
||||||
end
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc)
|
saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc)
|
||||||
end
|
end
|
||||||
@ -100,3 +102,53 @@ end
|
|||||||
if config and snow.legacy ~= config.legacy then
|
if config and snow.legacy ~= config.legacy then
|
||||||
saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc)
|
saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--MENU
|
||||||
|
|
||||||
|
local get_formspec = function()
|
||||||
|
local p = -0.5
|
||||||
|
local formspec = "label[0,-0.3;Settings:]"
|
||||||
|
for i,v in pairs(snow) do
|
||||||
|
local t = type(v)
|
||||||
|
if t == "string" or t == "number" then
|
||||||
|
p = p + 1.5
|
||||||
|
formspec = formspec.."field[0.3,"..p..";2,1;snow:"..i..";"..i..";"..v.."]"
|
||||||
|
elseif t == "boolean" then
|
||||||
|
p = p + 0.5
|
||||||
|
formspec = formspec.."checkbox[0,"..p..";snow:"..i..";"..i..";"..tostring(v).."]"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
p = p + 1
|
||||||
|
formspec = "size[4,"..p..";]\n"..formspec
|
||||||
|
return formspec
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
if formname == "snow:menu" then
|
||||||
|
for i,v in pairs(snow) do
|
||||||
|
local t = type(v)
|
||||||
|
if t == "string" or t == "number" or t == "boolean" then
|
||||||
|
if fields["snow:"..i] then
|
||||||
|
if t == "string" then
|
||||||
|
snow[i] = fields["snow:"..i]
|
||||||
|
end
|
||||||
|
if t == "number" then
|
||||||
|
snow[i] = tonumber(fields["snow:"..i])
|
||||||
|
end
|
||||||
|
if t == "boolean" then
|
||||||
|
if fields["snow:"..i] == "true" then snow[i] = true end
|
||||||
|
if fields["snow:"..i] == "false" then snow[i] = false end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_chatcommand("snow", {
|
||||||
|
description = "Show a menu for various actions",
|
||||||
|
func = function(name, param)
|
||||||
|
minetest.show_formspec(name, "snow:menu", get_formspec())
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user