Skip to content

Commit

Permalink
Util function for card pools, no_collection
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurelius7309 committed Dec 19, 2024
1 parent 0bf99d1 commit 47691b4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 230 deletions.
123 changes: 8 additions & 115 deletions lovely/ui.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ target = "functions/UI_definitions.lua"
pattern = '''local joker_options = {}'''
position = "before"
payload = '''
local joker_pool = {}
if G.ACTIVE_MOD_UI then
for _, v in ipairs(G.P_CENTER_POOLS.Joker) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then joker_pool[#joker_pool+1] = v end
end
else
joker_pool = G.P_CENTER_POOLS.Joker
end'''
local joker_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Joker)'''
match_indent = true

# create_UIBox_your_collection_jokers()
Expand Down Expand Up @@ -61,14 +54,7 @@ target = "functions/button_callbacks.lua"
pattern = '''for i = 1, 5 do'''
position = "before"
payload = '''
local joker_pool = {}
if G.ACTIVE_MOD_UI then
for _, v in ipairs(G.P_CENTER_POOLS.Joker) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then joker_pool[#joker_pool+1] = v end
end
else
joker_pool = G.P_CENTER_POOLS.Joker
end
local joker_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Joker)
'''
match_indent = true

Expand All @@ -89,15 +75,7 @@ target = "functions/UI_definitions.lua"
pattern = '''G.GAME.viewed_back = Back(G.P_CENTERS.b_red)'''
position = "at"
payload = '''
local deck_pool = {}
if G.ACTIVE_MOD_UI then
for _, v in ipairs(G.P_CENTER_POOLS.Back) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then deck_pool[#deck_pool+1] = v end
end
else
deck_pool = G.P_CENTER_POOLS.Back
end
local deck_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Back)
G.GAME.viewed_back = Back(G.ACTIVE_MOD_UI and deck_pool[1] or G.P_CENTERS.b_red)'''
match_indent = true

Expand Down Expand Up @@ -130,14 +108,7 @@ target = "functions/button_callbacks.lua"
pattern = '''G.GAME.viewed_back:change_to(G.P_CENTER_POOLS.Back[args.to_key])'''
position = "at"
payload = '''
local deck_pool = {}
if G.ACTIVE_MOD_UI then
for _, v in ipairs(G.P_CENTER_POOLS.Back) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then deck_pool[#deck_pool+1] = v end
end
else
deck_pool = G.P_CENTER_POOLS.Back
end
local deck_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Back)
G.GAME.viewed_back:change_to(deck_pool[args.to_key])'''
match_indent = true

Expand All @@ -149,14 +120,7 @@ target = "functions/UI_definitions.lua"
pattern = '''local booster_options = {}'''
position = "before"
payload = '''
local booster_pool = {}
if G.ACTIVE_MOD_UI then
for _, v in ipairs(G.P_CENTER_POOLS.Booster) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then booster_pool[#booster_pool+1] = v end
end
else
booster_pool = G.P_CENTER_POOLS.Booster
end'''
local booster_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Booster)'''
match_indent = true

# create_UIBox_your_collection_boosters()
Expand Down Expand Up @@ -188,14 +152,7 @@ target = "functions/button_callbacks.lua"
pattern = '''G.FUNCS.your_collection_booster_page = function(args)'''
position = "after"
payload = '''
local booster_pool = {}
if G.ACTIVE_MOD_UI then
for k, v in pairs(G.P_CENTER_POOLS.Booster) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then booster_pool[#booster_pool+1] = v end
end
else
booster_pool = G.P_CENTER_POOLS.Booster
end'''
local booster_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Booster)'''
match_indent = true

# G.FUNCS.your_collection_booster_page
Expand All @@ -215,14 +172,7 @@ target = "functions/UI_definitions.lua"
pattern = '''local voucher_options = {}'''
position = "before"
payload = '''
local voucher_pool = {}
if G.ACTIVE_MOD_UI then
for _, v in ipairs(G.P_CENTER_POOLS.Voucher) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then voucher_pool[#voucher_pool+1] = v end
end
else
voucher_pool = G.P_CENTER_POOLS.Voucher
end'''
local voucher_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Voucher)'''
match_indent = true

# create_UIBox_your_collection_vouchers()
Expand Down Expand Up @@ -264,14 +214,7 @@ target = "functions/button_callbacks.lua"
pattern = '''G.FUNCS.your_collection_voucher_page = function(args)'''
position = "after"
payload = '''
local voucher_pool = {}
if G.ACTIVE_MOD_UI then
for _, v in ipairs(G.P_CENTER_POOLS.Voucher) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then voucher_pool[#voucher_pool+1] = v end
end
else
voucher_pool = G.P_CENTER_POOLS.Voucher
end'''
local voucher_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Voucher)'''
match_indent = true

# G.FUNCS.your_collection_voucher_page
Expand All @@ -283,56 +226,6 @@ position = "at"
payload = '''local center = voucher_pool[i+(j-1)*4 + (8*(args.cycle_config.current_option - 1))]'''
match_indent = true

## Blinds Tab
# create_UIBox_your_collection_blinds()
[[patches]]
[patches.regex]
target = 'functions/UI_definitions.lua'
pattern = '''(?<indent>[\t ]*)local blind_matrix = \{(\n.*){6}'''
position = 'at'
payload = '''
local blind_matrix = {
{},{},{}, {}, {}, {}
}
local blind_tab = {}
if G.ACTIVE_MOD_UI then
for _, v in pairs(G.P_BLINDS) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then blind_tab[#blind_tab+1] = v end
end
else
for k, v in pairs(G.P_BLINDS) do
blind_tab[#blind_tab+1] = v
end
end'''
line_prepend = '$indent'

## Seal Tab
# create_UIBox_your_collection_seals()
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = '''for k, v in ipairs(G.P_CENTER_POOLS['Seal']) do'''
position = "at"
payload = '''
local seal_pool = {}
if G.ACTIVE_MOD_UI then
for _, v in pairs(G.P_CENTER_POOLS.Seal) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then seal_pool[#seal_pool+1] = v end
end
else
seal_pool = G.P_CENTER_POOLS.Seal
end
for k, v in ipairs(seal_pool) do'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = '''local t = create_UIBox_generic_options({ infotip = localize('ml_edition_seal_enhancement_explanation'), back_func = exit or 'your_collection', snap_back = true, contents = {'''
position = "at"
payload = '''local t = create_UIBox_generic_options({ infotip = localize('ml_edition_seal_enhancement_explanation'), back_func = G.ACTIVE_MOD_UI and "openModUI_"..G.ACTIVE_MOD_UI.id or exit or 'your_collection', snap_back = true, contents = {'''
match_indent = true

# create_UIBox_your_collection()
[[patches]]
[patches.regex]
Expand Down
17 changes: 9 additions & 8 deletions src/game_object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -931,14 +931,7 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
)
end

local consumable_pool = {}
if G.ACTIVE_MOD_UI then
for _, v in ipairs(G.P_CENTER_POOLS[self.key]) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then consumable_pool[#consumable_pool+1] = v end
end
else
consumable_pool = G.P_CENTER_POOLS[self.key]
end
local consumable_pool = SMODS.collection_pool(G.P_CENTER_POOLS[self.key])

local sum = 0
for j = 1, #G.your_collection do
Expand Down Expand Up @@ -2666,6 +2659,14 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
SMODS.process_loc_text(G.localization.descriptions.Other, self.key, self.loc_txt)
SMODS.process_loc_text(G.localization.misc.labels, self.key, self.loc_txt, 'label')
end,
register = function(self)
if self.registered then
sendWarnMessage(('Detected duplicate register call on object %s'):format(self.key), self.set)
return
end
SMODS.Sticker.super.register(self)
self.order = #self.obj_buffer
end,
inject = function(self)
self.sticker_sprite = Sprite(0, 0, G.CARD_W, G.CARD_H, G.ASSET_ATLAS[self.atlas], self.pos)
G.shared_stickers[self.key] = self.sticker_sprite
Expand Down
92 changes: 9 additions & 83 deletions src/overrides.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,9 @@ function create_UIBox_your_collection_blinds(exit)
)
end

local blind_tab = {}
for k, v in pairs(G.P_BLINDS) do
if not G.ACTIVE_MOD_UI or v.mod == G.ACTIVE_MOD_UI then
blind_tab[#blind_tab + 1] = v
end
end
local blind_tab = SMODS.collection_pool(G.P_BLINDS)
local blinds_amt = #blind_tab

table.sort(blind_tab, function(a, b)
return a.order < b.order
end)

local this_page = {}
for i, v in ipairs(blind_tab) do
if i > rows*cols*(page-1) and i <= rows*cols*page then
Expand Down Expand Up @@ -297,16 +288,7 @@ function G.FUNCS.your_collection_blinds_page(args)
local cols = 5
local rows = 6
local page = args.cycle_config.current_option
local blind_tab = {}
for k, v in pairs(G.P_BLINDS) do
if not G.ACTIVE_MOD_UI or v.mod == G.ACTIVE_MOD_UI then
blind_tab[#blind_tab + 1] = v
end
end

table.sort(blind_tab, function(a, b)
return a.order < b.order
end)
local blind_tab = SMODS.collection_pool(G.P_BLINDS)

local this_page = {}
for i, v in ipairs(blind_tab) do
Expand Down Expand Up @@ -413,24 +395,11 @@ function create_UIBox_your_collection_tags_content(page)
local tag_matrix = {}
local rows = 4
local cols = 6
local tag_tab = {}
local tag_pool = {}
if G.ACTIVE_MOD_UI then
for k, v in pairs(G.P_TAGS) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then tag_pool[k] = v end
end
else
tag_pool = G.P_TAGS
end
for k, v in pairs(tag_pool) do
tag_tab[#tag_tab + 1] = v
end
local tag_tab = SMODS.collection_pool(G.P_TAGS)
for i = 1, math.ceil(rows) do
table.insert(tag_matrix, {})
end

table.sort(tag_tab, function(a, b) return a.order < b.order end)

local tags_to_be_alerted = {}
local row, col = 1, 1
for k, v in ipairs(tag_tab) do
Expand Down Expand Up @@ -1217,14 +1186,7 @@ end
--#region editions
function create_UIBox_your_collection_editions(exit)
local deck_tables = {}
local edition_pool = {}
if G.ACTIVE_MOD_UI then
for _, v in pairs(G.P_CENTER_POOLS.Edition) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then edition_pool[#edition_pool+1] = v end
end
else
edition_pool = G.P_CENTER_POOLS.Edition
end
local edition_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Edition)
local rows, cols = (#edition_pool > 5 and 2 or 1), 5
local page = 0

Expand Down Expand Up @@ -1312,14 +1274,7 @@ G.FUNCS.your_collection_editions_page = function(args)
if not args or not args.cycle_config then
return
end
local edition_pool = {}
if G.ACTIVE_MOD_UI then
for _, v in ipairs(G.P_CENTER_POOLS.Edition) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then edition_pool[#edition_pool+1] = v end
end
else
edition_pool = G.P_CENTER_POOLS.Edition
end
local edition_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Edition)
local rows = (#edition_pool > 5 and 2 or 1)
local cols = 5
local page = args.cycle_config.current_option
Expand Down Expand Up @@ -1638,15 +1593,7 @@ function create_UIBox_your_collection_enhancements(exit)
local deck_tables = {}
local rows, cols = 2, 4
local page = 0
local enhancement_pool = {}
if G.ACTIVE_MOD_UI then
for _, v in ipairs(G.P_CENTER_POOLS.Enhanced) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then enhancement_pool[#enhancement_pool+1] = v end
end
else
enhancement_pool = G.P_CENTER_POOLS.Enhanced
end

local enhancement_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Enhanced)
G.your_collection = {}
for j = 1, rows do
G.your_collection[j] = CardArea(G.ROOM.T.x + 0.2 * G.ROOM.T.w / 2, G.ROOM.T.h, 4.25 * G.CARD_W, 1.03 * G.CARD_H,
Expand Down Expand Up @@ -1733,14 +1680,7 @@ G.FUNCS.your_collection_enhancements_page = function(args)
local rows = 2
local cols = 4
local page = args.cycle_config.current_option
local enhancement_pool = {}
if G.ACTIVE_MOD_UI then
for _, v in ipairs(G.P_CENTER_POOLS.Enhanced) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then enhancement_pool[#enhancement_pool+1] = v end
end
else
enhancement_pool = G.P_CENTER_POOLS.Enhanced
end
local enhancement_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Enhanced)
if page > math.ceil(#enhancement_pool / (rows * cols)) then
page = page - math.ceil(#enhancement_pool / (rows * cols))
end
Expand Down Expand Up @@ -1778,14 +1718,7 @@ end
--#region seals ui
function create_UIBox_your_collection_seals(exit)
local deck_tables = {}
local seal_pool = {}
if G.ACTIVE_MOD_UI then
for _, v in pairs(G.P_CENTER_POOLS.Seal) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then seal_pool[#seal_pool + 1] = v end
end
else
seal_pool = G.P_CENTER_POOLS.Seal
end
local seal_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Seal)
local rows, cols = (#seal_pool > 5 and 2 or 1), 5
local page = 0

Expand Down Expand Up @@ -1872,14 +1805,7 @@ G.FUNCS.your_collection_seals_page = function(args)
if not args or not args.cycle_config then
return
end
local seal_pool = {}
if G.ACTIVE_MOD_UI then
for _, v in pairs(G.P_CENTER_POOLS.Seal) do
if v.mod and G.ACTIVE_MOD_UI.id == v.mod.id then seal_pool[#seal_pool + 1] = v end
end
else
seal_pool = G.P_CENTER_POOLS.Seal
end
local seal_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Seal)
local rows, cols = (#seal_pool > 5 and 2 or 1), 5
local page = args.cycle_config.current_option
if page > math.ceil(#seal_pool / (rows * cols)) then
Expand Down
Loading

0 comments on commit 47691b4

Please sign in to comment.