-
Notifications
You must be signed in to change notification settings - Fork 10
/
save.lua
61 lines (56 loc) · 1.56 KB
/
save.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function write_key_file() pcall(function()
local file = love.filesystem.newFile("keys.txt")
file:open("w")
file:write(json.encode(K))
file:close()
end) end
function read_key_file() pcall(function()
local K=K
local file = love.filesystem.newFile("keys.txt")
file:open("r")
local teh_json = file:read(file:getSize())
local user_conf = json.decode(teh_json)
file:close()
-- TODO: remove this later, it just converts the old format.
if #user_conf == 0 then
local new_conf = {}
for k,v in pairs(user_conf) do
new_conf[k:sub(3)] = v
end
user_conf = {new_conf, {}, {}, {}}
end
for k,v in ipairs(user_conf) do
K[k]=v
end
end) end
function write_conf_file() pcall(function()
local file = love.filesystem.newFile("conf.json")
file:open("w")
file:write(json.encode(config))
file:close()
end) end
function read_conf_file() pcall(function()
local file = love.filesystem.newFile("conf.json")
file:open("r")
local teh_json = file:read(file:getSize())
for k,v in pairs(json.decode(teh_json)) do
config[k] = v
end
file:close()
end) end
function read_replay_file() pcall(function()
local file = love.filesystem.newFile("replay.txt")
file:open("r")
local teh_json = file:read(file:getSize())
replay = json.decode(teh_json)
if type(replay.in_buf) == "table" then
replay.in_buf=table.concat(replay.in_buf)
write_replay_file()
end
end) end
function write_replay_file() pcall(function()
local file = love.filesystem.newFile("replay.txt")
file:open("w")
file:write(json.encode(replay))
file:close()
end) end