From 9b2bcebc6f47380f8029147d04fc8954f506796e Mon Sep 17 00:00:00 2001 From: mleaf233 Date: Thu, 25 Jun 2026 14:23:17 +0800 Subject: [PATCH] Fix bosses_used compatibility on save load --- lovely/blind.toml | 15 +++++++++++++++ src/game_objects/blind.lua | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lovely/blind.toml b/lovely/blind.toml index dc56813bc..166209ab0 100644 --- a/lovely/blind.toml +++ b/lovely/blind.toml @@ -651,6 +651,21 @@ payload = ''' SMODS.reset_blind_choices(self.GAME.round_resets.blind_choices) ''' +# Restore bosses_used compatibility on loaded saves. +[[patches]] +[patches.pattern] +target = 'game.lua' +match_indent = true +position = 'after' +pattern = ''' +self.GAME = saveTable and saveTable.GAME or self:init_game_object() +''' +payload = ''' +if saveTable and SMODS.normalize_bosses_used_table then + self.GAME.bosses_used = SMODS.normalize_bosses_used_table(self.GAME.bosses_used) +end +''' + # Handle setting new blinds [[patches]] [patches.pattern] diff --git a/src/game_objects/blind.lua b/src/game_objects/blind.lua index 1790df71d..9c1840bf2 100644 --- a/src/game_objects/blind.lua +++ b/src/game_objects/blind.lua @@ -68,6 +68,38 @@ SMODS.Blinds.modifies_draw = { bl_serpent = true } +function SMODS.normalize_bosses_used_table(bosses_used) + local normalized = { boss = {}, small = {}, big = {} } + local typed_keys = { boss = true, small = true, big = true } + + if type(bosses_used) == 'table' then + for key, value in pairs(bosses_used) do + if typed_keys[key] and type(value) == 'table' then + for blind_key, count in pairs(value) do + normalized[key][blind_key] = count + end + elseif not typed_keys[key] and type(value) ~= 'table' then + normalized.boss[key] = value + end + end + end + + for key, blind in pairs(G.P_BLINDS or {}) do + if blind.boss and normalized.boss[key] == nil then normalized.boss[key] = 0 end + if blind.small and normalized.small[key] == nil then normalized.small[key] = 0 end + if blind.big and normalized.big[key] == nil then normalized.big[key] = 0 end + end + + return setmetatable(normalized, { + __index = function(t, key) + return t.boss[key] or t.big[key] or t.small[key] + end, + __newindex = function(t, key, value) + rawset(t.boss, key, value) + end + }) +end + function SMODS.add_boss_to_used_table(boss_key, type) if G.P_BLINDS[boss_key][type].allow_others then G.GAME.bosses_used[type][boss_key] = G.GAME.bosses_used[type][boss_key] + 1 @@ -112,4 +144,4 @@ function SMODS.reset_blind_choices(choices) for _, k in ipairs(G.GAME.round_resets.blind_order) do choices[k] = SMODS.get_new_blind(string.lower(k)) end -end \ No newline at end of file +end