Skip to content

Commit

Permalink
Added updating the Collection page progress when collecting items
Browse files Browse the repository at this point in the history
  • Loading branch information
wofsauge committed Jan 30, 2022
1 parent 4f0ad9c commit 507f4b7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
17 changes: 16 additions & 1 deletion eid_api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,21 @@ end

-- Returns true if an item needs to be collected for the collection page
function EID:requiredForCollectionPage(itemID)
if game:GetVictoryLap() > 0 or game:GetSeeds():IsCustomRun() or not EID.SaveGame or EID.Config["SaveGameNumber"] == 0 then return false end
if not EID.SaveGame or EID.Config["SaveGameNumber"] == 0 or game:GetVictoryLap() > 0 or game:GetSeeds():IsCustomRun() then return false end
return not EID.SaveGame[EID.Config["SaveGameNumber"]].ItemCollection[itemID]
end

-- Updates the item collection state of the players, based on the QueuedItem value.
-- TODO: also check for D100 / MissingNo Item collections
function EID:checkPlayersForMissingItems()
if not EID.SaveGame or EID.Config["SaveGameNumber"] == 0 or game:GetVictoryLap() > 0 or game:GetSeeds():IsCustomRun() then return end
if EID.GameUpdateCount % 5 ~= 0 then return end

for i = 0, game:GetNumPlayers() - 1 do
local player = Isaac.GetPlayer(i)
if player.QueuedItem.Item and EID.SaveGame[EID.Config["SaveGameNumber"]].ItemNeedsPickup[player.QueuedItem.Item.ID] then
table.insert(EID.CollectedItems, player.QueuedItem.Item.ID)
EID.SaveGame[EID.Config["SaveGameNumber"]].ItemNeedsPickup[player.QueuedItem.Item.ID] = nil
end
end
end
31 changes: 23 additions & 8 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ EID.itemConfig = Isaac.GetItemConfig()
EID.itemUnlockStates = {}
EID.CraneItemType = {}
EID.absorbedItems = {}
EID.CollectedItems = {}
local pathsChecked = {}
local altPathItemChecked = {}

Expand Down Expand Up @@ -823,7 +824,8 @@ EID.RecheckVoid = false

function EID:onGameUpdate()
EID.GameUpdateCount = EID.GameUpdateCount + 1

EID:checkPlayersForMissingItems()

if collSpawned then
collSpawned = false

Expand Down Expand Up @@ -946,6 +948,7 @@ local function onRender(t)
-- Increases by 60 per second, ignores pauses
EID.GameRenderCount = EID.GameRenderCount + 1
EID:resumeCoroutines()


EID.isDisplaying = false
EID:setPlayer()
Expand Down Expand Up @@ -1205,21 +1208,31 @@ EID:AddCallback(ModCallbacks.MC_POST_RENDER, onRender)
-- only save and load configs when using MCM. Otherwise Config file changes arent valid
if EID.MCMLoaded or REPENTANCE then
local json = require("json")
local configIgnoreList = {
["BagContent"] = true,
["BagFloorContent"] = true,
["CraneItemType"] = true,
["FlipItemPositions"] = true,
["AbsorbedItems"] = true,
["CollectedItems"] = true,
}
--------------------------------
--------Handle Savadata---------
--------------------------------
function OnGameStart(_,isSave)
--Loading Moddata--
local configIgnoreList = {
["BagContent"] = true,
["BagFloorContent"] = true,
["CraneItemType"] = true,
["FlipItemPositions"] = true,
["AbsorbedItems"] = true,
}

if EID:HasData() then
local savedEIDConfig = json.decode(Isaac.LoadModData(EID))

-- collection progress
EID.CollectedItems = savedEIDConfig["CollectedItems"] or {}
if EID.Config["SaveGameNumber"] > 0 then
for _, id in ipairs(EID.CollectedItems) do
EID.SaveGame[EID.Config["SaveGameNumber"]].ItemNeedsPickup[id] = nil
end
end

if REPENTANCE then
EID.BagItems = {}
EID.CraneItemType = {}
Expand Down Expand Up @@ -1305,6 +1318,8 @@ if EID.MCMLoaded or REPENTANCE then
end
EID.Config["FlipItemPositions"] = flipItemTable or {}
end
EID.Config["CollectedItems"] = EID.CollectedItems

EID.SaveData(EID, json.encode(EID.Config))
EID:hidePermanentText()
EID.itemUnlockStates[CollectibleType.COLLECTIBLE_CUBE_OF_MEAT] = nil
Expand Down

0 comments on commit 507f4b7

Please sign in to comment.