Skip to content

Commit

Permalink
Declutter collection UI code
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurelius7309 committed Dec 28, 2024
1 parent 8f494f8 commit 1cc5381
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 796 deletions.
179 changes: 1 addition & 178 deletions lovely/ui.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,6 @@ priority = 0

### Addition Tab

## Jokers tab
# create_UIBox_your_collection_jokers()
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = '''local joker_options = {}'''
position = "before"
payload = '''
local joker_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Joker)'''
match_indent = true

# create_UIBox_your_collection_jokers()
[[patches]]
[patches.regex]
target = 'functions/UI_definitions.lua'
pattern = '''(?<indent>[\t ]*)for i = 1, math\.ceil\(#G\.P_CENTER_POOLS\.Joker\/\(5\*#G\.your_collection\)\) do\n[\s\S]{4}table\.insert\(joker_options, localize\('k_page'\)..' '..tostring\(i\)..'\/'..tostring\(math\.ceil\(#G\.P_CENTER_POOLS\.Joker\/\(5\*#G\.your_collection\)\)\)\)'''
position = 'at'
payload = '''
for i = 1, math.ceil(#joker_pool/(5*#G.your_collection)) do
table.insert(joker_options, localize('k_page')..' '..tostring(i)..'/'..tostring(math.ceil(#joker_pool/(5*#G.your_collection))))'''
line_prepend = '$indent'

# create_UIBox_your_collection_jokers()
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = '''local center = G.P_CENTER_POOLS["Joker"][i+(j-1)*5]'''
position = "at"
payload = '''
local center = joker_pool[i+(j-1)*5]
if not center then break end'''
match_indent = true

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

# G.FUNCS.your_collections_joker_page
[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = '''for i = 1, 5 do'''
position = "before"
payload = '''
local joker_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Joker)
'''
match_indent = true

# G.FUNCS.your_collection_joker_page
[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = '''local center = G.P_CENTER_POOLS["Joker"][i+(j-1)*5 + (5*#G.your_collection*(args.cycle_config.current_option - 1))]'''
position = "at"
payload = '''local center = joker_pool[i+(j-1)*5 + (5*#G.your_collection*(args.cycle_config.current_option - 1))]'''
match_indent = true

## Decks tab
# create_UIBox_your_collection_decks()
[[patches]]
Expand All @@ -91,8 +29,7 @@ for k, v in ipairs(deck_pool) do
end'''
line_prepend = '$indent'

## Note: This covers Decks, Boosters, and Tags
# create_UIBox_your_collection_decks() and create_UIBox_your_collection_boosters() and create_UIBox_your_collection_tags()
# create_UIBox_your_collection_decks()
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
Expand All @@ -112,120 +49,6 @@ 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

## Boosters Page
# create_UIBox_your_collection_boosters()
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = '''local booster_options = {}'''
position = "before"
payload = '''
local booster_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Booster)'''
match_indent = true

# create_UIBox_your_collection_boosters()
[[patches]]
[patches.regex]
target = 'functions/UI_definitions.lua'
pattern = '''(?<indent>[\t ]*)for i = 1, math\.ceil\(#G\.P_CENTER_POOLS\.Booster\/8\) do\n[\s\S]{4}table\.insert\(booster_options, localize\('k_page'\)..' '..tostring\(i\)..'\/'..tostring\(math\.ceil\(#G\.P_CENTER_POOLS\.Booster\/8\)\)\)'''
position = 'at'
payload = '''
for i = 1, math.ceil(#booster_pool/8) do
table.insert(booster_options, localize('k_page')..' '..tostring(i)..'/'..tostring(math.ceil(#booster_pool/8)))'''
line_prepend = '$indent'

# create_UIBox_your_collection_boosters()
[[patches]]
[patches.pattern]
target = 'functions/UI_definitions.lua'
pattern = '''local center = G.P_CENTER_POOLS["Booster"][i+(j-1)*4]'''
position = 'at'
payload = '''
local center = booster_pool[i+(j-1)*4]
if not center then break end'''
match_indent = true

# G.FUNCS.your_collection_booster_page
[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = '''G.FUNCS.your_collection_booster_page = function(args)'''
position = "after"
payload = '''
local booster_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Booster)'''
match_indent = true

# G.FUNCS.your_collection_booster_page
[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = '''local center = G.P_CENTER_POOLS["Booster"][i+(j-1)*4 + (8*(args.cycle_config.current_option - 1))]'''
position = "at"
payload = '''local center = booster_pool[i+(j-1)*4 + (8*(args.cycle_config.current_option - 1))]'''
match_indent = true

## Voucher Tabs
# create_UIBox_your_collection_vouchers()
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = '''local voucher_options = {}'''
position = "before"
payload = '''
local voucher_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Voucher)'''
match_indent = true

# create_UIBox_your_collection_vouchers()
[[patches]]
[patches.regex]
target = 'functions/UI_definitions.lua'
pattern = '''(?<indent>[\t ]*)for i = 1, math\.ceil\(#G\.P_CENTER_POOLS\.Voucher\/\(4\*#G\.your_collection\)\) do\n[\s\S]{4}table\.insert\(voucher_options, localize\('k_page'\)..' '..tostring\(i\)..'\/'..tostring\(math\.ceil\(#G\.P_CENTER_POOLS\.Voucher\/\(4\*#G\.your_collection\)\)\)\)'''
position = 'at'
payload = '''
for i = 1, math.ceil(#voucher_pool/(4*#G.your_collection)) do
table.insert(voucher_options, localize('k_page')..' '..tostring(i)..'/'..tostring(math.ceil(#voucher_pool/(4*#G.your_collection))))'''
line_prepend = '$indent'

# create_UIBox_your_collection_boosters()
[[patches]]
[patches.pattern]
target = 'functions/UI_definitions.lua'
pattern = '''local center = G.P_CENTER_POOLS["Voucher"][i+(j-1)*4]'''
position = 'at'
payload = '''
local center = voucher_pool[i+(j-1)*4]
if not center then break end'''
match_indent = true

## Note: This covers Blinds and Vouchers
# create_UIBox_your_collection_vouchers() and create_UIBox_your_collection_blinds()
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = '''local t = create_UIBox_generic_options({ back_func = exit or 'your_collection', contents = {'''
position = "at"
payload = '''local t = create_UIBox_generic_options({ back_func = G.ACTIVE_MOD_UI and "openModUI_"..G.ACTIVE_MOD_UI.id or exit or 'your_collection', contents = {'''
match_indent = true

# G.FUNCS.your_collection_voucher_page
[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = '''G.FUNCS.your_collection_voucher_page = function(args)'''
position = "after"
payload = '''
local voucher_pool = SMODS.collection_pool(G.P_CENTER_POOLS.Voucher)'''
match_indent = true

# G.FUNCS.your_collection_voucher_page
[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = '''local center = G.P_CENTER_POOLS["Voucher"][i+(j-1)*4 + (8*(args.cycle_config.current_option - 1))]'''
position = "at"
payload = '''local center = voucher_pool[i+(j-1)*4 + (8*(args.cycle_config.current_option - 1))]'''
match_indent = true

# create_UIBox_your_collection()
[[patches]]
[patches.regex]
Expand Down
108 changes: 3 additions & 105 deletions src/game_object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -913,75 +913,11 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
prefix_config = { key = false },
collection_rows = { 6, 6 },
create_UIBox_your_collection = function(self)
local deck_tables = {}

G.your_collection = {}
for j = 1, #self.collection_rows do
G.your_collection[j] = CardArea(
G.ROOM.T.x + 0.2 * G.ROOM.T.w / 2, G.ROOM.T.h,
(self.collection_rows[j] + 0.25) * G.CARD_W,
1 * G.CARD_H,
{ card_limit = self.collection_rows[j], type = 'title', highlight_limit = 0, collection = true })
table.insert(deck_tables,
{
n = G.UIT.R,
config = { align = "cm", padding = 0, no_fill = true },
nodes = {
{ n = G.UIT.O, config = { object = G.your_collection[j] } }
}
}
)
end

local consumable_pool = SMODS.collection_pool(G.P_CENTER_POOLS[self.key])

local sum = 0
for j = 1, #G.your_collection do
for i = 1, self.collection_rows[j] do
sum = sum + 1
local center = consumable_pool[sum]
if not center then break end
local card = Card(G.your_collection[j].T.x + G.your_collection[j].T.w / 2, G.your_collection[j].T.y,
G.CARD_W, G.CARD_H, nil, center)
card:start_materialize(nil, i > 1 or j > 1)
G.your_collection[j]:emplace(card)
end
end

local center_options = {}
for i = 1, math.ceil(#consumable_pool / sum) do
table.insert(center_options,
localize('k_page') ..
' ' .. tostring(i) .. '/' .. tostring(math.ceil(#consumable_pool / sum)))
end

INIT_COLLECTION_CARD_ALERTS()
local option_nodes = { create_option_cycle({
options = center_options,
w = 4.5,
cycle_shoulders = true,
opt_callback = 'your_collection_' .. string.lower(self.key) .. '_page',
focus_args = { snap_to = true, nav = 'wide' },
current_option = 1,
colour = G.C.RED,
no_pips = true
}) }
local type_buf = {}
if G.ACTIVE_MOD_UI then
for _, v in ipairs(SMODS.ConsumableType.ctype_buffer) do
if modsCollectionTally(G.P_CENTER_POOLS[v]).of > 0 then type_buf[#type_buf + 1] = v end
end
else
type_buf = SMODS.ConsumableType.ctype_buffer
for _, v in ipairs(SMODS.ConsumableType.ctype_buffer) do
if not v.no_collection and (not G.ACTIVE_MOD_UI or modsCollectionTally(G.P_CENTER_POOLS[v]).of > 0) then type_buf[#type_buf + 1] = v end
end
local t = create_UIBox_generic_options({
back_func = #type_buf>3 and 'your_collection_consumables' or G.ACTIVE_MOD_UI and "openModUI_"..G.ACTIVE_MOD_UI.id or 'your_collection',
contents = {
{ n = G.UIT.R, config = { align = "cm", minw = 2.5, padding = 0.1, r = 0.1, colour = G.C.BLACK, emboss = 0.05 }, nodes = deck_tables },
{ n = G.UIT.R, config = { align = "cm", padding = 0 }, nodes = option_nodes },
}
})
return t
return SMODS.card_collection_UIBox(G.P_CENTER_POOLS[self.key], self.collection_rows, { back_func = #type_buf>3 and 'your_collection_consumables' or nil })
end,
register = function(self)
SMODS.ConsumableType.super.register(self)
Expand All @@ -1001,44 +937,6 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
definition = self:create_UIBox_your_collection(),
}
end
G.FUNCS['your_collection_' .. string.lower(self.key) .. '_page'] = function(args)
if not args or not args.cycle_config then return end
for j = 1, #G.your_collection do
for i = #G.your_collection[j].cards, 1, -1 do
local c = G.your_collection[j]:remove_card(G.your_collection[j].cards[i])
c:remove()
c = nil
end
end
local sum = 0
for j = 1, #G.your_collection do
sum = sum + self.collection_rows[j]
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

sum = sum * (args.cycle_config.current_option - 1)
for j = 1, #G.your_collection do
for i = 1, self.collection_rows[j] do
sum = sum + 1
local center = consumable_pool[sum]
if not center then break end
local card = Card(G.your_collection[j].T.x + G.your_collection[j].T.w / 2,
G.your_collection[j].T.y, G
.CARD_W, G.CARD_H, G.P_CARDS.empty, center)
card:start_materialize(nil, i > 1 or j > 1)
G.your_collection[j]:emplace(card)
end
end
INIT_COLLECTION_CARD_ALERTS()
end
end,
process_loc_text = function(self)
if not next(self.loc_txt) then return end
Expand Down
Loading

0 comments on commit 1cc5381

Please sign in to comment.