-
Notifications
You must be signed in to change notification settings - Fork 4
/
CharacterTool.ttslua
1416 lines (1254 loc) · 46.7 KB
/
CharacterTool.ttslua
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
--[[
Character Tool
Made by Sionar
--]]
------------------Constants
VERSION = '1.10.6'
PLAYER_DIST = {{0,0,0,1},{1,0,0,1},{2,0,0,1},{3,0,0,1},{3,0,1,1},{3,1,1,1},{5,0,1,1},{5,1,1,1},{5,2,1,1},{7,0,2,1},{7,1,2,1},{7,2,2,1},{9,0,3,1},{9,1,3,1},{9,2,3,1},{9,2,3,1},{9,2,3,1},{9,2,3,1},{9,2,3,1},{9,2,3,1}} --layout: player count = {townsfolk, outsiders, minions, demons}
COLORS_BBC = {Townsfolk = '[1E87FF]', Outsider = '[20B09A]', Minion = '[F3631C]', Demon = '[DA1917]', Traveler = '[30B22A]'}
BUTTON_Y = 0.1
Z_START = -7
Z_INC = 0.44
DEFAULT_CUSTOM_IMAGE_URL = 'http://cloud-3.steamusercontent.com/ugc/1670238751989216770/8DBF91FC7E2DB8D829AE795A1F53983822ADCED0/'
DEFAULT_NIGHT_SHEET_URL = 'http://cloud-3.steamusercontent.com/ugc/1669111897321786410/8A824CC043EDD270040F97F7DACA93A2C9E3CA08/'
#include GUIDs.ttslua
------------------Variables
objects = {}
mode = 'TB'
numPlayers = 0
numTrav = 0
menu = 'start'
dist = {}
characters = {}
unused = {}
selected = {}
lock = {}
found = {}
saveLoadPage = 1
saveFile = {}
saveCategoryName = {}
for i = 1,100 do
saveFile[i] = {name = 'Save' .. i, charList = {}, imageUrl = ''}
end
for i = 1,10 do
saveCategoryName[i] = 'Page ' .. i
end
batchList = {}
imageLoaded = false
customImageUrl = ''
customNightSheetUrl = ''
------------------Functions
function onLoad(saveString)
if not (saveString == '') then
local save = JSON.decode(saveString)
characters = save['c']
saveFile = save['s']
saveCategoryName = save['sc']
saveLoadPage = save['p']
end
assignObjects()
moveBoard()
startMenu()
TABLE_OFFSET = Global.getVar('TABLE_OFFSET')
self.setDescription('v ' .. VERSION .. '\nMade by Sionar')
end
function onSave()
local save = {}
save['c'] = characters
save['s'] = saveFile
save['sc'] = saveCategoryName
save['p'] = saveLoadPage
local saveString = JSON.encode(save)
return saveString
end
function assignObjects()
objects.storageBag = getObjectFromGUID(STORAGE_BAG_GUID)
end
function moveBoard()
local modName = Global.getVar('MOD_NAME')
local TABLE_OFFSET, STORYTELLER_TABLE_DIST
if modName == 'Blood on the Clocktower' then
local allObjects = getAllObjects()
local count = 0
for k,v in pairs(allObjects) do
if v.getName() == 'Character Tool' then
count = count + 1
end
end
if count > 1 then
return
end
TABLE_OFFSET = Global.getVar('TABLE_OFFSET')
STORYTELLER_TABLE_DIST = Global.getVar('STORYTELLER_TABLE_DIST')
self.setPositionSmooth({0,1.2,TABLE_OFFSET + STORYTELLER_TABLE_DIST + 8})
self.setRotationSmooth({0,0,0})
self.setLock(true)
end
end
function nullFunc() end
function unusedRemove(clickedObject, playerColor, index)
if playerColor ~= 'Black' then
return
end
local char = unused[index]
if char ~= 'Legion' then
table.remove(unused, index)
end
table.insert(selected, char)
refreshUI()
end
for k = 1,40 do
_G['unusedRemove' .. k] = function(obj, col)
unusedRemove(obj, col, k)
end
end
function selectedRemove(clickedObject, playerColor, index)
if playerColor ~= 'Black' then
return
end
local char = selected[index]
table.remove(selected, index)
if char ~= 'Legion' then
table.insert(unused, char)
end
lock[char] = false
refreshUI()
end
for k = 1,40 do
_G['selectedRemove' .. k] = function(obj, col)
selectedRemove(obj, col, k)
end
end
function toggleLock(clickedObject, playerColor, index)
if playerColor ~= 'Black' then
return
end
if lock[selected[index]] == nil then
lock[selected[index]] = true
elseif lock[selected[index]] == false then
lock[selected[index]] = true
elseif lock[selected[index]] == true then
lock[selected[index]] = false
end
refreshUI()
end
for k = 1,40 do
_G['toggleLock' .. k] = function(obj, col)
toggleLock(obj, col, k)
end
end
function label(input)
return COLORS_BBC[CHARACTERS[input].Type] .. input
end
function modeTB(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
setMode(1)
end
function modeBM(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
setMode(2)
end
function modeSV(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
setMode(3)
end
function modeCU(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
setMode(4)
end
function setMode(state)
local objs = getAllObjects()
local name
if state == 1 then
mode = 'TB'
name = 'Trouble Brewing'
characters = TB_LIST
elseif state == 2 then
mode = 'BM'
name = 'Bad Moon Rising'
characters = BM_LIST
elseif state == 3 then
mode = 'SV'
name = 'Sects & Violets'
characters = SV_LIST
elseif state == 4 then
mode = 'CU'
name = 'Custom'
characters = {}
end
if mode ~= 'CU' then
spawnSet(characters, name)
else
spawnSet(CU_LIST, name)
end
unused = {}
for k,v in pairs(characters) do
table.insert(unused, v)
end
selected = {}
lock = {}
Global.setVar('mode', mode)
for k,v in pairs(objs) do
if string.match(v.getName(), ': Characters')
or string.match(v.getName(), ': Night Sheet') then
if v.getStateId() ~= state then
v.setState(state)
end
end
end
Global.call('showExtensionUI')
refreshUI()
end
function random(clickedObject, playerColor)
local players
local unusedChars = {Townsfolk = {}, Outsider = {}, Minion = {}, Demon = {}, Traveler = {}}
local lockedChars = {Townsfolk = {}, Outsider = {}, Minion = {}, Demon = {}, Traveler = {}}
local rand, currentChar, travDist, count
if playerColor ~= 'Black' and not debug then
return
end
if numPlayers == 0 then
numPlayers = Global.call('getNumPlayers')
if numPlayers <= 1 then
numPlayers = 5
end
end
unused = {}
for k,v in pairs(characters) do
table.insert(unused, v)
end
if #selected ~= 0 then
for i = #selected, 1, -1 do
if lock[selected[i]] then
for k1,v1 in pairs(unused) do
if selected[i] == v1 and selected[i] ~= 'Legion' then
table.remove(unused, k1)
end
end
else
table.remove(selected,i)
end
end
end
for k,v in pairs(unused) do
table.insert(unusedChars[CHARACTERS[v].Type], v)
end
for k,v in pairs(unusedChars) do
shuffleTable(v)
end
for k,v in pairs(selected) do
table.insert(lockedChars[CHARACTERS[v].Type], v)
end
dist = {}
for k,v in pairs(PLAYER_DIST[numPlayers]) do
table.insert(dist,v)
end
for i = 1,4 do
dist[i] = dist[i] - #lockedChars[TYPES[i]]
end
travDist = numTrav - #lockedChars['Traveler']
if dist[4] < 0 and lockedChars['Demon'][1] ~= 'Legion' then
Player['Black'].print('Error: Too many Demons are locked.', {1,0,0})
refreshUI()
return
elseif dist[3] < 0 then
Player['Black'].print('Error: Too many Minions are locked.', {1,0,0})
refreshUI()
return
elseif #lockedChars['Outsider'] > PLAYER_DIST[numPlayers][2] then
Player['Black'].print('Error: Too many Outsiders are locked.', {1,0,0})
refreshUI()
return
elseif #lockedChars['Outsider'] == PLAYER_DIST[numPlayers][2] and #lockedChars['Outsider'] ~= 0 and lockedChars['Demon'][1] == 'Vigormortis' then
Player['Black'].print('Error: Too many Outsiders are locked.', {1,0,0})
refreshUI()
return
elseif dist[1] < 0 then
Player['Black'].print('Error: Too many Townsfolk are locked.', {1,0,0})
refreshUI()
return
elseif travDist < 0 then
Player['Black'].print('Error: Too many Travelers are locked.', {1,0,0})
refreshUI()
return
end
for k,v in pairs(lockedChars['Demon']) do
if v == 'Legion' then
setRandomLegionGame()
return
end
adjustOutsiders(v)
end
for k,v in pairs(lockedChars['Minion']) do
adjustOutsiders(v)
end
for k,v in pairs(lockedChars['Townsfolk']) do
adjustOutsiders(v)
end
count = 1
for i = 1, dist[4] do
while not checkValid(unusedChars.Demon[i], #lockedChars['Outsider']) do
i = i + 1
if i > #unusedChars.Demon then
Player['Black'].print('Error: Invalid setup.', {1,0,0})
refreshUI()
return
end
end
currentChar = unusedChars.Demon[i]
if currentChar == 'Legion' then
setRandomLegionGame()
return
end
table.insert(selected, currentChar)
for k,v in pairs(unused) do
if v == currentChar and v ~= 'Legion' then
table.remove(unused,k)
end
end
adjustOutsiders(currentChar)
end
for i = 1, dist[3] do
while not checkValid(unusedChars.Minion[count], #lockedChars['Outsider']) do
i = i + 1
if i > #unusedChars.Minion then
Player['Black'].print('Error: Invalid setup.', {1,0,0})
refreshUI()
return
end
end
currentChar = unusedChars.Minion[i]
table.insert(selected, currentChar)
for k,v in pairs(unused) do
if v == currentChar then
table.remove(unused,k)
end
end
adjustOutsiders(currentChar)
end
local townIdx = 1
while dist[1] > 0 do
currentChar = unusedChars.Townsfolk[townIdx]
if currentChar == 'Balloonist' or currentChar == 'Chieftain' and dist[1] == 1 then
townIdx = townIdx + 1
currentChar = unusedChars.Townsfolk[townIdx]
end
table.insert(selected, currentChar)
for k,v in pairs(unused) do
if v == currentChar then
table.remove(unused,k)
end
end
dist[1] = dist[1] - 1
townIdx = townIdx + 1
adjustOutsiders(currentChar)
end
for i = 1, dist[2] do
currentChar = unusedChars.Outsider[i]
table.insert(selected, currentChar)
for k,v in pairs(unused) do
if v == currentChar then
table.remove(unused,k)
end
end
end
for i = 1, travDist do
currentChar = unusedChars.Traveler[i]
table.insert(selected, currentChar)
for k,v in pairs(unused) do
if v == currentChar then
table.remove(unused,k)
end
end
end
refreshUI()
end
function setRandomLegionGame()
local numLegion = math.ceil((numPlayers+1)/2)
local numLockedLegion = 0
local numNonLegion = 0
local newSelected = {}
local shuffledUnused = {}
unused = {}
for k,v in pairs(characters) do
table.insert(unused, v)
end
for i,v in ipairs(selected) do
if lock[selected[i]] == true then
table.insert(newSelected, selected[i])
if selected[i] ~= 'Legion' then
numNonLegion = numNonLegion + 1
for k2, v2 in pairs(unused) do
if v2 == selected[i] then
table.remove(unused, k2)
end
end
else
numLockedLegion = numLockedLegion + 1
end
end
end
if numNonLegion > numPlayers - numLegion then
numLegion = numPlayers - numNonLegion
Player['Black'].print('Warning: Too many non Legion characters are locked.', {1,0,0})
end
for i = 1, numLegion - numLockedLegion do
table.insert(selected, 'Legion')
end
for k,v in pairs(unused) do
if CHARACTERS[v].Type == 'Townsfolk' or CHARACTERS[v].Type == 'Outsider' then
table.insert(shuffledUnused, v)
end
end
shuffleTable(shuffledUnused)
for i = 1, numPlayers - numLegion - numNonLegion do
table.insert(selected, shuffledUnused[i])
for k,v in pairs(unused) do
if v == shuffledUnused[i] then
table.remove(unused, k)
end
end
end
refreshUI()
end
function start(clickedObject, playerColor)
if playerColor ~= 'Black' and not debug then
return
end
if #selected == 0 then
Player[playerColor].print('Error: No characters have been selected.')
return
end
if mode == 'CU' then
updateCustomDecalUI()
editCustomNotebookTab()
import()
else
dealChars()
end
end
function dealChars()
local bags = {}
local dealBagPos
local takeObj
local bagObjs
local name, foundIndex
local objs = getAllObjects()
local TABLE_OFFSET = Global.getVar('TABLE_OFFSET')
local STORYTELLER_TABLE_DIST = Global.getVar('STORYTELLER_TABLE_DIST')
bags.deal = getObjectFromGUID(DEAL_BAG_GUID)
if bags.deal == nil then
printToColor('ERROR: Deal bag not found.', 'Black', {1,0,0})
return
end
dealBagPos = bags.deal.getPosition()
dealBagPos['y'] = dealBagPos['y'] + 6
for k,v in pairs(objs) do
if string.match(v.getName(), ': Demons') then
bags.Demon = v
elseif string.match(v.getName(), ': Minions') then
bags.Minion = v
elseif string.match(v.getName(), ': Outsiders') then
bags.Outsider = v
elseif string.match(v.getName(), ': Townsfolk') then
bags.Townsfolk = v
elseif string.match(v.getName(), ': Travelers') then
bags.Traveler = v
end
end
for k,v in pairs(selected) do
name = v
foundIndex = nil
bagObjs = bags[CHARACTERS[v].Type].getObjects()
for k1, v1 in pairs(bagObjs) do
if v1.name == name then
foundIndex = v1.index
break
end
end
if foundIndex ~= nil then
takeObj = bags[CHARACTERS[v].Type].takeObject({position = dealBagPos, index = foundIndex})
bags.deal.putObject(takeObj)
end
end
Wait.time(function() bags.deal.shuffle() end, 0.5)
Wait.time(function () bags.deal.setPositionSmooth({0, 1.2, TABLE_OFFSET + STORYTELLER_TABLE_DIST}) end, 1)
self.clearButtons()
objects.storageBag.putObject(self)
end
function import()
local reminderBagJSON
Global.setTable('customList', characters)
if not imageLoaded then
Global.setVar('customSet', true)
Global.call('drawAllCharSheets')
end
spawnSet(characters, 'Custom')
Wait.time(dealChars, 1)
end
function checkValid(char, numLockedOutsiders)
if char == 'Fang Gu' or char == 'Godfather' or char == 'Balloonist' or char == 'Chieftain' or char == 'Eclipse' then
if dist[1] == 0 then
return false
end
elseif char == 'Vigormortis' then
if numLockedOutsiders > 0 and dist[2] <= 0 then
return false
end
elseif char == 'Baron' or char == 'Conspirator' then
if dist[1] <= 1 then
return false
end
end
return true
end
function adjustOutsiders(char)
if char == 'Fang Gu' or char == 'Godfather' or char == 'Balloonist' or char == 'Chieftain' or char == 'Eclipse' then
dist[2] = dist[2] + 1
dist[1] = dist[1] - 1
elseif char == 'Vigormortis' then
if dist[2] ~= 0 then
dist[2] = dist[2] - 1
dist[1] = dist[1] + 1
end
elseif char == 'Baron' or char == 'Conspirator' then
dist[2] = dist[2] + 2
dist[1] = dist[1] - 2
end
end
function shuffleTable(tab)
local rand
if tab == nil then
return nil
end
for i = #tab, 1, -1 do
rand = math.random(1,i)
tab[i], tab[rand] = tab[rand], tab[i]
end
return tab
end
function charInput(obj, color, input, stillEditing)
if not stillEditing then
local found = false
for k,v in pairs(CHARACTERS) do
if string.lower(k) == string.lower(input) and input ~= '' then
charAdd = k
found = true
break
end
end
if found then
refreshUI()
return 1
end
for k,v in pairs(CHARACTERS) do
if string.match(string.lower(k), string.lower(input)) and input ~= '' then
charAdd = k
break
end
end
refreshUI()
return 1
end
end
function removeChar()
if charAdd == '' then
return
end
for k,v in pairs(characters) do
if v == charAdd then
table.remove(characters, k)
end
end
unused = {}
for k,v in pairs(characters) do
table.insert(unused, v)
end
selected = {}
lock = {}
refreshUI()
end
function addChar()
if charAdd == '' then
return
end
for k,v in pairs(characters) do
if v == charAdd then
return
end
end
table.insert(characters, charAdd)
unused = {}
selected = {}
for k,v in pairs(characters) do
table.insert(unused, v)
end
lock = {}
sortChars()
refreshUI()
end
function sortChars()
local newCharList = {}
for k,v in pairs(TYPES) do
for k1,v1 in pairs(characters) do
if CHARACTERS[v1].Type == v then
table.insert(newCharList, v1)
end
end
end
characters = newCharList
end
function clear()
characters = {}
unused = {}
selected = {}
lock = {}
refreshUI()
end
function numPlayersInput(obj, color, input, stillEditing)
if not stillEditing then
numPlayers = tonumber(input)
if numPlayers == nil then
numPlayers = 5
elseif numPlayers > 15 then
numPlayers = 15
elseif numPlayers < 5 then
numPlayers = 5
end
refreshUI()
return 1
end
end
function numTravInput(obj, color, input, stillEditing)
if not stillEditing then
numTrav = tonumber(input)
if numTrav == nil then
numTrav = 0
elseif numTrav > 5 then
numTrav = 5
elseif numTrav < 0 then
numTrav = 0
end
refreshUI()
return 1
end
end
function batchImportMenu()
menu = 'batchimport'
self.clearButtons()
self.clearInputs()
self.createInput({
input_function = 'updateBatchList',
function_owner = self,
label = 'Import a bunch of characters at once.\nOne character per line, no commas.\nYou do not need to type in the full name.\nFor example, you can enter math for Mathematician.\nYou can also paste the JSON from the official BotC script tool and click Load.',
width = 4000,
height = 6000,
font_size = 200,
color = {0.2,0.2,0.2},
font_color = {1,1,1},
alignment = 3,
})
self.createButton({
click_function = 'nullFunc',
function_owner = self,
label = 'Batch Import',
position = {0,BUTTON_Y,-7.5},
width = 0,
height = 0,
font_size = 400,
color = {1,1,1,1},
font_color = {1,1,1},
})
self.createButton({
click_function = 'batchImport',
function_owner = self,
label = 'Load',
position = {-2,BUTTON_Y,7.5},
width = 1300,
height = 500,
font_size = 400,
color = {1,1,1,1},
font_color = {0,0,0},
})
self.createButton({
click_function = 'refreshUI',
function_owner = self,
label = 'Cancel',
position = {2,BUTTON_Y,7.5},
width = 1300,
height = 500,
font_size = 400,
color = {1,1,1,1},
font_color = {0,0,0},
})
end
function updateBatchList(obj, color, input, stillEditing)
local sub
if not stillEditing then
batchList = {}
local entry, jsonInput
if string.sub(input, 1, 1) == '[' then
jsonInput = JSON.decode(input)
for i,v in ipairs(jsonInput) do
sub = string.gsub(v.id, "_", " ")
table.insert(batchList, sub)
end
else
for s in input:gmatch("[^\r\n]+") do
entry = s
table.insert(batchList, entry)
end
end
end
end
function batchImport()
characters = {}
local match
for k,v in pairs(batchList) do
match = getKey(CHARACTERS, v)
if match then
table.insert(characters,match)
end
end
unused = {}
selected = {}
for k,v in pairs(characters) do
table.insert(unused, v)
end
lock = {}
sortChars()
refreshUI()
end
function getKey(table, value)
for k,v in pairs(table) do
if string.lower(k) == string.lower(value) and value ~= '' then
return k
end
end
for k,v in pairs(table) do
if string.match(string.lower(k), string.lower(value)) and value ~= '' then
return k
end
end
return false
end
function radius(rad, angle, height)
return {rad*math.sin(angle*math.pi/180), height, rad*math.cos(angle*math.pi/180)}
end
function updateCustomDecalUI()
local xml = UI.getXmlTable()
local entry
local sortedChars = {}
for k,v in pairs(TYPES) do
for k1,v1 in pairs(characters) do
if CHARACTERS[v1].Type == v then
table.insert(sortedChars, v1)
end
end
end
for k,v in pairs(xml) do
if v.attributes.id == 'placeDecalCU' then
v.children[2].children = {}
v.children[2].children[1] = {tag = 'Option', value = 'None', attributes = {selected = 'true'}, children = {}}
for k1,v1 in pairs(sortedChars) do
entry = {tag = 'Option', value = v1, attributes = {}, children = {}}
table.insert(v.children[2].children, entry)
end
end
end
UI.setXmlTable(xml)
end
function editCustomNotebookTab()
local tab = {index = 6, title = 'Custom Script Characters', color = 'Grey'}
local text = 'Disclaimer: The custom made characters are made by fans of the game. They are not endorsed by The Pandemonium Institute.\r\n\r\n'
for k,v in pairs(TYPES) do
text = text .. '[i]' .. v .. '[/i]\r\n'
for k1,v1 in pairs(characters) do
if CHARACTERS[v1].Type == v then
text = text .. '\r\n[b]' .. v1 .. '[/b] - ' .. CHARACTERS[v1].Description
end
end
text = text .. '\r\n\n\r\n'
end
tab.body = text
Notes.editNotebookTab(tab)
end
function setSaveName(obj, color, input, stillEditing, index)
if not stillEditing then
saveFile[index].name = input
saveLoadMenu()
return 1
end
end
function save(clickedObject, playerColor, index)
saveFile[index].charList = characters
if imageLoaded then
saveFile[index].imageUrl = customImageUrl
saveFile[index].nightSheetUrl = customNightSheetUrl
else
saveFile[index].imageUrl = ''
end
Player[playerColor].print('Current character list saved to slot ' .. index .. '.')
saveLoadMenu()
end
function load(clickedObject, playerColor, index)
characters = {}
for k,v in pairs(saveFile[index].charList) do
if CHARACTERS[v] then
table.insert(characters,v)
end
end
if saveFile[index].imageUrl == '' then
imageLoaded = false
customImageUrl = DEFAULT_CUSTOM_IMAGE_URL
else
imageLoaded = true
customImageUrl = saveFile[index].imageUrl
customNightSheetUrl = saveFile[index].nightSheetUrl
Wait.time(loadCharSheetAsset, 1)
end
if saveFile[index].nightSheetUrl == '' or saveFile[index].nightSheetUrl == nil then
customNightSheetUrl = DEFAULT_NIGHT_SHEET_URL
else
customNightSheetUrl = saveFile[index].nightSheetUrl
end
loadImage()
updateNightSheet()
Player[playerColor].print('Character list [1E87FF]' .. saveFile[index].name .. ' [-]loaded.')
unused = {}
selected = {}
for k,v in pairs(characters) do
table.insert(unused, v)
end
lock = {}
spawnSet(characters, saveFile[index].name)
refreshUI()
end
function loadCharSheetAsset()
local assets = Global.UI.getCustomAssets()
for i,v in ipairs(assets) do
if v.name == 'CharsCU' then
v.url = customImageUrl
break
end
end
Global.UI.setCustomAssets(assets)
end
for k = 1,100 do
_G['setSaveName' .. k] = function(obj, col, input, editing)
setSaveName(obj, col, input, editing, k)
end
_G['save' .. k] = function(obj, col)
save(obj, col, k)
end
_G['load' .. k] = function(obj, col)
load(obj, col, k)
end
end
function slPageFirst(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
saveLoadPage = 1
saveLoadMenu()
end
function slPagePrev(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
saveLoadPage = saveLoadPage - 1
if saveLoadPage == 0 then
saveLoadPage = 1
end
saveLoadMenu()
end
function slPageNext(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
saveLoadPage = saveLoadPage + 1
if saveLoadPage == 11 then
saveLoadPage = 10
end
saveLoadMenu()
end
function slPageLast(clickedObject, playerColor)
if playerColor ~= 'Black' then
return
end
saveLoadPage = 10
saveLoadMenu()
end
function setCategoryName(obj, color, input, stillEditing, index)
if not stillEditing then
saveCategoryName[index] = input
saveLoadMenu()
return 1
end
end
for k = 1,10 do
_G['setCategoryName' .. k] = function(obj, col, input, editing)
setCategoryName(obj, col, input, editing, k)
end
end