summaryrefslogtreecommitdiff
path: root/gitexporter.lua
blob: 27384e9ca7f026e5c7443b603320cac12fc39b0c (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
-- 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



tb = serialize_lib.read_table_from_file(inpath.."/advtrains_atlatc.ls")


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)
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 "")
	end
end