init
This commit is contained in:
commit
53466eed17
18 changed files with 687 additions and 0 deletions
78
panel.lua
Normal file
78
panel.lua
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
-- 4. CONTROLLER (Das Panel)
|
||||
minetest.register_node("smart_light:controller", {
|
||||
description = "Smart Light Controller Panel",
|
||||
tiles = {
|
||||
"smart_light_panel_sides.png", "smart_light_panel_sides.png",
|
||||
"smart_light_panel_sides.png", "smart_light_panel_sides.png",
|
||||
"smart_light_panel_sides.png", "smart_light_panel_front_normal.png"
|
||||
},
|
||||
drawtype = "nodebox", paramtype = "light", paramtype2 = "facedir",
|
||||
groups = {cracky = 2, oddly_breakable_by_hand = 1},
|
||||
node_box = { type = "fixed", fixed = {{-0.5, -0.5, 0.4, 0.5, 0.5, 0.5}} },
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local area = meta:get_string("area_id")
|
||||
local name = clicker:get_player_name()
|
||||
|
||||
if area == "" then
|
||||
local fs = "size[5,3]field[0.8,1;4,1;area_id;Panel Area ID (z.B. Schule);]button_exit[1,2;3,1;set_area;Area festlegen]"
|
||||
minetest.show_formspec(name, "smart_light:setup_" .. minetest.pos_to_string(pos), fs)
|
||||
return
|
||||
end
|
||||
|
||||
local fs = "size[11,9]label[0.5,0.2;Zentrale: " .. area:upper() .. "]" ..
|
||||
"label[6,0.2;Global:]" ..
|
||||
"button[7,0;1.2,0.6;all_off;OFF]button[8.5,0;1.2,0.6;all_on;ON]"
|
||||
|
||||
local y, x, count, channels = 1.2, 0.5, 0, {}
|
||||
if smart_light.registry.areas[area] and smart_light.registry.areas[area].channels then
|
||||
for c_id, _ in pairs(smart_light.registry.areas[area].channels) do table.insert(channels, c_id) end
|
||||
table.sort(channels)
|
||||
for _, c_id in ipairs(channels) do
|
||||
-- Status AN/AUS statt Anzahl
|
||||
local status = smart_light.get_status_text(area, c_id)
|
||||
fs = fs .. "button["..x..","..y..";2.5,0.8;chan_"..c_id..";" .. c_id .. " ("..status..")]"
|
||||
x, count = x + 2.6, count + 1
|
||||
if count % 4 == 0 then x, y = 0.5, y + 1 end
|
||||
end
|
||||
else
|
||||
fs = fs .. "label[0.5,2;Keine Lichter für diese Area registriert.]"
|
||||
end
|
||||
minetest.show_formspec(name, "smart_light:main_" .. minetest.pos_to_string(pos), fs)
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata)
|
||||
local area = oldmetadata.fields.area_id
|
||||
if area and area ~= "" and smart_light.registry.areas[area] then
|
||||
if smart_light.registry.areas[area].channels then
|
||||
for c_id, c_data in pairs(smart_light.registry.areas[area].channels) do
|
||||
-- 1. Lampen zurücksetzen
|
||||
local nodes = c_data.nodes or {}
|
||||
for p_str, _ in pairs(nodes) do
|
||||
local l_pos = minetest.string_to_pos(p_str)
|
||||
local l_node = minetest.get_node(l_pos)
|
||||
if l_node.name ~= "ignore" then
|
||||
local original = smart_light.shadow_to_original[l_node.name] or l_node.name
|
||||
minetest.swap_node(l_pos, {name = original, param2 = l_node.param2})
|
||||
local l_meta = minetest.get_meta(l_pos)
|
||||
l_meta:set_string("sl_area", "")
|
||||
l_meta:set_string("sl_chan", "")
|
||||
end
|
||||
end
|
||||
-- 2. Schalter zurücksetzen
|
||||
local switches = c_data.switches or {}
|
||||
for s_str, _ in pairs(switches) do
|
||||
local s_pos = minetest.string_to_pos(s_str)
|
||||
minetest.swap_node(s_pos, {name = "smart_light:switch"})
|
||||
local s_meta = minetest.get_meta(s_pos)
|
||||
s_meta:set_string("sl_area", "")
|
||||
s_meta:set_string("sl_chan", "")
|
||||
s_meta:set_string("infotext", "")
|
||||
end
|
||||
end
|
||||
end
|
||||
smart_light.registry.areas[area] = nil
|
||||
smart_light.save()
|
||||
end
|
||||
end,
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue