-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathtalisman.lua
More file actions
1209 lines (1127 loc) · 49.4 KB
/
talisman.lua
File metadata and controls
1209 lines (1127 loc) · 49.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
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
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local lovely = require("lovely")
local nativefs = require("nativefs")
local info = nativefs.getDirectoryItemsInfo(lovely.mod_dir)
local talisman_path = ""
for i, v in pairs(info) do
if v.type == "directory" and nativefs.getInfo(lovely.mod_dir .. "/" .. v.name .. "/talisman.lua") then talisman_path = lovely.mod_dir .. "/" .. v.name end
end
if not nativefs.getInfo(talisman_path) then
error(
'Could not find proper Talisman folder.\nPlease make sure that Talisman is installed correctly and the folders arent nested.')
end
-- "Borrowed" from Trance
function load_file_with_fallback2(a, aa)
local success, result = pcall(function() return assert(load(nativefs.read(a)))() end)
if success then
return result
end
local fallback_success, fallback_result = pcall(function() return assert(load(nativefs.read(aa)))() end)
if fallback_success then
return fallback_result
end
end
local talismanloc = init_localization
function init_localization()
local abc = load_file_with_fallback2(
talisman_path.."/localization/" .. (G.SETTINGS.language or "en-us") .. ".lua",
talisman_path .. "/localization/en-us.lua"
)
for k, v in pairs(abc) do
if k ~= "descriptions" then
G.localization.misc.dictionary[k] = v
end
-- todo error messages(?)
G.localization.misc.dictionary[k] = v
end
talismanloc()
end
Talisman = {config_file = {disable_anims = false, break_infinity = "omeganum", score_opt_id = 2}, mod_path = talisman_path, default_notation = "Balatro"}
local config_read_result = nativefs.read(talisman_path.."/config.lua")
if config_read_result then
Talisman.config_file = STR_UNPACK(config_read_result)
if Talisman.config_file.break_infinity == "bignumber" then
Talisman.config_file.break_infinity = "omeganum"
Talisman.config_file.score_opt_id = 2
end
if not Talisman.config_file.notation_key then
Talisman.config_file.notation_key = "Balatro"
end
if Talisman.config_file.score_opt_id == 3 then Talisman.config_file.score_opt_id = 2 end
if Talisman.config_file.break_infinity and type(Talisman.config_file.break_infinity) ~= 'string' then
Talisman.config_file.break_infinity = "omeganum"
end
end
if not SMODS or not JSON then
local createOptionsRef = create_UIBox_options
function create_UIBox_options()
contents = createOptionsRef()
local m = UIBox_button({
minw = 5,
button = "talismanMenu",
label = {
localize({ type = "name_text", set = "Spectral", key = "c_talisman" })
},
colour = G.C.GOLD
})
table.insert(contents.nodes[1].nodes[1].nodes[1].nodes, #contents.nodes[1].nodes[1].nodes[1].nodes + 1, m)
return contents
end
end
Talisman.notations = {
loc_keys = {
"talisman_notations_hypere",
-- "talisman_notations_letter",
"talisman_notations_array",
-- "k_ante"
},
filenames = {
"Balatro",
-- "LetterNotation",
"ArrayNotation",
-- "AnteNotation",
}
}
local function getlocs(key_array)
local ret = {}
for _,entry in ipairs(key_array) do
table.insert(ret, localize(entry))
end
return ret
end
Talisman.config_tab = function()
tal_nodes = {{n=G.UIT.R, config={align = "cm"}, nodes={
{n=G.UIT.O, config={object = DynaText({string = localize("talisman_string_A"), colours = {G.C.WHITE}, shadow = true, scale = 0.4})}},
}},create_toggle({label = localize("talisman_string_B"), ref_table = Talisman.config_file, ref_value = "disable_anims",
callback = function(_set_toggle)
nativefs.write(talisman_path .. "/config.lua", STR_PACK(Talisman.config_file))
end}),
create_option_cycle({
label = localize("talisman_string_C"),
scale = 0.8,
w = 6,
options = {localize("talisman_vanilla"), localize("talisman_omeganum") .. "(e308##e308)"},
opt_callback = 'talisman_upd_score_opt',
current_option = Talisman.config_file.score_opt_id,
}),
create_option_cycle({
label = localize("talisman_notation"),
scale = 0.8,
w = 6,
options = getlocs(Talisman.notations.loc_keys),
opt_callback = 'talisman_upd_notation_opt',
current_option = Talisman.config_file.notation_id,
})}
return {
n = G.UIT.ROOT,
config = {
emboss = 0.05,
minh = 6,
r = 0.1,
minw = 10,
align = "cm",
padding = 0.2,
colour = G.C.BLACK
},
nodes = tal_nodes
}
end
G.FUNCS.talismanMenu = function(e)
local tabs = create_tabs({
snap_to_nav = true,
tabs = {
{
label = localize({ type = "name_text", set = "Spectral", key = "c_talisman" }),
chosen = true,
tab_definition_function = Talisman.config_tab
},
}})
G.FUNCS.overlay_menu{
definition = create_UIBox_generic_options({
back_func = "options",
contents = {tabs}
}),
config = {offset = {x=0,y=10}}
}
end
G.FUNCS.talisman_upd_score_opt = function(e)
Talisman.config_file.score_opt_id = e.to_key
local score_opts = {"", "omeganum"}
Talisman.config_file.break_infinity = score_opts[e.to_key]
nativefs.write(talisman_path .. "/config.lua", STR_PACK(Talisman.config_file))
end
G.FUNCS.talisman_upd_notation_opt = function(e)
Talisman.config_file.notation_id = e.to_key
Talisman.config_file.notation_key = Talisman.notations.filenames[e.to_key]
nativefs.write(talisman_path .. "/config.lua", STR_PACK(Talisman.config_file))
end
if Talisman.config_file.break_infinity then
Big, err = nativefs.load(talisman_path.."/big-num/"..Talisman.config_file.break_infinity..".lua")
if not err then Big = Big() else Big = nil end
Notations = nativefs.load(talisman_path.."/big-num/notations.lua")()
-- We call this after init_game_object to leave room for mods that add more poker hands
Talisman.igo = function(obj)
for _, v in pairs(obj.hands) do
v.chips = to_big(v.chips)
v.mult = to_big(v.mult)
v.s_chips = to_big(v.s_chips)
v.s_mult = to_big(v.s_mult)
v.l_chips = to_big(v.l_chips)
v.l_mult = to_big(v.l_mult)
v.level = to_big(v.level)
end
obj.starting_params.dollars = to_big(obj.starting_params.dollars)
return obj
end
local nf = number_format
function number_format(num, e_switch_point)
if is_number(num) then
num = to_big(num)
if num.str then return num.str end
if num:arraySize() > 2 then
local str = Notations[Talisman.config_file.notation_key or Talisman.default_notation]:format(num, 3)
num.str = str
return str
end
G.E_SWITCH_POINT = Notations[Talisman.config_file.notation_key or Talisman.default_notation].E_SWITCH_POINT or G.E_SWITCH_POINT or 100000000000
if ((num or 0) < (to_big(G.E_SWITCH_POINT) or 0)) and not Notations[Talisman.config_file.notation_key or Talisman.default_notation].always_use then
return nf(num:to_number(), e_switch_point)
else
return Notations[Talisman.config_file.notation_key or Talisman.default_notation]:format(num, 3)
end
else return nf(num, e_switch_point) end
end
local mf = math.floor
function math.floor(x)
if type(x) == 'table' then return x.floor and x:floor() or x end
return mf(x)
end
local mc = math.ceil
function math.ceil(x)
if type(x) == 'table' then return x:ceil() end
return mc(x)
end
function lenient_bignum(x)
if type(x) == "number" then return x end
if to_big(x) < to_big(1e300) and to_big(x) > to_big(-1e300) then
return x:to_number()
end
return x
end
--despite the name, it only works best with m6x11plus\
--and only support the following characters: `0-9`, `e`, `{`, `}`, `,`,\
--`#` and `.` for the sake of number format simplicity
function tal_get_string_pixel_length(num)
if is_number(num) then
local num_text, length = number_format(num, G.E_SWITCH_POINT), 0
for i = 1, #num_text do
if string.sub(num_text, i, i) == "," or string.sub(num_text, i, i) == "." then
length = length + 3/6
elseif string.sub(num_text, i, i) == "{" or string.sub(num_text, i, i) == "}" then
length = length + 1
elseif string.sub(num_text, i, i) == "#" then
length = length + 8/6
else
length = length + 7/6
end
end
return length
end
end
-- I'm completely overriding this since I don't think any other mods
-- would alter a text scale adjustment function (HuyTheKiller)
function score_number_scale(scale, amt)
G.E_SWITCH_POINT = Notations[Talisman.config_file.notation_key or Talisman.default_notation].E_SWITCH_POINT or G.E_SWITCH_POINT or 100000000000
if not is_number(amt) then return 0.7*(scale or 1) end
if to_big(amt) >= to_big(G.E_SWITCH_POINT) or Talisman.config_file.notation_key ~= "Balatro" then
return math.min(6/math.floor(tal_get_string_pixel_length(amt)+1), 0.7)*(scale or 1)
elseif to_big(amt) >= to_big(1000000) then
return 14*0.75/(math.floor(math.log(amt))+4)*(scale or 1)
else
return 0.75*(scale or 1)
end
end
local gftsj = G.FUNCS.text_super_juice
function G.FUNCS.text_super_juice(e, _amount)
if type(_amount) == "table" then
if _amount > to_big(1e300) then
_amount = 1e300
else
_amount = _amount:to_number()
end
end
return gftsj(e, _amount)
end
local l10 = math.log10
function math.log10(x)
if type(x) == 'table' then
if x.log10 then return lenient_bignum(x:log10()) end
return lenient_bignum(l10(math.min(x:to_number(),1e300)))
end
return lenient_bignum(l10(x))
end
local lg = math.log
function math.log(x, y)
if not y then y = 2.718281828459045 end
if type(x) == 'table' then
if x.log then return lenient_bignum(x:log(to_big(y))) end
if x.logBase then return lenient_bignum(x:logBase(to_big(y))) end
return lenient_bignum(lg(math.min(x:to_number(),1e300),y))
end
return lenient_bignum(lg(x,y))
end
function math.exp(x)
local big_e = to_big(2.718281828459045)
if type(big_e) == "number" then
return lenient_bignum(big_e ^ x)
else
return lenient_bignum(big_e:pow(x))
end
end
if SMODS then
function SMODS.get_blind_amount(ante)
local k = to_big(0.75)
local scale = G.GAME.modifiers.scaling
local amounts = {
to_big(300),
to_big(700 + 100*scale),
to_big(1400 + 600*scale),
to_big(2100 + 2900*scale),
to_big(15000 + 5000*scale*math.log(scale)),
to_big(12000 + 8000*(scale+1)*(0.4*scale)),
to_big(10000 + 25000*(scale+1)*((scale/4)^2)),
to_big(50000 * (scale+1)^2 * (scale/7)^2)
}
if ante < 1 then return to_big(100) end
if ante <= 8 then
local amount = amounts[ante]
if (amount:lt(R.E_MAX_SAFE_INTEGER)) then
local exponent = to_big(10)^(math.floor(amount:log10() - to_big(1))):to_number()
amount = math.floor(amount / exponent):to_number() * exponent
end
amount:normalize()
return amount
end
local a, b, c, d = amounts[8], amounts[8]/amounts[7], ante-8, 1 + 0.2*(ante-8)
local amount = math.floor(a*(b + (b*k*c)^d)^c)
if (amount:lt(R.E_MAX_SAFE_INTEGER)) then
local exponent = to_big(10)^(math.floor(amount:log10() - to_big(1))):to_number()
amount = math.floor(amount / exponent):to_number() * exponent
end
amount:normalize()
return amount
end
end
-- There's too much to override here so we just fully replace this function
-- Note that any ante scaling tweaks will need to manually changed...
local gba = get_blind_amount
function get_blind_amount(ante)
if G.GAME.modifiers.scaling and (G.GAME.modifiers.scaling ~= 1 and G.GAME.modifiers.scaling ~= 2 and G.GAME.modifiers.scaling ~= 3) then return SMODS.get_blind_amount(ante) end
if type(to_big(1)) == 'number' then return gba(ante) end
local k = to_big(0.75)
if not G.GAME.modifiers.scaling or G.GAME.modifiers.scaling == 1 then
local amounts = {
to_big(300), to_big(800), to_big(2000), to_big(5000), to_big(11000), to_big(20000), to_big(35000), to_big(50000)
}
if ante < 1 then return to_big(100) end
if ante <= 8 then return amounts[ante] end
local a, b, c, d = amounts[8],1.6,ante-8, 1 + 0.2*(ante-8)
local amount = a*(b+(k*c)^d)^c
if (amount:lt(R.E_MAX_SAFE_INTEGER)) then
local exponent = to_big(10)^(math.floor(amount:log10() - to_big(1))):to_number()
amount = math.floor(amount / exponent):to_number() * exponent
end
amount:normalize()
return amount
elseif G.GAME.modifiers.scaling == 2 then
local amounts = {
to_big(300), to_big(900), to_big(2600), to_big(8000), to_big(20000), to_big(36000), to_big(60000), to_big(100000)
--300, 900, 2400, 7000, 18000, 32000, 56000, 90000
}
if ante < 1 then return to_big(100) end
if ante <= 8 then return amounts[ante] end
local a, b, c, d = amounts[8],1.6,ante-8, 1 + 0.2*(ante-8)
local amount = a*(b+(k*c)^d)^c
if (amount:lt(R.E_MAX_SAFE_INTEGER)) then
local exponent = to_big(10)^(math.floor(amount:log10() - to_big(1))):to_number()
amount = math.floor(amount / exponent):to_number() * exponent
end
amount:normalize()
return amount
elseif G.GAME.modifiers.scaling == 3 then
local amounts = {
to_big(300), to_big(1000), to_big(3200), to_big(9000), to_big(25000), to_big(60000), to_big(110000), to_big(200000)
--300, 1000, 3000, 8000, 22000, 50000, 90000, 180000
}
if ante < 1 then return to_big(100) end
if ante <= 8 then return amounts[ante] end
local a, b, c, d = amounts[8],1.6,ante-8, 1 + 0.2*(ante-8)
local amount = a*(b+(k*c)^d)^c
if (amount:lt(R.E_MAX_SAFE_INTEGER)) then
local exponent = to_big(10)^(math.floor(amount:log10() - to_big(1))):to_number()
amount = math.floor(amount / exponent):to_number() * exponent
end
amount:normalize()
return amount
end
end
function check_and_set_high_score(score, amt)
if G.GAME.round_scores[score] and to_big(math.floor(amt)) > to_big(G.GAME.round_scores[score].amt) then
G.GAME.round_scores[score].amt = to_big(math.floor(amt))
end
if G.GAME.seeded then return end
--[[if G.PROFILES[G.SETTINGS.profile].high_scores[score] and math.floor(amt) > G.PROFILES[G.SETTINGS.profile].high_scores[score].amt then
if G.GAME.round_scores[score] then G.GAME.round_scores[score].high_score = true end
G.PROFILES[G.SETTINGS.profile].high_scores[score].amt = math.floor(amt)
G:save_settings()
end--]] --going to hold off on modifying this until proper save loading exists
end
local ics = inc_career_stat
-- This is used often for unlocks, so we can't just prevent big money from being added
-- Also, I'm completely overriding this, since I don't think any mods would want to change it
function inc_career_stat(stat, mod)
if G.GAME.seeded or G.GAME.challenge then return end
if not G.PROFILES[G.SETTINGS.profile].career_stats[stat] then G.PROFILES[G.SETTINGS.profile].career_stats[stat] = 0 end
G.PROFILES[G.SETTINGS.profile].career_stats[stat] = G.PROFILES[G.SETTINGS.profile].career_stats[stat] + (mod or 0)
-- Make sure this isn't ever a talisman number
if type(G.PROFILES[G.SETTINGS.profile].career_stats[stat]) == 'table' then
if G.PROFILES[G.SETTINGS.profile].career_stats[stat] > to_big(1e300) then
G.PROFILES[G.SETTINGS.profile].career_stats[stat] = to_big(1e300)
elseif G.PROFILES[G.SETTINGS.profile].career_stats[stat] < to_big(-1e300) then
G.PROFILES[G.SETTINGS.profile].career_stats[stat] = to_big(-1e300)
end
G.PROFILES[G.SETTINGS.profile].career_stats[stat] = G.PROFILES[G.SETTINGS.profile].career_stats[stat]:to_number()
end
G:save_settings()
end
local sn = scale_number
function scale_number(number, scale, max, e_switch_point)
if not Big then return sn(number, scale, max, e_switch_point) end
if type(scale) ~= "table" then scale = to_big(scale) end
if type(number) ~= "table" then number = Big:ensureBig(number) end
if number.scale then return number.scale end
G.E_SWITCH_POINT = G.E_SWITCH_POINT or 100000000000
if not number or not is_number(number) then return scale end
if not max then max = 10000 end
if type(number) ~= "table" then math.min(3, scale:to_number()) end
if number.e and number.e == 10^1000 then
scale = scale*math.floor(math.log(max*10, 10))/7
end
if not e_switch_point and number:arraySize() > 2 then --this is noticable faster than >= on the raw number for some reason
if number:arraySize() <= 2 and (number.array[1] or 0) <= 999 then --gross hack
scale = scale*math.floor(math.log(max*10, 10))/7 --this divisor is a constant so im precalcualting it
else
scale = scale*math.floor(math.log(max*10, 10))/math.floor(math.max(7,string.len(number.str or number_format(number))-1))
end
elseif math.abs(to_big(number)) >= to_big(e_switch_point or G.E_SWITCH_POINT) then
if number:arraySize() <= 2 and (number.array[1] or 0) <= 999 then --gross hack
scale = scale*math.floor(math.log(max*10, 10))/7 --this divisor is a constant so im precalcualting it
else
scale = scale*math.floor(math.log(max*10, 10))/math.floor(math.max(7,string.len(number_format(number))-1))
end
elseif math.abs(to_big(number)) >= to_big(max) then
scale = scale*math.floor(math.log(max*10, 10))/math.floor(math.log(math.abs(number)*10, 10))
end
local scale = math.min(3, scale:to_number())
number.scale = scale
return scale
end
local tsj = G.FUNCS.text_super_juice
function G.FUNCS.text_super_juice(e, _amount)
if type(_amount) == 'table' then
if _amount > to_big(2) then _amount = 2 end
else
if _amount > 2 then _amount = 2 end
end
return tsj(e, _amount)
end
local max = math.max
--don't return a Big unless we have to - it causes nativefs to break
function math.max(x, y)
if type(x) == 'table' or type(y) == 'table' then
x = to_big(x)
y = to_big(y)
if (x > y) then
return x
else
return y
end
else return max(x,y) end
end
local min = math.min
function math.min(x, y)
if type(x) == 'table' or type(y) == 'table' then
x = to_big(x)
y = to_big(y)
if (x < y) then
return x
else
return y
end
else return min(x,y) end
end
local sqrt = math.sqrt
function math.sqrt(x)
if type(x) == 'table' then
if getmetatable(x) == BigMeta then return x:sqrt() end
if getmetatable(x) == OmegaMeta then return x:pow(0.5) end
end
return sqrt(x)
end
local old_abs = math.abs
function math.abs(x)
if type(x) == 'table' then
x = to_big(x)
if (x < to_big(0)) then
return -1 * x
else
return x
end
else return old_abs(x) end
end
end
function is_number(x)
if type(x) == 'number' then return true end
if type(x) == 'table' and ((x.e and x.m) or (x.array and x.sign)) then return true end
return false
end
function to_big(x, y)
if type(x) == 'string' and x == "0" then --hack for when 0 is asked to be a bignumber need to really figure out the fix
return 0
elseif Big and Big.m then
local x = Big:new(x,y)
return x
elseif Big and Big.array then
local result = Big:create(x)
result.sign = y or result.sign or x.sign or 1
return result
elseif is_number(x) then
return x * 10^(y or 0)
elseif type(x) == "nil" then
return 0
else
if ((#x>=2) and ((x[2]>=2) or (x[2]==1) and (x[1]>308))) then
return 1e309
end
if (x[2]==1) then
return math.pow(10,x[1])
end
return x[1]*(y or 1);
end
end
function to_number(x)
if type(x) == 'table' and (getmetatable(x) == BigMeta or getmetatable(x) == OmegaMeta) then
return x:to_number()
else
return x
end
end
function uncompress_big(str, sign)
local curr = 1
local array = {}
for i, v in pairs(str) do
for i2 = 1, v[2] do
array[curr] = v[1]
curr = curr + 1
end
end
return to_big(array, y)
end
--patch to remove animations
local cest = card_eval_status_text
function card_eval_status_text(a,b,c,d,e,f)
if not Talisman.config_file.disable_anims then cest(a,b,c,d,e,f) end
end
local jc = juice_card
function juice_card(x)
if not Talisman.config_file.disable_anims then jc(x) end
end
local cju = Card.juice_up
function Card:juice_up(...)
if not Talisman.config_file.disable_anims then cju(self, ...) end
end
function tal_uht(config, vals)
local col = G.C.GREEN
if vals.chips and G.GAME.current_round.current_hand.chips ~= vals.chips then
local delta = (is_number(vals.chips) and is_number(G.GAME.current_round.current_hand.chips)) and (vals.chips - G.GAME.current_round.current_hand.chips) or 0
if to_big(delta) < to_big(0) then delta = number_format(delta); col = G.C.RED
elseif to_big(delta) > to_big(0) then delta = '+'..number_format(delta)
else delta = number_format(delta)
end
if type(vals.chips) == 'string' then delta = vals.chips end
G.GAME.current_round.current_hand.chips = vals.chips
if (G.hand_text_area.chips or {config = {}}).config.object then
G.hand_text_area.chips:update(0)
end
end
if vals.mult and G.GAME.current_round.current_hand.mult ~= vals.mult then
local delta = (is_number(vals.mult) and is_number(G.GAME.current_round.current_hand.mult))and (vals.mult - G.GAME.current_round.current_hand.mult) or 0
if to_big(delta) < to_big(0) then delta = number_format(delta); col = G.C.RED
elseif to_big(delta) > to_big(0) then delta = '+'..number_format(delta)
else delta = number_format(delta)
end
if type(vals.mult) == 'string' then delta = vals.mult end
G.GAME.current_round.current_hand.mult = vals.mult
if (G.hand_text_area.mult or {config = {}}).config.object then
G.hand_text_area.mult:update(0)
end
end
if vals.handname and G.GAME.current_round.current_hand.handname ~= vals.handname then
G.GAME.current_round.current_hand.handname = vals.handname
end
if vals.chip_total then G.GAME.current_round.current_hand.chip_total = vals.chip_total;G.hand_text_area.chip_total.config.object:pulse(0.5) end
if vals.level and G.GAME.current_round.current_hand.hand_level ~= ' '..localize('k_lvl')..tostring(vals.level) then
if vals.level == '' then
G.GAME.current_round.current_hand.hand_level = vals.level
else
G.GAME.current_round.current_hand.hand_level = ' '..localize('k_lvl')..tostring(vals.level)
if is_number(vals.level) then
G.hand_text_area.hand_level.config.colour = G.C.HAND_LEVELS[type(vals.level) == "number" and math.floor(math.min(vals.level, 7)) or math.floor(to_number(math.min(vals.level, 7)))]
else
G.hand_text_area.hand_level.config.colour = G.C.HAND_LEVELS[1]
end
end
end
return true
end
local uht = update_hand_text
function update_hand_text(config, vals)
if Talisman.config_file.disable_anims then
if G.latest_uht then
local chips = G.latest_uht.vals.chips
local mult = G.latest_uht.vals.mult
if not vals.chips then vals.chips = chips end
if not vals.mult then vals.mult = mult end
end
G.latest_uht = {config = config, vals = vals}
else uht(config, vals)
end
end
G.FUNCS.evaluate_play = function(e)
Talisman.scoring_state = "intro"
text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta = evaluate_play_intro()
if not G.GAME.blind:debuff_hand(G.play.cards, poker_hands, text) then
Talisman.scoring_state = "main"
text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta = evaluate_play_main(text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta)
else
Talisman.scoring_state = "debuff"
text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta = evaluate_play_debuff(text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta)
end
Talisman.scoring_state = "final_scoring"
text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta = evaluate_play_final_scoring(text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta)
Talisman.scoring_state = "after"
evaluate_play_after(text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta)
Talisman.scoring_state = nil
end
local upd = Game.update
function Game:update(dt)
upd(self, dt)
if G.latest_uht and G.latest_uht.config and G.latest_uht.vals then
tal_uht(G.latest_uht.config, G.latest_uht.vals)
G.latest_uht = nil
end
if Talisman.dollar_update then
G.HUD:get_UIE_by_ID('dollar_text_UI').config.object:update()
G.HUD:recalculate()
Talisman.dollar_update = false
end
end
Talisman.F_NO_COROUTINE = false --easy disabling for bugfixing, since the coroutine can make it hard to see where errors are
if not Talisman.F_NO_COROUTINE then
--scoring coroutine
local oldplay = G.FUNCS.evaluate_play
function G.FUNCS.evaluate_play(...)
G.SCORING_COROUTINE = coroutine.create(oldplay)
G.LAST_SCORING_YIELD = love.timer.getTime()
G.CARD_CALC_COUNTS = {} -- keys = cards, values = table containing numbers
local success, err = coroutine.resume(G.SCORING_COROUTINE, ...)
if not success then
error(err)
end
end
function G.FUNCS.tal_abort()
tal_aborted = true
end
local oldupd = love.update
function love.update(dt, ...)
oldupd(dt, ...)
if G.SCORING_COROUTINE then
if collectgarbage("count") > 1024*1024 then
collectgarbage("collect")
end
if coroutine.status(G.SCORING_COROUTINE) == "dead" or tal_aborted then
G.SCORING_COROUTINE = nil
G.FUNCS.exit_overlay_menu()
local totalCalcs = 0
for i, v in pairs(G.CARD_CALC_COUNTS) do
totalCalcs = totalCalcs + v[1]
end
G.GAME.LAST_CALCS = totalCalcs
G.GAME.LAST_CALC_TIME = G.CURRENT_CALC_TIME
G.CURRENT_CALC_TIME = 0
if tal_aborted and Talisman.scoring_state == "main" then
evaluate_play_final_scoring(text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta)
end
tal_aborted = nil
Talisman.scoring_state = nil
else
G.SCORING_TEXT = nil
if not G.OVERLAY_MENU then
G.scoring_text = {localize("talisman_string_D"), "", "", ""}
G.SCORING_TEXT = {
{n = G.UIT.C, nodes = {
{n = G.UIT.R, config = {padding = 0.1, align = "cm"}, nodes = {
{n=G.UIT.O, config={object = DynaText({string = {{ref_table = G.scoring_text, ref_value = 1}}, colours = {G.C.UI.TEXT_LIGHT}, shadow = true, pop_in = 0, scale = 1, silent = true})}},
}},{n = G.UIT.R, nodes = {
{n=G.UIT.O, config={object = DynaText({string = {{ref_table = G.scoring_text, ref_value = 2}}, colours = {G.C.UI.TEXT_LIGHT}, shadow = true, pop_in = 0, scale = 0.4, silent = true})}},
}},{n = G.UIT.R, nodes = {
{n=G.UIT.O, config={object = DynaText({string = {{ref_table = G.scoring_text, ref_value = 3}}, colours = {G.C.UI.TEXT_LIGHT}, shadow = true, pop_in = 0, scale = 0.4, silent = true})}},
}},{n = G.UIT.R, nodes = {
{n=G.UIT.O, config={object = DynaText({string = {{ref_table = G.scoring_text, ref_value = 4}}, colours = {G.C.UI.TEXT_LIGHT}, shadow = true, pop_in = 0, scale = 0.4, silent = true})}},
}},{n = G.UIT.R, nodes = {
UIBox_button({
colour = G.C.BLUE,
button = "tal_abort",
label = { localize("talisman_string_E") },
minw = 4.5,
focus_args = { snap_to = true },
})}},
}}}
G.FUNCS.overlay_menu({
definition =
{n=G.UIT.ROOT, minw = G.ROOM.T.w*5, minh = G.ROOM.T.h*5, config={align = "cm", padding = 9999, offset = {x = 0, y = -3}, r = 0.1, colour = {G.C.GREY[1], G.C.GREY[2], G.C.GREY[3],0.7}}, nodes= G.SCORING_TEXT},
config = {align="cm", offset = {x=0,y=0}, major = G.ROOM_ATTACH, bond = 'Weak'}
})
else
if G.OVERLAY_MENU and G.scoring_text then
local totalCalcs = 0
for i, v in pairs(G.CARD_CALC_COUNTS) do
totalCalcs = totalCalcs + v[1]
end
local jokersYetToScore = #G.jokers.cards + #G.play.cards - #G.CARD_CALC_COUNTS
G.CURRENT_CALC_TIME = (G.CURRENT_CALC_TIME or 0) + dt
G.scoring_text[1] = localize("talisman_string_D")
G.scoring_text[2] = localize("talisman_string_F")..tostring(totalCalcs).." ("..tostring(number_format(G.CURRENT_CALC_TIME)).."s)"
G.scoring_text[3] = localize("talisman_string_G")..tostring(jokersYetToScore)
G.scoring_text[4] = localize("talisman_string_H") .. tostring(G.GAME.LAST_CALCS or localize("talisman_string_I")) .." ("..tostring(G.GAME.LAST_CALC_TIME and number_format(G.GAME.LAST_CALC_TIME) or "???").."s)"
end
end
--this coroutine allows us to stagger GC cycles through
--the main source of waste in terms of memory (especially w joker retriggers) is through local variables that become garbage
--this practically eliminates the memory overhead of scoring
--event queue overhead seems to not exist if Talismans Disable Scoring Animations is off.
--event manager has to wait for scoring to finish until it can keep processing events anyways.
G.LAST_SCORING_YIELD = love.timer.getTime()
local success, msg = coroutine.resume(G.SCORING_COROUTINE)
if not success then
error(msg)
end
end
end
end
TIME_BETWEEN_SCORING_FRAMES = 0.03 -- 30 fps during scoring
-- we dont want overhead from updates making scoring much slower
-- originally 10 fps, I think 30 fps is a good way to balance it while making it look smooth, too
--wrap everything in calculating contexts so we can do more things with it
Talisman.calculating_joker = false
Talisman.calculating_score = false
Talisman.calculating_card = false
Talisman.dollar_update = false
local ccj = Card.calculate_joker
function Card:calculate_joker(context)
--scoring coroutine
G.CURRENT_SCORING_CARD = self
G.CARD_CALC_COUNTS = G.CARD_CALC_COUNTS or {}
if G.CARD_CALC_COUNTS[self] then
G.CARD_CALC_COUNTS[self][1] = G.CARD_CALC_COUNTS[self][1] + 1
else
G.CARD_CALC_COUNTS[self] = {1, 1}
end
if G.LAST_SCORING_YIELD and ((love.timer.getTime() - G.LAST_SCORING_YIELD) > TIME_BETWEEN_SCORING_FRAMES) and coroutine.running() then
coroutine.yield()
end
Talisman.calculating_joker = true
local ret, trig = ccj(self, context)
if ret and type(ret) == "table" and ret.repetitions then
if not ret.card then
G.CARD_CALC_COUNTS.other = G.CARD_CALC_COUNTS.other or {1,1}
G.CARD_CALC_COUNTS.other[2] = G.CARD_CALC_COUNTS.other[2] + ret.repetitions
else
G.CARD_CALC_COUNTS[ret.card] = G.CARD_CALC_COUNTS[ret.card] or {1,1}
G.CARD_CALC_COUNTS[ret.card][2] = G.CARD_CALC_COUNTS[ret.card][2] + ret.repetitions
end
end
Talisman.calculating_joker = false
return ret, trig
end
local cuc = Card.use_consumable
function Card:use_consumable(x,y)
Talisman.calculating_score = true
local ret = cuc(self, x,y)
Talisman.calculating_score = false
return ret
end
local gfep = G.FUNCS.evaluate_play
G.FUNCS.evaluate_play = function(e)
Talisman.calculating_score = true
local ret = gfep(e)
Talisman.calculating_score = false
return ret
end
end
--[[local ec = eval_card
function eval_card()
Talisman.calculating_card = true
local ret = ec()
Talisman.calculating_card = false
return ret
end--]]
local sm = Card.start_materialize
function Card:start_materialize(a,b,c)
if Talisman.config_file.disable_anims and (Talisman.calculating_joker or Talisman.calculating_score or Talisman.calculating_card) then return end
return sm(self,a,b,c)
end
local sd = Card.start_dissolve
function Card:start_dissolve(a,b,c,d)
if Talisman.config_file.disable_anims and (Talisman.calculating_joker or Talisman.calculating_score or Talisman.calculating_card) then self:remove() return end
return sd(self,a,b,c,d)
end
local ss = Card.set_seal
function Card:set_seal(a,b,immediate)
return ss(self,a,b,Talisman.config_file.disable_anims and (Talisman.calculating_joker or Talisman.calculating_score or Talisman.calculating_card) or immediate)
end
if not SMODS then
function Card:get_chip_x_bonus()
if self.debuff then return 0 end
if self.ability.set == 'Joker' then return 0 end
if (self.ability.x_chips or 0) <= 1 then return 0 end
return self.ability.x_chips
end
end
function Card:get_chip_e_bonus()
if self.debuff then return 0 end
if self.ability.set == 'Joker' then return 0 end
if (self.ability.e_chips or 0) <= 1 then return 0 end
return self.ability.e_chips
end
function Card:get_chip_ee_bonus()
if self.debuff then return 0 end
if self.ability.set == 'Joker' then return 0 end
if (self.ability.ee_chips or 0) <= 1 then return 0 end
return self.ability.ee_chips
end
function Card:get_chip_eee_bonus()
if self.debuff then return 0 end
if self.ability.set == 'Joker' then return 0 end
if (self.ability.eee_chips or 0) <= 1 then return 0 end
return self.ability.eee_chips
end
function Card:get_chip_hyper_bonus()
if self.debuff then return {0,0} end
if self.ability.set == 'Joker' then return {0,0} end
if type(self.ability.hyper_chips) ~= 'table' then return {0,0} end
if (self.ability.hyper_chips[1] <= 0 or self.ability.hyper_chips[2] <= 0) then return {0,0} end
return self.ability.hyper_chips
end
function Card:get_chip_e_mult()
if self.debuff then return 0 end
if self.ability.set == 'Joker' then return 0 end
if (self.ability.e_mult or 0) <= 1 then return 0 end
return self.ability.e_mult
end
function Card:get_chip_ee_mult()
if self.debuff then return 0 end
if self.ability.set == 'Joker' then return 0 end
if (self.ability.ee_mult or 0) <= 1 then return 0 end
return self.ability.ee_mult
end
function Card:get_chip_eee_mult()
if self.debuff then return 0 end
if self.ability.set == 'Joker' then return 0 end
if (self.ability.eee_mult or 0) <= 1 then return 0 end
return self.ability.eee_mult
end
function Card:get_chip_hyper_mult()
if self.debuff then return {0,0} end
if self.ability.set == 'Joker' then return {0,0} end
if type(self.ability.hyper_mult) ~= 'table' then return {0,0} end
if (self.ability.hyper_mult[1] <= 0 or self.ability.hyper_mult[2] <= 0) then return {0,0} end
return self.ability.hyper_mult
end
--Easing fixes
--Changed this to always work; it's less pretty but fine for held in hand things
local edo = ease_dollars
function ease_dollars(mod, instant)
if Talisman.config_file.disable_anims then--and (Talisman.calculating_joker or Talisman.calculating_score or Talisman.calculating_card) then
mod = mod or 0
if to_big(mod) > to_big(0) then inc_career_stat('c_dollars_earned', mod) end
G.GAME.dollars = G.GAME.dollars + mod
Talisman.dollar_update = true
else return edo(mod, instant) end
end
local su = G.start_up
function safe_str_unpack(str)
local chunk, err = loadstring(str)
if chunk then
setfenv(chunk, {Big = Big, BigMeta = BigMeta, OmegaMeta = OmegaMeta, to_big = to_big, inf = 1.79769e308, uncompress_big=uncompress_big}) -- Use an empty environment to prevent access to potentially harmful functions
local success, result = pcall(chunk)
if success then
return result
else
print("[Talisman] Error unpacking string: " .. result)
print(tostring(str))
return nil
end
else
print("[Talisman] Error loading string: " .. err)
print(tostring(str))
return nil
end
end
function G:start_up()
STR_UNPACK = safe_str_unpack
su(self)
STR_UNPACK = safe_str_unpack
end
--Skip round animation things
local gfer = G.FUNCS.evaluate_round
function G.FUNCS.evaluate_round()
if Talisman.config_file.disable_anims then
if to_big(G.GAME.chips) >= to_big(G.GAME.blind.chips) then
add_round_eval_row({dollars = G.GAME.blind.dollars, name='blind1', pitch = 0.95})
else
add_round_eval_row({dollars = 0, name='blind1', pitch = 0.95, saved = true})
end
local arer = add_round_eval_row
add_round_eval_row = function() return end
local dollars = gfer()
add_round_eval_row = arer
add_round_eval_row({name = 'bottom', dollars = Talisman.dollars})
else
return gfer()
end
end
local g_start_run = Game.start_run
function Game:start_run(args)
local ret = g_start_run(self, args)
self.GAME.round_resets.ante_disp = self.GAME.round_resets.ante_disp or number_format(self.GAME.round_resets.ante, 1000000)
return ret
end
-- Steamodded calculation API: add extra operations
if SMODS and SMODS.calculate_individual_effect then
local scie = SMODS.calculate_individual_effect
function SMODS.calculate_individual_effect(effect, scored_card, key, amount, from_edition)
-- For some reason, some keys' animations are completely removed
-- I think this is caused by a lovely patch conflict
--if key == 'chip_mod' then key = 'chips' end
--if key == 'mult_mod' then key = 'mult' end
--if key == 'Xmult_mod' then key = 'x_mult' end
local ret = scie(effect, scored_card, key, amount, from_edition)
if ret then
return ret
end
if (key == 'e_chips' or key == 'echips' or key == 'Echip_mod') and amount ~= 1 then
if effect.card then juice_card(effect.card) end
if SMODS.Scoring_Parameters then
local chips = SMODS.Scoring_Parameters["chips"]
chips:modify(chips.current ^ amount - chips.current)
else