local save = {} local lunajson = API.load("ext/lunajson") save.data = {} save.path = Misc.episodePath()..string.match(Level.filename(), "(.+)%..+$")..".spdlvl" save.default = {} local function dataValidation(t) for k, v in ipairs(t) do if t[k].sectionsplit == nil then t[k].sectionsplit = {} end end return t end local function read_file(path) local file = io.open(path, "r") -- r read mode if not file then return nil end local content = file:read("*all") -- *a or *all reads the whole file file:close() return content end function save.save() local writefile = io.open(save.path, "w") if not writefile then return end writefile:write(lunajson.encode(save.data)) writefile:close() end function save.reset() save.data = table.clone(save.default) save.save() end function save.load() local savedata = read_file(save.path) if savedata == nil or savedata == "" then save.reset() else save.data = dataValidation(lunajson.decode(savedata)) end end -- Load settings! save.load() return save