2023-06-06 18:08:11 +02:00
|
|
|
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
|
|
|
|
|
2023-06-07 17:09:59 +02:00
|
|
|
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
|
|
|
|
|
2023-06-06 18:08:11 +02:00
|
|
|
return save
|
|
|
|
end
|
|
|
|
|
|
|
|
return savegen
|