summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--controller.lua27
-rw-r--r--controllerfw.lua24
-rw-r--r--init.lua1
-rw-r--r--pairingtool.lua43
-rw-r--r--pilantern.lua141
-rw-r--r--textures/celevator_pi_arrow.pngbin0 -> 7001 bytes
-rw-r--r--textures/celevator_pi_background.pngbin0 -> 5953 bytes
-rw-r--r--textures/celevator_transparent.pngbin0 -> 563 bytes
8 files changed, 234 insertions, 2 deletions
diff --git a/controller.lua b/controller.lua
index a607666..8bfa1af 100644
--- a/controller.lua
+++ b/controller.lua
@@ -433,6 +433,33 @@ function celevator.controller.finish(pos,mem)
celevator.callbutton.setlight(minetest.get_position_from_hash(hash),"down",newdownbuttonlights[landing])
end
end
+ local oldpitext = oldmem.pifloor or "--"
+ local newpitext = mem.pifloor or "--"
+ if oldpitext ~= newpitext then
+ local pis = minetest.deserialize(meta:get_string("pis")) or {}
+ for hash in pairs(pis) do
+ local pipos = minetest.get_position_from_hash(hash)
+ celevator.pi.settext(pipos,newpitext)
+ end
+ end
+ local oldpiuparrow = oldmem.piuparrow
+ local newpiuparrow = mem.piuparrow
+ local oldpidownarrow = oldmem.pidownarrow
+ local newpidownarrow = mem.pidownarrow
+ if oldpiuparrow ~= newpiuparrow then
+ local pis = minetest.deserialize(meta:get_string("pis")) or {}
+ for hash in pairs(pis) do
+ local pipos = minetest.get_position_from_hash(hash)
+ celevator.pi.setarrow(pipos,"up",newpiuparrow)
+ end
+ end
+ if oldpidownarrow ~= newpidownarrow then
+ local pis = minetest.deserialize(meta:get_string("pis")) or {}
+ for hash in pairs(pis) do
+ local pipos = minetest.get_position_from_hash(hash)
+ celevator.pi.setarrow(pipos,"down",newpidownarrow)
+ 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 "")
diff --git a/controllerfw.lua b/controllerfw.lua
index f9dfacc..8285583 100644
--- a/controllerfw.lua
+++ b/controllerfw.lua
@@ -284,7 +284,7 @@ elseif event.type == "ui" then
mem.editingfloor = mem.editingfloor - 1
end
elseif mem.screenstate == "oobe_floortable_edit" or mem.screenstate == "floortable_edit" then
- if event.fields.back then
+ if event.fields.back or event.fields.save then
mem.screenstate = (mem.screenstate == "oobe_floortable_edit" and "oobe_floortable" or "floortable")
local height = tonumber(event.fields.height)
if height then
@@ -710,4 +710,26 @@ else
mem.showrunning = false
end
+mem.pifloor = mem.params.floornames[getpos()]
+local hidepi = {
+ bfdemand = true,
+ uninit = true,
+ stop = true,
+ fault = true,
+ mrinspect = true,
+ carinspect = true,
+ inspconflict = true,
+}
+if hidepi[mem.carstate] then mem.pifloor = "--" end
+local arrowenabled = {
+ normal = true,
+ fs1 = true,
+ fs2 = true,
+ indep = true,
+ capture = true,
+ test = true,
+}
+mem.piuparrow = mem.drive.status.vel > 0 and arrowenabled[mem.carstate]
+mem.pidownarrow = mem.drive.status.vel < 0 and arrowenabled[mem.carstate]
+
return pos,mem
diff --git a/init.lua b/init.lua
index 6de4cb6..eb7ebdc 100644
--- a/init.lua
+++ b/init.lua
@@ -4,6 +4,7 @@ local components = {
"controller",
"callbuttons",
"pairingtool",
+ "pilantern",
}
for _,v in ipairs(components) do
diff --git a/pairingtool.lua b/pairingtool.lua
index 770c7d7..0b00a38 100644
--- a/pairingtool.lua
+++ b/pairingtool.lua
@@ -69,8 +69,49 @@ minetest.register_tool("celevator:pairingtool",{
else
minetest.chat_send_player(name,"Controller or dispatcher has been removed. Punch a new controller or dispatcher to pair to that one.")
end
+ elseif minetest.get_item_group(node.name,"_celevator_pi") then
+ local stackmeta = itemstack:get_meta()
+ local nodemeta = minetest.get_meta(pos)
+ local oldpairing = minetest.string_to_pos(nodemeta:get_string("controllerpos"))
+ local controllerpos = minetest.string_to_pos(stackmeta:get_string("controllerpos"))
+ if not controllerpos then
+ minetest.chat_send_player(name,"Nothing has been selected to pair with! Punch a controller or dispatcher first.")
+ elseif oldpairing then
+ local controllermeta = minetest.get_meta(oldpairing)
+ local pairings = minetest.deserialize(controllermeta:get_string("pis"))
+ if pairings then
+ local hash = minetest.hash_node_position(pos)
+ pairings[hash] = nil
+ controllermeta:set_string("pis",minetest.serialize(pairings))
+ end
+ nodemeta:set_string("controllerpos","")
+ nodemeta:set_int("uparrow",0)
+ nodemeta:set_int("downarrow",0)
+ nodemeta:set_int("flash_fs",0)
+ nodemeta:set_int("flash_is",0)
+ nodemeta:set_string("text","")
+ celevator.pi.updatedisplay(pos)
+ minetest.chat_send_player(player:get_player_name(),"Unpaired from "..minetest.pos_to_string(oldpairing))
+ elseif celevator.controller.iscontroller(controllerpos) then
+ if minetest.is_protected(controllerpos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
+ minetest.chat_send_player(name,"Unable to pair - controller at "..minetest.pos_to_string(controllerpos).." is protected!")
+ minetest.record_protection_violation(controllerpos,name)
+ elseif minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
+ minetest.chat_send_player(name,"Unable to pair - item to be paired is protected!")
+ minetest.record_protection_violation(pos,name)
+ else
+ local controllermeta = minetest.get_meta(controllerpos)
+ nodemeta:set_string("controllerpos",minetest.pos_to_string(controllerpos))
+ local pairings = minetest.deserialize(controllermeta:get_string("pis")) or {}
+ local hash = minetest.hash_node_position(pos)
+ pairings[hash] = true
+ controllermeta:set_string("pis",minetest.serialize(pairings))
+ minetest.chat_send_player(player:get_player_name(),"Paired to "..minetest.pos_to_string(controllerpos))
+ end
+ else
+ minetest.chat_send_player(name,"Controller or dispatcher has been removed. Punch a new controller or dispatcher to pair to that one.")
+ end
end
return itemstack
end,
})
-
diff --git a/pilantern.lua b/pilantern.lua
new file mode 100644
index 0000000..d2620f5
--- /dev/null
+++ b/pilantern.lua
@@ -0,0 +1,141 @@
+celevator.pi = {}
+
+local boringside = "[combine:64x64:0,0=celevator_cabinet_sides.png:32,0=celevator_cabinet_sides.png:0,32=celevator_cabinet_sides.png:32,32=celevator_cabinet_sides.png"
+local displaytex = boringside..":16,40=celevator_pi_background.png"
+
+minetest.register_entity("celevator:pi_entity",{
+ initial_properties = {
+ visual = "upright_sprite",
+ physical = false,
+ collisionbox = {0,0,0,0,0,0,},
+ textures = {"celevator_transparent.png",},
+ },
+})
+
+local function removeentity(pos)
+ local entitiesnearby = minetest.get_objects_inside_radius(pos,1.5)
+ for _,i in pairs(entitiesnearby) do
+ if i:get_luaentity() and i:get_luaentity().name == "celevator:pi_entity" then
+ i:remove()
+ end
+ end
+end
+
+local function generatetexture(text,uparrow,downarrow)
+ local out = "[combine:600x600:0,0=celevator_transparent.png"
+ for i=1,string.len(text),1 do
+ local char = string.byte(string.sub(text,i,i))
+ if char ~= " " then out = out..string.format(":%d,%d=celevator_pi_%02X.png",(i-1)*50+260,440,(char >= 0x20 and char < 0x7F and char or 0x2A)) end
+ end
+ if uparrow then out = out..":200,440=celevator_pi_arrow.png"
+ elseif downarrow then out = out..":200,440=(celevator_pi_arrow.png^[transformFY)" end
+ return out
+end
+
+function celevator.pi.updatedisplay(pos)
+ removeentity(pos)
+ local meta = minetest.get_meta(pos)
+ local text = meta:get_string("text")
+ local entity = minetest.add_entity(pos,"celevator:pi_entity")
+ local fdir = minetest.facedir_to_dir(minetest.get_node(pos).param2)
+ local uparrow = meta:get_int("uparrow") > 0
+ local downarrow = meta:get_int("downarrow") > 0
+ local flash_fs = meta:get_int("flash_fs") > 0
+ local flash_is = meta:get_int("flash_is") > 0
+ local flashtimer = meta:get_int("flashtimer") > 0
+ local etex = generatetexture(text,uparrow,downarrow)
+ if flash_fs then
+ if flashtimer then etex = generatetexture(" FS",uparrow,downarrow) end
+ entity:set_properties({_flash_fs = true,_flash_is = false,})
+ elseif flash_is then
+ if flashtimer then etex = generatetexture(" IS",uparrow,downarrow) end
+ entity:set_properties({_flash_fs = false,_flash_is = true,})
+ else
+ entity:set_properties({_flash_fs = false,_flash_is = false,})
+ end
+ entity:set_properties({textures={etex}})
+ entity:set_yaw((fdir.x ~= 0) and math.pi/2 or 0)
+ entity:setpos(vector.add(pos,vector.multiply(fdir,-0.61)))
+end
+
+function celevator.pi.flash(pos,what)
+ if minetest.get_item_group(minetest.get_node(pos).name,"_celevator_pi") ~= 1 then return end
+ local meta = minetest.get_meta(pos)
+ if what == "FS" then
+ meta:set_int("flash_is",0)
+ meta:set_int("flash_fs",1)
+ elseif what == "IS" then
+ meta:set_int("flash_is",1)
+ meta:set_int("flash_fs",0)
+ else
+ meta:set_int("flash_is",0)
+ meta:set_int("flash_fs",0)
+ end
+ celevator.pi.updatedisplay(pos)
+end
+
+function celevator.pi.settext(pos,text)
+ if minetest.get_item_group(minetest.get_node(pos).name,"_celevator_pi") ~= 1 then return end
+ local meta = minetest.get_meta(pos)
+ if string.len(text) < 3 then
+ text = string.rep(" ",3-string.len(text))..text
+ end
+ meta:set_string("text",string.sub(text,1,3))
+ celevator.pi.updatedisplay(pos)
+end
+
+function celevator.pi.setarrow(pos,which,active)
+ if minetest.get_item_group(minetest.get_node(pos).name,"_celevator_pi") ~= 1 then return end
+ local meta = minetest.get_meta(pos)
+ if which == "up" then
+ meta:set_int("uparrow",active and 1 or 0)
+ elseif which == "down" then
+ meta:set_int("downarrow",active and 1 or 0)
+ end
+ celevator.pi.updatedisplay(pos)
+end
+
+minetest.register_node("celevator:pi",{
+ description = "Position Indicator",
+ groups = {
+ dig_immediate = 2,
+ _celevator_pi = 1,
+ },
+ tiles = {
+ boringside,
+ boringside,
+ boringside,
+ boringside,
+ boringside,
+ displaytex,
+ },
+ paramtype = "light",
+ paramtype2 = "facedir",
+ drawtype = "nodebox",
+ node_box = {
+ type = "fixed",
+ fixed = {
+ { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
+ {-0.25,-0.453, -0.6,0.25,-0.125, -0.5 },
+ },
+ },
+ on_destruct = removeentity,
+ on_construct = function(pos)
+ local meta = minetest.get_meta(pos)
+ meta:set_string("text","621")
+ celevator.pi.updatedisplay(pos)
+ end,
+})
+
+minetest.register_abm({
+ label = "Respawn / Flash PI displays",
+ nodenames = {"group:_celevator_pi"},
+ interval = 1,
+ chance = 1,
+ action = function(pos)
+ local meta = minetest.get_meta(pos)
+ local flashtimer = meta:get_int("flashtimer") > 0
+ meta:set_int("flashtimer",flashtimer and 0 or 1)
+ celevator.pi.updatedisplay(pos)
+ end,
+})
diff --git a/textures/celevator_pi_arrow.png b/textures/celevator_pi_arrow.png
new file mode 100644
index 0000000..70d67eb
--- /dev/null
+++ b/textures/celevator_pi_arrow.png
Binary files differ
diff --git a/textures/celevator_pi_background.png b/textures/celevator_pi_background.png
new file mode 100644
index 0000000..66ea82e
--- /dev/null
+++ b/textures/celevator_pi_background.png
Binary files differ
diff --git a/textures/celevator_transparent.png b/textures/celevator_transparent.png
new file mode 100644
index 0000000..ac69e11
--- /dev/null
+++ b/textures/celevator_transparent.png
Binary files differ