forked from Mysthaps/blindexpander
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblindexpander.lua
More file actions
573 lines (543 loc) · 23 KB
/
blindexpander.lua
File metadata and controls
573 lines (543 loc) · 23 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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
--- G.GAME.blind.original_blind (string): Key of the first Blind if Blinds are summoned
--- G.GAME.current_round.phases_beaten (number): Amount of times Blind was beaten if Blind has phases
---
--- NOTES
---
--- Localization for Passives are taken from G.localization.descriptions.Passive
--- Passive key should be "psv_[mod prefix]_[key]" for consistency
--- SMODS.Blind.defeat(self) is called on the current blind if it has a summon
--- If passive description is too long, changing how it is formatted instead of changing UIBox width is preferred
to_big = to_big or function(x) return x end
local BLINDEXPANDER_VERSION = 102000
local function startup()
if blindexpander.started_up then return end
blindexpander.started_up = true
-- copied from cryptid's cry_deep_copy
function lobc_deep_copy(obj, seen)
if type(obj) ~= 'table' then return obj end
if seen and seen[obj] then return seen[obj] end
local s = seen or {}
local res = setmetatable({}, getmetatable(obj))
s[obj] = res
for k, v in pairs(obj) do res[lobc_deep_copy(k, s)] = lobc_deep_copy(v, s) end
return res
end
local set_blindref = Blind.set_blind
function Blind.set_blind(self, blind, reset, silent)
if not reset then
self.passives = blind and lobc_deep_copy(blind.passives)
if self.passives then
self.passives_data = {}
for _, key in ipairs(self.passives) do
local obj = blindexpander.Passives[key]
local cfg = {}
if obj then
cfg = copy_table(obj.config)
obj:apply(false)
end
self.passives_data[#self.passives_data + 1] = {
disabled = false,
key = key,
config = cfg
}
end
self.children.alert = UIBox{
definition = create_UIBox_card_alert(),
config = {
align = "tri",
offset = {
x = 0.1, y = 0
},
parent = self
}
}
else
self.children.alert = nil
end
end
set_blindref(self, blind, reset, silent)
end
local blind_saveref = Blind.save
function Blind.save(self)
local blindTable = blind_saveref(self)
blindTable.passives = self.passives
blindTable.passives_data = self.passives_data
blindTable.original_blind = self.original_blind
return blindTable
end
local blind_loadref = Blind.load
function Blind.load(self, blindTable)
self.passives = blindTable.passives
self.passives_data = blindTable.passives_data
self.original_blind = blindTable.original_blind
blind_loadref(self, blindTable)
end
function info_from_passive(passive_data)
local width = 6
for _, v in ipairs(SMODS.Mods) do
if v.passive_ui_size and type(v.passive_ui_size) == "function" then
width = math.max(width, v.passive_ui_size())
end
end
local obj = blindexpander.Passives[passive_data.key]
local disabled = G.GAME.blind.disabled or passive_data.disabled
local loc_res = {}
if obj then
loc_res = obj:loc_vars(G.GAME.blind, passive_data) or {}
end
local no_name = loc_res.no_name
local loc_key = loc_res.key or passive_data.key
local loc_set = loc_res.set or "Passive"
local desc_nodes = {}
localize{type = 'descriptions', key = loc_key, set = loc_set, nodes = desc_nodes, vars = loc_res.vars or {}}
local desc = {}
for _, v in ipairs(desc_nodes) do
desc[#desc+1] = {n=G.UIT.R, config={align = "cl"}, nodes=v}
end
local name_nodes = localize{type = 'name', key = loc_key, set = loc_set, name_nodes = {}, vars = loc_res.vars or {}}
if disabled then
name_nodes[1].nodes[1].nodes[1].config.strikethrough = G.C.RED
end
return
{n=G.UIT.R, config={align = "cl", colour = lighten(G.C.GREY, 0.4), r = 0.1, padding = 0.05}, nodes={
(not no_name) and {n=G.UIT.R, config={align = "cl", padding = 0.05, r = 0.1}, nodes = name_nodes} or nil,
{n=G.UIT.R, config={align = "cl", minw = width, minh = 0.4, r = 0.1, padding = 0.05, colour = desc_nodes.background_colour or G.C.WHITE}, nodes={{n=G.UIT.R, config={align = "cm", padding = 0.03}, nodes=desc}}}
}}
end
function Blind:disable_passive(key)
if find_passive(key) then
for _, data in ipairs(self.passives_data) do
if data.key == key and not data.disabled then
data.disabled = true
local obj = blindexpander.Passives[key]
if obj then
obj:remove(self, data, true)
end
G.E_MANAGER:add_event(Event({
trigger = 'immediate',
func = function()
if self.boss and G.GAME.chips - G.GAME.blind.chips >= 0 then
G.STATE = G.STATES.NEW_ROUND
G.STATE_COMPLETE = false
end
return true
end
}))
for _, v in ipairs(G.playing_cards) do
self:debuff_card(v)
end
for _, v in ipairs(G.jokers.cards) do
self:debuff_card(v)
end
if not self.children.alert then
self.children.alert = UIBox{
definition = create_UIBox_card_alert(),
config = {
align = "tri",
offset = {
x = 0.1, y = 0
},
parent = self
}
}
end
self:wiggle()
break
end
end
end
end
function Blind:enable_passive(key)
if find_passive(key) then
for _, data in ipairs(self.passives_data) do
if data.key == key and data.disabled then
data.disabled = false
local obj = blindexpander.Passives[key]
if obj then
obj:apply(self, data, true)
end
G.E_MANAGER:add_event(Event({
trigger = 'immediate',
func = function()
if self.boss and G.GAME.chips - G.GAME.blind.chips >= 0 then
G.STATE = G.STATES.NEW_ROUND
G.STATE_COMPLETE = false
end
return true
end
}))
for _, v in ipairs(G.playing_cards) do
self:debuff_card(v)
end
for _, v in ipairs(G.jokers.cards) do
self:debuff_card(v)
end
if not self.children.alert and not self.disabled then
self.children.alert = UIBox{
definition = create_UIBox_card_alert(),
config = {
align = "tri",
offset = {
x = 0.1, y = 0
},
parent = self
}
}
end
self:wiggle()
break
end
end
end
end
function Blind:add_passive(key)
if not find_passive(key) then
local obj = blindexpander.Passives[key]
local cfg = {}
if obj then
cfg = copy_table(obj.config)
end
local data = {
disabled = false,
key = key,
config = cfg
}
if obj then
obj:apply(self, data, false)
end
self.passives_data[#self.passives_data + 1] = data
G.E_MANAGER:add_event(Event({
trigger = 'immediate',
func = function()
if self.boss and G.GAME.chips - G.GAME.blind.chips >= 0 then
G.STATE = G.STATES.NEW_ROUND
G.STATE_COMPLETE = false
end
return true
end
}))
for _, v in ipairs(G.playing_cards) do
self:debuff_card(v)
end
for _, v in ipairs(G.jokers.cards) do
self:debuff_card(v)
end
if not self.children.alert then
self.children.alert = UIBox{
definition = create_UIBox_card_alert(),
config = {
align = "tri",
offset = {
x = 0.1, y = 0
},
parent = self
}
}
end
self:wiggle()
end
end
function Blind:remove_passive(key)
if find_passive(key) then
for i, data in ipairs(self.passives_data) do
if data.key == key then
local obj = blindexpander.Passives[key]
if obj then
obj:remove(self, data, false)
end
table.remove(self.passives_data, i)
G.E_MANAGER:add_event(Event({
trigger = 'immediate',
func = function()
if self.boss and G.GAME.chips - G.GAME.blind.chips >= 0 then
G.STATE = G.STATES.NEW_ROUND
G.STATE_COMPLETE = false
end
return true
end
}))
for _, v in ipairs(G.playing_cards) do
self:debuff_card(v)
end
for _, v in ipairs(G.jokers.cards) do
self:debuff_card(v)
end
if #self.passives_data ~= 0 and not self.children.alert then
self.children.alert = UIBox{
definition = create_UIBox_card_alert(),
config = {
align = "tri",
offset = {
x = 0.1, y = 0
},
parent = self
}
}
end
self:wiggle()
break
end
end
end
end
function get_actual_original_blind(key)
local obj = G.P_BLINDS[key]
if obj.precedes_original and not obj.summon then
print("WARNING: precedes_original was set, but Blind does not have a summon")
end
if obj.precedes_original and obj.summon then
return get_actual_original_blind(obj.summon)
end
return key
end
---@param blind Blind
function create_UIBox_blind_passive(blind)
local passive_lines = {}
for _, v in ipairs(blind.passives_data) do
passive_lines[#passive_lines+1] = info_from_passive(v)
end
return
{n=G.UIT.ROOT, config = {align = 'cm', colour = lighten(G.C.JOKER_GREY, 0.5), r = 0.1, emboss = 0.05, padding = 0.05}, nodes={
{n=G.UIT.R, config={align = "cm", emboss = 0.05, r = 0.1, minw = 2.5, padding = 0.05, colour = G.C.GREY}, nodes={
{n=G.UIT.C, config = {align = "lm", padding = 0.1}, nodes = passive_lines}
}}
}}
end
local blind_hoverref = Blind.hover
function Blind.hover(self)
if not G.CONTROLLER.dragging.target or G.CONTROLLER.using_touch then
if not self.hovering and self.states.visible and self.children.animatedSprite.states.visible then
if self.passives_data then
G.blind_passive = UIBox{
definition = create_UIBox_blind_passive(self),
config = {
major = self,
parent = nil,
offset = {
x = 0.15,
y = 0.2 + 0.38*#self.passives_data,
},
type = "cr",
}
}
G.blind_passive.attention_text = true
G.blind_passive.states.collide.can = false
G.blind_passive.states.drag.can = false
if self.children.alert then
self.children.alert:remove()
self.children.alert = nil
end
end
end
end
blind_hoverref(self)
end
local blind_stop_hoverref = Blind.stop_hover
function Blind.stop_hover(self)
if G.blind_passive then
G.blind_passive:remove()
G.blind_passive = nil
end
blind_stop_hoverref(self)
end
function find_passive(key)
if G.GAME.blind and G.GAME.blind.passives_data then
for _, v in ipairs(G.GAME.blind.passives_data) do
if v.key == key then return true end
end
end
return false
end
local update_new_roundref = Game.update_new_round
function Game.update_new_round(self, dt)
if self.buttons then self.buttons:remove(); self.buttons = nil end
if self.shop then self.shop:remove(); self.shop = nil end
if not G.STATE_COMPLETE and (not G.GAME.blind.disabled or (G.GAME.blind.config.blind.summon and G.GAME.blind.config.blind.summon_while_disabled)) and (G.GAME.blind.config.blind.summon or G.GAME.blind.config.blind.phases or G.GAME.blind.original_blind) then
if G.GAME.blind.original_blind and not G.GAME.blind.config.blind.summon then -- Triggers if blind is not the original blind
-- Reset to the original blind's values
if G.GAME.blind.original_blind ~= G.GAME.blind.config.blind.key then
G.GAME.blind:set_blind(G.P_BLINDS[G.GAME.blind.original_blind])
G.GAME.blind.chips = -1 -- force win blind
G.GAME.blind.children.alert = nil
end
local valueToPutInIf = (Talisman and to_big and to_big(G.GAME.chips):gte(to_big(G.GAME.blind.chips))) or to_big(G.GAME.chips) >= to_big(G.GAME.blind.chips)
if valueToPutInIf then
local obj = G.GAME.blind.config.blind
if obj.pre_defeat and type(obj.pre_defeat) == "function" then
obj:pre_defeat()
end
end
else
local valueToPutInIf = (Talisman and to_big and to_big(G.GAME.chips):lt(to_big(G.GAME.blind.chips))) or to_big(G.GAME.chips) < to_big(G.GAME.blind.chips)
if G.GAME.current_round.hands_left <= 0 and valueToPutInIf then
G.GAME.blind.original_blind = nil
G.STATE_COMPLETE = true
end_round()
return
else
G.GAME.current_round.phases_beaten = G.GAME.current_round.phases_beaten + 1
end
if G.GAME.blind.config.blind.phases and G.GAME.current_round.phases_beaten >= G.GAME.blind.config.blind.phases then
return update_new_roundref(self, dt)
end
if G.GAME.blind.config.blind.phase_refresh then
-- Refresh deck
G.FUNCS.draw_from_discard_to_deck()
G.FUNCS.draw_from_hand_to_deck()
G.E_MANAGER:add_event(Event({
trigger = 'before',
delay = 1,
blockable = false,
func = function()
G.E_MANAGER:add_event(Event({
trigger = 'immediate',
func = function()
G.deck:shuffle(G.GAME.blind.config.blind.key..'_refresh')
G.deck:hard_set_T()
return true
end
}))
return true
end
}))
end
local obj = G.GAME.blind.config.blind
if obj.phase_change and type(obj.phase_change) == "function" then
obj:phase_change()
end
if G.GAME.blind.config.blind.summon then
local obj = G.GAME.blind.config.blind
G.P_BLINDS[obj.key].discovered = true
if obj.defeat and type(obj.defeat) == 'function' then
obj:defeat()
end
G.GAME.blind.original_blind = G.GAME.blind.original_blind or get_actual_original_blind(G.GAME.blind.config.blind.key)
G.GAME.blind:set_blind(G.P_BLINDS[G.GAME.blind.config.blind.summon])
G.GAME.blind.dollars = G.P_BLINDS[G.GAME.blind.original_blind].dollars
G.GAME.blind.boss = G.P_BLINDS[G.GAME.blind.original_blind].boss
G.GAME.current_round.dollars_to_be_earned = G.GAME.blind.dollars > 0 and (string.rep(localize('$'), G.GAME.blind.dollars)..'') or ('')
end
G.STATE = G.STATES.DRAW_TO_HAND
G.E_MANAGER:add_event(Event({
trigger = 'ease',
blocking = false,
ref_table = G.GAME,
ref_value = 'chips',
ease_to = 0,
delay = 0.3 * G.SETTINGS.GAMESPEED,
func = (function(t) return math.floor(t) end)
}))
end
end
if G.STATE ~= G.STATES.DRAW_TO_HAND then
update_new_roundref(self, dt)
for _, v in ipairs(G.playing_cards) do
if v.ability.big_bird_enchanted and v.children.lobc_big_bird_particles then
v.children.lobc_big_bird_particles:remove()
v.children.lobc_big_bird_particles = nil
end
end
end
end
local new_roundref = new_round
function new_round()
new_roundref()
G.GAME.current_round.phases_beaten = 0
end
local calculate_round_scoreref = SMODS.calculate_round_score
function SMODS.calculate_round_score(flames)
local score = calculate_round_scoreref(flames)
if G.GAME.blind then
local obj = G.GAME.blind.config.blind
if obj.mod_score and type(obj.mod_score) == "function" then
return obj:mod_score(score)
end
end
return score
end
local blind_calcref = Blind.calculate
function Blind:calculate(context)
local blind_eff = blind_calcref(self, context)
local final_ret = { blind_eff }
if self.passives_data and not self.disabled then
for _, data in ipairs(self.passives_data) do
local obj = blindexpander.Passives[data.key]
if obj and not data.disabled then
final_ret[#final_ret+1] = obj:calculate(self, data, context)
end
end
end
if #final_ret == 0 then
return nil
elseif #final_ret == 1 then
return final_ret[1]
else
return SMODS.merge_defaults(unpack(final_ret))
end
end
end
blindexpander = blindexpander or {}
if not blindexpander.ver or blindexpander.ver < BLINDEXPANDER_VERSION then
blindexpander.ver = BLINDEXPANDER_VERSION
blindexpander.startup = startup
end
function UIElement:draw_pixellated_strikethough(_type, _parallax, _emboss, _progress)
if not self.pixellated_rect or
#self.pixellated_rect[_type].vertices < 1 or
_parallax ~= self.pixellated_rect.parallax or
self.pixellated_rect.w ~= self.VT.w or
self.pixellated_rect.h ~= self.VT.h or
self.pixellated_rect.sw ~= self.shadow_parrallax.x or
self.pixellated_rect.sh ~= self.shadow_parrallax.y or
self.pixellated_rect.progress ~= (_progress or 1)
then
self.pixellated_rect = {
w = self.VT.w,
h = self.VT.h,
sw = self.shadow_parrallax.x,
sh = self.shadow_parrallax.y,
progress = (_progress or 1),
fill = {vertices = {}},
shadow = {vertices = {}},
line = {vertices = {}},
emboss = {vertices = {}},
line_emboss = {vertices = {}},
parallax = _parallax
}
local ext_up = self.config.ext_up and self.config.ext_up*G.TILESIZE or 0
local totw, toth = self.VT.w*G.TILESIZE, (self.VT.h + math.abs(ext_up)/G.TILESIZE)*G.TILESIZE
local vertices = {
totw,toth/2+ext_up,
0, toth/2+ext_up,
0, toth/2+ext_up+1,
totw,toth/2+ext_up+1
}
for k, v in ipairs(vertices) do
if k%2 == 1 and v > totw*self.pixellated_rect.progress then v = totw*self.pixellated_rect.progress end
self.pixellated_rect.fill.vertices[k] = v
if k > 4 then
self.pixellated_rect.line.vertices[k-4] = v
if _emboss then
self.pixellated_rect.line_emboss.vertices[k-4] = v + (k%2 == 0 and -_emboss*self.shadow_parrallax.y or -0.7*_emboss*self.shadow_parrallax.x)
end
end
if k%2 == 0 then
self.pixellated_rect.shadow.vertices[k] = v -self.shadow_parrallax.y*_parallax
if _emboss then
self.pixellated_rect.emboss.vertices[k] = v + _emboss*G.TILESIZE
end
else
self.pixellated_rect.shadow.vertices[k] = v -self.shadow_parrallax.x*_parallax
if _emboss then
self.pixellated_rect.emboss.vertices[k] = v
end
end
end
end
love.graphics.polygon("fill", self.pixellated_rect.fill.vertices)
end
local injectItemsref = SMODS.injectItems
function SMODS.injectItems()
injectItemsref()
blindexpander.startup()
end