forked from tetraminus/Tetrapak
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTetrapak.lua
More file actions
429 lines (292 loc) · 10.4 KB
/
Tetrapak.lua
File metadata and controls
429 lines (292 loc) · 10.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
--- STEAMODDED HEADER
--- MOD_NAME: Tetrapak
--- MOD_ID: tetraminus_tetrapak
--- PREFIX: tetrapak
--- MOD_AUTHOR: [tetraminus]
--- MOD_DESCRIPTION: A Content pack for Balatro.
--- DISPLAY_NAME: Tetrapak
--- BADGE_COLOUR: 3333aa
----------------------------------------------
------------MOD CODE -------------------------
TETRAPAKID = "tetraminus_tetrapak"
tpmakeID = function(id)
--to lazy to refactor all the old code
return id
end
tpjokerSlug = function(id)
return "j_tetrapak_" .. tpmakeID(id)
end
tpconsumableSlug = function(id)
return "c_tetrapak_" .. tpmakeID(id)
end
tpvoucherSlug = function(id)
return "v_tetrapak_" .. tpmakeID(id)
end
tpblindSlug = function(id)
return "bl_tetrapak_" .. tpmakeID(id)
end
CURSERARITY = "tetrapak_Curses"
Tetrapak = {}
GENPAGE = true
function table.tostring(tbl, depth)
local MAX_DEPTH = 3
if not depth then
depth = 1
end
local indents = string.rep(" ", depth)
local str = "{\n"
for k, v in pairs(tbl) do
if depth > MAX_DEPTH then
str = str .. indents .. k .. " = \"...\",\n"
break
end
if type(v) == "table" then
str = str .. indents .. k .. " = " .. table.tostring(v, depth + 1) .. ",\n"
elseif type(v) == "string" then
str = str .. indents .. k .. " = [[" .. v .. "]],\n"
else
str = str .. indents .. k .. " = " .. tostring(v) .. ",\n"
end
end
str = str .. indents .. "}"
return str
end
local function RegisterAndLoad(alldefs)
for k, defs in pairs(alldefs) do
for k, def in pairs(defs) do
if def.load_effect then
def.load_effect()
end
end
end
end
local function loadSprites(directory, folder, slugFunction, sprites)
local mod = SMODS.current_mod
local spritesFiles = NFS.getDirectoryItems(directory)
for k, file in pairs(spritesFiles) do
if string.find(file, ".png") then
name = string.sub(file, 1, string.len(file) - 4)
print("loading sprite: " .. name)
local sprite = SMODS.Atlas(
{
key = (name),
raw_key = true,
path = folder .. "/" .. file,
px=71,
py=95,
}
)
G.ASSET_ATLAS[name] = {}
table.insert(sprites, sprite)
end
end
end
local function Load_atlas()
local mod = SMODS.Mods['tetraminus_tetrapak']
local sprites = {}
-- jokers
loadSprites(mod.path.."assets/1x/jokers", "jokers", tpjokerSlug, sprites)
-- spectrals
loadSprites(mod.path.."assets/1x/spectrals", "spectrals", tpconsumableSlug, sprites)
-- vouchers
loadSprites(mod.path.."assets/1x/vouchers", "vouchers", tpvoucherSlug, sprites)
-- blinds
local spritesFiles = NFS.getDirectoryItems(mod.path.."assets/1x/blinds")
for k, file in pairs(spritesFiles) do
print("checking " .. file)
if string.find(file, ".png") then
name = string.sub(file, 1, string.len(file) - 4)
local sprite = SMODS.Atlas(--{
{
key = name,
raw_key = true,
path = "blinds/" .. file,
px=34,
py=34,
atlas_table = "ANIMATION_ATLAS",
frames = 12
}
)
G.ANIMATION_ATLAS[name] = {}
table.insert(sprites, sprite)
print("Loaded sprite: " .. file)
end
end
print(table.tostring(G.ASSET_ATLAS))
for k, v in pairs(Tetrapak.Registry) do
for k, v in pairs(v) do
local atlasname = v.key
-- remove the prefix by after the second iinstance of _
atlasname = string.sub(atlasname, string.find(atlasname, "_") + 1)
atlasname = string.sub(atlasname, string.find(atlasname, "_") + 1)
if v.placeholders then
atlasname = "Jokers"
end
v.atlas = atlasname
print(v.atlas)
end
end
for k, sprite in pairs(sprites) do
--sprite:register()
end
end
local mod = SMODS.current_mod
local modpath = mod.path
-- load stuff
NFS.load(modpath.."ConfigHelper.lua")()
NFS.load(modpath.."WebGenerator.lua")()
Load_Config()
G.P_JOKER_RARITY_POOLS[CURSERARITY] = {}
G.C.RARITY[CURSERARITY] = HEX("444444")
SMODS.current_mod.process_loc_text = function()
G.localization.misc.dictionary["k_"..CURSERARITY] = "Curse"
G.localization.descriptions.Other["k_curse_tip"] = {
name = "Curse",
text = {
"This card is cursed.",
"It cannot be sold.",
"+1 Joker slot"
}
}
end
local loc_colour_ref = loc_colour
function loc_colour(key, _default)
if key == CURSERARITY then return HEX("444444")
else return loc_colour_ref(key, _default) end
end
local get_badge_colourref = get_badge_colour
function get_badge_colour(key)
local fromRef = get_badge_colourref(key)
if key == CURSERARITY then return HEX("444444")
else return fromRef end
end
Tetrapak.Registry = {}
Tetrapak.Jokers = {}
Tetrapak.Spectrals = {}
Tetrapak.Vouchers = {}
Tetrapak.Blinds = {}
local alldefs = {}
--load all files in the jokers folder
local jokerFiles = NFS.getDirectoryItems(mod.path.."jokers")
local jokerdefs = {}
for k, file in pairs(jokerFiles) do
lowercasename = string.sub(file, 1, string.len(file) - 4):lower()
print("checking " .. lowercasename)
if string.find(file, ".lua") and G.TETRAPAK_Config.Enabled[lowercasename] then
print("loading joker: " .. file)
local joker = NFS.load(mod.path.."jokers/"..file)()
table.insert(jokerdefs, joker)
end
end
print(table.tostring(jokerdefs))
table.insert(alldefs, jokerdefs)
-- load all files in the spectrals folder
local spectralFiles = NFS.getDirectoryItems(mod.path.."spectrals")
local spectraldefs = {}
for k, file in pairs(spectralFiles) do
if string.find(file, ".lua") and G.TETRAPAK_Config.Enabled[string.sub(file, 1, string.len(file) - 4):lower()] then
local spectral = NFS.load(mod.path.."spectrals/"..file)()
table.insert(spectraldefs, spectral)
end
end
table.insert(alldefs, spectraldefs)
-- load all files in the vouchers folder
local voucherFiles = NFS.getDirectoryItems(mod.path.."vouchers")
local voucherdefs = {}
for k, file in pairs(voucherFiles) do
if string.find(file, ".lua") and G.TETRAPAK_Config.Enabled[string.sub(file, 1, string.len(file) - 4):lower()] then
local voucher = NFS.load(mod.path.."vouchers/"..file)()
table.insert(voucherdefs, voucher)
end
end
table.insert(alldefs, voucherdefs)
-- place voucherdefs in the correct order by the after field, ex: after = "emptycage"
local function sort_voucherdefs(a, b)
if a.after == b.name then
print("aligned")
return true
end
return false
end
table.sort(voucherdefs, sort_voucherdefs)
-- load all files in the blinds folder
local blindFiles = NFS.getDirectoryItems(mod.path.."blinds")
local blinddefs = {}
for k, file in pairs(blindFiles) do
if string.find(file, ".lua") and G.TETRAPAK_Config.Enabled[string.sub(file, 1, string.len(file) - 4):lower()] then
local blind = NFS.load(mod.path.."blinds/"..file)()
table.insert(blinddefs, blind)
end
end
table.insert(alldefs, blinddefs)
--- DISABLE DEBUG MODE AFTER TESTING
--G.DEBUG = true
_RELEASE_MODE = false
for k, defs in pairs(alldefs) do
for k, def in pairs(defs) do
if def.init then
def.init()
end
end
end
Tetrapak.Registry = {
Jokers = Tetrapak.Jokers,
Spectrals = Tetrapak.Spectrals,
Vouchers = Tetrapak.Vouchers,
Blinds = Tetrapak.Blinds
}
Load_atlas()
injectitemsold = SMODS.injectItems
function SMODS.injectItems()
injectitemsold()
RegisterAndLoad(alldefs)
end
local cansell_ref = Card.can_sell_card
function Card:can_sell_card(context)
if self.config.center and self.config.center.rarity == CURSERARITY then
return false
end
return cansell_ref(self,context)
end
local add_to_deck_ref = Card.add_to_deck
function Card:add_to_deck(from_debuff)
add_to_deck_ref(self, from_debuff)
if self.config.center.rarity == CURSERARITY and (not from_debuff) and self.ability.name ~= "Bound" then
G.jokers.config.card_limit = G.jokers.config.card_limit + 1
end
return
end
local remove_from_deck_ref = Card.remove_from_deck
function Card.remove_from_deck(self, from_debuff)
if self.config.center.rarity == CURSERARITY and (not from_debuff) and self.added_to_deck and self.ability.name ~= "Bound" then
G.jokers.config.card_limit = G.jokers.config.card_limit - 1
end
remove_from_deck_ref(self, from_debuff)
end
-- add curse tooltips
for k, v in pairs(SMODS.Centers) do
if v.rarity == CURSERARITY then
local old_tooltip = v.tooltip
v.tooltip = function (_c, info_queue)
if old_tooltip then
old_tooltip(_c, info_queue)
end
info_queue[#info_queue + 1] = { set = 'Other', key = 'k_curse_tip'}
end
end
end
if GENPAGE then
WebGenerator:generateWeb()
end
-- load challenges
local challengeFiles = NFS.getDirectoryItems(mod.path.."challenges")
for k, file in pairs(challengeFiles) do
if string.find(file, ".lua") then
NFS.load(mod.path.."challenges/"..file)()
end
end
function table.addall(t1, t2)
for k, v in pairs(t2) do
table.insert(t1, tostring(k))
end
end