Update Clique.lua (#4)

fix event driven profile swapping
linting
This commit is contained in:
Anthony Narkevicius
2025-05-28 12:38:07 -07:00
committed by GitHub
parent 3b440fb15f
commit 960eafdab0
+67 -61
View File
@@ -1,13 +1,15 @@
--[[--------------------------------------------------------------------------------- --[[---------------------------------------------------------------------------------
Clique by Cladhaire <cladhaire@gmail.com> Clique by Cladhaire <cladhaire@gmail.com>
----------------------------------------------------------------------------------]] ----------------------------------------------------------------------------------]] Clique = {
Locals = {}
Clique = {Locals = {}} }
assert(DongleStub, string.format("Clique requires DongleStub.")) assert(DongleStub, string.format("Clique requires DongleStub."))
DongleStub("Dongle-1.2"):New("Clique", Clique) DongleStub("Dongle-1.2"):New("Clique", Clique)
Clique.version = GetAddOnMetadata("Clique", "Version") Clique.version = GetAddOnMetadata("Clique", "Version")
if Clique.version == "wowi:revision" then Clique.version = "SVN" end if Clique.version == "wowi:revision" then
Clique.version = "SVN"
end
local L = Clique.Locals local L = Clique.Locals
@@ -22,16 +24,15 @@ function Clique:Enable()
[L.CLICKSET_DEFAULT] = {}, [L.CLICKSET_DEFAULT] = {},
[L.CLICKSET_HARMFUL] = {}, [L.CLICKSET_HARMFUL] = {},
[L.CLICKSET_HELPFUL] = {}, [L.CLICKSET_HELPFUL] = {},
[L.CLICKSET_OOC] = {}, [L.CLICKSET_OOC] = {}
}, },
blacklist = { blacklist = {},
}, tooltips = false
tooltips = false,
}, },
char = { char = {
switchSpec = false, switchSpec = false,
downClick = false, downClick = false
}, }
} }
self.db = self:InitializeDB("CliqueDB", self.defaults) self.db = self:InitializeDB("CliqueDB", self.defaults)
@@ -53,7 +54,9 @@ function Clique:Enable()
end end
end end
ClickCastFrames = setmetatable({}, {__newindex=newindex}) ClickCastFrames = setmetatable({}, {
__newindex = newindex
})
Clique:OptionsOnLoad() Clique:OptionsOnLoad()
Clique:EnableFrames() Clique:EnableFrames()
@@ -67,7 +70,7 @@ function Clique:Enable()
self:RegisterEvent("PLAYER_REGEN_DISABLED") self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("LEARNED_SPELL_IN_TAB") self:RegisterEvent("LEARNED_SPELL_IN_TAB")
self:RegisterEvent("COMMENTATOR_SKIRMISH_QUEUE_REQUEST") self:RegisterEvent("ASCENSION_CA_SPECIALIZATION_ACTIVE_ID_CHANGED")
self:RegisterEvent("ADDON_LOADED") self:RegisterEvent("ADDON_LOADED")
-- Change to correct profile based on talent spec -- Change to correct profile based on talent spec
@@ -113,7 +116,8 @@ function Clique:Enable()
self.cmd:RegisterSlashHandler("debug - Enables extra messages for debugging purposes", "debug", "ShowAttributes") self.cmd:RegisterSlashHandler("debug - Enables extra messages for debugging purposes", "debug", "ShowAttributes")
self.cmd:InjectDBCommands(self.db, "copy", "delete", "list", "reset", "set") self.cmd:InjectDBCommands(self.db, "copy", "delete", "list", "reset", "set")
self.cmd:RegisterSlashHandler("tooltip - Enables binding lists in tooltips.", "tooltip", "ToggleTooltip") self.cmd:RegisterSlashHandler("tooltip - Enables binding lists in tooltips.", "tooltip", "ToggleTooltip")
self.cmd:RegisterSlashHandler("showbindings - Shows a window that contains the current bindings", "showbindings", "ShowBindings") self.cmd:RegisterSlashHandler("showbindings - Shows a window that contains the current bindings", "showbindings",
"ShowBindings")
-- Place the Clique tab -- Place the Clique tab
self:LEARNED_SPELL_IN_TAB() self:LEARNED_SPELL_IN_TAB()
@@ -125,26 +129,10 @@ function Clique:Enable()
end end
function Clique:EnableFrames() function Clique:EnableFrames()
local tbl = { local tbl = {PlayerFrame, PetFrame, PartyMemberFrame1, PartyMemberFrame2, PartyMemberFrame3, PartyMemberFrame4,
PlayerFrame, PartyMemberFrame1PetFrame, PartyMemberFrame2PetFrame, PartyMemberFrame3PetFrame,
PetFrame, PartyMemberFrame4PetFrame, TargetFrame, TargetFrameToT, FocusFrame, FocusFrameToT, Boss1TargetFrame,
PartyMemberFrame1, Boss2TargetFrame, Boss3TargetFrame, Boss4TargetFrame}
PartyMemberFrame2,
PartyMemberFrame3,
PartyMemberFrame4,
PartyMemberFrame1PetFrame,
PartyMemberFrame2PetFrame,
PartyMemberFrame3PetFrame,
PartyMemberFrame4PetFrame,
TargetFrame,
TargetFrameToT,
FocusFrame,
FocusFrameToT,
Boss1TargetFrame,
Boss2TargetFrame,
Boss3TargetFrame,
Boss4TargetFrame,
}
for i, frame in pairs(tbl) do for i, frame in pairs(tbl) do
rawset(self.ccframes, frame, true) rawset(self.ccframes, frame, true)
@@ -183,7 +171,7 @@ function Clique:SpellBookButtonPressed(frame, button)
["texture"] = texture, ["texture"] = texture,
["type"] = type, ["type"] = type,
["arg1"] = name, ["arg1"] = name,
["arg2"] = rank, ["arg2"] = rank
} }
local key = t.modifier .. t.button local key = t.modifier .. t.button
@@ -373,7 +361,6 @@ function Clique:DONGLE_PROFILE_RESET(event, db, parent, svname, profileKey)
end end
end end
function Clique:DONGLE_PROFILE_DELETED(event, db, parent, svname, profileKey) function Clique:DONGLE_PROFILE_DELETED(event, db, parent, svname, profileKey)
if db == self.db then if db == self.db then
self:PrintF(L.PROFILE_DELETED, profileKey) self:PrintF(L.PROFILE_DELETED, profileKey)
@@ -527,7 +514,9 @@ end
function Clique:ShowAttributes() function Clique:ShowAttributes()
self:Print("Enabled enhanced debugging.") self:Print("Enabled enhanced debugging.")
PlayerFrame:SetScript("OnAttributeChanged", function(...) self:Print(...) end) PlayerFrame:SetScript("OnAttributeChanged", function(...)
self:Print(...)
end)
self:UnregisterFrame(PlayerFrame) self:UnregisterFrame(PlayerFrame)
self:RegisterFrame(PlayerFrame) self:RegisterFrame(PlayerFrame)
end end
@@ -543,17 +532,28 @@ function Clique:UpdateTooltip()
local harm = self.clicksets[L.CLICKSET_HARMFUL] local harm = self.clicksets[L.CLICKSET_HARMFUL]
local help = self.clicksets[L.CLICKSET_HELPFUL] local help = self.clicksets[L.CLICKSET_HELPFUL]
for k,v in pairs(tt_ooc) do tt_ooc[k] = nil end for k, v in pairs(tt_ooc) do
for k,v in pairs(tt_help) do tt_help[k] = nil end tt_ooc[k] = nil
for k,v in pairs(tt_harm) do tt_harm[k] = nil end end
for k,v in pairs(tt_default) do tt_default[k] = nil end for k, v in pairs(tt_help) do
tt_help[k] = nil
end
for k, v in pairs(tt_harm) do
tt_harm[k] = nil
end
for k, v in pairs(tt_default) do
tt_default[k] = nil
end
-- Build the ooc lines, which includes both helpful and harmful -- Build the ooc lines, which includes both helpful and harmful
for k, v in pairs(ooc) do for k, v in pairs(ooc) do
local button = self:GetButtonText(v.button) local button = self:GetButtonText(v.button)
local mod = string.format("%s%s", v.modifier or "", button) local mod = string.format("%s%s", v.modifier or "", button)
local action = string.format("%s (%s)", v.arg1 or "", v.type) local action = string.format("%s (%s)", v.arg1 or "", v.type)
table.insert(tt_ooc, {mod = mod, action = action}) table.insert(tt_ooc, {
mod = mod,
action = action
})
end end
-- Build the default lines -- Build the default lines
@@ -561,7 +561,10 @@ function Clique:UpdateTooltip()
local button = self:GetButtonText(v.button) local button = self:GetButtonText(v.button)
local mod = string.format("%s%s", v.modifier or "", button) local mod = string.format("%s%s", v.modifier or "", button)
local action = string.format("%s (%s)", v.arg1 or "", v.type) local action = string.format("%s (%s)", v.arg1 or "", v.type)
table.insert(tt_default, {mod = mod, action = action}) table.insert(tt_default, {
mod = mod,
action = action
})
end end
-- Build the harm lines -- Build the harm lines
@@ -569,7 +572,10 @@ function Clique:UpdateTooltip()
local button = self:GetButtonText(v.button) local button = self:GetButtonText(v.button)
local mod = string.format("%s%s", v.modifier or "", button) local mod = string.format("%s%s", v.modifier or "", button)
local action = string.format("%s (%s)", v.arg1 or "", v.type) local action = string.format("%s (%s)", v.arg1 or "", v.type)
table.insert(tt_harm, {mod = mod, action = action}) table.insert(tt_harm, {
mod = mod,
action = action
})
end end
-- Build the help lines -- Build the help lines
@@ -577,7 +583,10 @@ function Clique:UpdateTooltip()
local button = self:GetButtonText(v.button) local button = self:GetButtonText(v.button)
local mod = string.format("%s%s", v.modifier or "", button) local mod = string.format("%s%s", v.modifier or "", button)
local action = string.format("%s (%s)", v.arg1 or "", v.type) local action = string.format("%s (%s)", v.arg1 or "", v.type)
table.insert(tt_help, {mod = mod, action = action}) table.insert(tt_help, {
mod = mod,
action = action
})
end end
local function sort(a, b) local function sort(a, b)
@@ -591,11 +600,17 @@ function Clique:UpdateTooltip()
end end
function Clique:AddTooltipLines() function Clique:AddTooltipLines()
if not self.profile.tooltips then return end if not self.profile.tooltips then
return
end
local frame = GetMouseFocus() local frame = GetMouseFocus()
if not frame then return end if not frame then
if not self.ccframes[frame] then return end return
end
if not self.ccframes[frame] then
return
end
-- Add a buffer line -- Add a buffer line
GameTooltip:AddLine(" ") GameTooltip:AddLine(" ")
@@ -632,8 +647,7 @@ end
function Clique:ToggleTooltip() function Clique:ToggleTooltip()
self.profile.tooltips = not self.profile.tooltips self.profile.tooltips = not self.profile.tooltips
self:PrintF("Listing of bindings in tooltips has been %s", self:PrintF("Listing of bindings in tooltips has been %s", self.profile.tooltips and "Enabled" or "Disabled")
self.profile.tooltips and "Enabled" or "Disabled")
end end
function Clique:ShowBindings() function Clique:ShowBindings()
@@ -655,7 +669,8 @@ function Clique:ShowBindings()
CliqueTooltip:SetMovable() CliqueTooltip:SetMovable()
CliqueTooltip:SetPadding(16) CliqueTooltip:SetPadding(16)
CliqueTooltip:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b); CliqueTooltip:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b);
CliqueTooltip:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b); CliqueTooltip:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g,
TOOLTIP_DEFAULT_BACKGROUND_COLOR.b);
CliqueTooltip:RegisterForDrag("LeftButton") CliqueTooltip:RegisterForDrag("LeftButton")
CliqueTooltip:SetScript("OnDragStart", function(self) CliqueTooltip:SetScript("OnDragStart", function(self)
@@ -710,14 +725,11 @@ function Clique:ShowBindings()
CliqueTooltip:Show() CliqueTooltip:Show()
end end
function Clique:COMMENTATOR_SKIRMISH_QUEUE_REQUEST(event, typeName, newGroup) function Clique:ASCENSION_CA_SPECIALIZATION_ACTIVE_ID_CHANGED(event, newGroup)
if typeName ~= "ASCENSION_CA_SPECIALIZATION_ACTIVE_ID_CHANGED" then return end
if self.db.char.switchSpec then if self.db.char.switchSpec then
self:Print("Detected a talent spec change, changing profile") self:Print("Detected a talent spec change, changing profile")
-- self:Print("Detected "..typeName..", changing profile to "..newGroup) -- self:Print("Detected "..typeName..", changing profile to "..newGroup)
newGroup = newGroup + 1
if self.db.char["spec" .. newGroup .. "Profile"] then if self.db.char["spec" .. newGroup .. "Profile"] then
self.db:SetProfile(self.db.char["spec" .. newGroup .. "Profile"]) self.db:SetProfile(self.db.char["spec" .. newGroup .. "Profile"])
end end
@@ -742,13 +754,7 @@ function Clique:SetClickType(frame)
end end
function Clique:EnableArenaFrames() function Clique:EnableArenaFrames()
local arenaFrames = { local arenaFrames = {ArenaEnemyFrame1, ArenaEnemyFrame2, ArenaEnemyFrame3, ArenaEnemyFrame4, ArenaEnemyFrame5}
ArenaEnemyFrame1,
ArenaEnemyFrame2,
ArenaEnemyFrame3,
ArenaEnemyFrame4,
ArenaEnemyFrame5,
}
for idx, frame in ipairs(arenaFrames) do for idx, frame in ipairs(arenaFrames) do
rawset(self.ccframes, frame, true) rawset(self.ccframes, frame, true)