From b1419ed0906cfc912add7f53ac4dc67d64becef4 Mon Sep 17 00:00:00 2001 From: cheapie Date: Fri, 31 Aug 2018 23:28:21 -0500 Subject: Add annunciator and re-alarm --- firealarm_panel/init.lua | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'firealarm_panel') diff --git a/firealarm_panel/init.lua b/firealarm_panel/init.lua index 7adc1ea..3071e31 100644 --- a/firealarm_panel/init.lua +++ b/firealarm_panel/init.lua @@ -66,6 +66,11 @@ local function setFormspec(pos) table.insert(devInfo.removeMenuDevList,dev) fs = fs..minetest.formspec_escape(v.name).."," end + for k,v in pairs(devInfo.associatedAnnunciators) do + local dev = {type = "annunciator",hash = k} + table.insert(devInfo.removeMenuDevList,dev) + fs = fs..minetest.formspec_escape(v.name).."," + end fs = string.sub(fs,1,-1).."]" else fs = fs.."label[0.5,5;No Devices Associated]" @@ -90,6 +95,7 @@ local function alarm(pos,initiator) end table.insert(devInfo.alarm,{initiator = initiatorHash,name = name}) devInfo.acked = false + devInfo.silenced = false firealarm.setDevInfo("panel",pos,devInfo) setFormspec(pos) end @@ -125,6 +131,9 @@ local function trouble(pos,initiator) if devInfo.associatedNotificationDevices[initiatorHash] then name = devInfo.associatedNotificationDevices[initiatorHash].name end + if devInfo.associatedAnnunciators[initiatorHash] then + name = devInfo.associatedAnnunciators[initiatorHash].name + end table.insert(devInfo.trouble,{initiator = initiatorHash,name = name}) devInfo.acked = false firealarm.setDevInfo("panel",pos,devInfo) @@ -197,7 +206,22 @@ local function handleFields(pos,_,fields,sender) devInfo.associatedNotificationDevices[minetest.hash_node_position(targetPos)] = devParams end else - minetest.chat_send_player(name,"Not a valid fire alarm device") + targetInfo = firealarm.getDevInfo("annunciator",targetPos) + if targetInfo then + if (minetest.is_protected(pos,name) and not minetest.check_player_privs(name,"protection_bypass")) or targetInfo.associated then + minetest.chat_send_player(name,"Device is protected or already associated") + else + targetInfo.associated = minetest.hash_node_position(pos) + local devParams = {} + devParams.name = fields.name + if not devInfo.associatedAnnunciators then + devInfo.associatedAnnunciators = {} + end + devInfo.associatedAnnunciators[minetest.hash_node_position(targetPos)] = devParams + end + else + minetest.chat_send_player(name,"Not a valid fire alarm device") + end end end else @@ -229,6 +253,14 @@ local function handleFields(pos,_,fields,sender) targetInfo.strobeActive = false firealarm.setDevInfo("notification",targetPos,targetInfo) end + elseif dev.type == "annunciator" then + devInfo.associatedAnnunciators[dev.hash] = nil + local targetPos = minetest.get_position_from_hash(dev.hash) + local targetInfo = firealarm.getDevInfo("annunciator",targetPos) + if targetInfo then + targetInfo.associated = nil + firealarm.setDevInfo("annunciator",targetPos,targetInfo) + end end end end @@ -579,8 +611,8 @@ function firealarm.panelABM(pos) if currentName ~= newName then node.name = newName minetest.set_node(pos,node) - setFormspec(pos) end + setFormspec(pos) end minetest.register_abm({ -- cgit v1.2.3