55 lines
1.1 KiB
Lua
55 lines
1.1 KiB
Lua
local savegen = {}
|
|
|
|
function savegen:new()
|
|
|
|
local save = {}
|
|
|
|
save.settings = {}
|
|
save.settings.eid = true
|
|
save.settings.visual = true
|
|
save.settings.showonblind = false
|
|
save.settings.maxid = 732
|
|
|
|
save.seen = {}
|
|
for i=1, save.settings.maxid do
|
|
save.seen[i] = false
|
|
end
|
|
|
|
function save:touch(id)
|
|
self.seen[id] = true
|
|
end
|
|
|
|
function save:dump()
|
|
-- Returns a string representation of the save
|
|
-- Bool to symbol
|
|
local f = function(x) return (x and "1") or "0" end
|
|
local result = f(self.settings.eid)..f(self.settings.visual)..f(self.settings.showonblind)
|
|
for i=1, save.settings.maxid do
|
|
result = result..f(save.seen[i])
|
|
end
|
|
return result
|
|
end
|
|
|
|
function save:load(text)
|
|
-- Change attributes based on the text
|
|
-- Symbol to bool
|
|
local f = function(x, i)
|
|
return x:sub(i,i)=="1"
|
|
end
|
|
if (#text>=3) then
|
|
-- First 3 are the settings
|
|
self.settings.eid = f(text,1)
|
|
self.settings.visual = f(text,2)
|
|
self.settings.showonblind = f(text,3)
|
|
end
|
|
local offset = 3
|
|
for id=1, self.settings.maxid do
|
|
self.seen[id] = f(text,offset+id)
|
|
end
|
|
end
|
|
|
|
return save
|
|
end
|
|
|
|
return savegen
|