forked from ToxicFrog/kessler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sfsmerge.lua
47 lines (36 loc) · 1.26 KB
/
sfsmerge.lua
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
-- usage: sfsmerge <target> <merge1> [merge2 ...]
-- format of an SFS file:
-- SFS := {ATOM}
-- ATOM := COMMENT | VALUE | STRUCTURE
-- COMMENT := // .*
-- VALUE := name '=' value
-- STRUCTURE := capsname '{' SFS '}'
--
-- All we care about from the merged files are the VESSEL and CREW blocks.
-- We ignore elapsed time - the time in the master file overrides everything.
-- We care about crew only so that we don't end up with multiple rockets using the same crew,
-- or rockets using crew that are already dead or don't exist yet.
require "util.init"
local sfs = require "sfs"
function log(...)
io.stderr:write(table.concat(table.map({...}, tostring), "\t").."\n")
end
function main(...)
local argv = { ... }
assert(#argv >= 2, "Usage: sfsmerge <target file> <merge file 1> [merge file 2] ...")
backup(argv[1])
log("Loading "..argv[1])
local original = sfs.load(argv[1])
for i=2,#argv do
log("Merging in "..argv[i])
original:merge(sfs.load(argv[i]))
end
log("Writing merged save file...")
original:save(argv[1])
end
function backup(file)
local name = file.."."..os.date("%F@%H.%M.%S")..".bak"
log("Backing up "..file.." to "..name)
io.writefile(name, io.readfile(file))
end
return main(...)