diff options
author | cheapie <no-email-for-you@example.com> | 2017-01-17 18:45:43 -0600 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2017-01-17 18:45:43 -0600 |
commit | 9751b4853ea6dbaf820b2f8cdb75cfd31b3cc46e (patch) | |
tree | 906fbeeb3aab3412018c207c76db61e262a9aed4 | |
parent | ca83b3e5010274dbe0d65e8cd7ea75fc82a5bdad (diff) | |
download | roads-9751b4853ea6dbaf820b2f8cdb75cfd31b3cc46e.tar roads-9751b4853ea6dbaf820b2f8cdb75cfd31b3cc46e.tar.gz roads-9751b4853ea6dbaf820b2f8cdb75cfd31b3cc46e.tar.bz2 roads-9751b4853ea6dbaf820b2f8cdb75cfd31b3cc46e.tar.xz roads-9751b4853ea6dbaf820b2f8cdb75cfd31b3cc46e.zip |
Add countdown pedestrian signals
23 files changed, 89 insertions, 0 deletions
diff --git a/trafficlight/init.lua b/trafficlight/init.lua index b842d11..b64af8a 100644 --- a/trafficlight/init.lua +++ b/trafficlight/init.lua @@ -84,6 +84,25 @@ streets.tlDigilineRules = { {x= 0, y= 1, z= 0} } +local function ped_on_flash_start(pos) + local timer = minetest.get_node_timer(pos) + timer:set(99,0) +end + +local function ped_on_flash_end(pos,record) + local objs = minetest.get_objects_inside_radius(pos,1.5) + for _,obj in pairs(objs) do + if obj:get_luaentity() and obj:get_luaentity().name == "streets:pedcountdown" then + obj:remove() + end + end + if not record then return end + local timer = minetest.get_node_timer(pos) + local meta = minetest.get_meta(pos) + meta:set_int("flashtime",math.min(timer:get_elapsed(),99)) + timer:stop() +end + streets.tlSwitch = function(pos,to) if not pos or not to then return @@ -100,6 +119,9 @@ streets.on_digiline_receive = function(pos, node, channel, msg) local name = minetest.get_node(pos).name if msg == "OFF" then if name:find("pedlight") then + if name == "streets:pedlight_top_flashingdontwalk" then + ped_on_flash_end(pos,false) + end streets.tlSwitch(pos,"streets:pedlight_top_off") elseif name:find("extender_left") then streets.tlSwitch(pos,"streets:trafficlight_top_extender_left_off") @@ -118,6 +140,9 @@ streets.on_digiline_receive = function(pos, node, channel, msg) end elseif msg == "GREEN" then if name:find("pedlight") then + if name == "streets:pedlight_top_flashingdontwalk" then + ped_on_flash_end(pos,false) + end streets.tlSwitch(pos,"streets:pedlight_top_walk") elseif name:find("extender_left") then streets.tlSwitch(pos,"streets:trafficlight_top_extender_left_green") @@ -136,6 +161,9 @@ streets.on_digiline_receive = function(pos, node, channel, msg) end elseif msg == "RED" then if name:find("pedlight") then + if name == "streets:pedlight_top_flashingdontwalk" then + ped_on_flash_end(pos,true) + end streets.tlSwitch(pos,"streets:pedlight_top_dontwalk") elseif name:find("extender_left") then streets.tlSwitch(pos,"streets:trafficlight_top_extender_left_off") @@ -154,6 +182,9 @@ streets.on_digiline_receive = function(pos, node, channel, msg) end elseif msg == "WARN" then if name:find("pedlight") then + if name ~= "streets:pedlight_top_flashingdontwalk" then + ped_on_flash_start(pos) + end streets.tlSwitch(pos,"streets:pedlight_top_flashingdontwalk") elseif name:find("extender_left") then streets.tlSwitch(pos,"streets:trafficlight_top_extender_left_off") @@ -172,6 +203,9 @@ streets.on_digiline_receive = function(pos, node, channel, msg) end elseif msg == "FLASHYELLOW" then if name:find("pedlight") then + if name ~= "streets:pedlight_top_flashingdontwalk" then + ped_on_flash_start(pos) + end streets.tlSwitch(pos,"streets:pedlight_top_flashingdontwalk") elseif name:find("extender_left") then streets.tlSwitch(pos,"streets:trafficlight_top_extender_left_flashyellow") @@ -190,6 +224,9 @@ streets.on_digiline_receive = function(pos, node, channel, msg) end elseif msg == "YELLOW" then if name:find("pedlight") then + if name ~= "streets:pedlight_top_flashingdontwalk" then + ped_on_flash_start(pos) + end streets.tlSwitch(pos,"streets:pedlight_top_flashingdontwalk") elseif name:find("extender_left") then streets.tlSwitch(pos,"streets:trafficlight_top_extender_left_yellow") @@ -208,6 +245,9 @@ streets.on_digiline_receive = function(pos, node, channel, msg) end elseif msg == "FLASHRED" then if name:find("pedlight") then + if name ~= "streets:pedlight_top_flashingdontwalk" then + ped_on_flash_start(pos) + end streets.tlSwitch(pos,"streets:pedlight_top_flashingdontwalk") elseif name:find("extender_left") then streets.tlSwitch(pos,"streets:trafficlight_top_extender_left_off") @@ -893,6 +933,8 @@ minetest.register_node(":streets:trafficlight_top_extender_right_green",{ end, }) + + minetest.register_node(":streets:pedlight_top_off",{ description = streets.S("Pedestrian Light"), drawtype="nodebox", @@ -1003,6 +1045,53 @@ minetest.register_node(":streets:pedlight_top_flashingdontwalk",{ }, }) +minetest.register_entity(":streets:pedcountdown",{ + physical = false, + collisionbox = {0,0,0,0,0,0}, + visual = "upright_sprite", + textures = {"streets_pl_number_9l.png^streets_pl_number_9r.png"} +}) + +minetest.register_abm({ + label = "Update pedestrian countdown time display", + nodenames = {"streets:pedlight_top_flashingdontwalk"}, + interval = 1, + chance = 1, + catch_up = false, + action = function(pos,node) + local meta = minetest.get_meta(pos) + local timer = minetest.get_node_timer(pos) + local totaltime = meta:get_int("flashtime") + local timesofar = timer:get_elapsed() + local timeleft = math.max(0,totaltime-timesofar) + local objs = minetest.get_objects_inside_radius(pos,1.5) + for _,obj in pairs(objs) do + if obj:get_luaentity() and obj:get_luaentity().name == "streets:pedcountdown" then + obj:remove() + end + end + local backdir = minetest.facedir_to_dir(node.param2) + local frontdir = vector.multiply(backdir,-1) + local entpos = vector.add(vector.multiply(frontdir,-0.495),pos) + local entity = minetest.add_entity(entpos,"streets:pedcountdown") + local yaw = 0 + if backdir.z == -1 then + yaw = math.pi + elseif backdir.x == 1 then + yaw = math.pi / 2 + elseif backdir.x == -1 then + yaw = math.pi / -2 + end + --Circles are hard... + entity:setyaw(yaw) + + local ldigit = math.floor(timeleft/10) + local rdigit = timeleft % 10 + local tex = string.format("streets_pl_number_%01dl.png^streets_pl_number_%01dr.png",ldigit,rdigit) + entity:set_properties({textures={tex}}) + end +}) + for _,i in pairs({"","_left","_right"}) do minetest.register_node(":streets:trafficlight_top"..i.."_off",{ diff --git a/trafficlight/textures/streets_pl_number_0l.png b/trafficlight/textures/streets_pl_number_0l.png Binary files differnew file mode 100644 index 0000000..99fc263 --- /dev/null +++ b/trafficlight/textures/streets_pl_number_0l.png diff --git a/trafficlight/textures/streets_pl_number_0r.png b/trafficlight/textures/streets_pl_number_0r.png Binary files differnew file mode 100644 index 0000000..6f9b143 --- /dev/null +++ b/trafficlight/textures/streets_pl_number_0r.png diff --git a/trafficlight/textures/streets_pl_number_1l.png b/trafficlight/textures/streets_pl_number_1l.png Binary files differnew file mode 100644 index 0000000..e35735a --- /dev/null +++ b/trafficlight/textures/streets_pl_number_1l.png diff --git a/trafficlight/textures/streets_pl_number_1r.png b/trafficlight/textures/streets_pl_number_1r.png Binary files differnew file mode 100644 index 0000000..b878ae6 --- /dev/null +++ b/trafficlight/textures/streets_pl_number_1r.png diff --git a/trafficlight/textures/streets_pl_number_2l.png b/trafficlight/textures/streets_pl_number_2l.png Binary files differnew file mode 100644 index 0000000..d439aa9 --- /dev/null +++ b/trafficlight/textures/streets_pl_number_2l.png diff --git a/trafficlight/textures/streets_pl_number_2r.png b/trafficlight/textures/streets_pl_number_2r.png Binary files differnew file mode 100644 index 0000000..dd9b4be --- /dev/null +++ b/trafficlight/textures/streets_pl_number_2r.png diff --git a/trafficlight/textures/streets_pl_number_3l.png b/trafficlight/textures/streets_pl_number_3l.png Binary files differnew file mode 100644 index 0000000..bdab896 --- /dev/null +++ b/trafficlight/textures/streets_pl_number_3l.png diff --git a/trafficlight/textures/streets_pl_number_3r.png b/trafficlight/textures/streets_pl_number_3r.png Binary files differnew file mode 100644 index 0000000..da7de9a --- /dev/null +++ b/trafficlight/textures/streets_pl_number_3r.png diff --git a/trafficlight/textures/streets_pl_number_4l.png b/trafficlight/textures/streets_pl_number_4l.png Binary files differnew file mode 100644 index 0000000..91d1ff4 --- /dev/null +++ b/trafficlight/textures/streets_pl_number_4l.png diff --git a/trafficlight/textures/streets_pl_number_4r.png b/trafficlight/textures/streets_pl_number_4r.png Binary files differnew file mode 100644 index 0000000..5468b00 --- /dev/null +++ b/trafficlight/textures/streets_pl_number_4r.png diff --git a/trafficlight/textures/streets_pl_number_5l.png b/trafficlight/textures/streets_pl_number_5l.png Binary files differnew file mode 100644 index 0000000..4d21bbd --- /dev/null +++ b/trafficlight/textures/streets_pl_number_5l.png diff --git a/trafficlight/textures/streets_pl_number_5r.png b/trafficlight/textures/streets_pl_number_5r.png Binary files differnew file mode 100644 index 0000000..9992ed9 --- /dev/null +++ b/trafficlight/textures/streets_pl_number_5r.png diff --git a/trafficlight/textures/streets_pl_number_6l.png b/trafficlight/textures/streets_pl_number_6l.png Binary files differnew file mode 100644 index 0000000..92f64be --- /dev/null +++ b/trafficlight/textures/streets_pl_number_6l.png diff --git a/trafficlight/textures/streets_pl_number_6r.png b/trafficlight/textures/streets_pl_number_6r.png Binary files differnew file mode 100644 index 0000000..ba84f54 --- /dev/null +++ b/trafficlight/textures/streets_pl_number_6r.png diff --git a/trafficlight/textures/streets_pl_number_7l.png b/trafficlight/textures/streets_pl_number_7l.png Binary files differnew file mode 100644 index 0000000..9328d86 --- /dev/null +++ b/trafficlight/textures/streets_pl_number_7l.png diff --git a/trafficlight/textures/streets_pl_number_7r.png b/trafficlight/textures/streets_pl_number_7r.png Binary files differnew file mode 100644 index 0000000..444ce49 --- /dev/null +++ b/trafficlight/textures/streets_pl_number_7r.png diff --git a/trafficlight/textures/streets_pl_number_8l.png b/trafficlight/textures/streets_pl_number_8l.png Binary files differnew file mode 100644 index 0000000..9a78cd8 --- /dev/null +++ b/trafficlight/textures/streets_pl_number_8l.png diff --git a/trafficlight/textures/streets_pl_number_8r.png b/trafficlight/textures/streets_pl_number_8r.png Binary files differnew file mode 100644 index 0000000..727afad --- /dev/null +++ b/trafficlight/textures/streets_pl_number_8r.png diff --git a/trafficlight/textures/streets_pl_number_9l.png b/trafficlight/textures/streets_pl_number_9l.png Binary files differnew file mode 100644 index 0000000..4830e0f --- /dev/null +++ b/trafficlight/textures/streets_pl_number_9l.png diff --git a/trafficlight/textures/streets_pl_number_9r.png b/trafficlight/textures/streets_pl_number_9r.png Binary files differnew file mode 100644 index 0000000..dabea2a --- /dev/null +++ b/trafficlight/textures/streets_pl_number_9r.png diff --git a/trafficlight/textures/streets_pl_number_template.png b/trafficlight/textures/streets_pl_number_template.png Binary files differnew file mode 100644 index 0000000..41ae2f1 --- /dev/null +++ b/trafficlight/textures/streets_pl_number_template.png diff --git a/trafficlight/textures/streets_pl_walk.png b/trafficlight/textures/streets_pl_walk.png Binary files differindex 392f024..4a79e54 100644 --- a/trafficlight/textures/streets_pl_walk.png +++ b/trafficlight/textures/streets_pl_walk.png |