-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
129 lines (112 loc) · 3.51 KB
/
Core.lua
File metadata and controls
129 lines (112 loc) · 3.51 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
local ADDON_NAME, ns = ...
-- Saved variables (initialized in ADDON_LOADED)
BeledarOrchestraDB = BeledarOrchestraDB or {}
-- Constants
ns.PREFIX = "BeledarOrch"
ns.TARGET_NPC_ID = 255888
ns.UPDATE_INTERVAL = 0.2
ns.MAX_MEASURES = 25
ns.RAID_SLOTS = 40
ns.ZONE_ID = 2215
ns.VERSION = C_AddOns.GetAddOnMetadata(ADDON_NAME, "Version") or "Unknown"
ns.ADDON_NAME = ADDON_NAME
-- Shared state
ns.state = {
currentMeasure = nil,
status = "YELLOW",
mismatchText = "No measure selected",
lastUpdate = 0,
activePlayers = {},
lastPingTime = 0,
performedEmotes = {},
danceMoving = {},
danceComplete = {},
measureLocked = false,
measureStarted = false,
countdownEndTime = nil,
countdownDuration = 10,
lastCompletedMeasure = nil,
}
-- Shared UI table
ns.ui = {}
-- Main event frame
ns.frame = CreateFrame("Frame")
-- Utility functions
function ns.Print(msg)
DEFAULT_CHAT_FRAME:AddMessage("|cff99ccffBeledar Orchestra:|r " .. tostring(msg))
end
function ns.GetNpcID(unit)
local id = UnitCreatureID(unit)
if id then return tonumber(id) end
return nil
end
function ns.IsTargetNpc(unit)
return ns.GetNpcID(unit) == ns.TARGET_NPC_ID
end
function ns.IsLeaderOrAssist()
return UnitIsGroupLeader("player") or UnitIsGroupAssistant("player")
end
function ns.GetAuraData(unit, spellId, filter)
if not unit or not spellId then return nil end
filter = filter or "HELPFUL"
for i = 1, 255 do
local aura = C_UnitAuras.GetAuraDataByIndex(unit, i, filter)
if not aura then break end
local auraSpellId = aura.spellId
if auraSpellId then
-- Use HasAnySecretValues if available (WoW 11.0.5+) to avoid crashes when
-- comparing "secret number values" (private auras) to a regular number.
local isSecret = HasAnySecretValues and HasAnySecretValues(auraSpellId)
if not isSecret then
-- Still use pcall for absolute safety against comparison errors
-- in all client versions.
local success, match = pcall(function() return auraSpellId == spellId end)
if success and match then
return aura
end
end
end
end
return nil
end
function ns.HasAura(unit, spellId)
return ns.GetAuraData(unit, spellId) ~= nil
end
function ns.MakeMovable(f)
f:SetMovable(true)
f:EnableMouse(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
end)
end
function ns.CreateBackdropFrame(name, parent, width, height)
local f = CreateFrame("Frame", name, parent, "BackdropTemplate")
f:SetSize(width, height)
f:SetBackdrop({
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
})
f:SetBackdropColor(0.05, 0.05, 0.05, 0.9)
f:SetBackdropBorderColor(0.25, 0.25, 0.25, 1)
return f
end
function ns.GetSpellNameSafe(spellId)
if C_Spell and C_Spell.GetSpellName then
local n = C_Spell.GetSpellName(spellId)
if n then return n end
end
return tostring(spellId)
end
function ns.GetSpellTextureSafe(spellId)
if C_Spell and C_Spell.GetSpellTexture then
local t = C_Spell.GetSpellTexture(spellId)
if t then return t end
end
return 134400
end