diff options
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 50 |
1 files changed, 31 insertions, 19 deletions
@@ -85,7 +85,7 @@ function atdump(t, intend) end dofile("vector.lua") -dofile("serialize.lua") +local serialize = dofile("serialize.lua") dofile("helpers.lua") dofile("tracks.lua") dofile("track_defs.lua") @@ -96,7 +96,7 @@ dofile("nodedb.lua") function parse_args(argv) local i = 1 local no_trains = false - local datapath, mappath + local datapath, mappath, worldimage while i <= #argv do local a = argv[i] if (a == "-m") or (a == "--map-file") then @@ -109,32 +109,44 @@ function parse_args(argv) elseif (a == "-t") or (a == "--no-trains") then -- do not draw trains no_trains = true + elseif (a == "-w") or (a == "--world-image") then + -- overlay over world image + i = i+1 + if not argv[i] then + error(("missing filename after `%s'"):format(a)) + end + worldimage = argv[i] else datapath = a end + i = i + 1 end - return datapath, mappath, no_trains + return datapath, mappath, no_trains, worldimage end -datapath, mappath, no_trains = parse_args(arg) +datapath, mappath, no_trains, worldimage = parse_args(arg) -- Load saves -local file, err = io.open(datapath.."advtrains", "r") -local tbl = minetest.deserialize(file:read("*a")) +local tbl = serialize.read_from_file(datapath.."advtrains_core.ls") +--local file, err = io.open(datapath.."advtrains_trains", "r") +--local tbl = minetest.deserialize(file:read("*a")) if type(tbl) ~= "table" then - error("not a table") + error("Trains file: not a table") end -if tbl.version then - advtrains.trains = tbl.trains - if not mappath then - advtrains.ndb.load_data(tbl.ndb) - end - -else - error("Incompatible save format!") -end -file:close() +advtrains.trains = tbl.trains +--file:close() + +--ndb contains the defs, while ndb2 is the actual contents +dofile("nodedb.lua") +local file, err = io.open(datapath.."advtrains_ndb4.ls", "r") +--tbl = minetest.deserialize(file:read("*a")) +--if type(tbl) ~= "table" then + --error("Node database file: not a table") +--end +--advtrains.ndb.load_data(tbl) +advtrains.ndb.load_callback(file) +--file:close() -- open svg file @@ -160,13 +172,13 @@ else <circle cx="0" cy="0" r="5" stroke="red" stroke-width="1" /> ]]) end -if wimg then +if worldimage then local wimx = -(wimresx*wimscale/2) local wimy = -(wimresy*wimscale/2) local wimw = wimresx*wimscale local wimh = wimresy*wimscale - svgfile:write('<image xlink:href="world.png" x="'..wimx..'" y="'..wimy..'" height="'..wimh..'px" width="'..wimw..'px"/>') + svgfile:write('<image xlink:href="'..worldimage..'" x="'..wimx..'" y="'..wimy..'" height="'..wimh..'px" width="'..wimw..'px"/>') end local function writec(text) |