Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lovely/blind.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
34 changes: 33 additions & 1 deletion src/game_objects/blind.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
end