From c1d5fb0e8ccc30e39919a910b30d5466a84a8464 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Fri, 26 Oct 2018 19:44:16 +0200 Subject: [PATCH] Add Interlocking Tool to inspect route locks --- advtrains_interlocking/init.lua | 1 + advtrains_interlocking/tcb_ts_ui.lua | 2 +- .../textures/at_il_tool.png | Bin 0 -> 337 bytes advtrains_interlocking/tool.lua | 66 ++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 advtrains_interlocking/textures/at_il_tool.png create mode 100644 advtrains_interlocking/tool.lua diff --git a/advtrains_interlocking/init.lua b/advtrains_interlocking/init.lua index d6625eb..1a0929d 100644 --- a/advtrains_interlocking/init.lua +++ b/advtrains_interlocking/init.lua @@ -12,6 +12,7 @@ dofile(modpath.."train_sections.lua") dofile(modpath.."route_prog.lua") dofile(modpath.."routesetting.lua") dofile(modpath.."tcb_ts_ui.lua") +dofile(modpath.."tool.lua") dofile(modpath.."lzb.lua") diff --git a/advtrains_interlocking/tcb_ts_ui.lua b/advtrains_interlocking/tcb_ts_ui.lua index a205165..450c756 100644 --- a/advtrains_interlocking/tcb_ts_ui.lua +++ b/advtrains_interlocking/tcb_ts_ui.lua @@ -635,7 +635,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) advtrains.interlocking.visualize_route(sigd, tcbs.routes[sel_rte], "disp_"..t) minetest.after(10, function() advtrains.interlocking.clear_visu_context("disp_"..t) end) end - if fields.renroute and hasprivs then + if fields.editroute and hasprivs then local rte = tcbs.routes[sel_rte] minetest.show_formspec(pname, formname.."_renroute_"..sel_rte, "field[name;Enter new route name;"..rte.name.."]") return diff --git a/advtrains_interlocking/textures/at_il_tool.png b/advtrains_interlocking/textures/at_il_tool.png new file mode 100644 index 0000000000000000000000000000000000000000..f6ce1cc7f908354a8e3eeba940f3da14d261c815 GIT binary patch literal 337 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPdmy{qU|Guji-T;N}dAc};Se!mP*)Z#{fr!I=5oPwt zK^!F>d=nHUZ?6n+;yL+D=ict`278_TCm1@j@ymKY*K6b1)zBWbY;E9`rBis!rfuI7 z`hV}kdX*1PuG#iAnr>j+*J%4e>cRQLoZn-Dd>PG^qP&hwej~U;f2CUGTGzPj$e^M){ql546qMex2~OSWucc_qN~VD}P=0{QS>-Orpnd e?)05Db&Ot-kr@?R-Bf`-W$<+Mb6Mw<&;$V47KCB| literal 0 HcmV?d00001 diff --git a/advtrains_interlocking/tool.lua b/advtrains_interlocking/tool.lua new file mode 100644 index 0000000..5d38b3a --- /dev/null +++ b/advtrains_interlocking/tool.lua @@ -0,0 +1,66 @@ +-- tool.lua +-- Interlocking tool + +local ilrs = advtrains.interlocking.route + +minetest.register_craftitem("advtrains_interlocking:tool",{ + description = "Interlocking tool\nright-click turnouts to inspect route locks", + groups = {cracky=1}, -- key=name, value=rating; rating=1..3. + inventory_image = "at_il_tool.png", + wield_image = "at_il_tool.png", + stack_max = 1, + on_place = function(itemstack, placer, pointed_thing) + local pname = placer:get_player_name() + if not pname then + return + end + if not minetest.check_player_privs(pname, {interlocking=true}) then + minetest.chat_send_player(pname, "Insufficient privileges to use this!") + return + end + if pointed_thing.type=="node" then + local pos=pointed_thing.under + if advtrains.is_passive(pos) then + local form = "size[7,5]label[0.5,0.5;Route lock inspector]" + local pts = minetest.pos_to_string(pos) + + local rtl = ilrs.has_route_lock(pts) + + if rtl then + form = form.."label[0.5,1;Route locks currently put:\n"..rtl.."]" + form = form.."button_exit[0.5,3.5; 5,1;clear;Clear]" + else + form = form.."label[0.5,1;No route locks set]" + form = form.."button_exit[0.5,3.5; 5,1;emplace;Emplace manual lock]" + end + + minetest.show_formspec(pname, "at_il_rtool_"..pts, form) + else + minetest.chat_send_player(pname, "Cannot use this here.") + return + end + end + end, +}) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + local pname = player:get_player_name() + if not minetest.check_player_privs(pname, "interlocking") then + return + end + local pos + local pts = string.match(formname, "^at_il_rtool_(.+)$") + if pts then + pos = minetest.string_to_pos(pts) + end + if pos then + if advtrains.is_passive(pos) then + if fields.clear then + ilrs.remove_route_locks(pts) + end + if fields.emplace then + ilrs.add_manual_route_lock(pts, "Manual lock ("..pname..")") + end + end + end +end)