forked from Tercioo/Details-Damage-Meter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.lua
1853 lines (1569 loc) · 58.7 KB
/
util.lua
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 Details = _G.Details
local Loc = LibStub("AceLocale-3.0"):GetLocale ( "Details" )
local addonName, Details222 = ...
local _
local upper = string.upper --lua local
local ipairs = ipairs --lua local
local pairs = pairs --lua local
local _math_floor = math.floor --lua local
local _math_max = math.max --lua local
local _math_min = math.min --lua local
local _math_random = math.random --lua local
local type = type --lua local
local _string_match = string.match --lua local
local _string_format = string.format --lua local
local loadstring = loadstring --lua local
local select = select
local tonumber = tonumber
local strsplit = strsplit
local _pcall = pcall
local GetTime = GetTime
local GetUnitName = _G.GetUnitName
local UnitExists = UnitExists
local UnitGUID = UnitGUID
local IsInRaid = IsInRaid --wow api local
local IsInGroup = IsInGroup --wow api local
local GetNumGroupMembers = GetNumGroupMembers --wow api local
local UnitAffectingCombat = UnitAffectingCombat --wow api local
local _InCombatLockdown = InCombatLockdown --wow api local
local playerRealmName = GetRealmName()
local gump = Details.gump --details local
function Details:IsInMythicPlus()
return C_ChallengeMode and C_ChallengeMode.IsChallengeModeActive and C_ChallengeMode.IsChallengeModeActive()
end
local predicateFunc = function(spellIdToFind, casterName, _, name, icon, applications, dispelName, duration, expirationTime, sourceUnitId, isStealable, nameplateShowPersonal, spellId, canApplyAura, isBossAura, isFromPlayerOrPlayerPet, nameplateShowAll, timeMod, applications)
if (spellIdToFind == spellId and UnitExists(sourceUnitId)) then
if (casterName == Details:GetUnitNameForAPI(sourceUnitId)) then
return true
end
end
end
do
---find the duration of a debuff by passing the spellId and the caster name
---@param unitId unit
---@param spellId spellid
---@param casterName actorname
---@return auraduration|nil auraDuration
---@return number|nil expirationTime
function Details:FindDebuffDuration(unitId, spellId, casterName)
local name, texture, count, debuffType, duration, expirationTime = AuraUtil.FindAura(predicateFunc, unitId, "HARMFUL", spellId, casterName)
if (name) then
return duration, expirationTime
end
end
function Details:FindDebuffDurationByUnitName(targetString, spellId, casterString)
local targetName = Details:Ambiguate(targetString)
local casterName = Details:Ambiguate(casterString)
return Details:FindDebuffDuration(targetName, spellId, casterName)
end
end
do
---find the duration of a buff by passing the spellId and the caster name
---@param unitId unit
---@param spellId spellid
---@param casterName actorname
---@return auraduration|nil auraDuration
---@return number|nil expirationTime
function Details:FindBuffDuration(unitId, spellId, casterName) --not called anywhere else except the function below
local name, texture, count, debuffType, duration, expirationTime = AuraUtil.FindAura(predicateFunc, unitId, "HELPFUL", spellId, casterName)
if (name) then
return duration, expirationTime
end
end
function Details:FindBuffDurationByUnitName(targetString, spellId, casterString)
local targetName = Details:Ambiguate(targetString)
local casterName = Details:Ambiguate(casterString)
return Details:FindBuffDuration(targetName, spellId, casterName)
end
end
do
function Details:FindBuffCastedBy(unitId, buffSpellId, casterName) --not called anywhere else except the function below
local auraName, texture, count, auraType, duration, expTime, sourceUnit, isStealable, nameplateShowPersonal, spellId, canApplyAura, isBossAura, playerOrPet, nameplateShowAll, timeMod, v1, v2, v3, v4, v5 = AuraUtil.FindAura(predicateFunc, unitId, "HELPFUL", buffSpellId, casterName)
if (auraName) then
return auraName, texture, count, auraType, duration, expTime, sourceUnit, isStealable, nameplateShowPersonal, spellId, canApplyAura, isBossAura, playerOrPet, nameplateShowAll, timeMod, v1, v2, v3, v4, v5
end
end
function Details:FindBuffCastedByUnitName(targetString, buffSpellId, casterString)
local targetName = Details:Ambiguate(targetString)
local casterName = Details:Ambiguate(casterString)
return Details:FindBuffCastedBy(targetName, buffSpellId, casterName)
end
end
---return the unitId by passing a unit serial (guid)
---@param unitSerial serial
---@return unit|nil unitId
function Details:FindUnitIDByUnitSerial(unitSerial)
--target
if (UnitExists("target")) then
if (UnitGUID("target") == unitSerial) then
return "target"
end
end
--focus
if (UnitExists("focus")) then
if (UnitGUID("focus") == unitSerial) then
return "focus"
end
end
--boss
for i = 1, 9 do
local unitId = Details222.UnitIdCache.Boss[i]
if (UnitExists(unitId)) then
if (UnitGUID(unitId) == unitSerial) then
return unitId
end
else
break
end
end
--nameplate
for i = 1, 40 do
local unitId = Details222.UnitIdCache.Nameplate[i]
if (UnitExists(unitId)) then
if (UnitGUID(unitId) == unitSerial) then
return unitId
end
end
end
--arena enemies
for i = 1, #Details222.UnitIdCache.Arena do
local unitId = Details222.UnitIdCache.Arena[i]
if (UnitExists(unitId)) then
if (UnitGUID(unitId) == unitSerial) then
return unitId
end
else
break
end
end
end
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--fade handler
Details.FadeHandler = {
frames = {}
}
--fade in is hidding the frame, it is the opposite of the stardard
local fadeINFinishedCallback = function(frame)
if (frame.fading_in) then
frame.hidden = true
frame.faded = true
frame.fading_in = false
frame:Hide()
end
end
--fade out is showing the frame
local fadeOUTFinishedCallback = function(frame)
if (frame:IsShown() and frame.fading_out) then
frame.hidden = false
frame.faded = false
frame.fading_out = false
else
frame:SetAlpha(0)
end
end
local just_fade_func = function(frame)
frame.hidden = false
frame.faded = true
frame.fading_in = false
end
local cancelFadeAnimation = function(frame)
Details.FadeHandler.frames[frame] = nil
end
Details.FadeHandler.OnUpdateFrame = CreateFrame("frame", "DetailsFadeFrameOnUpdate", UIParent)
Details.FadeHandler.OnUpdateFrame:SetScript("OnUpdate", function(self, deltaTime)
for frame, frameSettings in pairs(Details.FadeHandler.frames) do
local totalTime = frameSettings.totalTime
local initAlpha = frameSettings.startAlpha
local targetAlpha = frameSettings.endAlpha
frameSettings.elapsed = frameSettings.elapsed + deltaTime
local currentAlpha = Lerp(initAlpha, targetAlpha, frameSettings.elapsed / totalTime)
if (frameSettings.elapsed >= totalTime) then
frame:SetAlpha(targetAlpha)
frameSettings.finishedCallback(frame)
--remove the frame from the list
Details.FadeHandler.frames[frame] = nil
else
frame:SetAlpha(currentAlpha)
end
end
end)
--fade in is hidding the frame
local startFadeINAnimation = function(frame, totalTime, startAlpha, endAlpha, callbackFunc)
frame.fading_out = nil
frame.fading_in = true
Details.FadeHandler.frames[frame] = {
totalTime = totalTime or Details.fade_speed,
startAlpha = startAlpha or frame:GetAlpha(),
endAlpha = endAlpha or 0,
finishedCallback = callbackFunc or fadeINFinishedCallback,
elapsed = 0,
}
end
--fade out is showing the frame
local startFadeOUTAnimation = function(frame, totalTime, startAlpha, endAlpha, callbackFunc)
frame.fading_in = nil
frame.fading_out = true
Details.FadeHandler.frames[frame] = {
totalTime = totalTime or Details.fade_speed,
startAlpha = startAlpha or frame:GetAlpha() or 0,
endAlpha = endAlpha or 1,
finishedCallback = callbackFunc or fadeOUTFinishedCallback,
elapsed = 0,
}
end
function Details.FadeHandler.Fader(frame, animationType, speed, hideType, param5)
if (frame == nil) then
frame, animationType, speed, hideType = animationType, speed, hideType, param5
end
--if is a table, might be passed an instance object
if (type(frame) == "table") then
--is it an instance
if (frame.meu_id) then
local instance = frame
--hide all bars in the instance
if (hideType == "barras") then
if (speed) then
for i = 1, instance.rows_created do
local instanceBar = instance.barras[i]
Details.FadeHandler.Fader(instanceBar, animationType, speed)
end
return
else
speed = speed or Details.fade_speed
for i = 1, instance.rows_created do
local instanceBar = instance.barras[i]
Details.FadeHandler.Fader(instanceBar, animationType, Details.fade_speed+(i/10))
end
return
end
--instant hide all bars in the instance
elseif (hideType == "hide_barras") then
for i = 1, instance.rows_created do
local instanceBar = instance.barras[i]
if (instanceBar.fading_in or instanceBar.fading_out) then
startFadeINAnimation(instanceBar, 0.01, instanceBar:GetAlpha(), instanceBar:GetAlpha())
end
instanceBar.hidden = true
instanceBar.faded = true
instanceBar.fading_in = false
instanceBar.fading_out = false
instanceBar:Hide()
instanceBar:SetAlpha(0)
end
return
end
--if is a framework widget
elseif (frame.dframework) then
frame = frame.widget
end
end
speed = speed or Details.fade_speed
--animationType = upper(animationType)
--hide all instanceBars on all instances
if (frame == "all") then
for _, instancia in ipairs(Details.tabela_instancias) do
if (hideType == "barras") then
for i = 1, instancia.rows_created do
local instanceBar = instancia.barras[i]
Details.FadeHandler.Fader(instanceBar, animationType, speed+(i/10))
end
end
end
return
elseif (upper(animationType) == "IN") then --hide the frame
--check if already hidden
if (frame:GetAlpha() == 0 and frame.hidden and not frame.fading_out) then
return
--chekc if already with an animation going on
elseif (frame.fading_in) then
return
end
--cancel face out animation if exists
if (frame.fading_out) then
frame.fading_out = false
end
startFadeINAnimation(frame, speed, frame:GetAlpha(), 0)
elseif (upper(animationType) == "OUT") then --show the frame
if (frame:GetAlpha() == 1 and not frame.hidden and not frame.fading_in) then --ja esta na tela
return
elseif (frame.fading_out) then --j� ta com fading out
return
end
if (frame.fading_in) then --se tiver uma anima��o de hidar em andamento se for true
frame.fading_in = false
end
frame:Show()
startFadeOUTAnimation(frame, speed, frame:GetAlpha(), 1.0)
frame.fading_out = true
elseif (animationType == 0) then --force show the frame
frame.hidden = false
frame.faded = false
frame.fading_out = false
frame.fading_in = false
cancelFadeAnimation(frame) --cancel any ongoing animation
frame:Show()
frame:SetAlpha(1)
elseif (animationType == 1) then --force hide the frame
frame.hidden = true
frame.faded = true
frame.fading_out = false
frame.fading_in = false
cancelFadeAnimation(frame) --cancel any ongoing animation
frame:SetAlpha(0)
frame:Hide()
elseif (animationType == -1) then --just fade to zero without hidding the frame
--check already hidden
if (frame:GetAlpha() == 0 and frame.hidden and not frame.fading_out) then
return
--check already hidding
elseif (frame.fading_in) then
return
end
if (frame.fading_out) then
frame.fading_out = false
end
startFadeINAnimation(frame, speed, frame:GetAlpha(), 0, just_fade_func)
elseif (upper(animationType) == "ALPHAANIM") then
local value = speed
local currentApha = frame:GetAlpha()
frame:Show()
if (currentApha < value) then
if (frame.fading_in) then
frame.fading_in = false
end
startFadeOUTAnimation(frame, Details.fade_speed, currentApha, value, function(frame) frame.fading_out = false end)
else
if (frame.fading_out) then
frame.fading_out = false
end
startFadeINAnimation(frame, Details.fade_speed, currentApha, value, function(frame) frame.fading_in = false end)
end
--set a fixed alpha value
elseif (upper(animationType) == "ALPHA") then
local alphaAmount = speed
if (frame.fading_in or frame.fading_out) then
startFadeINAnimation(frame, speed, alphaAmount, alphaAmount)
end
frame.hidden = false
frame.faded = false
frame.fading_in = false
frame.fading_out = false
frame:Show()
frame:SetAlpha(alphaAmount)
end
end
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--details api functions
--get the npc id from guid
function Details:GetNpcIdFromGuid (guid)
local NpcId = select( 6, strsplit( "-", guid ) )
if (NpcId) then
return tonumber( NpcId )
end
return 0
end
function Details:GetSourceFromNpcId (npcId)
for index, container in ipairs(Details.tabela_vigente) do
if (index <= 4) then
local t = container._ActorTable
for i = 1, #t do
if (Details:GetNpcIdFromGuid (t[i].serial) == npcId) then
return t[i].nome
end
end
end
end
end
function Details:GetRaidLeader()
if (IsInRaid()) then
for i = 1, GetNumGroupMembers() do
local actorName, rank = GetRaidRosterInfo(i)
if (rank == 2) then
return actorName, "raid" .. i
end
end
end
end
---unpack a death table
---@param deathTable table
---@return actorname actorName name of the actor
---@return actorclass actorClass class of the actor
---@return unixtime deathTime unittime of when the death occurred
---@return combattime deathCombatTime time in seconds since the combat start
---@return timestring deathTimeString time in string format
---@return number maxHealth max health of the actor
---@return table deathEvents events that lead the actor to death
---@return {key1: unixtime, key2: spellid}
---@return specializationid specId
function Details:UnpackDeathTable(deathTable)
local deathEvents = deathTable[1]
local deathTime = deathTable[2]
local playerName = deathTable[3]
local playerClass = deathTable[4]
local playerMaxHealth = deathTable[5]
local deathTimeString = deathTable[6]
local lastCooldown = deathTable.last_cooldown
local deathCombatTime = deathTable.dead_at
local spec = deathTable.spec
return playerName, playerClass, deathTime, deathCombatTime, deathTimeString, playerMaxHealth, deathEvents, lastCooldown, spec
end
---get a random fraction number
---@return number
function Details:GetOrderNumber() --anyString
--local name = upper(anyString .. "zz")
--local byte1 = abs(_string_byte(name, 2)-91) / 1000000
--return byte1 + abs(_string_byte(name, 1)-91) / 10000
return _math_random(1000, 9000) / 1000000
end
--/script print(tonumber(4/1000000)) - 4e-006
--0.000004
--set all table keys to lower
local temptable = {}
function Details:LowerizeKeys (_table)
for key, value in pairs(_table) do
temptable [string.lower(key)] = value
end
temptable, _table = Details:Destroy(_table), temptable
return _table
end
Details.ToKFunctions = {}
--krKR by @yuk6196 (http://wow.curseforge.com/profiles/yuk6196)
function Details:UseEastAsianNumericalSystem()
--try to auto detect the language
local symbol_1K, symbol_10K, symbol_1B
if (LibStub("AceLocale-3.0"):NewLocale ("Details", "koKR")) then --Korea
symbol_1K, symbol_10K, symbol_1B = "천", "만", "억"
elseif (LibStub("AceLocale-3.0"):NewLocale ("Details", "zhCN")) then --China
symbol_1K, symbol_10K, symbol_1B = "千", "万", "亿"
elseif (LibStub("AceLocale-3.0"):NewLocale ("Details", "zhTW")) then --Taiwan
symbol_1K, symbol_10K, symbol_1B = "千", "萬", "億"
end
--override, force details! to use symbols for a specific language.
--usage: _detalhes:SetNumericalSystemOverride (language) language can be: "kr", "cn", "tw"
--just in case the user mess up something
if (type(Details.numerical_system_symbols) ~= "string") then
Details.numerical_system_symbols = "auto"
end
--do the override
if (Details.numerical_system_symbols ~= "auto") then
local locale = string.lower(Details.numerical_system_symbols)
if (locale == "kr") then
symbol_1K, symbol_10K, symbol_1B = "천", "만", "억"
elseif (locale == "cn") then
symbol_1K, symbol_10K, symbol_1B = "千", "万", "亿"
elseif (locale == "tw") then
symbol_1K, symbol_10K, symbol_1B = "千", "萬", "億"
end
end
if (not symbol_1K) then
--if a english client is trying to use east asian numeral system and there is no override, let's just use the chinese as default.
--if the user is from kr or tw and want to use english client, an override must be used.
symbol_1K, symbol_10K, symbol_1B = "千", "万", "亿"
end
function Details:ToK (numero)
if (numero > 100000000) then
return _string_format ("%.2f", numero/100000000) .. symbol_1B
elseif (numero > 10000) then
return _string_format ("%.2f", numero/10000) .. symbol_10K
elseif (numero > 1000) then
return _string_format ("%.1f", numero/1000) .. symbol_1K
end
return _string_format ("%.0f", numero)
end
function Details:ToK2 (numero)
if (numero > 99999999) then
return _string_format ("%.2f", numero/100000000) .. symbol_1B
elseif (numero > 999999) then
return _string_format ("%.2f", numero/10000) .. symbol_10K
elseif (numero > 99999) then
return _math_floor(numero/10000) .. symbol_10K
elseif (numero > 9999) then
return _string_format ("%.1f", (numero/10000)) .. symbol_10K
elseif (numero > 999) then
return _string_format ("%.1f", (numero/1000)) .. symbol_1K
end
return _string_format ("%.1f", numero)
end
--short numbers no numbers after comma
function Details:ToK0 (numero)
if (numero > 100000000) then
return _string_format ("%.0f", numero/100000000) .. symbol_1B
elseif (numero > 10000) then
return _string_format ("%.0f", numero/10000) .. symbol_10K
elseif (numero > 1000) then
return _string_format ("%.0f", numero/1000) .. symbol_1K
end
return _string_format ("%.0f", numero)
end
function Details:ToKMin (numero)
if (numero > 100000000) then
return _string_format ("%.2f", numero/100000000) .. symbol_1B
elseif (numero > 10000) then
return _string_format ("%.2f", numero/10000) .. symbol_10K
elseif (numero > 1000) then
return _string_format ("%.1f", numero/1000) .. symbol_1K
end
return _string_format ("%.0f", numero)
end
function Details:ToK2Min (numero)
if (numero > 99999999) then
return _string_format ("%.2f", numero/100000000) .. symbol_1B
elseif (numero > 999999) then
return _string_format ("%.2f", numero/10000) .. symbol_10K
elseif (numero > 99999) then
return _math_floor(numero/10000) .. symbol_10K
elseif (numero > 9999) then
return _string_format ("%.1f", (numero/10000)) .. symbol_10K
elseif (numero > 999) then
return _string_format ("%.1f", (numero/1000)) .. symbol_1K
end
return _string_format ("%.1f", numero)
end
--short numbers no numbers after comma
function Details:ToK0Min (numero)
if (numero > 100000000) then
return _string_format ("%.0f", numero/100000000) .. symbol_1B
elseif (numero > 10000) then
return _string_format ("%.0f", numero/10000) .. symbol_10K
elseif (numero > 1000) then
return _string_format ("%.0f", numero/1000) .. symbol_1K
end
return _string_format ("%.0f", numero)
end
--short numbers no numbers after comma
function Details:ToKReport (numero)
if (numero > 100000000) then
return _string_format ("%.2f", numero/100000000) .. symbol_1B
elseif (numero > 10000) then
return _string_format ("%.1f", numero/10000) .. symbol_10K
elseif (numero > 1000) then
return _string_format ("%.0f", numero/1000) .. symbol_1K
end
return numero
end
function Details:Format (n, custom)
n = _math_floor(n)
if (custom) then
if (n > 99999999) then
return _string_format (custom, n/100000000) .. symbol_1B
elseif (n > 9999) then
return _string_format (custom, n/10000) .. symbol_10K
elseif (n > 999) then
return _string_format (custom, (n/1000))
else
return n
end
else
return Details.ToKFunctions [Details.ps_abbreviation] (nil, n)
end
end
--no changes
function Details:NoToK (numero)
return _math_floor(numero)
end
-- thanks http://richard.warburton.it
function Details:comma_value (n)
if (not n) then return "0" end
n = _math_floor(n)
if (n == 0) then
return "0"
end
local left,num,right = _string_match (n,'^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
end
function Details:comma_value_raw (n)
local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
end
Details:Destroy(Details.ToKFunctions)
table.insert(Details.ToKFunctions, Details.NoToK)
table.insert(Details.ToKFunctions, Details.ToK)
table.insert(Details.ToKFunctions, Details.ToK2)
table.insert(Details.ToKFunctions, Details.ToK0)
table.insert(Details.ToKFunctions, Details.ToKMin)
table.insert(Details.ToKFunctions, Details.ToK2Min)
table.insert(Details.ToKFunctions, Details.ToK0Min)
table.insert(Details.ToKFunctions, Details.comma_value)
end
function Details:UseWestNumericalSystem()
--short numbers
function Details:ToK (numero)
if (numero > 999999999) then
return format("%.2f", numero/1000000000) .. "B"
elseif (numero > 1000000) then
return _string_format ("%.2f", numero/1000000) .. "M"
elseif (numero > 999) then
return _string_format ("%.1f", numero/1000) .. "K"
end
return _string_format ("%.0f", numero)
end
function Details:ToK2 (numero)
if (numero > 999999999) then
return format("%.2f", numero/1000000000) .. "B"
elseif (numero > 999999) then
return _string_format ("%.2f", numero/1000000) .. "M"
elseif (numero > 99999) then
return _math_floor(numero/1000) .. "K"
elseif (numero > 999) then
return _string_format ("%.1f", (numero/1000)) .. "K"
end
return _string_format ("%.0f", numero)
end
--short numbers no numbers after comma
function Details:ToK0 (numero)
if (numero > 999999999) then
return format("%.2f", numero/1000000000) .. "B"
elseif (numero > 1000000) then
return _string_format ("%.0f", numero/1000000) .. "M"
elseif (numero > 1000) then
return _string_format ("%.0f", numero/1000) .. "K"
end
return _string_format ("%.0f", numero)
end
function Details:ToKMin (numero)
if (numero > 1000000) then
return _string_format ("%.2f", numero/1000000) .. "m"
elseif (numero > 1000) then
return _string_format ("%.1f", numero/1000) .. "k"
end
return _string_format ("%.0f", numero)
end
function Details:ToK2Min (numero)
if (numero > 999999) then
return _string_format ("%.2f", numero/1000000) .. "m"
elseif (numero > 99999) then
return _math_floor(numero/1000) .. "k"
elseif (numero > 999) then
return _string_format ("%.1f", (numero/1000)) .. "k"
end
return _string_format ("%.0f", numero)
end
--short numbers no numbers after comma
function Details:ToK0Min (numero)
if (numero > 1000000) then
return _string_format ("%.0f", numero/1000000) .. "m"
elseif (numero > 1000) then
return _string_format ("%.0f", numero/1000) .. "k"
end
return _string_format ("%.0f", numero)
end
--short numbers no numbers after comma
function Details:ToKReport (numero)
if (numero > 1000000) then
return _string_format ("%.2f", numero/1000000) .. "M"
elseif (numero > 1000) then
return _string_format ("%.1f", numero/1000) .. "K"
end
return numero
end
function Details:Format (n, custom)
n = _math_floor(n)
if (custom) then
if (n > 999999) then
return _string_format (custom, n/1000000) .. "M"
elseif (n > 999) then
return _string_format (custom, (n/1000))
else
return n
end
else
return Details.ToKFunctions [Details.ps_abbreviation] (nil, n)
end
end
--no changes
function Details:NoToK (numero)
return _math_floor(numero)
end
-- thanks http://richard.warburton.it
function Details:comma_value (n)
if (not n) then return "0" end
n = _math_floor(n)
if (n == 0) then
return "0"
end
local left,num,right = _string_match (n,'^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
end
function Details:comma_value_raw (n)
local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
end
Details:Destroy(Details.ToKFunctions)
table.insert(Details.ToKFunctions, Details.NoToK)
table.insert(Details.ToKFunctions, Details.ToK)
table.insert(Details.ToKFunctions, Details.ToK2)
table.insert(Details.ToKFunctions, Details.ToK0)
table.insert(Details.ToKFunctions, Details.ToKMin)
table.insert(Details.ToKFunctions, Details.ToK2Min)
table.insert(Details.ToKFunctions, Details.ToK0Min)
table.insert(Details.ToKFunctions, Details.comma_value)
--
end
--load western as default, the proper method is loaded within the profile
Details:UseWestNumericalSystem()
function Details:GetCurrentToKFunction()
return Details.ToKFunctions [Details.ps_abbreviation]
end
--alias
---transfor an integer into a string separating thousands with a comma
---@param number number
---@return string
function Details:CommaValue(number)
return Details:comma_value(number)
end
------------------------------------------------------------------------------------------------------------
--numerical system
function Details:SetNumericalSystemOverride (language)
if (not language) then
language = "auto"
end
Details.numerical_system_symbols = language
Details:Msg("NumSystem override is now:", language)
Details:SelectNumericalSystem()
end
function Details:GetNumericalSystem()
return Details.numerical_system
end
function Details:SelectNumericalSystem (system)
if (not system or type(system) ~= "number") then
system = Details.numerical_system or 1
end
Details.numerical_system = system
if (system == 1) then
Details:UseWestNumericalSystem()
elseif (system == 2) then
Details:UseEastAsianNumericalSystem()
end
Details:UpdateToKFunctions()
end
function Details:UpdateToKFunctions()
Details.atributo_damage:UpdateSelectedToKFunction()
Details.atributo_heal:UpdateSelectedToKFunction()
Details.atributo_energy:UpdateSelectedToKFunction()
Details.atributo_misc:UpdateSelectedToKFunction()
Details.atributo_custom:UpdateSelectedToKFunction()
Details:RefreshMainWindow(-1, true)
end
--------end of ToK functions----
--replacing data for custom texts
Details.string = {}
local function_cache = {}
local arguments_cache = {}
local parameters_cache = {}
local replace_arg = function(i)
return arguments_cache [tonumber(i)]
end
local run_function = function(str)
--cache functions
local func, errortext = function_cache [str]
if (not func) then
func = loadstring (str)
if (not func) then
Details:Msg("|cFFFF9900error compiling script on custom text|r: ", errortext)
return 0
end
DetailsFramework:SetEnvironment(func)
function_cache [str] = func
end
local okey, value = _pcall (func, parameters_cache [1], parameters_cache [2], parameters_cache [3], parameters_cache [4], arguments_cache[1], arguments_cache[2], arguments_cache[3])
if (not okey) then
Details:Msg("|cFFFF9900error on custom text|r:", value)
return 0
end
return value or 0
end
function Details.string.replace (str, v1, v2, v3, v4, v5, v6, v7)
arguments_cache [1] = v1
arguments_cache [2] = v2
arguments_cache [3] = v3
parameters_cache [1] = v4
parameters_cache [2] = v5
parameters_cache [3] = v6
parameters_cache [4] = v7
return (str:gsub("{data(%d+)}", replace_arg):gsub("{func(.-)}", run_function))
end
--remove a index from a hash table
function Details:tableRemove (tabela, indexName)
local newtable = {}
for hash, value in pairs(tabela) do
if (hash ~= indexName) then
newtable [hash] = value
end
end
return newtable
end
--return if the numeric table have an object
function Details:tableIN (tabela, objeto)
for index, valor in ipairs(tabela) do
if (valor == objeto) then
return index
end
end
return false
end
--reverse numerical table
function Details:reverse_table (t)
local new = {}
local index = 1
for i = #t, 1, -1 do
new [index] = t[i]
index = index + 1
end
return new
end
Details.table = {}
function Details.table.reverse (t)
local new = {}
local index = 1
for i = #t, 1, -1 do
new [index] = t[i]
index = index + 1
end
return new
end
--yah, i know
function Details.table.copy(t1, t2)
for key, value in pairs(t2) do
if (type(value) == "table") then
t1 [key] = Details.CopyTable(value)
else
t1 [key] = value
end
end
return t1
end
function Details.table.deploy(t1, t2)
for key, value in pairs(t2) do
if (type(value) == "table") then
t1 [key] = t1 [key] or {}
Details.table.deploy(t1 [key], t2 [key])
elseif (t1 [key] == nil) then
t1 [key] = value
end
end
end
function Details.table.overwrite (t1, t2)
for key, value in pairs(t2) do
if (type(value) == "table") then
t1 [key] = t1 [key] or {}
Details.table.overwrite (t1 [key], t2 [key])
else
t1 [key] = value
end
end
end
function Details.table.dump (t, s, deep)
if (type(t) == "number") then
return t
end
s = s or ""
deep = deep or 0
local space = ""
for i = 1, deep do