-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInit.lua
More file actions
247 lines (225 loc) · 8.5 KB
/
Init.lua
File metadata and controls
247 lines (225 loc) · 8.5 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
local _, ns = ...
local frame = ns.frame
local state = ns.state
local ui = ns.ui
local PREFIX = ns.PREFIX
local Print = ns.Print
local function IsInCorrectZone()
return C_Map.GetBestMapForUnit("player") == ns.ZONE_ID
end
-- Slash commands
SLASH_BELEDARORCHESTRA1 = "/conductor"
SlashCmdList.BELEDARORCHESTRA = function(msg)
local cmd, rest = msg:match("^(%S*)%s*(.-)$")
cmd = cmd and cmd:lower() or ""
if cmd == "" then
if ui.main:IsShown() then
ui.main:Hide()
state.leaderUIOpen = false
else
ui.main:Show()
state.leaderUIOpen = true
end
return
elseif cmd == "show" then
ui.main:Show()
state.leaderUIOpen = true
return
elseif cmd == "hide" then
ui.main:Hide()
state.leaderUIOpen = false
return
elseif cmd == "player" then
if ui.playerFrame:IsShown() then
state.playerUIClosed = true
ui.playerFrame:Hide()
else
state.playerUIClosed = nil
ui.playerFrame:Show()
end
return
elseif cmd == "playershow" then
state.playerUIClosed = nil
ui.playerFrame:Show()
return
elseif cmd == "playerhide" then
state.playerUIClosed = true
ui.playerFrame:Hide()
return
elseif cmd == "measure" then
local n = tonumber(rest)
if not n then
Print("Usage: /conductor measure <1-25>")
return
end
ns.SetMeasure(n)
ns.UpdatePlayerPanel()
ns.ValidateTarget()
return
elseif cmd == "reset" then
ns.SetMeasure(nil)
ns.UpdatePlayerPanel()
ns.ValidateTarget()
return
elseif cmd == "debug" then
local observed, anyAura = ns.BuildObservedCounts()
if not anyAura then
Print("No helpful auras on target")
return
end
for spellId, count in pairs(observed) do
Print(ns.GetSpellNameSafe(spellId) .. " x" .. tostring(count) .. " (" .. tostring(spellId) .. ")")
end
return
elseif cmd == "slot" then
local slot = ns.GetRaidSlotForPlayer()
Print("Computed slot: " .. tostring(slot or "nil"))
return
end
Print("Commands: /conductor, /conductor show, /conductor hide, /conductor player, /conductor playershow, /conductor playerhide, /conductor measure <1-25>, /conductor reset, /conductor debug, /conductor slot")
end
-- Event handler
frame:SetScript("OnEvent", function(_, event, ...)
if event == "ZONE_CHANGED_NEW_AREA" or event == "ZONE_CHANGED" or event == "ZONE_CHANGED_INDOORS" then
if IsInCorrectZone() then
if ui.main and state.leaderUIOpen then ui.main:Show() end
if ui.playerFrame and ns.IsTargetNpc("target") then ui.playerFrame:Show() end
else
if ui.main then ui.main:Hide() end
if ui.playerFrame then ui.playerFrame:Hide() end
end
return
end
if event == "ADDON_LOADED" then
local loadedName = ...
if loadedName ~= ns.ADDON_NAME then return end
BeledarOrchestraDB.Overrides = BeledarOrchestraDB.Overrides or {}
BeledarOrchestraDB.SavedSets = BeledarOrchestraDB.SavedSets or {}
state.lastCompletedMeasure = BeledarOrchestraDB.LastCompletedMeasure
-- Migration from flat SavedSets to measure-based SavedSets
local needsMigration = false
for k, v in pairs(BeledarOrchestraDB.SavedSets) do
if type(k) == "string" and type(v) == "table" then
for mk in pairs(v) do
if type(mk) == "number" then
needsMigration = true
break
end
end
end
if needsMigration then break end
end
if needsMigration then
local newSets = {}
for name, set in pairs(BeledarOrchestraDB.SavedSets) do
if type(name) == "string" and type(set) == "table" then
for m, slots in pairs(set) do
if type(m) == "number" then
newSets[m] = newSets[m] or {}
newSets[m][name] = slots
end
end
end
end
BeledarOrchestraDB.SavedSets = newSets
Print("Migrated assignment sets to measure-based format.")
end
C_ChatInfo.RegisterAddonMessagePrefix(PREFIX)
ns.CreateLeaderUI()
ns.CreatePlayerUI()
ns.SetMeasure(nil, true)
ns.UpdatePlayerPanel()
ns.SetStatus("YELLOW", "No measure selected", {})
elseif event == "CHAT_MSG_ADDON" then
local prefix, message, _, sender = ...
if prefix ~= PREFIX then return end
ns.HandleAddonMessage(message, sender)
elseif InCombatLockdown() then
return
elseif event == "GROUP_ROSTER_UPDATE" or event == "PLAYER_TARGET_CHANGED" then
if event == "PLAYER_TARGET_CHANGED" and IsInCorrectZone() and ns.IsLeaderOrAssist() and ns.IsTargetNpc("target") then
if ui.main and not ui.main:IsShown() then
ui.main:Show()
state.leaderUIOpen = true
end
end
ns.UpdatePlayerPanel()
ns.ValidateTarget()
if event == "GROUP_ROSTER_UPDATE" and ns.ShowMode and state.currentViewMode then
ns.ShowMode(state.currentViewMode)
end
elseif event == "UNIT_AURA" then
local unit = ...
if unit == "target" then
ns.ValidateTarget()
end
elseif event == "PLAYER_STARTED_MOVING" then
local slot = ns.GetRaidSlotForPlayer()
local measure = state.currentMeasure
if slot and measure and state.measureLocked then
local token = ns.GetMeasureEmote(measure, slot)
if token == "DANCE" and not state.danceMoving[slot] then
state.danceMoving[slot] = true
if IsInGroup() then
local channel = IsInRaid() and "RAID" or "PARTY"
C_ChatInfo.SendAddonMessage(PREFIX, string.format("DANCE_MOVING:%d:%d", measure, slot), channel)
end
ns.UpdatePlayerPanel()
end
end
elseif event == "PLAYER_STOPPED_MOVING" then
local slot = ns.GetRaidSlotForPlayer()
local measure = state.currentMeasure
if slot and measure and state.measureLocked then
local token = ns.GetMeasureEmote(measure, slot)
if token == "DANCE" and state.danceMoving[slot] and not state.danceComplete[slot] then
state.danceComplete[slot] = true
if IsInGroup() then
local channel = IsInRaid() and "RAID" or "PARTY"
C_ChatInfo.SendAddonMessage(PREFIX, string.format("DANCE_STOPPED:%d:%d", measure, slot), channel)
end
frame:UnregisterEvent("PLAYER_STARTED_MOVING")
frame:UnregisterEvent("PLAYER_STOPPED_MOVING")
ns.UpdatePlayerPanel()
end
end
end
end)
-- OnUpdate timer
frame:SetScript("OnUpdate", function(_, elapsed)
if InCombatLockdown() then return end
if not IsInCorrectZone() then return end
-- Countdown tick: always check even if no UI is visible, so measureStarted
-- is set promptly when the countdown expires (player may not be targeting NPC)
if state.countdownEndTime and not state.measureStarted then
local remaining = state.countdownEndTime - GetTime()
if remaining <= 0 then
state.measureStarted = true
state.countdownEndTime = nil
ns.UpdatePlayerPanel()
ns.UpdateAssignmentGrid()
end
end
if not ((ui.main and ui.main:IsShown()) or (ui.playerFrame and ui.playerFrame:IsShown())) then
return
end
state.lastUpdate = state.lastUpdate + elapsed
if state.lastUpdate >= ns.UPDATE_INTERVAL then
state.lastUpdate = 0
if ui.playerFrame and ui.playerFrame:IsShown() then
ns.UpdatePlayerPanel()
end
if ui.main and ui.main:IsShown() then
ns.ValidateTarget()
end
end
end)
-- Register events
frame:RegisterEvent("ADDON_LOADED")
frame:RegisterEvent("CHAT_MSG_ADDON")
frame:RegisterEvent("GROUP_ROSTER_UPDATE")
frame:RegisterEvent("PLAYER_TARGET_CHANGED")
frame:RegisterEvent("UNIT_AURA")
frame:RegisterEvent("ZONE_CHANGED_NEW_AREA")
frame:RegisterEvent("ZONE_CHANGED")
frame:RegisterEvent("ZONE_CHANGED_INDOORS")