-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfile.lua
41 lines (36 loc) · 885 Bytes
/
file.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
require 'write'
love.filesystem.mkdir 'saves'
local modules = {map=map, graphics=graphics,
ui=ui, player=player, ai=ai, ships=ships,
physics=physics, mainmenu=mainmenu,
base=base, mission=mission,
diplomacy=diplomacy, help=help, conv=conv}
function savegame(filename)
local buildsave = {}
for key, mod in pairs(modules) do
buildsave[key] = {}
for k, v in pairs(mod) do
if mod.allowsave(k) then
buildsave[key][k] = v
end
end
end
-- now write buildsave to filename
f = love.filesystem.newFile('saves/'..filename)
f:open'w'
f:write(write_table(buildsave))
f:close()
end
function loadgame(filename)
local ok, chunk = pcall(love.filesystem.load, 'saves/'..filename)
if ok then
for key, mod in pairs(chunk()) do
for k, v in pairs(mod) do
modules[key][k] = v
end
end
hook.call('load_game')
else
-- display a distressing message?
end
end