diff --git a/main.lua b/main.lua index 0e2f9b7..399e859 100644 --- a/main.lua +++ b/main.lua @@ -1,12 +1,16 @@ local modname = "DeadGod Helper" local mod = RegisterMod(modname, 1) -local json = require("json") local math = require("math") mod.print = Isaac.ConsoleOutput mod.game = Game() local save = include("save"):new() if mod:HasData() then - save = json.decode(mod:LoadData()) + save:load(mod:LoadData()) + local c = 0 + for i,v in ipairs(save.seen) do + if v then c = c+1 end + end + mod.print(modname.." Loaded, "..c.." items seen\n") end mod.font = Font() @@ -30,7 +34,8 @@ function mod.registerTouched(id) end -- Save - mod:SaveData(json.encode(save)) + mod:RemoveData() + mod:SaveData(save:dump()) end -- Used to check if EID's description should be modified @@ -64,10 +69,10 @@ function mod:update() if player:GetCollectibleNum(data._deadgodlastid)>data._deadgodlastcount then -- Have it on me -- Then I just picked it up, yay mod.registerTouched(data._deadgodlastid) + mod.print("> "..tostring(data._deadgodlastid).."\n") data._deadgodlastid = 0 data._deadgodlastcount = 0 - end - end + end end end if item and item:IsCollectible() then data._deadgodlastid = item.ID @@ -88,6 +93,13 @@ function mod:PickupDrawCallback(pickupEntity, _) end end +function mod:preGameExit() + mod:RemoveData() + mod:SaveData(save:dump()) +end + +mod:AddCallback(ModCallbacks.MC_PRE_GAME_EXIT, mod.preGameExit) + mod:AddCallback(ModCallbacks.MC_POST_UPDATE, mod.update) mod:AddCallback(ModCallbacks.MC_POST_PICKUP_RENDER, mod.PickupDrawCallback) diff --git a/metadata.xml b/metadata.xml index 85a278f..56d8559 100644 --- a/metadata.xml +++ b/metadata.xml @@ -4,7 +4,7 @@ deadgod helper 2985754961 - 1.1 + 1.3 Private diff --git a/save.lua b/save.lua index caf45a1..c6ee6be 100644 --- a/save.lua +++ b/save.lua @@ -19,6 +19,35 @@ function savegen:new() 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 diff --git a/workshop/deadgodhelpericon.png b/workshop/deadgodhelpericon.png index 45a6384..3de6067 100644 Binary files a/workshop/deadgodhelpericon.png and b/workshop/deadgodhelpericon.png differ