From c5954749b7cba8f17bb4ce551946f1537b803fc0 Mon Sep 17 00:00:00 2001 From: cheapie Date: Thu, 25 Apr 2024 14:00:54 -0500 Subject: Add door light curtain --- car.lua | 30 ++++++++++++++++++++++++++++++ controllerfw.lua | 8 ++++++++ doors.lua | 4 ++++ 3 files changed, 42 insertions(+) diff --git a/car.lua b/car.lua index 13730e8..7a77b3d 100644 --- a/car.lua +++ b/car.lua @@ -73,6 +73,36 @@ local pieces = { "celevator_car_wallpaper.png^celevator_car_wall_bottom.png^celevator_car_switch_panel.png", "celevator_cabinet_sides.png", }, + on_timer = function(pos) + local carid = minetest.get_meta(pos):get_int("carid") + local carinfo = minetest.deserialize(celevator.storage:get_string(string.format("car%d",carid))) + if not (carinfo and carinfo.controllerpos) then return end + local yaw = minetest.dir_to_yaw(minetest.fourdir_to_dir(minetest.get_node(pos).param2)) + local positions = { + vector.new(-0.25,-0.1,-0.5), + vector.new(0.25,-0.1,-0.5), + vector.new(0.75,-0.1,-0.5), + vector.new(1.25,-0.1,-0.5), + } + local playerseen = false + for _,searchpos in ipairs(positions) do + local rotatedpos = vector.rotate_around_axis(searchpos,vector.new(0,1,0),yaw) + local erefs = minetest.get_objects_inside_radius(vector.add(pos,rotatedpos),0.5) + for _,ref in pairs(erefs) do + if ref:is_player() then + playerseen = true + break + end + end + if playerseen then break end + end + if playerseen then + celevator.controller.run(carinfo.controllerpos,{ + type = "lightcurtain", + }) + end + return true + end, }, { _position = "001", diff --git a/controllerfw.lua b/controllerfw.lua index 9f12981..dedb182 100644 --- a/controllerfw.lua +++ b/controllerfw.lua @@ -675,6 +675,14 @@ elseif event.type == "remotemsg" then elseif event.channel == "carcall" and mem.carstate == "normal" then mem.carcalls[event.msg] = true end +elseif event.type == "lightcurtain" then + if mem.carstate == "normal" or mem.carstate == "indep" then + if mem.doorstate == "closing" then + open() + elseif mem.doorstate == "open" and mem.carstate == "normal" then + interrupt(mem.params.doortimer,"close") + end + end end local oldstate = mem.carstate diff --git a/doors.lua b/doors.lua index 26e95b1..f87c7ad 100644 --- a/doors.lua +++ b/doors.lua @@ -430,6 +430,8 @@ function celevator.doors.carstep(dtime) end celevator.get_meta(data.positions[1]):set_string("doorstate","closed") cardoors_moving[hash] = nil + local cartimer = minetest.get_node_timer(data.positions[1]) + cartimer:stop() end end else @@ -490,6 +492,8 @@ end function celevator.doors.caropen(pos) local cardoors_moving = minetest.deserialize(celevator.storage:get_string("cardoors_moving")) or {} local hash = minetest.hash_node_position(pos) + local cartimer = minetest.get_node_timer(pos) + cartimer:start(0.25) if not cardoors_moving[hash] then local fdir = minetest.fourdir_to_dir(celevator.get_node(pos).param2) local otherpanel = vector.add(pos,vector.rotate_around_axis(fdir,vector.new(0,1,0),-math.pi/2)) -- cgit v1.2.3