forked from Balatro-Paperback/paperback
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaperback.lua
More file actions
362 lines (307 loc) · 11.4 KB
/
paperback.lua
File metadata and controls
362 lines (307 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
PB_UTIL = {}
-- By Eremel from Stocking Stuffer's PotatoPatch utils
PB_UTIL.CREDITS = {}
PB_UTIL.CREDITS.generate_string = function(developers, prefix)
if type(developers) ~= 'table' then return end
local amount = #developers
local credit_string = {
n = G.UIT.R,
config = { align = 'tm' },
nodes = {
{ n = G.UIT.R, config = { align = 'cm' }, nodes = { { n = G.UIT.T, config = { text = localize(prefix), shadow = true, colour = G.C.UI.BACKGROUND_WHITE, scale = 0.27 } } } }
}
}
for i, name in ipairs(developers) do
local target_row = math.ceil(i / 3)
local dev = PB_UTIL.Developers[name] or {}
if target_row > #credit_string.nodes then
table.insert(credit_string.nodes,
{ n = G.UIT.R, config = { align = 'cm' }, nodes = {} })
end
table.insert(credit_string.nodes[target_row].nodes, {
n = G.UIT.O,
config = {
object = DynaText({
string = dev.loc and localize(dev.loc) or dev.name or name,
colours = { dev and dev.colour or G.C.UI.BACKGROUND_WHITE },
scale = 0.27,
silent = true,
shadow = true,
y_offset = -0.6,
})
}
})
if i < amount then
table.insert(credit_string.nodes[target_row].nodes,
{ n = G.UIT.T, config = { text = localize(i + 1 == amount and 'paperback_and_spacer' or 'paperback_comma_spacer'), shadow = true, colour = G.C.UI.BACKGROUND_WHITE, scale = 0.27 } })
end
end
return credit_string
end
local card_popup_ref = G.UIDEF.card_h_popup
function G.UIDEF.card_h_popup(card)
local ret_val = card_popup_ref(card)
if PB_UTIL.config.show_credits then
local obj = card.config.center and card.config.center.paperback_credit
local target = ret_val.nodes[1].nodes[1].nodes[1].nodes
local owned = function(card)
if next(SMODS.find_card(card.config.center.key, true)) then
if PB_UTIL.find(SMODS.find_card(card.config.center.key), card) then
return true
end
end
return false
end
if obj then
if (not obj.hidden) or
(obj.hidden and owned(card)) then
if obj.artist then
local str = PB_UTIL.CREDITS.generate_string(obj.artist, 'paperback_art_credit')
if str then
table.insert(target, str)
end
else
local str = PB_UTIL.CREDITS.generate_string({ 'papermoonqueen' }, 'paperback_art_credit')
if str then
table.insert(target, str)
end
end
if obj.coder then
local str = PB_UTIL.CREDITS.generate_string(obj.coder, 'paperback_code_credit')
if str then
table.insert(target, str)
end
end
if obj.composer then
local str = PB_UTIL.CREDITS.generate_string(obj.composer, 'paperback_music_credit')
if str then
table.insert(target, str)
end
end
end
end
end
return ret_val
end
PB_UTIL.Developers = { internal_count = 0 }
PB_UTIL.Developer = Object:extend()
function PB_UTIL.Developer:init(args)
self.name = args.name
self.colour = args.colour
self.loc = args.loc and type(args.loc) == 'boolean' and 'paperback_dev_' .. args.name or args.loc
PB_UTIL.Developers[args.name] = self
PB_UTIL.Developers.internal_count = PB_UTIL.Developers.internal_count + 1
end
-- Load utility functions into PB_UTIL
SMODS.load_file("utilities/developers.lua")()
SMODS.load_file("utilities/definitions.lua")()
SMODS.load_file("utilities/misc_functions.lua")()
SMODS.load_file("utilities/ui.lua")()
SMODS.load_file("utilities/hooks.lua")()
SMODS.load_file("utilities/cross-mod.lua")()
-- Load the atlases
SMODS.load_file("content/atlas.lua")()
-- Load Jokers
PB_UTIL.register_items(PB_UTIL.ENABLED_JOKERS, "content/joker")
-- Load Minor Arcana if they are enabled
if PB_UTIL.config.minor_arcana_enabled then
-- Register the consumable type to be used by Minor Arcana
SMODS.ConsumableType {
key = 'minor_arcana',
prefix_config = { key = true }, -- Add the prefix of the mod to the key
primary_colour = G.C.PAPERBACK_MINOR_ARCANA,
secondary_colour = G.C.PAPERBACK_MINOR_ARCANA, -- Color of the collection button and badge
shop_rate = 0, -- These will not appear in the shop
default = 'c_paperback_ace_of_cups', -- Card to spawn if pool is empty
collection_rows = { 7, 7 }
}
-- Register the sprite for undiscovered Minor Arcana
SMODS.UndiscoveredSprite {
key = 'minor_arcana',
prefix_config = { key = true },
atlas = "minor_arcana_atlas",
pos = { x = 0, y = 8 }
}
-- Register Minor Arcana cards
PB_UTIL.register_items(PB_UTIL.ENABLED_MINOR_ARCANA, "content/minor_arcana")
-- Register Minor Arcana boosters
PB_UTIL.register_items(PB_UTIL.ENABLED_MINOR_ARCANA_BOOSTERS, "content/booster")
-- Register music for Minor Arcana boosters
SMODS.Sound {
key = 'music_minor_arcana',
path = 'music_minor_arcana.ogg',
select_music_track = function(self)
-- We only check the booster once there are cards in the pack_cards area
local booster = G.pack_cards and G.pack_cards.cards and SMODS.OPENED_BOOSTER
-- If it's a minor arcana pack, we return the priority of this music
if booster and booster.config.center_key:find('p_paperback_minor_arcana_') then
return 1e10
end
end
}
end
-- Load E.G.O Gifts if they are enabled
if PB_UTIL.config.ego_gifts_enabled then
-- Register the consumable type to be used by E.G.O Gifts
SMODS.ConsumableType {
key = 'ego_gift',
prefix_config = { key = true }, -- Add the prefix of the mod to the key
primary_colour = G.C.PAPERBACK_EGO_GIFT_YELLOW,
secondary_colour = G.C.PAPERBACK_EGO_GIFT_RED, -- Color of the collection button and badge
shop_rate = 0, -- These will not appear in the shop
default = 'c_paperback_dark_vestige', -- Card to spawn if pool is empty
collection_rows = { 6, 6 },
}
-- Register the sprite for undiscovered E.G.O Gifts
SMODS.UndiscoveredSprite {
key = 'ego_gift',
prefix_config = { key = true },
atlas = "ego_gift_atlas",
pos = { x = 7, y = 1 },
no_overlay = true,
}
-- Register E.G.O Gift cards
PB_UTIL.register_items(PB_UTIL.ENABLED_EGO_GIFTS, "content/ego_gift")
-- Register E.G.O Gift boosters
PB_UTIL.register_items(PB_UTIL.ENABLED_EGO_GIFT_BOOSTERS, "content/booster")
end
-- Load Spectral cards if they are enabled
if PB_UTIL.config.spectrals_enabled then
PB_UTIL.register_items(PB_UTIL.ENABLED_SPECTRALS, "content/spectrals")
end
-- Load enhancements if they are enabled
if PB_UTIL.config.enhancements_enabled then
PB_UTIL.register_items(PB_UTIL.ENABLED_ENHANCEMENTS, "content/enhancement")
end
-- Load editions if they are enabled
if PB_UTIL.config.editions_enabled then
PB_UTIL.register_items(PB_UTIL.ENABLED_EDITIONS, "content/edition")
end
-- Load Paperclips if they are enabled
if PB_UTIL.config.paperclips_enabled then
PB_UTIL.register_items(PB_UTIL.ENABLED_PAPERCLIPS, "content/paperclip")
end
-- Load stickers regardless of config
PB_UTIL.register_items(PB_UTIL.ENABLED_STICKERS, 'content/stickers')
-- Load custom suits and spectrums if they are enabled
if PB_UTIL.config.suits_enabled then
PB_UTIL.register_items(PB_UTIL.ENABLED_SUITS, "content/suit")
-- Register Spectrum poker hand if some other Spectrum mods are not installed
if PB_UTIL.should_load_spectrum_items() then
PB_UTIL.register_items(PB_UTIL.ENABLED_POKER_HANDS, "content/pokerhand")
PB_UTIL.register_items(PB_UTIL.ENABLED_PLANETS, "content/planet")
end
end
-- Load custom ranks if they are enabled
if PB_UTIL.config.ranks_enabled then
PB_UTIL.register_items(PB_UTIL.ENABLED_RANKS, "content/rank")
end
-- Load Vouchers if they're enabled
if PB_UTIL.config.vouchers_enabled then
PB_UTIL.register_items(PB_UTIL.ENABLED_VOUCHERS, "content/voucher")
end
-- Load Blinds if they're enabled
if PB_UTIL.config.blinds_enabled then
PB_UTIL.register_items(PB_UTIL.ENABLED_BLINDS, "content/blind")
end
-- Load Tags if they're enabled
if PB_UTIL.config.tags_enabled then
PB_UTIL.register_items(PB_UTIL.ENABLED_TAGS, "content/tag")
end
-- Load custom Decks
PB_UTIL.register_items(PB_UTIL.ENABLED_DECKS, "content/deck")
-- Load custom Challenges
PB_UTIL.register_items(PB_UTIL.ENABLED_CHALLENGES, "content/challenge")
-- Register DeckSkins for Friends of Paperback
for _, data in ipairs(PB_UTIL.DECK_SKINS) do
for _, suit in ipairs(data.suits) do
local key = data.id .. "_" .. suit:lower()
-- Common ranks used in both palettes
local ranks = { 'Jack', 'Queen', 'King', 'Ace' }
local display_ranks = PB_UTIL.reverse_table(ranks)
local atlas_lc = SMODS.Atlas {
key = key .. '_lc',
path = 'collabs/lc/' .. key .. '_lc.png',
px = 71,
py = 95
}
local atlas_hc = SMODS.Atlas {
key = key .. '_hc',
path = 'collabs/hc/' .. key .. '_hc.png',
px = 71,
py = 95
}
SMODS.DeckSkin {
key = key,
suit = suit,
loc_txt = {
['en-us'] = data.name
},
palettes = {
{
key = 'lc',
ranks = ranks,
display_ranks = display_ranks,
pos_style = 'ranks',
atlas = atlas_lc.key
},
{
key = 'hc',
ranks = ranks,
display_ranks = display_ranks,
pos_style = 'ranks',
atlas = atlas_hc.key,
hc_default = true
}
}
}
end
end
-- Collect valid objects to apply Paperback config to
local objects = {}
for _, v in pairs(SMODS.Centers) do
objects[#objects + 1] = { obj = v, center = true }
end
for _, v in pairs(SMODS.Tags) do
objects[#objects + 1] = { obj = v, tag = true }
end
-- Apply said config to each valid object
for _, v in ipairs(objects) do
local obj = v.obj
if obj and type(obj) == "table" and obj.paperback then
local func_ref = obj.in_pool or function() return true end
local config = obj.paperback
if config.requires_crowns or config.requires_stars then
config.requires_custom_suits = true
end
config.requirements = {}
for k, _ in pairs(config) do
local data = PB_UTIL.requirement_map[k]
if data then
table.insert(config.requirements, data)
end
end
-- Hook the in_pool function, adding extra logic depending on the
-- config provided by this center
obj.in_pool = function(self, args)
local ret, dupes = func_ref(self, args)
for _, req in ipairs(config.requirements) do
ret = ret and PB_UTIL.config[req.setting]
end
if config.requires_crowns then
ret = ret and PB_UTIL.has_suit_in_deck('paperback_Crowns', true)
end
if config.requires_stars then
ret = ret and PB_UTIL.has_suit_in_deck('paperback_Stars', true)
end
if config.requires_spectrum_or_suit then
ret = ret and (PB_UTIL.spectrum_played() or PB_UTIL.has_modded_suit_in_deck())
end
return ret, dupes
end
-- Add an extra button if it exists in the config
if config.extra_button then
PB_UTIL.setup_extra_button(obj, config.extra_button)
end
end
end