added custom overrides, motion-sensors and more...
This commit is contained in:
parent
53466eed17
commit
ff423fc029
11 changed files with 348 additions and 26 deletions
47
handlers.lua
47
handlers.lua
|
|
@ -65,19 +65,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
local pos_str = formname:sub(21)
|
||||
local pos = minetest.string_to_pos(pos_str)
|
||||
if not pos then return end
|
||||
|
||||
if fields.save_switch then
|
||||
local area, chan = fields.area_sel, fields.chan_sel
|
||||
if area == "-- Bitte wählen --" or chan == "-- Bitte wählen --" then
|
||||
minetest.chat_send_player(name, "FEHLER: Bitte Area UND Kanal auswählen!")
|
||||
return
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("sl_area", area)
|
||||
meta:set_string("sl_chan", chan)
|
||||
meta:set_string("infotext", "Schalter: " .. area .. ":" .. chan)
|
||||
|
||||
if smart_light.registry.areas[area] and smart_light.registry.areas[area].channels[chan] then
|
||||
smart_light.registry.areas[area].channels[chan].switches = smart_light.registry.areas[area].channels[chan].switches or {}
|
||||
smart_light.registry.areas[area].channels[chan].switches[pos_str] = true
|
||||
|
|
@ -88,13 +85,48 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
end
|
||||
return
|
||||
end
|
||||
|
||||
if fields.area_sel and fields.area_sel ~= "-- Bitte wählen --" then
|
||||
minetest.get_meta(pos):set_string("sl_area", fields.area_sel)
|
||||
minetest.registered_tools["smart_light:programmer"].on_place(player:get_wielded_item(), player, {type="node", under=pos})
|
||||
end
|
||||
end
|
||||
|
||||
-- --- NEU: BEWEGUNGSMELDER PROGRAMMIERER (Kanal-Zuweisung) ---
|
||||
if formname:sub(1, 20) == "smart_light:prog_ms_" then
|
||||
local pos_str = formname:sub(21)
|
||||
local pos = minetest.string_to_pos(pos_str)
|
||||
if not pos then return end
|
||||
if fields.save_ms then
|
||||
local area, chan = fields.area_sel, fields.chan_sel
|
||||
if area == "-- Bitte wählen --" or chan == "-- Bitte wählen --" then
|
||||
minetest.chat_send_player(name, "FEHLER: Bitte Area UND Kanal auswählen!")
|
||||
return
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("sl_area", area)
|
||||
meta:set_string("sl_chan", chan)
|
||||
meta:set_string("infotext", "Bewegungsmelder: " .. area .. ":" .. chan)
|
||||
minetest.get_node_timer(pos):start(1.5) -- Timer starten
|
||||
minetest.chat_send_player(name, "Bewegungsmelder verknüpft!")
|
||||
return
|
||||
end
|
||||
if fields.area_sel and fields.area_sel ~= "-- Bitte wählen --" then
|
||||
minetest.get_meta(pos):set_string("sl_area", fields.area_sel)
|
||||
minetest.registered_tools["smart_light:programmer"].on_place(player:get_wielded_item(), player, {type="node", under=pos})
|
||||
end
|
||||
end
|
||||
|
||||
-- --- NEU: BEWEGUNGSMELDER WERTE (Radius/Dauer) ---
|
||||
if formname:sub(1, 19) == "smart_light:sensor_" then
|
||||
if fields.save_sensor then
|
||||
local pos = minetest.string_to_pos(formname:sub(20))
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_int("range", tonumber(fields.range) or 8)
|
||||
meta:set_int("duration", tonumber(fields.duration) or 30)
|
||||
minetest.chat_send_player(name, "Sensor-Parameter gespeichert.")
|
||||
end
|
||||
end
|
||||
|
||||
-- --- LICHT PROGRAMMIERER ---
|
||||
if formname:sub(1, 17) == "smart_light:prog_" and formname:sub(1, 20) ~= "smart_light:prog_sw_" then
|
||||
if fields.save then
|
||||
|
|
@ -102,17 +134,14 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
local pos = minetest.string_to_pos(pos_str)
|
||||
local area, chan = fields.area_sel, fields.chan_in
|
||||
if not area or area == "-- Bitte wählen --" or chan == "" then return end
|
||||
|
||||
minetest.get_meta(pos):set_string("sl_area", area)
|
||||
minetest.get_meta(pos):set_string("sl_chan", chan)
|
||||
|
||||
local item = player:get_wielded_item()
|
||||
local t_meta = item:get_meta()
|
||||
t_meta:set_string("last_area", area)
|
||||
t_meta:set_string("last_channel", chan)
|
||||
t_meta:set_string("description", "Programmer Area: " .. area .. "\nChannel: " .. chan)
|
||||
player:set_wielded_item(item)
|
||||
|
||||
smart_light.registry.areas[area] = smart_light.registry.areas[area] or { channels = {} }
|
||||
smart_light.registry.areas[area].channels[chan] = smart_light.registry.areas[area].channels[chan] or { nodes = {}, last_level = "max", brightness = "max" }
|
||||
smart_light.registry.areas[area].channels[chan].nodes[pos_str] = true
|
||||
|
|
@ -126,7 +155,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
local pos_str = formname:sub(18)
|
||||
local pos = minetest.string_to_pos(pos_str)
|
||||
local area = minetest.get_meta(pos):get_string("area_id")
|
||||
|
||||
if fields.all_off then
|
||||
for c,_ in pairs(smart_light.registry.areas[area].channels) do smart_light.switch_channel(area, c, "off") end
|
||||
minetest.registered_nodes["smart_light:controller"].on_rightclick(pos, nil, player)
|
||||
|
|
@ -140,7 +168,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
local count = smart_light.get_count(area, cid)
|
||||
local status = smart_light.get_status_text(area, cid)
|
||||
local last_lvl = smart_light.registry.areas[area].channels[cid].last_level or "max"
|
||||
|
||||
local subfs = "size[4,5.5]label[0.5,0.2;Channel: " .. cid .. "]" ..
|
||||
"label[0.5,0.7;Anzahl Leuchten: " .. count .. "]" ..
|
||||
"label[0.5,1.2;Status: " .. status .. "]" ..
|
||||
|
|
@ -164,7 +191,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
local meta = minetest.get_meta(pos)
|
||||
local area = meta:get_string("area_id")
|
||||
if area == "" then area = meta:get_string("sl_area") end
|
||||
|
||||
for k, _ in pairs(fields) do
|
||||
local cid, action = k:match("^sub_(.+)_([%a%d]+)$")
|
||||
if cid and action then
|
||||
|
|
@ -172,7 +198,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
local count = smart_light.get_count(area, cid)
|
||||
local status = smart_light.get_status_text(area, cid)
|
||||
local last_lvl = smart_light.registry.areas[area].channels[cid].last_level or "max"
|
||||
|
||||
local subfs = "size[4,5.5]label[0.5,0.2;Channel: " .. cid .. "]" ..
|
||||
"label[0.5,0.7;Anzahl Leuchten: " .. count .. "]" ..
|
||||
"label[0.5,1.2;Status: " .. status .. "]" ..
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue