block def

master
BuckarooBanzay 2019-10-11 10:21:57 +02:00
parent d2f0b2ebf0
commit 27619c529c
3 changed files with 99 additions and 1 deletions

View File

@ -1,4 +1,8 @@
globals = {
"epic_weather"
}
read_globals = {
-- Stdlib
string = {fields = {"split"}},
@ -10,5 +14,5 @@ read_globals = {
"dump", "VoxelArea",
-- deps
"epic"
"epic", "screwdriver"
}

View File

@ -0,0 +1,92 @@
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)
local weathername = meta:get_string("weathername")
meta:set_string("infotext", "Set weather block: name=" .. weathername)
local selected = 1
local list = ""
for i, def in ipairs(weatherdefs) do
if def.name == weathername then
selected = i
end
list = list .. minetest.formspec_escape(def.name)
if i < #weatherdefs then
-- not end of list
list = list .. ","
end
end
meta:set_string("formspec", "size[8,6;]" ..
"textlist[0,0.1;8,5;weathername;" .. list .. ";" .. selected .. "]" ..
"button_exit[0.1,5.5;8,1;save;Save]" ..
"")
end
minetest.register_node("epic:set_weather", {
description = "Epic set weather block",
tiles = {
"epic_node_bg.png",
"epic_node_bg.png",
"epic_node_bg.png",
"epic_node_bg.png",
"epic_node_bg.png",
"epic_node_bg.png^epic_sky.png",
},
paramtype2 = "facedir",
groups = {cracky=3,oddly_breakable_by_hand=3,epic=1},
on_rotate = screwdriver.rotate_simple,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("weathername", "None")
update_formspec(meta, pos)
end,
on_receive_fields = function(pos, _, fields, sender)
if not sender or minetest.is_protected(pos, sender:get_player_name()) then
-- not allowed
return
end
local meta = minetest.get_meta(pos);
if fields.weathername then
local parts = fields.weathername:split(":")
if parts[1] == "CHG" then
local selected_def = tonumber(parts[2])
local weatherdef = weatherdefs[selected_def]
if weatherdef and weatherdef.name then
meta:set_string("weathername", weatherdef.name)
end
update_formspec(meta, pos)
end
end
end,
epic = {
on_enter = function(_, meta, player, ctx)
--local weathername = meta:get_string("weathername")
-- TODO
ctx.next()
end
}
})

View File

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