Skip to content

Commit 5c9999e

Browse files
authored
Changes to badge colour handling (#1219)
1 parent ab656a6 commit 5c9999e

File tree

9 files changed

+68
-5
lines changed

9 files changed

+68
-5
lines changed

lovely/edition.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pattern = 'return G.BADGE_COL[key] or {1, 0, 0, 1}'
9393
position = 'before'
9494
match_indent = true
9595
payload = '''
96+
if G.BADGE_COL[key] then return G.BADGE_COL[key] end
9697
for _, v in ipairs(G.P_CENTER_POOLS.Edition) do
9798
G.BADGE_COL[v.key:sub(3)] = v.badge_colour
9899
end'''

lovely/ui.toml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ target = 'functions/UI_definitions.lua'
294294
pattern = 'local card_type_colour = get_type_colour(card.config.center or card.config, card)'
295295
position = 'after'
296296
match_indent = true
297-
payload = 'local card_type_text_colour = (AUT.card_type and SMODS.ConsumableTypes[AUT.card_type] and SMODS.ConsumableTypes[AUT.card_type].text_colour) or G.C.UI.TEXT_LIGHT'
297+
payload = "local card_type_text_colour = SMODS.get_card_type_text_colour(AUT.card_type, card.config.center or card.config, card)"
298298

299299
# G.UIDEF.card_h_popup():
300300
# pass "card_type_text_colour" variable to create_badge() when creating the badge for a card type
@@ -306,6 +306,26 @@ position = 'at'
306306
match_indent = true
307307
payload = "badges[#badges + 1] = create_badge(((card.ability.name == 'Pluto' or card.ability.name == 'Ceres' or card.ability.name == 'Eris') and localize('k_dwarf_planet')) or (card.ability.name == 'Planet X' and localize('k_planet_q') or card_type), card_type_colour, card_type_text_colour, 1.2)"
308308

309+
# G.UIDEF.card_h_popup():
310+
# pass text colour when creating other badges
311+
[[patches]]
312+
[patches.pattern]
313+
target = 'functions/UI_definitions.lua'
314+
pattern = 'badges[#badges + 1] = create_badge(localize(v, "labels"), get_badge_colour(v))'
315+
position = 'at'
316+
match_indent = true
317+
payload = 'badges[#badges + 1] = create_badge(localize(v, "labels"), get_badge_colour(v), SMODS.get_badge_text_colour(v))'
318+
319+
# get_type_colour:
320+
# get badge colour from centers
321+
[[patches]]
322+
[patches.pattern]
323+
target = 'functions/common_events.lua'
324+
pattern = "(_c.set == 'Joker' and G.C.RARITY[_c.rarity]) or "
325+
position = 'before'
326+
match_indent = true
327+
payload = "_c.badge_colour or"
328+
309329
# Fixing description error when info_queue has multi-box descriptions.
310330

311331
[[patches]]

lsp_def/classes/center.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
---@field eternal_compat? boolean Sets whether the center can have "Eternal" sticker.
1818
---@field perishable_compat? boolean Sets whether the center can have "Perishable" sticker.
1919
---@field display_size? table|{w: integer, h: integer} Changes the display size of card.
20-
---@field pixel_size? table|{w: integer, h: integer} Change the size of the sprite drawn onto the card.
20+
---@field pixel_size? table|{w: integer, h: integer} Change the size of the sprite drawn onto the card.
21+
---@field badge_text_colour? table Colour of the label for the badge (supersedes Rarities and ConsumableTypes).
22+
---@field badge_colour? table Colour of the badge (supersedes Rarities and ConsumableTypes).
2123
---@field __call? fun(self: SMODS.Center|table, o: SMODS.Center|table): nil|table|SMODS.Center
2224
---@field extend? fun(self: SMODS.Center|table, o: SMODS.Center|table): table Primary method of creating a class.
2325
---@field check_duplicate_register? fun(self: SMODS.Center|table): boolean? Ensures objects already registered will not register.

lsp_def/classes/edition.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
---@field in_shop? boolean Sets if the Edition spawns naturally in the shop.
1111
---@field weight? number The weight of the Edition.
1212
---@field extra_cost? number Extra cost applied to cards in the shop with this Edition.
13-
---@field apply_to_float? boolean Sets if the shader is drawn on floating sprites.
13+
---@field apply_to_float? boolean Sets if the shader is drawn on floating sprites.
14+
---@field text_colour? table Colour of the label for the badge.
1415
---@field badge_colour? table HEX color of the Edition's badge
1516
---@field sound? table|{sound: string, per?: number, vol?: number} Used to set a custom sound when the Edition is applied.
1617
---@field disable_shadow? boolean Sets if the shadow is drawn under the card with this Edition.

lsp_def/classes/rarity.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
---@field loc_txt? table|{name: string} Contains strings used for displaying text related to this object.
77
---@field super? SMODS.GameObject|table Parent class.
88
---@field pools? table Table with a list of ObjectTypes keys this rarity should be added to.
9-
---@field badge_colour? table HEX color the rarity badge uses.
9+
---@field text_colour? table Colour of the label for the badge.
10+
---@field badge_colour? table HEX color the rarity badge uses.
1011
---@field default_weight? number Default weight of the rarity. When referenced in ObjectTypes with just the key, this value is used as the default.
1112
---@field disable_if_empty? boolean Disables polling of the rarity if set to `true` if there are no available objects.
1213
---@field __call? fun(self: SMODS.Rarity|table, o: SMODS.Rarity|table): nil|table|SMODS.Rarity

lsp_def/classes/seal.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
---@field atlas? string Key to the seal's atlas.
99
---@field pos? table|{x: integer, y: integer} Position of the seal's sprite.
1010
---@field unlocked? boolean Sets the unlock state of the center.
11+
---@field text_colour? table Colour of the label for the badge.
1112
---@field badge_colour? table HEX color the seal badge uses.
1213
---@field sound? table|{} Controls the sound that plays when the seal is applied. `sound`: Key to the sound, `per`: Sound pitch, `vol`: Sound volume.
1314
---@field badge_to_key? string[] Contains keys to each seal indexed by seal badge (`key:lower()..'_seal`).

lsp_def/classes/sticker.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
---@field order? number Position of the sticker in collections menu.
1010
---@field rate? number Change of this sticker applying onto an eligible card.
1111
---@field hide_badge? boolean Sets if the sticker badge shows up on the card.
12+
---@field text_colour? table Colour of the label for the badge.
1213
---@field badge_colour? table HEX color the sticker badge uses.
1314
---@field default_compat? boolean Default compatibility with cards.
1415
---@field compat_exceptions? string[] Array of keys to centers that are exceptions to `default_compat`.

lsp_def/utils.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,4 +780,16 @@ function SMODS.challenge_is_unlocked(challenge, k) end
780780
--- a string, which changes the displayed text, a boolean, which disables StatusText when set to `false`,
781781
--- a table, which defines the `attention_text` function settings, or a function that takes the key of
782782
--- the hand and scoring parameter being upgraded as arguments and returns a boolean, string or table
783-
function SMODS.upgrade_poker_hands(args) end
783+
function SMODS.upgrade_poker_hands(args) end
784+
785+
---Returns the text colour for the card type's badge or nil if none
786+
---@param type string?
787+
---@param center SMODS.Center|table?
788+
---@param card Card|table?
789+
---@return table?
790+
function SMODS.get_card_type_text_colour(type, center, card) end
791+
792+
---Returns the text colour for the badge of an object with this key or nil if none
793+
---@param key string
794+
---@return table?
795+
function SMODS.get_badge_text_colour(key) end

src/utils.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,3 +3431,27 @@ end
34313431
SMODS.custom_debuff_handling = {
34323432
'j_shoot_the_moon', 'j_baron', 'j_reserved_parking', 'j_raised_fist'
34333433
}
3434+
3435+
function SMODS.get_card_type_text_colour(type, center, card)
3436+
if (card or {}).debuff then return end
3437+
if (center or {}).badge_text_colour then return center.badge_text_colour end
3438+
if type == 'Joker' and center then
3439+
local rarity = ({"Common", "Uncommon", "Rare", "Legendary"})[center.rarity] or center.rarity
3440+
return SMODS.Rarities[rarity] and SMODS.Rarities[rarity].text_colour
3441+
end
3442+
if type and SMODS.ConsumableTypes[type] then
3443+
return SMODS.ConsumableTypes[type].text_colour
3444+
end
3445+
end
3446+
3447+
function SMODS.get_badge_text_colour(key)
3448+
if not key then return end
3449+
if (SMODS.Rarities[key] or {}).text_colour then return SMODS.Rarities[key].text_colour end
3450+
if (SMODS.Stickers[key] or {}).text_colour then return SMODS.Stickers[key].text_colour end
3451+
for _, v in ipairs(G.P_CENTER_POOLS.Edition) do
3452+
if v.key:sub(3) == key and v.text_colour then return v.text_colour end
3453+
end
3454+
for k, v in pairs(SMODS.Seals) do
3455+
if k:lower()..'_seal' == key and v.text_colour then return v.text_colour end
3456+
end
3457+
end

0 commit comments

Comments
 (0)