-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDNDMiniInjector.lua
More file actions
3304 lines (3129 loc) · 129 KB
/
DNDMiniInjector.lua
File metadata and controls
3304 lines (3129 loc) · 129 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
-- DNDMiniInjector
-- Credit to HP Bar Writer by Kijan
--[[LUAStart
className = "DNDMiniInjector_Mini"
versionNumber = "4.7.9"
--[[LUAMoveStart
move_const_gridTargetScale = 0.3
move_const_sectionMultiplier = 5
move_const_sectionMultiplier_metric = 1.5
move_startLocation = nil
move_currentLocation = nil
move_currentAdjacentLocations = nil
move_allLocations = {}
move_drawLocations = {}
move_lastTargetLoc = nil
move_numDiagonals = 0
function getDistance()
local multiplier = move_const_sectionMultiplier
if metricMode == true then
multiplier = move_const_sectionMultiplier_metric
end
local totalDistance = (#move_allLocations - 1) * multiplier
if alternateDiag == true then
totalDistance = totalDistance + (math.floor(move_numDiagonals / 2.0) * multiplier)
end
return totalDistance
end
function resetMoves()
move_allLocations = {}
move_drawLocations = {}
move_numDiagonals = 0
updateCurrentLocation(move_startLocation)
end
function getTargetColor()
local player = move_targetObject.getVar("player")
local colorTint = move_targetObject.getColorTint()
if player == true then
local miniHighlight = move_targetObject.getVar("miniHighlight")
if miniHighlight == "highlightWhite" then
colorTint = Color.White
elseif miniHighlight == "highlightBrown" then
colorTint = Color.Brown
elseif miniHighlight == "highlightRed" then
colorTint = Color.Red
elseif miniHighlight == "highlightOrange" then
colorTint = Color.Orange
elseif miniHighlight == "highlightYellow" then
colorTint = Color.Yellow
elseif miniHighlight == "highlightGreen" then
colorTint = Color.Green
elseif miniHighlight == "highlightTeal" then
colorTint = Color.Teal
elseif miniHighlight == "highlightBlue" then
colorTint = Color.Blue
elseif miniHighlight == "highlightPurple" then
colorTint = Color.Purple
elseif miniHighlight == "highlightPink" then
colorTint = Color.Pink
elseif miniHighlight == "highlightBlack" then
colorTint = Color.Black
end
else
colorTint = Color.White
end
return colorTint
end
function updateCurrentLocation(newLocation)
-- find Y of the floor directly below the mini's center point at the target location
-- use that as the new location
newLocation = Vector(newLocation.x, move_targetObject.getBounds().center.y, newLocation.z)
local hitList = Physics.cast({
origin = newLocation,
direction = {0,-1,0},
type = 1,
max_distance = 10,
debug = false,
})
for _, hitTable in ipairs(hitList) do
-- Find the first object directly below the mini
if hitTable ~= nil and hitTable.point ~= nil and hitTable.hit_object ~= mtoken then
newLocation = hitTable.point
newLocation.y = newLocation.y + 0.2
break
else
if debuggingEnabled == true then
print("Did not find object below mini.")
end
end
end
-- Ensure the first point starts below the move token
if #move_allLocations < 1 then
newLocation.y = self.getPosition().y
end
table.insert(move_allLocations, newLocation)
table.insert(move_drawLocations, self.positionToLocal(newLocation))
move_currentAdjacentLocations = getAdjacentLocations(newLocation.x, newLocation.z)
--pingAdjacents()
move_currentLocation = newLocation
--print(newLocation)
if #move_drawLocations > 1 then
self.setVectorLines({{
points = move_drawLocations,
color = getTargetColor()
}})
else
self.setVectorLines({})
end
if #self.getButtons() > 0 then
self.editButton({index = 0, label = tostring(getDistance())})
end
end
function pingAdjacents()
for _, player in ipairs(Player.getPlayers()) do
for i,point in ipairs(move_currentAdjacentLocations) do
local pinger = Vector(point.x, self.getPosition().y, point.y)
--print(pinger)
player.pingTable(pinger)
end
break
end
end
function onUpdate()
if move_startLocation == nil then
move_startLocation = self.getPosition()
local fontSize = 600
if metricMode then
fontSize = 500
end
self.createButton({
click_function = "onLoad",
function_owner = self,
label = "00",
position = {x=0, y=0.1, z=0},
width = 0,
height = 0,
font_size = fontSize
})
local gd = getGridDims()
if gd.width < gd.height then
self.setScale({
x= gd.width / 2.2,
y= 0.2,
z= gd.width / 2.2
})
else
self.setScale({
x= gd.height / 2.2,
y= 0.2,
z= gd.height / 2.2
})
end
updateCurrentLocation(move_startLocation)
end
if move_targetObject == nil or move_targetObject.held_by_color == nil then
destroyObject(self)
return
end
local targetLoc = move_targetObject.getPosition()
if move_lastTargetLoc ~= nil and targetLoc:distance(move_lastTargetLoc) < 0.05 then
--print("nomove")
return
end
local targetSameHeight = targetLoc.set
local acceptDistance = getAcceptDistance()
if #move_allLocations > 1 and
math.abs(targetLoc.x - move_startLocation.x) < acceptDistance
and math.abs(targetLoc.z - move_startLocation.z) < acceptDistance then
resetMoves()
end
-- the target has moved
-- see if it's outside the bounding box/circle
if Grid.type == 2 or Grid.type == 3 then
-- we are using hex grids, use a circle from start to determine bounding
local maxDistance = getFirstAdjacentLocation():distance(move_currentLocation)
local currentDistance = targetLoc:distance(move_currentLocation)
if currentDistance > maxDistance then
-- we are outside the bounding circle, move to closest adjacent
updateCurrentLocation(getClosestAdjacentLocation(targetLoc))
end
else
-- we are using square grids, use the square bounding box
local gd = getGridDims()
if targetLoc.x < move_currentLocation.x - gd.width or
targetLoc.x > move_currentLocation.x + gd.width or
targetLoc.z < move_currentLocation.z - gd.height or
targetLoc.z > move_currentLocation.z + gd.height then
-- we are outside the bounding box, move to closest adjacent
updateCurrentLocation(getClosestAdjacentLocation(targetLoc))
end
end
--see if it's nearby an adjacent location
for i,point in ipairs(move_currentAdjacentLocations) do
local testPoint = Vector(point.x, targetLoc.y, point.y)
if testPoint:distance(targetLoc) < acceptDistance then
if point.isDiagonal == true then
move_numDiagonals = move_numDiagonals + 1
--print("diagonals: " .. move_numDiagonals)
end
updateCurrentLocation(testPoint)
end
end
move_lastTargetLoc = targetLoc
end
function getFirstAdjacentLocation()
for i,point in ipairs(move_currentAdjacentLocations) do
return Vector(point.x, self.getPosition().y, point.y)
end
end
function getClosestAdjacentLocation(testLocation)
local closestAdjacent = getFirstAdjacentLocation()
local closestDistance = closestAdjacent:distance(testLocation)
for i,point in ipairs(move_currentAdjacentLocations) do
local testAdjacent = Vector(point.x, testLocation.y, point.y)
local testDistance = testAdjacent:distance(testLocation)
if testDistance < closestDistance then
closestAdjacent = testAdjacent
closestDistance = testDistance
end
end
return closestAdjacent
end
function getAcceptDistance()
local gd = getGridDims()
if gd.width < gd.height then
return move_const_gridTargetScale * gd.width
else
return move_const_gridTargetScale * gd.height
end
end
function getGridDims()
if Grid.type == 1 then
return {
width = Grid.sizeX,
height = Grid.sizeY
}
elseif Grid.type == 2 then
return {
width = Grid.sizeX * 0.75,
height = Grid.sizeY * math.sqrt(3) / 2.0
}
elseif Grid.type == 3 then
return {
width = Grid.sizeX * math.sqrt(3) / 2.0,
height = Grid.sizeY * 0.75
}
end
print("INVALID GRID FORMAT")
return nil
end
function getAdjacentLocations(currentX, currentY)
local gd = getGridDims()
local adjacents = {}
if Grid.type == 1 then
table.insert(adjacents, {
x = currentX,
y = currentY + gd.height,
isDiagonal = false
})
table.insert(adjacents, {
x = currentX + gd.width,
y = currentY + gd.height,
isDiagonal = true
})
table.insert(adjacents, {
x = currentX + gd.width,
y = currentY,
isDiagonal = false
})
table.insert(adjacents, {
x = currentX + gd.width,
y = currentY - gd.height,
isDiagonal = true
})
table.insert(adjacents, {
x = currentX,
y = currentY - gd.height,
isDiagonal = false
})
table.insert(adjacents, {
x = currentX - gd.width,
y = currentY - gd.height,
isDiagonal = true
})
table.insert(adjacents, {
x = currentX - gd.width,
y = currentY,
isDiagonal = false
})
table.insert(adjacents, {
x = currentX - gd.width,
y = currentY + gd.height,
isDiagonal = true
})
elseif Grid.type == 2 then
table.insert(adjacents, {
x = currentX,
y = currentY + gd.height,
isDiagonal = false
})
table.insert(adjacents, {
x = currentX + gd.width,
y = currentY + (gd.height / 2.0),
isDiagonal = false
})
table.insert(adjacents, {
x = currentX + gd.width,
y = currentY - (gd.height / 2.0),
isDiagonal = false
})
table.insert(adjacents, {
x = currentX,
y = currentY - gd.height,
isDiagonal = false
})
table.insert(adjacents, {
x = currentX - gd.width,
y = currentY - (gd.height / 2.0),
isDiagonal = false
})
table.insert(adjacents, {
x = currentX - gd.width,
y = currentY + (gd.height / 2.0),
isDiagonal = false
})
elseif Grid.type == 3 then
table.insert(adjacents, {
x = currentX + (gd.width / 2.0),
y = currentY + gd.height,
isDiagonal = false
})
table.insert(adjacents, {
x = currentX + gd.width,
y = currentY,
isDiagonal = false
})
table.insert(adjacents, {
x = currentX + (gd.width / 2.0),
y = currentY - gd.height,
isDiagonal = false
})
table.insert(adjacents, {
x = currentX - (gd.width / 2.0),
y = currentY - gd.height,
isDiagonal = false
})
table.insert(adjacents, {
x = currentX - gd.width,
y = currentY,
isDiagonal = false
})
table.insert(adjacents, {
x = currentX - (gd.width / 2.0),
y = currentY + gd.height,
isDiagonal = false
})
end
return adjacents
end
LUAMoveStop--lua]]
--[[LUACommentRemove
scaleMultiplierX = 1.0
scaleMultiplierY = 1.0
scaleMultiplierZ = 1.0
finishedLoading = false
calibratedOnce = false
debuggingEnabled = false
onUpdateTriggerCount = 0
onSaveFrameCount = 0
onUpdateScale = 1.0
onUpdateGridSize = 1.0
loadTime = 1.0
saveVersion = 1
a = {}
triggerNames = {}
showing = false
savedAttachScales = {}
health = {value = 10, max = 10}
mana = {value = 10, max = 10}
extra = {value = 10, max = 10}
player = false
measureMove = false
alternateDiag = false
metricMode = false
stabilizeOnDrop = false
miniHighlight = "highlightNone"
highlightToggle = true
hideFromPlayers = false
firstEdit = true
options = {
HP2Desc = false,
belowZero = false,
aboveMax = false,
heightModifier = 110,
showBaseButtons = false,
showBarButtons = false,
hideHp = false,
hideMana = true,
hideExtra = true,
incrementBy = 1,
rotation = 90,
initSettingsIncluded = true,
initSettingsRolling = true,
initSettingsMod = 0,
initSettingsValue = 100,
initRealActive = false,
initRealValue = 0,
initMockActive = false,
initMockValue = 0
}
function resetInitiative()
options.initSettingsValue = 100
options.initRealActive = false
options.initRealValue = 0
options.initMockActive = false
options.initMockValue = 0
self.UI.setAttribute("InitValueInput", "text", options.initSettingsValue)
updateSave()
end
function getInitiative(inputActive)
if options.initRealActive == true then
if debuggingEnabled then
print(self.getName() .. ' init real cache ' .. options.initRealValue)
end
return options.initRealValue
end
if inputActive == true then
options.initRealActive = true
if options.initMockActive == true then
options.initRealValue = options.initMockValue
else
options.initRealValue = calculateInitiative()
end
if debuggingEnabled then
print(self.getName() .. ' init real calc' .. options.initRealValue)
end
updateSave()
return options.initRealValue
end
if options.initMockActive == true then
if debuggingEnabled then
print(self.getName() .. ' init mock cache ' .. options.initMockValue)
end
return options.initMockValue
end
options.initMockActive = true
options.initMockValue = calculateInitiative()
if debuggingEnabled then
print(self.getName() .. ' init mock calc ' .. options.initMockValue)
end
updateSave()
return options.initMockValue
end
function calculateInitiative()
if options.initSettingsRolling == true then
return math.random(1,20) + tonumber(options.initSettingsMod)
else
return tonumber(options.initSettingsValue)
end
end
function updateSave()
if onSaveFrameCount > 0 then
onSaveFrameCount = 120
return
end
onSaveFrameCount = 120
startLuaCoroutine(self, "updateSaveActual")
end
function updateSaveActual()
while onSaveFrameCount > 0 do
onSaveFrameCount = onSaveFrameCount - 1
coroutine.yield(0)
end
saveVersion = saveVersion + 1
if debuggingEnabled then
print(self.getName() .. " saving, version " .. saveVersion .. ".")
end
local encodedAttachScales = {}
if #savedAttachScales > 0 then
for _, scaleVector in ipairs(savedAttachScales) do
table.insert(encodedAttachScales, {x=scaleVector.x, y=scaleVector.y, z=scaleVector.z})
end
end
self.script_state = JSON.encode({
scale_multiplier_x = scaleMultiplierX,
scale_multiplier_y = scaleMultiplierY,
scale_multiplier_z = scaleMultiplierZ,
calibrated_once = calibratedOnce,
health = health,
mana = mana,
extra = extra,
options = options,
encodedAttachScales = encodedAttachScales,
statNames = statNames,
player = player,
measureMove = measureMove,
alternateDiag = alternateDiag,
metricMode = metricMode,
stabilizeOnDrop = stabilizeOnDrop,
miniHighlight = miniHighlight,
highlightToggle = highlightToggle,
hideFromPlayers = hideFromPlayers,
saveVersion = saveVersion
})
return 1
end
function onLoad(save_state)
function onLoad_helper()
coroutine.yield(0)
if stabilizeOnDrop == true and self.held_by_color == nil then
coroutine.yield(0)
stabilize()
end
local saved_data = nil
local my_saved_data = nil
local bestVersion = 0
if save_state ~= "" then
saved_data = JSON.decode(save_state)
my_saved_data = saved_data
if saved_data.saveVersion ~= nil then
bestVersion = saved_data.saveVersion
end
end
-- ALRIGHTY, let's see which state data we need to use
states = self.getStates()
if states ~= nil then
for _, s in pairs(states) do
test_data = JSON.decode(s.lua_script_state)
if test_data ~= nil and test_data.saveVersion ~= nil and test_data.saveVersion > bestVersion then
saved_data = test_data
bestVersion = test_data.saveVersion
coroutine.yield(0)
end
end
end
if debuggingEnabled then
print(self.getName() .. " best version: " .. bestVersion)
end
if saved_data ~= nil then
if saved_data.health then
for heal,_ in pairs(health) do
health[heal] = saved_data.health[heal]
end
end
if saved_data.mana then
for res,_ in pairs(mana) do
mana[res] = saved_data.mana[res]
end
end
if saved_data.extra then
for res,_ in pairs(extra) do
extra[res] = saved_data.extra[res]
end
end
if saved_data.options then
for opt,_ in pairs(options) do
if saved_data.options[opt] ~= nil then
options[opt] = saved_data.options[opt]
end
end
end
if saved_data.encodedAttachScales then
for _,encodedScale in pairs(saved_data.encodedAttachScales) do
if debuggingEnabled then
print("loaded vector: " .. encodedScale.x .. ", " .. encodedScale.y .. ", " .. encodedScale.z)
end
table.insert(savedAttachScales, vector(encodedScale.x, encodedScale.y, encodedScale.z))
coroutine.yield(0)
end
end
if saved_data.statNames then
for stat,_ in pairs(statNames) do
statNames[stat] = saved_data.statNames[stat]
end
end
-- Check if we need to override the scale calibration
-- This state's calibration takes precedence over other states
if my_saved_data ~= nil and my_saved_data.calibrated_once == true then
saved_data.calibrated_once = my_saved_data.calibrated_once
saved_data.scale_multiplier_x = my_saved_data.scale_multiplier_x
saved_data.scale_multiplier_y = my_saved_data.scale_multiplier_y
saved_data.scale_multiplier_z = my_saved_data.scale_multiplier_z
if my_saved_data.options ~= nil then
options["heightModifier"] = my_saved_data.options["heightModifier"]
end
end
if saved_data.scale_multiplier_x ~= nil then
scaleMultiplierX = saved_data.scale_multiplier_x
end
if saved_data.scale_multiplier_y ~= nil then
scaleMultiplierY = saved_data.scale_multiplier_y
end
if saved_data.scale_multiplier_z ~= nil then
scaleMultiplierZ = saved_data.scale_multiplier_z
end
if saved_data.calibrated_once ~= nil then
calibratedOnce = saved_data.calibrated_once
end
if saved_data.player ~= nil then
player = saved_data.player
end
if saved_data.measureMove ~= nil then
measureMove = saved_data.measureMove
end
if saved_data.alternateDiag ~= nil then
alternateDiag = saved_data.alternateDiag
end
if saved_data.metricMode ~= nil then
metricMode = saved_data.metricMode
end
if saved_data.stabilizeOnDrop ~= nil then
stabilizeOnDrop = saved_data.stabilizeOnDrop
end
if saved_data.miniHighlight ~= nil then
miniHighlight = saved_data.miniHighlight
end
if saved_data.highlightToggle ~= nil then
highlightToggle = saved_data.highlightToggle
end
if saved_data.hideFromPlayers ~= nil then
hideFromPlayers = saved_data.hideFromPlayers
if player == true then
hideFromPlayers = false
end
end
if saved_data.saveVersion ~= nil then
saveVersion = saved_data.saveVersion
if debuggingEnabled then
print(self.getName() .. " loading, version " .. saveVersion .. ".")
end
end
end
self.setVar("className", "DNDMiniInjector_Mini")
self.setVar("player", player)
self.setVar("measureMove", measureMove)
self.setVar("alternateDiag", alternateDiag)
self.setVar("metricMode", metricMode)
self.setVar("stabilizeOnDrop", stabilizeOnDrop)
self.setVar("miniHighlight", miniHighlight)
self.setVar("highlightToggle", highlightToggle)
self.setVar("hideFromPlayers", hideFromPlayers)
coroutine.yield(0)
loadStageOne()
coroutine.yield(0)
loadStageTwo()
coroutine.yield(0)
finishedLoading = true
self.setVar("finishedLoading", true)
return 1
end
startLuaCoroutine(self, "onLoad_helper")
end
function loadStageOne()
local script = self.getLuaScript()
local xml = script:sub(script:find("StartXML")+8, script:find("StopXML")-1)
self.UI.setXml(xml)
coroutine.yield(0)
end
function loadStageTwo()
self.UI.setAttribute("panel", "position", "0 0 -" .. self.getBounds().size.y / self.getScale().y * options.heightModifier)
self.UI.setAttribute("progressBar", "percentage", health.value / health.max * 100)
self.UI.setAttribute("hpText", "text", health.value .. "/" .. health.max)
self.UI.setAttribute("progressBarS", "percentage", mana.value / mana.max * 100)
self.UI.setAttribute("manaText", "text", mana.value .. "/" .. mana.max)
self.UI.setAttribute("extraProgress", "percentage", extra.value / extra.max * 100)
self.UI.setAttribute("extraText", "text", extra.value .. "/" .. extra.max)
self.UI.setAttribute("manaText", "textColor", "#FFFFFF")
self.UI.setAttribute("increment", "text", options.incrementBy)
self.UI.setAttribute("InitModInput", "text", options.initSettingsMod)
self.UI.setAttribute("InitValueInput", "text", options.initSettingsValue)
coroutine.yield(0)
for i,j in pairs(statNames) do
if j == true then
self.UI.setAttribute(i, "active", true)
coroutine.yield(0)
end
end
coroutine.yield(0)
self.UI.setAttribute("statePanel", "width", getStatsCount()*300)
if options.showBarButtons == true then
self.UI.setAttribute("addSub", "active", true)
self.UI.setAttribute("addSubS", "active", true)
self.UI.setAttribute("addSubE", "active", true)
coroutine.yield(0)
end
if health.max == 0 then
options.hideHp = true
end
if mana.max == 0 then
options.hideMana = true
end
if extra.max == 0 then
options.hideExtra = true
end
self.UI.setAttribute("hiddenButtonBar", "active", (options.hideHp == true and options.hideMana == true and options.hideExtra == true) and "True" or "False")
self.UI.setAttribute("resourceBar", "active", options.hideHp == true and "False" or "True")
self.UI.setAttribute("resourceBarS", "active", options.hideMana == true and "False" or "True")
self.UI.setAttribute("extraBar", "active", options.hideExtra == true and "False" or "True")
self.UI.setAttribute("addSub", "active", options.showBarButtons == true and "True" or "False")
self.UI.setAttribute("addSubS", "active", options.showBarButtons == true and "True" or "False")
self.UI.setAttribute("addSubE", "active", options.showBarButtons == true and "True" or "False")
self.UI.setAttribute("panel", "rotation", options.rotation .. " 270 90")
coroutine.yield(0)
self.UI.setAttribute("PlayerCharToggle", "textColor", player == true and "#AA2222" or "#FFFFFF")
self.UI.setAttribute("MeasureMoveToggle", "textColor", measureMove == true and "#AA2222" or "#FFFFFF")
self.UI.setAttribute("AlternateDiagToggle", "textColor", alternateDiag == true and "#AA2222" or "#FFFFFF")
self.UI.setAttribute("MetricModeToggle", "textColor", metricMode == true and "#AA2222" or "#FFFFFF")
self.UI.setAttribute("StabilizeToggle", "textColor", stabilizeOnDrop == true and "#AA2222" or "#FFFFFF")
self.UI.setAttribute("HH", "textColor", options.hideHp == true and "#AA2222" or "#FFFFFF")
self.UI.setAttribute("HM", "textColor", options.hideMana == true and "#AA2222" or "#FFFFFF")
self.UI.setAttribute("HE", "textColor", options.hideExtra == true and "#AA2222" or "#FFFFFF")
self.UI.setAttribute("HB", "textColor", options.showBarButtons == true and "#AA2222" or "#FFFFFF")
self.UI.setAttribute("BZ", "textColor", options.belowZero == true and "#AA2222" or "#FFFFFF")
self.UI.setAttribute("AM", "textColor", options.aboveMax == true and "#AA2222" or "#FFFFFF")
coroutine.yield(0)
self.UI.setAttribute("InitiativeIncludeToggle", "textColor", options.initSettingsIncluded == true and "#AA2222" or "#FFFFFF")
self.UI.setAttribute("InitiativeRollingToggle", "textColor", options.initSettingsRolling == true and "#AA2222" or "#FFFFFF")
coroutine.yield(0)
-- Look for the mini injector, if available
local allObjects = getAllObjects()
for _, obj in ipairs(allObjects) do
if obj ~= self and obj ~= nil then
local typeCheck = obj.getVar("className")
if typeCheck == "MiniInjector" then
autoCalibrate = obj.getVar("autoCalibrateEnabled")
if autoCalibrate == true then
calibrateScale()
end
-- grab ui settings
local injOptions = obj.getTable("options")
alternateDiag = injOptions.alternateDiag
self.UI.setAttribute("AlternateDiagToggle", "textColor", alternateDiag == true and "#AA2222" or "#FFFFFF")
metricMode = injOptions.metricMode
self.UI.setAttribute("MetricModeToggle", "textColor", metricMode == true and "#AA2222" or "#FFFFFF")
coroutine.yield(0)
if player == true then
self.UI.setAttribute("progressBar", "visibility", "")
self.UI.setAttribute("progressBarS", "visibility", "")
self.UI.setAttribute("extraProgress", "visibility", "")
self.UI.setAttribute("hpText", "visibility", "")
self.UI.setAttribute("manaText", "visibility", "")
self.UI.setAttribute("extraText", "visibility", "")
self.UI.setAttribute("addSub", "visibility", "")
self.UI.setAttribute("addSubS", "visibility", "")
self.UI.setAttribute("addSubE", "visibility", "")
self.UI.setAttribute("editPanel", "visibility", "")
self.UI.setAttribute("leftSide1", "visibility", "")
self.UI.setAttribute("editButton0", "visibility", "")
self.UI.setAttribute("editButton1", "visibility", "")
self.UI.setAttribute("editButtonS1", "visibility", "")
self.UI.setAttribute("leftSide2", "visibility", "")
self.UI.setAttribute("editButton2", "visibility", "")
self.UI.setAttribute("editButtonS2", "visibility", "")
self.UI.setAttribute("leftSide3", "visibility", "")
self.UI.setAttribute("editButton3", "visibility", "")
self.UI.setAttribute("editButtonS3", "visibility", "")
coroutine.yield(0)
else
if injOptions.hideBar == true then
self.UI.setAttribute("progressBar", "visibility", "Black")
self.UI.setAttribute("progressBarS", "visibility", "Black")
self.UI.setAttribute("extraProgress", "visibility", "Black")
else
self.UI.setAttribute("progressBar", "visibility", "")
self.UI.setAttribute("progressBarS", "visibility", "")
self.UI.setAttribute("extraProgress", "visibility", "")
end
if injOptions.hideText == true then
self.UI.setAttribute("hpText", "visibility", "Black")
self.UI.setAttribute("manaText", "visibility", "Black")
self.UI.setAttribute("extraText", "visibility", "Black")
else
self.UI.setAttribute("hpText", "visibility", "")
self.UI.setAttribute("manaText", "visibility", "")
self.UI.setAttribute("extraText", "visibility", "")
end
if injOptions.editText == true then
self.UI.setAttribute("addSub", "visibility", "Black")
self.UI.setAttribute("addSubS", "visibility", "Black")
self.UI.setAttribute("addSubE", "visibility", "Black")
self.UI.setAttribute("editPanel", "visibility", "Black")
else
self.UI.setAttribute("addSub", "visibility", "")
self.UI.setAttribute("addSubS", "visibility", "")
self.UI.setAttribute("addSubE", "visibility", "")
self.UI.setAttribute("editPanel", "visibility", "")
end
self.UI.setAttribute("panel", "active", injOptions.showAll == true and "true" or "false")
coroutine.yield(0)
self.UI.setAttribute("editButton0", "visibility", "Black")
self.UI.setAttribute("leftSide1", "visibility", "Black")
self.UI.setAttribute("editButton1", "visibility", "Black")
self.UI.setAttribute("editButtonS1", "visibility", "Black")
self.UI.setAttribute("leftSide2", "visibility", "Black")
self.UI.setAttribute("editButton2", "visibility", "Black")
self.UI.setAttribute("editButtonS2", "visibility", "Black")
self.UI.setAttribute("leftSide3", "visibility", "Black")
self.UI.setAttribute("editButton3", "visibility", "Black")
self.UI.setAttribute("editButtonS3", "visibility", "Black")
coroutine.yield(0)
end
end
end
end
rebuildContextMenu()
coroutine.yield(0)
updateHighlight()
coroutine.yield(0)
self.auto_raise = true
self.interactable = true
onUpdateScale = 1.0
onUpdateGridSize = 1.0
loadTime = os.clock()
instantiateTriggers()
coroutine.yield(0)
if hideFromPlayers then
aColors = Player.getAvailableColors()
for k, v in ipairs(aColors) do
if v == "Black" or v == "Grey" or v == "White" then
table.remove(aColors, k)
end
end
table.insert(aColors, "Grey")
table.insert(aColors, "White")
if debuggingEnabled then
print(self.getName() .. " gone.")
end
self.setInvisibleTo(aColors)
-- In this case attachments are already shrunk, don't worry about them
coroutine.yield(0)
end
updateSave()
autoFogOfWarReveal()
return 1
end
function onObjectSpawn(object)
if object.type == "FogOfWar" then
Wait.time(function() autoFogOfWarReveal() end, 5)
end
end
function afowr_helper()
coroutine.yield(0)
self.ignore_fog_of_war = true
self.ignore_fog_of_war = false
coroutine.yield(0)
self.ignore_fog_of_war = true
self.ignore_fog_of_war = false
return 1
end
function autoFogOfWarReveal()
if player == true then
-- We're a PC, set IFOW for a single frame, then reset
startLuaCoroutine(self, "afowr_helper")
end
end
function instantiateTriggers()
for i = 0, 99 do
triggerNames[i] = nil
if self.AssetBundle ~= nil and self.AssetBundle.getTriggerEffects() ~= nil and self.AssetBundle.getTriggerEffects()[i] ~= nil then
a[i] = false
triggerNames[i] = self.AssetBundle.getTriggerEffects()[i].name
-- create a new global function
_G["TriggerFunction" .. i] = function()
-- that simply calls our real target function
self.AssetBundle.playTriggerEffect(i - 1)
end
coroutine.yield(0)
end
end
end
function onPlayerConnect(player)
-- Wait 30 seconds for them to load fully.
Wait.time(updateHighlight, 30)
end
function changeHighlight(player, value, id)
miniHighlight = id
highlightToggle = true
updateHighlight(miniHighlight)
end
function toggleHighlight(player, value, id)
highlightToggle = not highlightToggle
updateHighlight()
end
function updateHighlight()
if highlightToggle == false then
self.highlightOff()
elseif miniHighlight == "highlightNone" then
self.highlightOff()
elseif miniHighlight == "highlightWhite" then
self.highlightOn(Color.White)
elseif miniHighlight == "highlightBrown" then
self.highlightOn(Color.Brown)
elseif miniHighlight == "highlightRed" then
self.highlightOn(Color.Red)
elseif miniHighlight == "highlightOrange" then
self.highlightOn(Color.Orange)
elseif miniHighlight == "highlightYellow" then
self.highlightOn(Color.Yellow)
elseif miniHighlight == "highlightGreen" then
self.highlightOn(Color.Green)
elseif miniHighlight == "highlightTeal" then
self.highlightOn(Color.Teal)
elseif miniHighlight == "highlightBlue" then
self.highlightOn(Color.Blue)
elseif miniHighlight == "highlightPurple" then
self.highlightOn(Color.Purple)
elseif miniHighlight == "highlightPink" then
self.highlightOn(Color.Pink)
elseif miniHighlight == "highlightBlack" then
self.highlightOn(Color.Black)
end
updateSave()
end
function onUpdate()
onUpdateTriggerCount = onUpdateTriggerCount + 1
if onUpdateTriggerCount > 60 then
onUpdateTriggerCount = 0
if finishedLoading == true and onUpdateScale ~= self.getScale().y then
local newScale = dec3(0.3 * (1.0 / self.getScale().y))
self.UI.setAttribute("panel", "scale", newScale .. " " .. newScale)
self.UI.setAttribute("panel", "position", "0 0 -" .. (options.heightModifier + 1))
self.UI.setAttribute("panel", "position", "0 0 -" .. options.heightModifier)
local vertical = 0
vertical = vertical + (options.hideHp == true and 0 or 100)
vertical = vertical + (options.hideMana == true and 0 or 100)
vertical = vertical + (options.hideExtra == true and 0 or 100)
self.UI.setAttribute("hiddenButtonBar", "active", (options.hideHp == true and options.hideMana == true and options.hideExtra == true) and "True" or "False")
self.UI.setAttribute("resourceBar", "active", options.hideHp == true and "False" or "True")
self.UI.setAttribute("resourceBarS", "active", options.hideMana == true and "False" or "True")
self.UI.setAttribute("extraBar", "active", options.hideExtra == true and "False" or "True")
self.UI.setAttribute("bars", "height", vertical)
onUpdateScale = self.getScale().y
updateSave()
end
if finishedLoading == true and onUpdateGridSize ~= Grid.sizeX then
resetScale()
end
end
end
function dec3(input)
return math.floor(input * 1000.0) / 1000.0
end
function rebuildContextMenu()
self.clearContextMenu()
self.addContextMenuItem("UI Height UP", uiHeightUp, true)
self.addContextMenuItem("UI Height DOWN", uiHeightDown, true)
self.addContextMenuItem("UI Rotate 90", uiRotate90, true)
if hideFromPlayers == true then