-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable-updater.lua
More file actions
1624 lines (1411 loc) · 50.8 KB
/
table-updater.lua
File metadata and controls
1624 lines (1411 loc) · 50.8 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
--[[StartXML
<Defaults>
<Panel color="#282828AA" />
<Panel class="npc_commander" rectAlignment="MiddleLeft" color="#FFE162" />
<Text class="npc_commander" color="#FFE162" />
<Panel class="initiative_mat" rectAlignment="MiddleLeft" color="#9ACFFD" />
<Text class="initiative_mat" color="#9ACFFD" />
<Panel class="player" rectAlignment="MiddleLeft" color="#EEEEEE" />
<Text class="player" color="#EEEEEE" />
<Button rectAlignment="UpperLeft" width="200" height="38" colors="#282828|#c8329b|#ff9b38|#dddddd" textColor="White" />
<Text fontSize="11" alignment="UpperLeft" rectAlignment="UpperLeft" />
<Text class="title" fontSize="18" fontStyle="Bold" />
<InputField rectAlignment="UpperLeft" onValueChanged="UI_UpdateInput" />
</Defaults>
StopXML--xml]]
function loadXML()
local script = self.getLuaScript()
local xml = script:sub(script:find("StartXML")+8, script:find("StopXML")-1)
self.UI.setXml(xml)
end
-- TODO: Implement saving and loading of variables such as GUIDs and player data etc.
-- Global variables --------------------- DO NOT TOUCH --------------------------
local magic_word = "mr developer"
local _require_restart = false
local _accepting_players = false
-- Github urls for the various scripts -- DO NOT TOUCH --------------------------
local _URLs = {
_v = "https://raw.githubusercontent.com/Zavian/Tabletop-Simulator-Scripts/master/VERSIONS",
_self = "https://raw.githubusercontent.com/Zavian/Tabletop-Simulator-Scripts/master/table-updater.lua",
npc_commander = "https://raw.githubusercontent.com/Zavian/Tabletop-Simulator-Scripts/master/Commander%20Gen%202/NPC%20Commander.v2.lua",
monster = "https://raw.githubusercontent.com/Zavian/Tabletop-Simulator-Scripts/master/Commander%20Gen%202/Monster%20Token/monster.lua",
initiative_mat = "https://raw.githubusercontent.com/Zavian/Tabletop-Simulator-Scripts/master/Commander%20Gen%202/Initiative%20Stuff/initiative-mat.lua",
player_manager = "https://raw.githubusercontent.com/Zavian/Tabletop-Simulator-Scripts/master/player_manager/player-manager.lua",
initiative_token = "https://raw.githubusercontent.com/Zavian/Tabletop-Simulator-Scripts/master/Commander%20Gen%202/Initiative%20Stuff/initiative-token.lua",
note = "https://raw.githubusercontent.com/Zavian/Tabletop-Simulator-Scripts/master/Clever%20Notecard/notecard.lua"
}
-- variable to store versions downloaded from github -----------------------------
local _versions = {
}
local _colors = {
"Green", "Purple", "Red", "Blue", "Yellow", "Brown", "White", "Teal", "Orange", "Pink"
}
--[[
Green, Purple, Red, Blue, Yellow, Brown, White, Teal, Orange, Pink
What needs to be stored:
- Each component with the following things:
- Version
- GUID
- Each player
- Color
- Character Name
- Manager GUID
- Mini GUID
An ideal _data should look like this:
_data = {
debug = false,
components = {
npc_commander = {
version = "2.2.1",
guid = "aa88ii"
},
monster = {
version = "1.0.0",
guid = "bb99ii"
},
initiative_mat = {
version = "1.0.0",
guid = "cc88ii"
},
player_manager = {
version = "1.0.0",
guid = "dd88ii"
}
},
players = {
red = {
name = "Zora",
manager_guid = "aa88oo",
mini_guid = "bb99oo"
},
blue = {
name = "Frank",
manager_guid = "aa88oo",
mini_guid = "bb99oo"
},
yellow = nil,
green = {
name = "Zavian",
manager_guid = "aa88oo",
mini_guid = "bb99oo"
},
teal = nil,
purple = nil,
brown = {
name = "Laura",
manager_guid = "aa88oo",
mini_guid = "bb99oo"
},
white = nil,
orange = nil,
pink = {
name = "Deborah",
manager_guid = "aa88oo",
mini_guid = "bb99oo"
}
}
}
--]]
local _data = {
debug = false
}
-- event functions --------------------------------------------------------------
function none() end
function onLoad(saved_data)
loadXML()
if saved_data ~= "" then
log("Found saved data.")
_data = JSON.decode(saved_data)
_debug(_data)
end
processVersions()
self.createButton({
click_function = 'start',
function_owner = self,
label = 'Start',
color = {r = 0.498, g = 0.831, b = 0.988},
position = {0, 0.1, 0},
scale = {0.5, 0.5, 0.5},
width = 950,
height = 950,
font_size = 400,
tooltip = ' '
})
if _data.debug then
broadcastNotice("Debug mode is on.")
start()
end
end
function onSave()
updateSave()
return self.script_state
end
function onCollisionEnter(collision_info)
-- collision_info table:
-- collision_object Object
-- contact_points Table {Vector, ...}
-- relative_velocity Vector
if _accepting_players then
if collision_info.collision_object.interactable then
local t = collision_info.collision_object.type
if t == "Tileset" then -- this is for the character mini
self.UI.setAttribute("playerMiniGUID", "text", collision_info.collision_object.guid)
self.UI.setAttribute("playerMiniGUID", "value", collision_info.collision_object.guid)
elseif t == "Checker" then -- this is for the character manager
self.UI.setAttribute("playerManagerGUID", "text", collision_info.collision_object.guid)
self.UI.setAttribute("playerManagerGUID", "value", collision_info.collision_object.guid)
end
end
end
end
function onChat(message, player)
if player.admin then
_debug("onChat admin chat")
if message:contains(magic_word) then
_debug("onChat contains magic word")
local command = message:replace(magic_word, ""):trim()
local args = {}
for word in command:gmatch("%S+") do
table.insert(args, word)
end
command = args[1]
if command == "update" then
broadcastNotice("Updating...")
updateAll()
elseif command == "debug" then
_data.debug = not _data.debug
if _data.debug then
broadcastNotice("Debugging is now on.")
else
broadcastNotice("Debugging is now off.")
end
elseif command == "help" then
print("Commands:")
print("\t[b]update[/b] - Updates all components and players.")
print("\t[b]component[/b] - Sets up a component.")
print("\t[b]player[/b] - Sets up a player.")
print("\t[b]debug[/b] - Toggles debug mode.")
print("\t[b]data[/b] - Prints the _data table.")
elseif command == "data" then
print("Printing _data table")
printTable(_data)
elseif command == "component" then
if #args == 1 then
print("[7FDBFF][i]Adds a component[/i].[-] [3D9970]Arguments: <[b]component name[/b]> <[b]component guid[/b]>[-].")
return
end
if #args == 2 then
broadcastError("You must specify a component and a GUID.")
return
end
local component = args[2]
local guid = args[3]
if not exists(guid) then
broadcastError("The GUID you specified does not exist.")
return
end
local possible_components = {
"npc_commander",
"monster",
"boss",
"initiative_token",
"note",
"initiative_mat"
}
if not tableContains(possible_components, component) then
broadcastError("The component you specified is not valid.")
return
end
_data.components[component] = {
version = "",
guid = guid
}
broadcastNotice("Added " .. component .. " with GUID " .. guid .. ".")
elseif command == "player" then
if #args == 1 then
print("[7FDBFF][i]Adds a player[/i].[-] [3D9970]Arguments: <[b]color[/b]> <[b]name[/b]> <[b]manager_guid[/b]> <[b]mini_guid[/b]>[-].")
return
end
if args[2] == nil then
broadcastError("You must specify a player color.")
return
end
local color = capitalize(args[2])
if not validColor(color) then
broadcastError("The color you specified is not valid.")
return
end
if args[3] == nil then
broadcastError("You must specify a character name.")
return
end
local name = args[3]
if args[4] == nil then
broadcastError("You must specify a manager GUID.")
return
end
local manager_guid = args[4]
if not exists(manager_guid) then
broadcastError("The manager GUID you specified does not exist.")
return
end
if args[5] == nil then
broadcastError("You must specify a mini GUID.")
return
end
local mini_guid = args[5]
if not exists(mini_guid) then
broadcastError("The mini GUID you specified does not exist.")
return
end
_data.players[color] = {
name = name,
manager_guid = manager_guid,
mini_guid = mini_guid
}
broadcastNotice("Added " .. color .. " player with name " .. name .. " and manager GUID " .. manager_guid .. " and mini GUID " .. mini_guid .. ".")
end
end
end
end
function start()
if not _data.debug then
if needsUpdate("_self") then
updateObj(
self,
"_self",
function()
broadcastNotice("Updated self to latest version.")
self.memo = _versions["_self"]
Wait.time(function()
self.reload()
end, 0.3)
end
)
end
end
startUI()
end
function processVersions()
_debug("processVersions")
WebRequest.get(
_URLs._v,
function(request)
log("Versions check: " .. request.response_code)
if request.is_error then
broadcastError(link .. "\n" .. request.error)
else
local versions = request.text
_debug("processVersions versions found")
local lines = split(versions, "\n")
lines = removeEmpty(lines)
for i, line in ipairs(lines) do
local splitLine = split(line, " ")
if splitLine[1] and splitLine[2] then
_debug(string.format("processVersions %s %s", splitLine[1], splitLine[2]))
if splitLine[1] == "table_updater" then splitLine[1] = "_self" end
_versions[splitLine[1]] = splitLine[2]
end
end
checkForUpdates()
end
end
)
end
function bump(component)
_debug("bump " .. component and component or "all")
processVersions()
if not component then
for c, v in pairs(_versions) do
if _data[c] then _data[c].version = v
else _data[c] = {version = v, guid = ""} end
end
else
if _data[component] then _data[component].version = _versions[component]
else _data[component] = {version = _versions[component], guid = ""} end
end
end
function checkForUpdates()
_debug("checkForUpdates")
for component, version in pairs(_versions) do
if needsUpdate(component) then
if component ~= "table_updater" then
broadcastNotice(component .. " needs an update.")
end
end
end
end
function updateAll()
broadcastNotice("Updating all components...")
for component, t in pairs(_data.components) do
_debug("updating " .. component .. " " .. t.guid)
if t then
if t.guid then
local obj = getObjectFromGUID(t.guid)
if obj then
if isInfiniteBag(obj) then
local o = extractObject(obj)
Wait.time(function()
if component == "boss" then
component = {"monster", "boss"}
end
updateObj(
o, component,
function(updated)
obj.reset()
updated.setLock(false)
if type(component) == "table" then
setComponentGUID(component[2], obj.guid)
else setComponentGUID(component, obj.guid) end
end
)
end, 1)
else
updateObj(obj, component, nil)
end
else broadcastError("Object not found: " .. t.guid .. " (" .. component ")") end
end
end
end
broadcastNotice("All components updated")
broadcastNotice("Updating players...")
local i = 0.5
for color, player in pairs(_data.players) do
Wait.time(function()
local obj = getObjectFromGUID(player.manager_guid)
if obj then
updateObj(obj, "player_manager", nil)
end
end, i)
i = i + 0.5
end
Wait.time(function()
broadcastNotice("Players updated")
end, i+0.2)
end
-- UI mod functions -------------------------------------------------------------
local _defaultHeight = 114
local _defaultWidth = 500
function startUI()
_debug("startUI")
local xml = self.UI.getXmlTable()
local panel = {
tag = "Panel",
attributes = {
id = "main",
position = "0 150 -10",
rotation = "180 180 0",
width = _defaultWidth,
height = _defaultHeight,
},
children = {
createButton("New Table", "34 38", "200", "38", "UI_NewTable", nil),
createButton("Update Table", "274 38", "200", "38", "UI_UpdateTable", nil)
}
}
xml = table.insert(xml, panel)
self.UI.setXmlTable(xml)
end
function negatePos(position)
local x = tonumber(split(position, " ")[1])
local y = tonumber(split(position, " ")[2])
y = y * -1
return x .. " " .. y
end
function createInput(placeholder, position, id, width, height, linetype, text, readonly)
position = negatePos(position)
return {
tag = "InputField",
attributes = {
id = id,
offsetXY = position,
rotation = "0 0 0",
width = width,
height = height,
placeholder = placeholder,
lineType = linetype,
text = text or "",
value = text or "",
readOnly = readonly or false
}
}
end
function createText(text, position, class, width, alignment)
position = negatePos(position)
return {
tag = "Text",
attributes = {
offsetXY = position,
rotation = "0 0 0",
text = text,
class = class,
width = width or "100%",
alignment = alignment or "UpperLeft"
}
}
end
function createButton(text, position, width, height, click_function, id, color)
position = negatePos(position)
if not color then color = "#282828|#c8329b|#ff9b38|#dddddd"
else color = color .. "|#c8329b|#ff9b38|#dddddd" end
return {
tag = "Button",
attributes = {
id = id,
offsetXY = position,
text = text,
width = width,
height = height,
onClick = click_function,
colors = color
}
}
end
function createColorBand(class, height)
return {
tag = "Panel",
attributes = {
id = class,
width = "19",
height = height,
class = class
}
}
end
function getPanel()
local xml = self.UI.getXmlTable()
return xml, xml[2]
end
function setUI(xml)
self.UI.setXmlTable(xml)
end
function emptyUI()
local xml, panel = getPanel()
panel.children = {}
setUI(xml)
end
function readInputs(IDs)
_debug("readInputs")
local values = {}
for i, id in ipairs(IDs) do
local input = self.UI.getAttribute(id, "value")
values[id] = input
end
_debug(values)
return values
end
function setPanel(width, height)
self.UI.setAttribute("main", "width", width)
self.UI.setAttribute("main", "height", height)
local offsetY = 0
local offsetX = 0
if height > _defaultHeight then
offsetY = (height - _defaultHeight)/2
end
if width > _defaultWidth then
offsetX = (width - _defaultWidth)/2
end
self.UI.setAttribute("main", "offsetXY", offsetX .. " " .. offsetY)
end
local _color_index = 0
local _current_player_index = 0
function createPlayerPage()
_accepting_players = true
local index = getNextPlayerIndex(_color_index)
if _color_index > #_colors then
broadcastNotice("No more players to create.")
_color_index = 0
_current_player_index = 0
createFinish()
return
end
local playerLen = getPlayerCount()
local player = _data.players[_colors[index]]
emptyUI()
setPanel(429, 103)
if player then
_debug(_color_index .. " " .. playerLen .. " " .. player.name)
end
local xml, panel = getPanel()
panel.children = {
createColorBand("player", 103),
createText(
string.format("Character Mini - %s - %d/%d", player.name, _current_player_index, playerLen),
"22 3",
"title player"
),
createInput("Character mini GUID...", "22 27", "playerMiniGUID", 199, 30),
createInput("Character manager GUID...", "224 27", "playerManagerGUID", 199, 30),
createButton("Confirm", "22 58", 401, 38, "UI_ConfirmPlayerTokens(" .. _colors[index] .. ")", nil)
}
setUI(xml)
end
function getNextPlayerIndex(index)
if index == nil then index = 0 end
_debug("getNextPlayerIndex " .. index)
index = index + 1
for i = index, #_colors do
local color = _colors[i]
if _data.players[color] then
_debug("Found player " .. color)
_debug("Index " .. i)
_debug(_current_player_index)
_color_index = i
_current_player_index = _current_player_index + 1
return _color_index
end
end
-- +1 needed for ending the whole process
-- this only happens when there is no player found
_color_index = index + 1
return _color_index
end
function getPlayerCount()
local count = 0
for i = 1, #_colors do
local color = _colors[i]
if _data.players[color] ~= nil then count = count + 1 end
end
return count
end
--function getNextExistingColor(index)
-- if index == nil then index = 0 end
--
-- index = index + 1
-- for i = index, #_colors do
-- local color = _colors[i]
-- local player = _data.players[color]
-- if player ~= nil then
-- _player_index = i
-- return color
-- end
-- end
--end
function createFinish()
emptyUI()
setPanel(500, 189)
local xml, panel = getPanel()
panel.children = {
createText(
"Setup process completed, however there are a few things that you’ll need to do:\n" ..
"- Link all of the player minis to make sure that they are ready for play.\n" ..
"- Check the initiative mat and select one player token with the GIZMO tool:\n" ..
"- > Move it up and down the initiative count. If it moves something that isn’t the X coordinate or it goes towards below 0 then add the following variables to the GM notres of the mat: “go_by” should be either “x” or “z”, “make_negative” should be either true or false.\n" ..
"- Save the table and restart it. There should be no errors.",
"10 5",
"player",
500 - 10
),
createButton("Close", "150 130", 200, 38, "UI_Close", nil)
}
setUI(xml)
end
function extractObject(bag)
local newPos = bag.getPosition()
newPos.y = newPos.y + 3
return bag.takeObject({
position = newPos,
callback_function = function(spawned)
spawned.setLock(true)
end
})
end
-- UI functions -----------------------------------------------------------------
function UI_UpdateInput(player, value, id)
self.UI.setAttribute(id, "value", value)
end
function UI_Close()
loadXML()
end
function UI_FindToken(player, id)
local obj = getObjectFromGUID(id)
player.pingTable(obj.getPosition())
obj.highlightOn(Color.Green, 2)
end
function UI_NewTable(player, mouse)
emptyUI()
setPanel(500, 181)
local xml, panel = getPanel()
panel.children = {
createColorBand("player", 181),
createText("Players", "22 3", "title player"),
createText(
"Insert the player characters and their colors by inserting character name=player color\nPossible colors: Green, Purple, Red, Blue, Yellow, Brown, White, Teal, Orange, Pink"
, "22 27", "player"
),
createInput(
"Player1=Blue\nPlayer2=Green\nPlayer3=Purple",
"22 58", "playerInput", "364", "120", "MultiLineNewLine",
getPlayers()
),
createButton("Confirm", "390 140", 105, 38, "UI_ConfirmPlayers", nil)
}
setUI(xml)
end
function UI_UpdateTable(player, mouse)
emptyUI()
setPanel(503, 495)
local xml, panel = getPanel()
local components = {
"npc_commander",
"monster",
"boss",
"initiative_token",
"initiative_mat",
"note"
}
--NPC Commander
--Monster Token
--Boss Token
--Initiative Token
--Notes
panel.children = {
createText("NPC Commander", "18 15", "title player", 156, "UpperRight"),
createInput(" ", "186 15", "npc_commander_guid", 103, 30, nil, getComponentGUID("npc_commander"), true),
createText("Monster Token", "18 45", "title player", 156, "UpperRight"),
createInput(" ", "186 45", "monster_token_guid", 103, 30, nil, getComponentGUID("monster"), true),
createText("Boss Token", "18 74", "title player", 156, "UpperRight"),
createInput(" ", "186 74", "boss_token_guid", 103, 30, nil, getComponentGUID("boss"), true),
createText("Initiative Token", "18 103", "title player", 156, "UpperRight"),
createInput(" ", "186 103", "initiative_token_guid", 103, 30, nil, getComponentGUID("initiative_token"), true),
createText("Initiative Mat", "18 132", "title player", 156, "UpperRight"),
createInput(" ", "186 132", "initiative_mat_guid", 103, 30, nil, getComponentGUID("initiative_mat"), true),
createText("Notes", "18 163", "title player", 156, "UpperRight"),
createInput(" ", "186 163", "note_guid", 103, 30, nil, getComponentGUID("note"), true),
}
for i,component in ipairs(components) do
local guid = getComponentGUID(component)
local pos = "292 " .. ((i-1)*29 + 15)
if guid then
local obj = getObjectFromGUID(guid)
if obj then
local isInBag = isInfiniteBag(obj)
table.insert(panel.children, createButton(
isInBag and "In Bag" or "Not In Bag",
pos,
90,
30,
"UI_FindToken(" .. guid .. ")",
"",
isInBag and "#0074D9" or "#2ECC40"
))
else
table.insert(panel.children, createButton(
"Error",
pos,
90,
30,
"none",
"",
"#FF4136"
))
end
else
table.insert(panel.children, createButton(
"Not Found",
pos,
90,
30,
"none",
""
))
end
end
table.insert(panel.children, createText(
"Players",
"18 190",
"title player",
nil,
nil
))
local i = 1
for color, player in pairs(_data.players) do
table.insert(panel.children, createButton(
player.name,
18 + (78*(i-1)) .. " 217",
75,
50,
"UI_FindToken(" .. player.manager_guid .. ")",
player.manager_guid,
color
))
i = i + 1
end
table.insert(panel.children, createButton(
"Update",
"292 442",
200,
38,
"UI_UpdateAll",
nil,
"#2ECC40"
))
table.insert(panel.children, createButton(
"Cancel",
"146 442",
135,
38,
"UI_CancelUpdate"
))
setUI(xml)
end
function UI_CancelUpdate()
loadXML()
end
function UI_UpdateAll()
updateAll()
end
function UI_UpdateComponent(player, component)
local url = _URLs[component]
if url == nil then
broadcastNotice("Component " .. component .. " not found.")
return
end
if _data.components[component] == nil then
broadcastNotice("Component " .. component .. " not found.")
return
end
_debug("updating " .. component)
end
function UI_ConfirmPlayers(player, mouse)
local input = readInputs({"playerInput"})["playerInput"]
if not validInput(input) then
broadcastError("Invalid input. Please try again.")
return
end
local lines = split(input, "\n")
lines = removeEmpty(lines)
local players = {}
_data.players = emptyPlayers()
for i, line in ipairs(lines) do
local splitLine = split(line, "=")
if splitLine[1] and splitLine[2] then
local name = capitalize(splitLine[1])
local color = capitalize(splitLine[2])
if not validInput(name) or not validInput(color) then
broadcastError("Invalid input. Please try again.")
return
end
if not validColor(color) then
broadcastError("Error in color parsing. Please try again.")
return
end
addPlayer(color, name)
else
broadcastError("Invalid input. Please try again.")
return
end
end
broadcastNotice("Players have been setup.")
emptyUI()
setPanel(500, 181)
local xml, panel = getPanel()
panel.children = {
createColorBand("npc_commander", 181),
createText("NPC Commander", "22 3", "title npc_commander"),
createInput("Insert NPC Commander's GUID...", "124 68", "commanderGUIDInput", 253, 30, "SingleLine", getComponentGUID("npc_commander") or ""),
createButton("Confirm GUID", "124 96", 253, 38, "UI_ConfirmCommanderGUID", nil)
}
setUI(xml)
end
function UI_ConfirmCommanderGUID(player, mouse)
local input = readInputs({"commanderGUIDInput"})["commanderGUIDInput"]:trim()
if not validInput(input) then
broadcastError("Invalid input. Please try again.")
return
end
if not exists(input) then
broadcastError("Invalid GUID. Please try again.")
return
end
updateObj(
getObjectFromGUID(input),
"npc_commander",
function()
setComponentGUID("npc_commander", input)
broadcastNotice("NPC Commander GUID has been set and it has been updated.")
end
)
emptyUI()
setPanel(456, 366)
local xml, panel = getPanel()
panel.children = {
createColorBand("npc_commander", 366),
createText("NPC Commander", "22 3", "title npc_commander"),
-----------------------------------------------------------
createText("Monster tokens are the monsters that do not have an image (generic monsters)", "22 24", "npc_commander"),
createInput("Monster token GUID...", "22 44", "monsterTokenGUIDInput", 210, 30),
createInput("Monster bag GUID...", "235 44", "monsterBagGUIDInput", 210, 30),
createButton("Confirm GUIDs", "22 72", 424, 23, "UI_ConfirmGenericToken(monster)", "confirmMonsterTokensBtn"),
-----------------------------------------------------------
createText("Boss tokens are the monsters that have an image (such as bosses)", "22 95", "npc_commander"),
createInput("Boss token GUID...", "22 115", "bossTokenGUIDInput", 210, 30),
createInput("Boss bag GUID...", "235 115", "bossBagGUIDInput", 210, 30),
createButton("Confirm GUIDs", "22 143", 424, 23, "UI_ConfirmGenericToken(boss)", "confirmBossTokensBtn"),
-----------------------------------------------------------
createText("Initiative tokens are the items that allow to track initiative in combat", "22 166", "npc_commander"),
createInput("Initiative token GUID...", "22 186", "initiative_tokenTokenGUIDInput", 210, 30),
createInput("Initiative bag GUID...", "235 186", "initiative_tokenBagGUIDInput", 210, 30),
createButton("Confirm GUIDs", "22 214", 424, 23, "UI_ConfirmGenericToken(initiative_token)", "confirmInitiativeTokensBtn"),
-----------------------------------------------------------
createText("Notes are used to store monster information (optional element)", "22 242", "npc_commander"),
createInput("Parsing note GUID...", "22 262", "noteTokenGUIDInput", 210, 30),
createInput("Parsing note bag GUID...", "235 262", "noteBagGUIDInput", 210, 30),
createButton("Confirm GUIDs", "22 290", 424, 23, "UI_ConfirmGenericToken(note)", "confirmNoteTokensBtn"),
-----------------------------------------------------------
createButton("Continue", "131 318", 195, 38, "UI_ConfirmTokens", nil)
}
setUI(xml)
end
function UI_ConfirmGenericToken(player, t, id)
_debug("UI_ConfirmGenericToken " .. t .. " " .. id)
local tokenInput = t .. "TokenGUIDInput"
local bagInput = t .. "BagGUIDInput"
local input = readInputs({tokenInput, bagInput})
if not validInput(input[tokenInput]) or not validInput(input[bagInput]) then
broadcastError("Invalid input. Please try again.")
return
end
if not exists(input[tokenInput]) or not exists(input[bagInput]) then
broadcastError("Invalid GUID. Please try again.")
return
end
local component = t
if t == "boss" then component = {"monster", "boss"} end
updateObj(
getObjectFromGUID(input[tokenInput]),
component,
function()
setComponentGUID(t, input[bagInput])
placeInBag(input[tokenInput], input[bagInput], _data.debug)
self.UI.setAttribute(id, "textColor", "Green")
broadcastNotice(capitalize(t) .. " has been setup.")
end
)