-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
847 lines (759 loc) · 22.1 KB
/
Copy pathCore.lua
File metadata and controls
847 lines (759 loc) · 22.1 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
local addonName, addonTable = ...
local LibChev = assert(addonTable and addonTable.LibChev, "libchev must load before Core.lua")
local NoPoizen = addonTable or {}
_G.NoPoizen = NoPoizen
NoPoizen.LibChev = LibChev
NoPoizen.addonName = addonName or "NoPoizen"
NoPoizen.MISSING_SOUND_FILE_PATH = "Interface\\AddOns\\NoPoizen\\nopoizen.wav"
NoPoizen.SATISFIED_SOUND_FILE_PATH = "Interface\\AddOns\\NoPoizen\\hahaha.wav"
NoPoizen.DRAGON_TEMPERED_BLADES_SPELL_ID = 381801
NoPoizen.WIDGET_SCALE_MIN = 0.6
NoPoizen.WIDGET_SCALE_MAX = 2.0
NoPoizen.WIDGET_SCALE_STEP = 0.05
NoPoizen.AUDIO_VOLUME_MIN = 0
NoPoizen.AUDIO_VOLUME_MAX = 1
NoPoizen.AUDIO_VOLUME_STEP = 0.05
NoPoizen.AUDIO_TRANSITION_ARM_DELAY_SECONDS = 5.0
NoPoizen.POST_LOAD_POISON_REFRESH_DELAY_SECONDS = 1.5
NoPoizen.DEFAULT_INDICATOR_ANCHOR = {
point = "CENTER",
relativePoint = "CENTER",
x = 0,
y = 140,
}
NoPoizen.DEFAULTS = {
enabled = true,
showVisualIndicator = true,
playAudioIndicator = true,
audioVolume = 0.5,
playSatisfiedAudioIndicator = true,
satisfiedAudioVolume = 0.5,
widgetScale = 1.0,
indicatorAnchor = {
point = "CENTER",
relativePoint = "CENTER",
x = 0,
y = 140,
},
}
NoPoizen.isInitialized = NoPoizen.isInitialized or false
NoPoizen.hasLoggedIn = NoPoizen.hasLoggedIn or false
NoPoizen.isEnabled = NoPoizen.isEnabled or false
NoPoizen.audioMissingState = NoPoizen.audioMissingState or false
NoPoizen.audioTransitionsArmed = NoPoizen.audioTransitionsArmed or false
NoPoizen.audioTransitionsArmAt = NoPoizen.audioTransitionsArmAt or 0
NoPoizen.isLoadingScreenActive = NoPoizen.isLoadingScreenActive or false
NoPoizen.postLoadRefreshAt = NoPoizen.postLoadRefreshAt or 0
NoPoizen.postLoadRefreshToken = NoPoizen.postLoadRefreshToken or 0
NoPoizen.runtimeEvents = {
"PLAYER_ENTERING_WORLD",
"LOADING_SCREEN_ENABLED",
"LOADING_SCREEN_DISABLED",
"UNIT_AURA",
"SPELLS_CHANGED",
"PLAYER_TALENT_UPDATE",
"ACTIVE_TALENT_GROUP_CHANGED",
"PLAYER_SPECIALIZATION_CHANGED",
"TRAIT_CONFIG_UPDATED",
"TRAIT_CONFIG_LIST_UPDATED",
"PLAYER_REGEN_ENABLED",
"PLAYER_ALIVE",
"PLAYER_EQUIPMENT_CHANGED",
"UNIT_INVENTORY_CHANGED",
"ADDON_RESTRICTION_STATE_CHANGED",
}
NoPoizen.API = NoPoizen.API
or {
Delay = function(delaySeconds, callbackFn)
if C_Timer and C_Timer.After then
C_Timer.After(delaySeconds, callbackFn)
end
end,
GetBuildInfo = function()
return GetBuildInfo()
end,
GetLocale = function()
return GetLocale()
end,
GetAddOnVersion = function(addon)
if C_AddOns and C_AddOns.GetAddOnMetadata then
return C_AddOns.GetAddOnMetadata(addon, "Version")
end
end,
UnitClass = function(unit)
return UnitClass(unit)
end,
PlaySoundFile = function(path, channel)
return PlaySoundFile(path, channel)
end,
GetTime = function()
return GetTime and GetTime() or 0
end,
}
-- These gates run before comparisons, indexing or formatting foreign values.
-- pcall contains API errors; it does not make tainted data secure.
function NoPoizen:CanAccessValue(value)
if type(issecretvalue) == "function" then
local ok, secret = pcall(issecretvalue, value)
if not ok or secret then
return false
end
end
if type(canaccessvalue) == "function" then
local ok, accessible = pcall(canaccessvalue, value)
if not ok or accessible ~= true then
return false
end
end
return true
end
function NoPoizen:CanAccessTable(value)
if not self:CanAccessValue(value) or type(value) ~= "table" then
return false
end
if type(canaccesstable) == "function" then
local ok, accessible = pcall(canaccesstable, value)
if not ok or accessible ~= true then
return false
end
end
return true
end
function NoPoizen:IsFiniteNumber(value)
return self:CanAccessValue(value)
and type(value) == "number"
and value == value
and value > -math.huge
and value < math.huge
end
function NoPoizen:ToFiniteNumber(value)
if not self:CanAccessValue(value) then
return nil
end
if type(value) ~= "number" and type(value) ~= "string" then
return nil
end
local number = tonumber(value)
return self:IsFiniteNumber(number) and number or nil
end
function NoPoizen:SafeToString(value, fallback)
if not self:CanAccessValue(value) then
return "<unavailable>"
end
if value == nil then
return fallback or ""
end
local kind = type(value)
if kind ~= "string" and kind ~= "number" and kind ~= "boolean" then
return "<" .. kind .. ">"
end
return tostring(value)
end
function NoPoizen:DeepCopy(value)
if type(value) ~= "table" then
return value
end
local copy = {}
for key, item in pairs(value) do
copy[key] = self:DeepCopy(item)
end
return copy
end
function NoPoizen:ApplyDefaults(destination, defaults)
if type(destination) ~= "table" or type(defaults) ~= "table" then
return destination
end
for key, defaultValue in pairs(defaults) do
if destination[key] == nil then
destination[key] = self:DeepCopy(defaultValue)
elseif type(defaultValue) == "table" and type(destination[key]) == "table" then
self:ApplyDefaults(destination[key], defaultValue)
end
end
return destination
end
function NoPoizen:Print(message)
local text = "|cffff4f4fNoPoizen|r: " .. self:SafeToString(message)
if DEFAULT_CHAT_FRAME and DEFAULT_CHAT_FRAME.AddMessage then
DEFAULT_CHAT_FRAME:AddMessage(text)
else
print("NoPoizen:", self:SafeToString(message))
end
end
function NoPoizen:GetPlayerClassFile()
local ok, _, classFile = pcall(self.API.UnitClass, "player")
if ok and self:CanAccessValue(classFile) and type(classFile) == "string" then
return classFile
end
return nil
end
function NoPoizen:IsPlayerRogue()
return self:GetPlayerClassFile() == "ROGUE"
end
function NoPoizen:NormalizeWidgetScale(value)
local numberValue = self:ToFiniteNumber(value)
if not numberValue then
return nil
end
local step = self.WIDGET_SCALE_STEP
numberValue = math.floor((numberValue / step) + 0.5) * step
numberValue = math.floor((numberValue * 100) + 0.5) / 100
if numberValue < self.WIDGET_SCALE_MIN or numberValue > self.WIDGET_SCALE_MAX then
return nil
end
return numberValue
end
function NoPoizen:NormalizeAudioVolume(value)
local numberValue = self:ToFiniteNumber(value)
if not numberValue then
return nil
end
local step = self.AUDIO_VOLUME_STEP
numberValue = math.floor((numberValue / step) + 0.5) * step
numberValue = math.floor((numberValue * 100) + 0.5) / 100
if numberValue < self.AUDIO_VOLUME_MIN or numberValue > self.AUDIO_VOLUME_MAX then
return nil
end
return numberValue
end
function NoPoizen:GetEffectiveAudioVolume(value)
local normalized = self:NormalizeAudioVolume(value)
if not normalized then
normalized = self:NormalizeAudioVolume(self:GetOption("audioVolume")) or self.DEFAULTS.audioVolume
end
return normalized
end
function NoPoizen:ResetAudioTransitionArming(delaySeconds)
local delay = self:ToFiniteNumber(delaySeconds)
if not delay or delay < 0 then
delay = self.AUDIO_TRANSITION_ARM_DELAY_SECONDS
end
local now = 0
if self.API and self.API.GetTime then
now = tonumber(self.API.GetTime()) or 0
elseif GetTime then
now = tonumber(GetTime()) or 0
end
self.audioMissingState = false
self.audioTransitionsArmed = false
self.audioTransitionsArmAt = now + delay
LibChev.Advance(self, "audioArmToken")
self.API.Delay(
delay,
LibChev.Fence(self, { "audioArmToken", "postLoadRefreshToken" }, function()
if self.isEnabled and not self.isLoggingOut and not self.isLoadingScreenActive then
self:RefreshPoisonState("AUDIO_BASELINE")
end
end)
)
end
function NoPoizen:SchedulePostLoadPoisonRefresh(delaySeconds)
local delay = self:ToFiniteNumber(delaySeconds)
if not delay or delay < 0 then
delay = self.POST_LOAD_POISON_REFRESH_DELAY_SECONDS
end
local now = 0
if self.API and self.API.GetTime then
now = tonumber(self.API.GetTime()) or 0
elseif GetTime then
now = tonumber(GetTime()) or 0
end
self.postLoadRefreshAt = now + delay
LibChev.Advance(self, "postLoadRefreshToken")
LibChev.Advance(self, "audioArmToken")
-- Arm transition audio no earlier than the first post-loading refresh.
self.audioTransitionsArmed = false
self.audioTransitionsArmAt = self.postLoadRefreshAt
if self.API and self.API.Delay then
self.API.Delay(
delay,
LibChev.Fence(self, { "postLoadRefreshToken" }, function()
if not self.isEnabled or self.isLoggingOut or self.isLoadingScreenActive then
return
end
if self.RefreshPoisonState then
self:RefreshPoisonState("POST_LOADING_REFRESH")
end
end)
)
end
end
function NoPoizen:InitializeDatabase()
if type(_G.NoPoizenDBChar) ~= "table" then
_G.NoPoizenDBChar = {}
end
self.db = _G.NoPoizenDBChar
self:ApplyDefaults(self.db, self.DEFAULTS)
self.db.widgetScale = self:NormalizeWidgetScale(self.db.widgetScale) or self.DEFAULTS.widgetScale
self.db.audioVolume = self:NormalizeAudioVolume(self.db.audioVolume) or self.DEFAULTS.audioVolume
self.db.satisfiedAudioVolume = self:NormalizeAudioVolume(self.db.satisfiedAudioVolume)
or self.DEFAULTS.satisfiedAudioVolume
for _, key in ipairs({ "enabled", "showVisualIndicator", "playAudioIndicator", "playSatisfiedAudioIndicator" }) do
if type(self.db[key]) ~= "boolean" then
self.db[key] = self.DEFAULTS[key]
end
end
self.db.indicatorAnchor = self:GetIndicatorAnchor()
end
function NoPoizen:GetOption(optionKey)
if not self.db then
return nil
end
return self.db[optionKey]
end
function NoPoizen:SetOption(optionKey, value)
if not self.db then
return false
end
local normalizedValue = value
if
optionKey == "showVisualIndicator"
or optionKey == "playAudioIndicator"
or optionKey == "playSatisfiedAudioIndicator"
or optionKey == "enabled"
then
if not self:CanAccessValue(value) or type(value) ~= "boolean" then
return false
end
normalizedValue = value
elseif optionKey == "widgetScale" then
normalizedValue = self:NormalizeWidgetScale(value)
if not normalizedValue then
return false
end
elseif optionKey == "audioVolume" or optionKey == "satisfiedAudioVolume" then
normalizedValue = self:NormalizeAudioVolume(value)
if not normalizedValue then
return false
end
else
return false
end
local oldValue = self.db[optionKey]
if oldValue == normalizedValue then
return true
end
self.db[optionKey] = normalizedValue
if optionKey == "enabled" then
if normalizedValue then
self:Enable()
else
self:Disable()
end
else
if self.RefreshPoisonState then
self:RefreshPoisonState("OPTION_CHANGED")
end
if self.RefreshPoisonIndicatorVisualState then
self:RefreshPoisonIndicatorVisualState()
end
end
if self.RefreshOptionsWindow then
self:RefreshOptionsWindow()
end
return true
end
local anchorPoints = {
TOPLEFT = true,
TOP = true,
TOPRIGHT = true,
LEFT = true,
CENTER = true,
RIGHT = true,
BOTTOMLEFT = true,
BOTTOM = true,
BOTTOMRIGHT = true,
}
function NoPoizen:IsAnchorPoint(point)
return self:CanAccessValue(point) and type(point) == "string" and anchorPoints[point] == true
end
function NoPoizen:GetIndicatorAnchor()
local anchor = self.db and self.db.indicatorAnchor
if not self:CanAccessTable(anchor) then
anchor = self.DEFAULT_INDICATOR_ANCHOR
end
local x, y = self:ToFiniteNumber(anchor.x), self:ToFiniteNumber(anchor.y)
return {
point = self:IsAnchorPoint(anchor.point) and anchor.point or self.DEFAULT_INDICATOR_ANCHOR.point,
relativePoint = self:IsAnchorPoint(anchor.relativePoint) and anchor.relativePoint
or self.DEFAULT_INDICATOR_ANCHOR.relativePoint,
x = x and math.abs(x) <= 10000 and x or self.DEFAULT_INDICATOR_ANCHOR.x,
y = y and math.abs(y) <= 10000 and y or self.DEFAULT_INDICATOR_ANCHOR.y,
}
end
function NoPoizen:SetIndicatorAnchor(point, relativePoint, x, y)
if not self.db then
return false
end
if not self:IsAnchorPoint(point) or not self:IsAnchorPoint(relativePoint) then
return false
end
local roundedX = self:ToFiniteNumber(x)
local roundedY = self:ToFiniteNumber(y)
if not roundedX or not roundedY or math.abs(roundedX) > 10000 or math.abs(roundedY) > 10000 then
return false
end
if roundedX >= 0 then
roundedX = math.floor(roundedX + 0.5)
else
roundedX = math.ceil(roundedX - 0.5)
end
if roundedY >= 0 then
roundedY = math.floor(roundedY + 0.5)
else
roundedY = math.ceil(roundedY - 0.5)
end
local existing = self:GetIndicatorAnchor()
local changed = existing.point ~= point
or existing.relativePoint ~= relativePoint
or existing.x ~= roundedX
or existing.y ~= roundedY
if not changed then
return false
end
self.db.indicatorAnchor = {
point = point,
relativePoint = relativePoint,
x = roundedX,
y = roundedY,
}
if self.ApplySavedIndicatorAnchor then
self:ApplySavedIndicatorAnchor()
end
return true
end
function NoPoizen:ResetIndicatorAnchor()
return self:SetIndicatorAnchor(
self.DEFAULT_INDICATOR_ANCHOR.point,
self.DEFAULT_INDICATOR_ANCHOR.relativePoint,
self.DEFAULT_INDICATOR_ANCHOR.x,
self.DEFAULT_INDICATOR_ANCHOR.y
)
end
-- Custom file playback has no documented volume override. Select pre-attenuated
-- addon assets instead of changing a shared sound-channel CVar and restoring later.
function NoPoizen:GetAlertSoundPath(soundFilePath, volume)
local stem
if soundFilePath == self.MISSING_SOUND_FILE_PATH then
stem = "nopoizen"
elseif soundFilePath == self.SATISFIED_SOUND_FILE_PATH then
stem = "hahaha"
else
return nil
end
local normalized = self:NormalizeAudioVolume(volume)
if not normalized or normalized <= 0 then
return nil
end
return string.format("Interface\\AddOns\\NoPoizen\\sounds\\%s-%03d.ogg", stem, math.floor(normalized * 100 + 0.5))
end
function NoPoizen:PlayAlertSound(soundFilePath, volumeOptionKey)
local path = self:GetAlertSoundPath(soundFilePath, self:GetEffectiveAudioVolume(self:GetOption(volumeOptionKey)))
if not path then
return false
end
local ok, willPlay = pcall(self.API.PlaySoundFile, path, "Master")
local played = ok and self:CanAccessValue(willPlay) and willPlay == true
self:LogDiagnostic("audio", played and "played" or "unavailable")
return played
end
function NoPoizen:PlayMissingPoisonSound()
return self:PlayAlertSound(self.MISSING_SOUND_FILE_PATH, "audioVolume")
end
function NoPoizen:PlaySatisfiedPoisonSound()
return self:PlayAlertSound(self.SATISFIED_SOUND_FILE_PATH, "satisfiedAudioVolume")
end
function NoPoizen:RegisterRuntimeEvents()
self.registeredRuntimeEvents = self.registeredRuntimeEvents or {}
wipe(self.registeredRuntimeEvents)
for _, eventName in ipairs(self.runtimeEvents) do
local ok, registered
if
(eventName == "UNIT_AURA" or eventName == "UNIT_INVENTORY_CHANGED") and self.eventFrame.RegisterUnitEvent
then
ok, registered = pcall(self.eventFrame.RegisterUnitEvent, self.eventFrame, eventName, "player")
else
ok, registered = pcall(self.eventFrame.RegisterEvent, self.eventFrame, eventName)
end
if ok and self:CanAccessValue(registered) and registered == true then
self.registeredRuntimeEvents[eventName] = true
else
self:LogDiagnostic("event-unavailable", eventName)
end
end
end
function NoPoizen:UnregisterRuntimeEvents()
for eventName in pairs(self.registeredRuntimeEvents or {}) do
self.eventFrame:UnregisterEvent(eventName)
end
if self.registeredRuntimeEvents then
wipe(self.registeredRuntimeEvents)
end
end
function NoPoizen:Enable()
if not self.db then
return false
end
self.db.enabled = true
if not self.hasLoggedIn then
return true
end
if self.isEnabled then
return true
end
self:RegisterRuntimeEvents()
self.isEnabled = true
self.isLoadingScreenActive = false
self.postLoadRefreshAt = 0
LibChev.Advance(self, "postLoadRefreshToken")
self:ResetAudioTransitionArming()
if self.EnsurePoisonIndicatorWidget then
self:EnsurePoisonIndicatorWidget()
end
if self.RefreshPoisonState then
self:RefreshPoisonState("ENABLE")
end
if self.TryRegisterEditModeCallbacks then
self:TryRegisterEditModeCallbacks()
end
if self.RefreshPoisonIndicatorVisualState then
self:RefreshPoisonIndicatorVisualState()
end
return true
end
function NoPoizen:Disable()
if not self.db then
return false
end
self.db.enabled = false
self.isEnabled = false
if self.UnregisterEditModeCallbacks then
self:UnregisterEditModeCallbacks()
end
if self.EndPoisonIndicatorEditMode then
self:EndPoisonIndicatorEditMode(false)
end
self.currentPoisonState = nil
self:UnregisterRuntimeEvents()
self.isLoadingScreenActive = false
self.postLoadRefreshAt = 0
LibChev.Advance(self, "postLoadRefreshToken")
self.audioMissingState = false
self.audioTransitionsArmed = false
self.audioTransitionsArmAt = 0
self.audioBaselinePending = true
if self.RefreshPoisonIndicatorVisualState then
self:RefreshPoisonIndicatorVisualState()
end
return true
end
function NoPoizen:OpenHudEditMode()
return self.BeginPoisonIndicatorEditMode and self:BeginPoisonIndicatorEditMode() or false
end
function NoPoizen:InitializeSlashCommands()
SLASH_NOPOIZEN1 = "/nopoizen"
SLASH_NOPOIZEN2 = "/np"
SlashCmdList.NOPOIZEN = function(input)
NoPoizen:HandleSlashCommand(input or "")
end
end
function NoPoizen:HandleSlashCommand(input)
local command = string.match(input or "", "^(%S+)") or ""
command = string.lower(command)
if command == "" or command == "options" then
if not self:OpenOptionsWindow() then
self:Print("Options are unavailable right now.")
end
return
end
if command == "edit" then
if not self:OpenHudEditMode() then
self:Print("Position editor unavailable while disabled, loading, or restricted.")
end
return
end
if command == "diagnostics" or command == "diag" then
self:ShowDiagnostics()
return
end
if command == "test" then
if self.RunTests then
self:RunTests()
else
self:Print("Tests are unavailable.")
end
return
end
if command == "enable" then
self:SetOption("enabled", true)
self:Print("NoPoizen enabled.")
return
end
if command == "disable" then
self:SetOption("enabled", false)
self:Print("NoPoizen disabled.")
return
end
self:Print("Commands: /nopoizen options | edit | enable | disable | test | diagnostics")
end
function NoPoizen:OnInitialize()
self:InitializeDatabase()
self:InitializeSlashCommands()
if self.InitializeOptionsWindow then
self:InitializeOptionsWindow()
end
self.isInitialized = true
end
function NoPoizen:OnLogin()
self.hasLoggedIn = true
if self:GetOption("enabled") then
self:Enable()
else
self:Disable()
end
end
function NoPoizen:ADDON_LOADED(_, loadedAddonName)
if self.isEnabled and self.TryRegisterEditModeCallbacks then
self:TryRegisterEditModeCallbacks()
end
if loadedAddonName ~= self.addonName then
return
end
if not self.isInitialized then
self:OnInitialize()
end
end
function NoPoizen:PLAYER_LOGIN()
if not self.isInitialized then
self:OnInitialize()
end
self:OnLogin()
end
function NoPoizen:PLAYER_ENTERING_WORLD()
if self.isEnabled then
if self.isLoadingScreenActive or (tonumber(self.postLoadRefreshAt) or 0) > 0 then
return
end
self:ResetAudioTransitionArming()
end
if self.isEnabled and self.RefreshPoisonState then
self:RefreshPoisonState("PLAYER_ENTERING_WORLD")
end
end
function NoPoizen:LOADING_SCREEN_ENABLED()
if not self.isEnabled then
return
end
self.isLoadingScreenActive = true
self.blizzardEditModeActive = false
if self.EndPoisonIndicatorEditMode then
self:EndPoisonIndicatorEditMode(false)
end
self.currentPoisonState = nil
if self.RefreshPoisonIndicatorVisualState then
self:RefreshPoisonIndicatorVisualState()
end
self.postLoadRefreshAt = 0
LibChev.Advance(self, "postLoadRefreshToken")
self:ResetAudioTransitionArming()
end
function NoPoizen:LOADING_SCREEN_DISABLED()
if not self.isEnabled then
return
end
self.isLoadingScreenActive = false
self:SchedulePostLoadPoisonRefresh()
end
function NoPoizen:UNIT_AURA(_, unitToken)
if not self.isEnabled or not self:CanAccessValue(unitToken) or unitToken ~= "player" then
return
end
if self.RefreshPoisonState then
self:RefreshPoisonState("UNIT_AURA")
end
end
function NoPoizen:PLAYER_TALENT_UPDATE()
if self.isEnabled and self.RefreshPoisonState then
self:RefreshPoisonState("PLAYER_TALENT_UPDATE")
end
end
function NoPoizen:SPELLS_CHANGED()
if self.isEnabled and self.RefreshPoisonState then
self:RefreshPoisonState("SPELLS_CHANGED")
end
end
function NoPoizen:ACTIVE_TALENT_GROUP_CHANGED()
if self.isEnabled and self.RefreshPoisonState then
self:RefreshPoisonState("ACTIVE_TALENT_GROUP_CHANGED")
end
end
function NoPoizen:PLAYER_SPECIALIZATION_CHANGED(_, unitToken)
if not self:CanAccessValue(unitToken) or unitToken ~= "player" then
return
end
if self.isEnabled and self.RefreshPoisonState then
self:RefreshPoisonState("PLAYER_SPECIALIZATION_CHANGED")
end
end
function NoPoizen:TRAIT_CONFIG_UPDATED()
if self.isEnabled and self.RefreshPoisonState then
self:RefreshPoisonState("TRAIT_CONFIG_UPDATED")
end
end
function NoPoizen:TRAIT_CONFIG_LIST_UPDATED()
if self.isEnabled and self.RefreshPoisonState then
self:RefreshPoisonState("TRAIT_CONFIG_LIST_UPDATED")
end
end
function NoPoizen:PLAYER_REGEN_ENABLED()
if self.isEnabled then
self:RefreshPoisonState("PLAYER_REGEN_ENABLED")
end
end
function NoPoizen:PLAYER_ALIVE()
if self.isEnabled then
self:RefreshPoisonState("PLAYER_ALIVE")
end
end
function NoPoizen:PLAYER_EQUIPMENT_CHANGED()
if self.isEnabled then
self:RefreshPoisonState("PLAYER_EQUIPMENT_CHANGED")
end
end
function NoPoizen:UNIT_INVENTORY_CHANGED(_, unit)
if self.isEnabled and self:CanAccessValue(unit) and unit == "player" then
self:RefreshPoisonState("UNIT_INVENTORY_CHANGED")
end
end
function NoPoizen:ADDON_RESTRICTION_STATE_CHANGED()
-- Restriction queries report false during event dispatch: defer the observation.
if not self.isEnabled then
return
end
LibChev.Advance(self, "restrictionRefreshToken")
self.API.Delay(
0,
LibChev.Fence(self, { "restrictionRefreshToken", "postLoadRefreshToken" }, function()
if self.isEnabled and not self.isLoggingOut then
self:RefreshPoisonState("ADDON_RESTRICTION_STATE_CHANGED")
end
end)
)
end
local function DispatchEvent(_, eventName, ...)
local handler = NoPoizen[eventName]
if type(handler) ~= "function" then
return
end
local ok, err = pcall(handler, NoPoizen, eventName, ...)
if not ok then
NoPoizen:LogDiagnostic("event-error", eventName .. ": " .. NoPoizen:SafeToString(err))
if type(geterrorhandler) == "function" then
geterrorhandler()(err)
end
end
end
NoPoizen.eventFrame = NoPoizen.eventFrame or CreateFrame("Frame")
NoPoizen.eventFrame:SetScript("OnEvent", DispatchEvent)
NoPoizen.eventFrame:RegisterEvent("ADDON_LOADED")
NoPoizen.eventFrame:RegisterEvent("PLAYER_LOGIN")