blob: 97417ae16e977b5a8697fe06bab891bace5c9e0f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
-- advtrains to git exporter
require "lfs"
script_path = arg[0]:match("(.*/)")
minetest = {} -- hack around serializelib
minetest.get_modpath = function () return script_path.."serialize_lib" end
minetest.log = function() end
minetest.get_current_modname = function() end
dofile(script_path.."serialize_lib/init.lua") -- load serialize lib
function usage()
print("Usage: gitexporter.lua worldpath outpath")
end
if #arg < 2 then
print("too few arguments!")
usage()
return
end
inpath = arg[1]
base_path = arg[2]
function ensure_dir(path)
if not (lfs.attributes(path, "mode") == "directory") then
lfs.mkdir(path)
end
end
function env_path(env)
return base_path.."/"..env
end
function node_file(env, pos)
base = env_path(env).."/nodes"
ensure_dir(base)
return base.."/"..pos..".lua"
end
v4path = inpath.."/advtrains_atlatc.ls"
tb = {}
if lfs.attributes(v4path) then
tb = serialize_lib.read_table_from_file(v4path)
else
tb = dofile(inpath.."/advtrains_luaautomation")
end
ensure_dir(base_path)
for env, data in pairs(tb.envs) do
pth = env_path(env)
ensure_dir(pth)
f = io.open(pth.."/init_code.lua", "w")
f:write(data.init_code)
f:close()
end
for k, j in pairs(tb.active.nodes) do
f = io.open(node_file(j.env,k), "w")
if f then
f:write(j.code or "")
f:close()
end
end
|