From 89b48e9a9af5be67e0c95840db30aacb43c7990f Mon Sep 17 00:00:00 2001 From: Singularis Date: Sat, 23 Nov 2024 20:44:12 +0100 Subject: [advtrains] přidána pomocná funkce advtrains.after_place_signal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - [advtrains_interlocking] výchozí názvy úseku a signalizace již neobsahují anglická slova - [advtrains_signals_ks] návěsti a návěstidla jsou nově po umístění orientována podle pohledu - [advtrains_signals_ks] oprava chyby, která způsobila, že se v paletě přemětů objevily všechny varianty rychlostní návěsti --- advtrains/helpers.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'advtrains/helpers.lua') diff --git a/advtrains/helpers.lua b/advtrains/helpers.lua index cf890ca..bfbcd0c 100644 --- a/advtrains/helpers.lua +++ b/advtrains/helpers.lua @@ -470,3 +470,43 @@ else end end end + +local variants = { + {"0", 0}, + {"30", 0}, + {"45", 0}, + {"60", 0}, + {"0", 1}, + {"30", 1}, + {"45", 1}, + {"60", 1}, + {"0", 2}, + {"30", 2}, + {"45", 2}, + {"60", 2}, + {"0", 3}, + {"30", 3}, + {"45", 3}, + {"60", 3}, + {"0", 0}, + {"30", 0}, + {"45", 0}, + {"60", 0}, +} + +function advtrains.after_place_signal(pos, placer, itemstack, pointed_thing) + if not minetest.is_player(placer) then return end + local name = itemstack:get_name() + if not name:match("_0$") then return end + local rn = minetest.registered_nodes + local prefix = name:sub(1, -2) + if not (rn[prefix.."30"] and rn[prefix.."45"] and rn[prefix.."60"]) then return end + local variant = math.floor(placer:get_look_horizontal() * -8 / math.pi + 16.5) + local n = variants[variant + 1] + if n == nil then return end + local node = minetest.get_node(pos) + if node.name ~= name then return end + node.name = prefix..n[1] + node.param2 = n[2] + minetest.swap_node(pos, node) +end -- cgit v1.2.3