From 61009bf00dc705077ca42d003e4c164d162f83ab Mon Sep 17 00:00:00 2001 From: Blockhead Date: Mon, 14 Sep 2020 19:59:15 +1000 Subject: Fix issues introduced by changes to switching The code I wrote worked only for my y-turnout and 3-way variants because it assumed the variant name == the switching state, which is obviously wrong for the default sw(l|r)(st|cr) variants. I have added a 'switchprefix' property to address this. --- advtrains/tracks.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/advtrains/tracks.lua b/advtrains/tracks.lua index 26d7b4b..39fdbd2 100644 --- a/advtrains/tracks.lua +++ b/advtrains/tracks.lua @@ -61,6 +61,7 @@ advtrains.ap.t_30deg_flat={ switchalt = "swlcr", switchmc = "on", switchst = "st", + switchprefix = "swl", }, swlcr={ conns = conns3(0,7,8), @@ -69,6 +70,7 @@ advtrains.ap.t_30deg_flat={ switchalt = "swlst", switchmc = "off", switchst = "cr", + switchprefix = "swl", }, swrst={ conns = conns3(0,8,9), @@ -77,6 +79,7 @@ advtrains.ap.t_30deg_flat={ switchalt = "swrcr", switchmc = "on", switchst = "st", + switchprefix = "swr", }, swrcr={ conns = conns3(0,9,8), @@ -85,6 +88,7 @@ advtrains.ap.t_30deg_flat={ switchalt = "swrst", switchmc = "off", switchst = "cr", + switchprefix = "swr", }, }, regtp=true, @@ -107,6 +111,7 @@ advtrains.ap.t_yturnout={ switchalt = "r", switchmc = "off", switchst = "l", + switchprefix = "", }, r={ conns = conns3(0,9,7), @@ -114,6 +119,7 @@ advtrains.ap.t_yturnout={ switchalt = "l", switchmc = "on", switchst = "r", + switchprefix = "", } }, regtp=true, @@ -127,23 +133,22 @@ advtrains.ap.t_s3way={ conns = { {c=0}, {c=7}, {c=8}, {c=9}, {["3"]=0} }, desc = "3-way turnout (left)", switchalt = "s", - --switchalt2 = , - --switchmc = "off", switchst="l", + switchprefix = "", }, s={ conns = { {c=0}, {c=8}, {c=7}, {c=9}, {["3"]=0} }, desc = "3-way turnout (straight)", switchalt ="r", - --switchmc = "on", switchst = "s", + switchprefix = "", }, r={ conns = { {c=0}, {c=9}, {c=8}, {c=7}, {["3"]=0} }, desc = "3-way turnout (right)", switchalt = "l", - switchst="r" - --switchmc = "off", + switchst="r", + switchprefix = "", } }, regtp=true, @@ -506,7 +511,7 @@ function advtrains.register_tracks(tracktype, def, preset) -- this code is only called from the internal setstate function, which -- ensures that it is safe to switch the turnout if newstate~=var.switchst then - advtrains.ndb.swap_node(pos, {name=def.nodename_prefix.."_"..newstate..rotation, param2=node.param2}) + advtrains.ndb.swap_node(pos, {name=def.nodename_prefix.."_"..(var.switchprefix or "")..newstate..rotation, param2=node.param2}) advtrains.invalidate_all_paths(pos) end end -- cgit v1.2.3