master
BuckarooBanzay 2019-10-11 10:25:36 +02:00
parent 27619c529c
commit cf7088ba9a
3 changed files with 21 additions and 17 deletions

View File

@ -1,18 +1,4 @@
local weatherdefs = {} -- list<weatherdef>
--[[
weatherdef = {
name = "",
on_step = function() end
}
--]]
epic_weather.register_weather = function(def)
table.insert(weatherdefs, def)
end
epic_weather.register_weather({ name = "None" })
local update_formspec = function(meta)
@ -22,13 +8,13 @@ local update_formspec = function(meta)
local selected = 1
local list = ""
for i, def in ipairs(weatherdefs) do
for i, def in ipairs(epic_weather.weatherdefs) do
if def.name == weathername then
selected = i
end
list = list .. minetest.formspec_escape(def.name)
if i < #weatherdefs then
if i < #epic_weather.weatherdefs then
-- not end of list
list = list .. ","
end
@ -73,7 +59,7 @@ minetest.register_node("epic:set_weather", {
local parts = fields.weathername:split(":")
if parts[1] == "CHG" then
local selected_def = tonumber(parts[2])
local weatherdef = weatherdefs[selected_def]
local weatherdef = epic_weather.weatherdefs[selected_def]
if weatherdef and weatherdef.name then
meta:set_string("weathername", weatherdef.name)
end

View File

@ -3,6 +3,7 @@ local MP = minetest.get_modpath("epic_weather")
epic_weather = {}
dofile(MP.."/register.lua")
dofile(MP.."/block.lua")
dofile(MP.."/weather.lua")

17
register.lua Normal file
View File

@ -0,0 +1,17 @@
epic_weather.weatherdefs = {} -- list<weatherdef>
--[[
weatherdef = {
name = "",
on_step = function() end
}
--]]
epic_weather.register_weather = function(def)
table.insert(epic_weather.weatherdefs, def)
end
epic_weather.register_weather({ name = "None" })