Handle tcb sides properly
This commit is contained in:
parent
2ba5a52fe2
commit
9f2bc5f4f1
35
routes.lua
35
routes.lua
@ -93,13 +93,21 @@ for k,v in pairs(advtrains.tcbs) do
|
|||||||
for j in (pos..","):gmatch("([^,]+),") do
|
for j in (pos..","):gmatch("([^,]+),") do
|
||||||
sp[#sp+1] = j
|
sp[#sp+1] = j
|
||||||
end
|
end
|
||||||
local sigpos = sp[1]..","..-sp[3].." "
|
|
||||||
|
|
||||||
|
local tcbsidestr = {}
|
||||||
|
local hasroutes = false
|
||||||
|
for s=1,2 do
|
||||||
local routestr = {}
|
local routestr = {}
|
||||||
|
local side = v[s]
|
||||||
|
local routes = side.routes or {}
|
||||||
|
local signame = side.signal_name or ""
|
||||||
|
local auto = nil
|
||||||
|
|
||||||
for i,r in pairs(routes) do
|
for i,r in pairs(routes) do
|
||||||
local pl = sigpos
|
hasroutes = true
|
||||||
|
|
||||||
local tcbps = {}
|
local tcbps = {}
|
||||||
|
local tcbs = {}
|
||||||
-- svgfile:write("<circle cx=\""..sp[1].."\" cy=\""..-sp[3].."\" r=\"3\" stroke=\"".."purple".."\" stroke-width=\"1\" fill=\"none\" />")
|
-- svgfile:write("<circle cx=\""..sp[1].."\" cy=\""..-sp[3].."\" r=\"3\" stroke=\"".."purple".."\" stroke-width=\"1\" fill=\"none\" />")
|
||||||
for ind,ps in ipairs(r) do
|
for ind,ps in ipairs(r) do
|
||||||
if ps.next then
|
if ps.next then
|
||||||
@ -107,25 +115,24 @@ for k,v in pairs(advtrains.tcbs) do
|
|||||||
-- print(minetest.serialize(ps.next))
|
-- print(minetest.serialize(ps.next))
|
||||||
if tcb and tcb.x then
|
if tcb and tcb.x then
|
||||||
tcbps[#tcbps+1] = tcb.x..","..tcb.y..","..tcb.z
|
tcbps[#tcbps+1] = tcb.x..","..tcb.y..","..tcb.z
|
||||||
pl = pl.." "..tcb.x..","..-tcb.z
|
tcbs[#tcbs+1] = ps.next.s
|
||||||
end
|
end
|
||||||
end
|
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
|
if #tcbps > 0 then
|
||||||
routestr[#routestr+1] = '{ "name": "'..r.name..'",\n"endpoint": "'..tcbps[#tcbps]..'",\n"ars": '..ars_to_text(r.ars)..' }'
|
routestr[#routestr+1] = '{ "name": "'..r.name..'",\n"endpoint": "'..tcbps[#tcbps]..'",\n"ars": '..ars_to_text(r.ars)..","..auto..', "endpoint_side": '..tcbs[#tcbs]..' }'
|
||||||
end
|
|
||||||
color = "blue"
|
|
||||||
if r.ars and r.ars.default then
|
|
||||||
color = "green"
|
|
||||||
end
|
|
||||||
if pl~="" then
|
|
||||||
-- svgfile:write("<polyline points=\""..pl.."\" fill=\"none\" stroke=\""..color.."\" />")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #routestr > 0 then
|
tcbsidestr[#tcbsidestr+1] = '{ "routes": [ '..table.concat(routestr, ",\n")..' ], "signal_name": "'..signame..'"}'
|
||||||
tcbstr[#tcbstr+1] = '"'..pos..'": { "type" : "Feature", "geometry": { "type": "Point", "coordinates": [ '..sp[1]..","..sp[3]..']}, "properties" : { "pos": "'..pos..'", "routes" : [\n'..table.concat(routestr,",\n").."]}}"
|
end
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
jsonfile:write("{"..table.concat(tcbstr,",\n").."}")
|
jsonfile:write("{"..table.concat(tcbstr,",\n").."}")
|
||||||
jsonfile:close()
|
jsonfile:close()
|
||||||
|
Loading…
Reference in New Issue
Block a user