diff options
author | cheapie <no-email-for-you@example.com> | 2023-08-04 13:02:38 -0500 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2023-08-04 13:02:38 -0500 |
commit | fe7684c847950afd10c24f8b1d25ab53e6354b72 (patch) | |
tree | 644586a14070cad681dcbe458886c714c9b3baff /controller.lua | |
parent | bbdf947d7c1bffb6d26d333c47c9b2a88109f058 (diff) | |
download | celevator-fe7684c847950afd10c24f8b1d25ab53e6354b72.tar celevator-fe7684c847950afd10c24f8b1d25ab53e6354b72.tar.gz celevator-fe7684c847950afd10c24f8b1d25ab53e6354b72.tar.bz2 celevator-fe7684c847950afd10c24f8b1d25ab53e6354b72.tar.xz celevator-fe7684c847950afd10c24f8b1d25ab53e6354b72.zip |
Add pairing tool and make call buttons functional
Diffstat (limited to 'controller.lua')
-rw-r--r-- | controller.lua | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/controller.lua b/controller.lua index a2071ec..a607666 100644 --- a/controller.lua +++ b/controller.lua @@ -419,6 +419,20 @@ function celevator.controller.finish(pos,mem) end local meta = minetest.get_meta(pos) local node = minetest.get_node(pos) + local oldmem = minetest.deserialize(meta:get_string("mem")) or {} + local oldupbuttonlights = oldmem.upcalls or {} + local olddownbuttonlights = oldmem.dncalls or {} + local newupbuttonlights = mem.upcalls or {} + local newdownbuttonlights = mem.dncalls or {} + local callbuttons = minetest.deserialize(meta:get_string("callbuttons")) or {} + for hash,landing in pairs(callbuttons) do + if oldupbuttonlights[landing] ~= newupbuttonlights[landing] then + celevator.callbutton.setlight(minetest.get_position_from_hash(hash),"up",newupbuttonlights[landing]) + end + if olddownbuttonlights[landing] ~= newdownbuttonlights[landing] then + celevator.callbutton.setlight(minetest.get_position_from_hash(hash),"down",newdownbuttonlights[landing]) + end + end meta:set_string("mem",minetest.serialize(mem)) if node.name == "celevator:controller_open" then meta:set_string("formspec",mem.formspec or "") end meta:set_string("formspec_hidden",mem.formspec or "") @@ -459,7 +473,7 @@ function celevator.controller.run(pos,event) local mem = minetest.deserialize(meta:get_string("mem")) if not mem then minetest.log("error","[celevator] [controller] Failed to load controller memory at "..minetest.pos_to_string(pos)) - mem = {} + return end mem.drive = {} mem.drive.commands = {} @@ -473,6 +487,21 @@ function celevator.controller.run(pos,event) end end +function celevator.controller.handlecallbutton(controllerpos,buttonpos,dir) + local buttonhash = minetest.hash_node_position(buttonpos) + local controllermeta = minetest.get_meta(controllerpos) + local pairings = minetest.deserialize(controllermeta:get_string("callbuttons")) or {} + if pairings[buttonhash] then + local landing = pairings[buttonhash] + local event = { + type = "callbutton", + landing = landing, + dir = dir, + } + celevator.controller.run(controllerpos,event) + end +end + function celevator.controller.checkiqueue(dtime) for hash,iqueue in pairs(celevator.controller.iqueue) do local pos = minetest.get_position_from_hash(hash) |