mirror of
https://github.com/Splizard/minetest-mod-snow.git
synced 2025-06-30 23:30:22 +02:00
some code updates
This commit is contained in:
47
src/util.lua
47
src/util.lua
@ -79,7 +79,9 @@ end
|
||||
|
||||
for i,v in pairs(snow) do
|
||||
local t = type(v)
|
||||
if t == "string" or t == "number" or t == "boolean" then
|
||||
if t == "string"
|
||||
or t == "number"
|
||||
or t == "boolean" then
|
||||
local v = minetest.setting_get("snow_"..i)
|
||||
if v ~= nil then
|
||||
if v == "true" then v = true end
|
||||
@ -99,7 +101,8 @@ if minetest.register_on_mapgen_init then
|
||||
else
|
||||
snow.legacy = true
|
||||
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)
|
||||
end
|
||||
|
||||
@ -110,7 +113,8 @@ local get_formspec = function()
|
||||
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
|
||||
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
|
||||
@ -124,22 +128,27 @@ local get_formspec = function()
|
||||
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]
|
||||
if formname ~= "snow:menu" then
|
||||
return
|
||||
end
|
||||
for i,v in pairs(snow) do
|
||||
local t = type(v)
|
||||
if t == "string" or t == "number" or t == "boolean" then
|
||||
local field = fields["snow:"..i]
|
||||
if field then
|
||||
if t == "string" then
|
||||
snow[i] = field
|
||||
end
|
||||
if t == "number" then
|
||||
snow[i] = tonumber(field)
|
||||
end
|
||||
if t == "boolean" then
|
||||
if field == "true" then
|
||||
snow[i] = true
|
||||
elseif field == "false" then
|
||||
snow[i] = false
|
||||
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
|
||||
@ -149,7 +158,7 @@ end)
|
||||
minetest.register_chatcommand("snow", {
|
||||
description = "Show a menu for various actions",
|
||||
privs = {server=true},
|
||||
func = function(name, param)
|
||||
func = function(name)
|
||||
minetest.show_formspec(name, "snow:menu", get_formspec())
|
||||
end,
|
||||
})
|
||||
|
Reference in New Issue
Block a user