summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2024-04-28 14:43:16 -0500
committercheapie <no-email-for-you@example.com>2024-04-28 14:43:16 -0500
commit3b666a974928e38ac7e5019608d9c00c6364b399 (patch)
tree197ba3e7d5185e19ca36ddd595590493046b767e
parent8072e72b9f0dd26c8f530d25ba50ab566557851d (diff)
downloadcelevator-3b666a974928e38ac7e5019608d9c00c6364b399.tar
celevator-3b666a974928e38ac7e5019608d9c00c6364b399.tar.gz
celevator-3b666a974928e38ac7e5019608d9c00c6364b399.tar.bz2
celevator-3b666a974928e38ac7e5019608d9c00c6364b399.tar.xz
celevator-3b666a974928e38ac7e5019608d9c00c6364b399.zip
Add Digilines interface
-rw-r--r--.luacheckrc1
-rw-r--r--digilines.lua134
-rw-r--r--init.lua1
-rw-r--r--mod.conf2
-rw-r--r--textures/celevator_digilinesio_top.pngbin0 -> 9156 bytes
5 files changed, 137 insertions, 1 deletions
diff --git a/.luacheckrc b/.luacheckrc
index 770a735..6b5385e 100644
--- a/.luacheckrc
+++ b/.luacheckrc
@@ -13,4 +13,5 @@ read_globals = {
"VoxelManip",
"laptop",
"mesecon",
+ "digilines",
}
diff --git a/digilines.lua b/digilines.lua
new file mode 100644
index 0000000..79fd087
--- /dev/null
+++ b/digilines.lua
@@ -0,0 +1,134 @@
+minetest.register_node("celevator:digilines_io",{
+ description = "Elevator Digilines Input/Output",
+ tiles = {
+ "celevator_digilinesio_top.png",
+ "celevator_cabinet_sides.png",
+ },
+ groups = {
+ dig_immediate = 2,
+ },
+ paramtype = "light",
+ drawtype = "nodebox",
+ node_box = {
+ type = "fixed",
+ fixed = {
+ {-0.5,-0.5,-0.5,0.5,-0.47,0.5},
+ {-0.438,-0.47,-0.438,0.438,-0.42,0.438},
+ },
+ },
+ digilines = {
+ receptor = {},
+ effector = {
+ action = function(pos,_,channel,msg)
+ if msg == "GET" then msg = {command = "GET"} end
+ if type(msg) ~= "table" or type(msg.command) ~= "string" then return end
+ local meta = minetest.get_meta(pos)
+ local setchannel = meta:get_string("channel")
+ if setchannel ~= channel then return end
+ local carid = meta:get_int("carid")
+ if carid == 0 then return end
+ local carinfo = minetest.deserialize(celevator.storage:get_string(string.format("car%d",carid))) or {}
+ if not carinfo.controllerpos then return end
+ if not celevator.controller.iscontroller(carinfo.controllerpos) then return end
+ msg.command = string.lower(msg.command)
+ if msg.command == "get" then
+ local mem = minetest.deserialize(minetest.get_meta(carinfo.controllerpos):get_string("mem"))
+ if not mem then return end
+ local ret = {
+ carstate = mem.carstate,
+ doorstate = mem.doorstate,
+ carcalls = mem.carcalls,
+ upcalls = mem.upcalls,
+ swingupcalls = mem.swingupcalls,
+ groupupcalls = mem.groupupcalls,
+ downcalls = mem.dncalls,
+ swingdowncalls = mem.swingdncalls,
+ groupdowncalls = mem.groupdncalls,
+ fireserviceled = mem.fs1led,
+ switches = {
+ stop = mem.controllerstopsw,
+ machineroominspection = mem.controllerinspectsw,
+ cartopinspection = mem.cartopinspectsw,
+ capture = mem.capturesw,
+ test = mem.testsw,
+ fireservice1 = mem.fs1switch,
+ fireservice2 = mem.fs2sw,
+ indpedendent = mem.indsw,
+ light = mem.lightsw,
+ fan = mem.fansw,
+ },
+ parameters = mem.params,
+ drivestatus = mem.drive.status,
+ direction = mem.direction,
+ }
+ digilines.receptor_send(pos,digilines.rules.default,channel,ret)
+ elseif msg.command == "carcall" and type(msg.floor) == "number" then
+ celevator.controller.run(carinfo.controllerpos,{
+ type = "remotemsg",
+ channel = "carcall",
+ msg = msg.floor,
+ })
+ elseif msg.command == "upcall" and type(msg.floor) == "number" then
+ celevator.controller.run(carinfo.controllerpos,{
+ type = "remotemsg",
+ channel = "upcall",
+ msg = msg.floor,
+ })
+ elseif msg.command == "downcall" and type(msg.floor) == "number" then
+ celevator.controller.run(carinfo.controllerpos,{
+ type = "remotemsg",
+ channel = "dncall",
+ msg = msg.floor,
+ })
+ elseif msg.command == "swingupcall" and type(msg.floor) == "number" then
+ celevator.controller.run(carinfo.controllerpos,{
+ type = "remotemsg",
+ channel = "swingupcall",
+ msg = msg.floor,
+ })
+ elseif msg.command == "swingdowncall" and type(msg.floor) == "number" then
+ celevator.controller.run(carinfo.controllerpos,{
+ type = "remotemsg",
+ channel = "swingdncall",
+ msg = msg.floor,
+ })
+ end
+ end,
+ },
+ },
+ after_place_node = function(pos)
+ local meta = minetest.get_meta(pos)
+ local fs = "formspec_version[7]size[8,4.5]"
+ fs = fs.."field[0.5,0.5;3,1;channel;Channel;${channel}]"
+ fs = fs.."field[4.5,0.5;3,1;carid;Car ID;${carid}]"
+ fs = fs.."button_exit[2.5,2;3,1;save;Save]"
+ meta:set_string("formspec",fs)
+ end,
+ on_receive_fields = function(pos,_,fields,player)
+ local meta = minetest.get_meta(pos)
+ if not fields.save then return end
+ local name = player:get_player_name()
+ if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
+ if player:is_player() then
+ minetest.record_protection_violation(pos,name)
+ end
+ return
+ end
+ if not tonumber(fields.carid) then return end
+ meta:set_int("carid",fields.carid)
+ local carid = tonumber(fields.carid)
+ local carinfo = minetest.deserialize(celevator.storage:get_string(string.format("car%d",carid))) or {}
+ if not carinfo.controllerpos then return end
+ if not celevator.controller.iscontroller(carinfo.controllerpos) then return end
+ if minetest.is_protected(carinfo.controllerpos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
+ if player:is_player() then
+ minetest.chat_send_player(name,"Can't connect to a controller you don't have access to.")
+ minetest.record_protection_violation(carinfo.controllerpos,name)
+ end
+ return
+ end
+ meta:set_string("channel",fields.channel)
+ local infotext = "Car: "..carid
+ meta:set_string("infotext",infotext)
+ end,
+})
diff --git a/init.lua b/init.lua
index 3a6cdcc..c60ef22 100644
--- a/init.lua
+++ b/init.lua
@@ -15,6 +15,7 @@ local components = {
local integrations = {
"laptop",
"mesecons",
+ "digilines",
}
for _,i in ipairs(integrations) do
diff --git a/mod.conf b/mod.conf
index 3c1daf2..56cc386 100644
--- a/mod.conf
+++ b/mod.conf
@@ -1,4 +1,4 @@
name = celevator
description = Realistic Elevators
-optional_depends = laptop,mesecons
+optional_depends = laptop,mesecons,digilines
author = cheapie
diff --git a/textures/celevator_digilinesio_top.png b/textures/celevator_digilinesio_top.png
new file mode 100644
index 0000000..163f9bf
--- /dev/null
+++ b/textures/celevator_digilinesio_top.png
Binary files differ