From 9f2bc5f4f17301fde5c93fc2d68158274bab9439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Thu, 2 Jul 2020 18:42:21 +0200 Subject: [PATCH] Handle tcb sides properly --- routes.lua | 59 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/routes.lua b/routes.lua index 25b4293..04b96fe 100755 --- a/routes.lua +++ b/routes.lua @@ -93,39 +93,46 @@ for k,v in pairs(advtrains.tcbs) do for j in (pos..","):gmatch("([^,]+),") do sp[#sp+1] = j end - local sigpos = sp[1]..","..-sp[3].." " - local routestr = {} - for i,r in pairs(routes) do - local pl = sigpos + local tcbsidestr = {} + local hasroutes = false + for s=1,2 do + local routestr = {} + local side = v[s] + local routes = side.routes or {} + local signame = side.signal_name or "" + local auto = nil - local tcbps = {} - -- svgfile:write("") - for ind,ps in ipairs(r) do - if ps.next then - local tcb = ps.next.p - -- print(minetest.serialize(ps.next)) - if tcb and tcb.x then - tcbps[#tcbps+1] = tcb.x..","..tcb.y..","..tcb.z - pl = pl.." "..tcb.x..","..-tcb.z + for i,r in pairs(routes) do + hasroutes = true + + local tcbps = {} + local tcbs = {} + -- svgfile:write("") + for ind,ps in ipairs(r) do + if ps.next then + local tcb = ps.next.p + -- print(minetest.serialize(ps.next)) + if tcb and tcb.x then + tcbps[#tcbps+1] = tcb.x..","..tcb.y..","..tcb.z + tcbs[#tcbs+1] = ps.next.s + end end end + local auto = '"auto": false' + if side.routeset and i == side.routeset and side.route_auto then + auto = '"auto": true' + end + if #tcbps > 0 then + routestr[#routestr+1] = '{ "name": "'..r.name..'",\n"endpoint": "'..tcbps[#tcbps]..'",\n"ars": '..ars_to_text(r.ars)..","..auto..', "endpoint_side": '..tcbs[#tcbs]..' }' + end end - - if #tcbps > 0 then - routestr[#routestr+1] = '{ "name": "'..r.name..'",\n"endpoint": "'..tcbps[#tcbps]..'",\n"ars": '..ars_to_text(r.ars)..' }' - end - color = "blue" - if r.ars and r.ars.default then - color = "green" - end - if pl~="" then - -- svgfile:write("") - end + tcbsidestr[#tcbsidestr+1] = '{ "routes": [ '..table.concat(routestr, ",\n")..' ], "signal_name": "'..signame..'"}' end - if #routestr > 0 then - tcbstr[#tcbstr+1] = '"'..pos..'": { "type" : "Feature", "geometry": { "type": "Point", "coordinates": [ '..sp[1]..","..sp[3]..']}, "properties" : { "pos": "'..pos..'", "routes" : [\n'..table.concat(routestr,",\n").."]}}" + if hasroutes then + tcbstr[#tcbstr+1] = '"'..pos..'": { "type" : "Feature", "geometry": { "type": "Point", "coordinates": [ '..sp[1]..","..sp[3]..']}, "properties" : { "pos": "'..pos..'", "sides" : [\n'..table.concat(tcbsidestr,",\n").."]}}" end end + jsonfile:write("{"..table.concat(tcbstr,",\n").."}") jsonfile:close()