Lighter save system
This commit is contained in:
parent
da29df87d2
commit
a8a0d6a7a7
22
main.lua
22
main.lua
@ -1,12 +1,16 @@
|
|||||||
local modname = "DeadGod Helper"
|
local modname = "DeadGod Helper"
|
||||||
local mod = RegisterMod(modname, 1)
|
local mod = RegisterMod(modname, 1)
|
||||||
local json = require("json")
|
|
||||||
local math = require("math")
|
local math = require("math")
|
||||||
mod.print = Isaac.ConsoleOutput
|
mod.print = Isaac.ConsoleOutput
|
||||||
mod.game = Game()
|
mod.game = Game()
|
||||||
local save = include("save"):new()
|
local save = include("save"):new()
|
||||||
if mod:HasData() then
|
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
|
end
|
||||||
|
|
||||||
mod.font = Font()
|
mod.font = Font()
|
||||||
@ -30,7 +34,8 @@ function mod.registerTouched(id)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Save
|
-- Save
|
||||||
mod:SaveData(json.encode(save))
|
mod:RemoveData()
|
||||||
|
mod:SaveData(save:dump())
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Used to check if EID's description should be modified
|
-- 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
|
if player:GetCollectibleNum(data._deadgodlastid)>data._deadgodlastcount then -- Have it on me
|
||||||
-- Then I just picked it up, yay
|
-- Then I just picked it up, yay
|
||||||
mod.registerTouched(data._deadgodlastid)
|
mod.registerTouched(data._deadgodlastid)
|
||||||
|
mod.print("> "..tostring(data._deadgodlastid).."\n")
|
||||||
data._deadgodlastid = 0
|
data._deadgodlastid = 0
|
||||||
data._deadgodlastcount = 0
|
data._deadgodlastcount = 0
|
||||||
end
|
end end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if item and item:IsCollectible() then
|
if item and item:IsCollectible() then
|
||||||
data._deadgodlastid = item.ID
|
data._deadgodlastid = item.ID
|
||||||
@ -88,6 +93,13 @@ function mod:PickupDrawCallback(pickupEntity, _)
|
|||||||
end
|
end
|
||||||
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_UPDATE, mod.update)
|
||||||
mod:AddCallback(ModCallbacks.MC_POST_PICKUP_RENDER, mod.PickupDrawCallback)
|
mod:AddCallback(ModCallbacks.MC_POST_PICKUP_RENDER, mod.PickupDrawCallback)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<directory>deadgod helper</directory>
|
<directory>deadgod helper</directory>
|
||||||
<id>2985754961</id>
|
<id>2985754961</id>
|
||||||
<description></description>
|
<description></description>
|
||||||
<version>1.1</version>
|
<version>1.3</version>
|
||||||
<visibility>Private</visibility>
|
<visibility>Private</visibility>
|
||||||
<tag id="Items"/>
|
<tag id="Items"/>
|
||||||
<tag id="Graphics"/>
|
<tag id="Graphics"/>
|
||||||
|
29
save.lua
29
save.lua
@ -19,6 +19,35 @@ function savegen:new()
|
|||||||
self.seen[id] = true
|
self.seen[id] = true
|
||||||
end
|
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
|
return save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 10 KiB |
Loading…
Reference in New Issue
Block a user