436 lines
19 KiB
Lua
436 lines
19 KiB
Lua
-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
|
|
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
|
|
-- Octo Spec Profiles: core (Claude lane, 2026-11-22).
|
|
-- Ports the Octo/Turtle addons SimpleActionSets (Brodrick, 0.47b) and GNS - Goblin Naming System (Tankmedady, 1.1)
|
|
-- to the 70334 client, and links each profile to an equipment set (owner request 2026-11-22).
|
|
-- A profile holds: the 120 action slots (10 bars x 12, SimpleActionSets' layout), per-bar apply switches, the talent
|
|
-- split it was saved with, an optional equipment set name and, for Device specs, the GNS display name.
|
|
-- The originals replaced Blizzard's PickupAction/UseAction/GetActionTexture and the 1.12 gossip button globals; on
|
|
-- 70334 that taints the secure action bars, so this port only calls the public API from outside and replaces nothing.
|
|
OctoSpecProfiles = OctoSpecProfiles or {}
|
|
local P = OctoSpecProfiles
|
|
|
|
P.NUM_BARS, P.BAR_SIZE = 10, 12
|
|
P.BAR_LABELS = {
|
|
"Main Action Bar", "Action Bar Page 2", "Page 3 / Right Bar", "Page 4 / Right Bar 2", "Page 5 / Bottom Right",
|
|
"Page 6 / Bottom Left", "Battle Stance / Cat / Stealth", "Defensive Stance", "Berserker Stance / Bear", "Unused",
|
|
}
|
|
P.DEVICE_SPECS = 4
|
|
P.ORDINALS = {"1st", "2nd", "3rd", "4th"}
|
|
|
|
local function Print(msg, r, g, b) DEFAULT_CHAT_FRAME:AddMessage("|cff33ffccSpec Profiles:|r " .. msg, r or 1, g or 1, b or 1) end
|
|
P.Print = Print
|
|
|
|
local function CharKey() return (UnitName("player") or "?") .. "-" .. (GetRealmName() or "?") end
|
|
|
|
function P.DB()
|
|
OctoSpecProfilesDB = OctoSpecProfilesDB or {}
|
|
local db = OctoSpecProfilesDB
|
|
db.options = db.options or {}
|
|
local o = db.options
|
|
if o.emptyBars == nil then o.emptyBars = true end -- SAS "Don't apply empty bars"
|
|
if o.emptyButtons == nil then o.emptyButtons = false end -- SAS "Don't apply empty buttons"
|
|
if o.autoSave == nil then o.autoSave = true end -- save the active spec's bars before the Device switches
|
|
if o.namePrompt == nil then o.namePrompt = true end -- GNS: ask for a name after "Save Nth Specialization"
|
|
if o.equip == nil then o.equip = true end -- equip the linked set when a profile is applied
|
|
if o.autoRestoreWarn == nil then o.autoRestoreWarn = true end -- SAS: warn when auto restore changed something
|
|
if o.minimap == nil then o.minimap = true end -- SAS minimap button
|
|
db.chars = db.chars or {}
|
|
local key = CharKey()
|
|
db.chars[key] = db.chars[key] or {profiles = {}, specNames = {}}
|
|
return db, db.chars[key], o
|
|
end
|
|
|
|
-- Device spec N is stored as the profile "Brainwasher<N>" (the SimpleActionSets set name, so the naming carries over).
|
|
function P.DeviceProfileName(n) return "Brainwasher" .. n end
|
|
function P.DeviceIndex(name) local n = name and name:match("^Brainwasher(%d)$"); return n and tonumber(n) end
|
|
|
|
function P.SpecName(n)
|
|
local _, char = P.DB()
|
|
return char.specNames[n] or (P.ORDINALS[n] .. " Specialization")
|
|
end
|
|
function P.SetSpecName(n, name)
|
|
local _, char = P.DB()
|
|
if name and name:match("%S") then
|
|
name = name:sub(1, 30)
|
|
-- Keeping the default name is not a custom name (it would be repeated after every Device line).
|
|
if name == P.ORDINALS[n] .. " Specialization" then char.specNames[n] = nil else char.specNames[n] = name end
|
|
end
|
|
end
|
|
|
|
function P.DisplayName(name)
|
|
local n = P.DeviceIndex(name)
|
|
if n then return string.format("Device spec %d: %s", n, P.SpecName(n)) end
|
|
return name
|
|
end
|
|
|
|
-- Talent points per tree in the Device's order (a/b/c). The Turtle talent provider (WoWHybridUI TurtleTalents, fed
|
|
-- by the gateway) is authoritative; the native specialization API is the fallback.
|
|
function P.TalentProvider()
|
|
local provider = GatewayTurtleTalents
|
|
if type(provider) == "table" and provider.state and type(provider.ClassTabs) == "function" then return provider end
|
|
end
|
|
function P.TalentSplit()
|
|
local provider = P.TalentProvider()
|
|
if provider then
|
|
-- Always the live talents, never a saved spec being previewed in the talent window.
|
|
local preview = provider.preview
|
|
provider.preview = nil
|
|
local parts = {}
|
|
for index, tab in ipairs(provider:ClassTabs()) do parts[index] = provider:Spent(tab.id, false) end
|
|
provider.preview = preview
|
|
if #parts > 0 then return table.concat(parts, "/") end
|
|
end
|
|
if not (C_SpecializationInfo and C_SpecializationInfo.GetSpecializationInfo) then return end
|
|
local parts = {}
|
|
for tree = 1, 3 do
|
|
local ok, _, _, _, _, _, _, points = pcall(C_SpecializationInfo.GetSpecializationInfo, tree)
|
|
if not ok or type(points) ~= "number" then return end
|
|
parts[tree] = points
|
|
end
|
|
return table.concat(parts, "/")
|
|
end
|
|
|
|
-------------------------------------------------------------------------------- actions
|
|
local function MacroIndexByName(name)
|
|
if not name then return end
|
|
for index = 1, 150 do
|
|
local macroName = GetMacroInfo(index)
|
|
if macroName == name then return index end
|
|
end
|
|
end
|
|
|
|
-- One action slot -> a stored record (nil for an empty slot).
|
|
local function Capture(slot)
|
|
local kind, id, subType = GetActionInfo(slot)
|
|
if not kind then return end
|
|
local rec = {t = kind, id = id, sub = subType}
|
|
if kind == "macro" then
|
|
local name, icon = GetMacroInfo(id)
|
|
rec.name, rec.icon = name, icon
|
|
elseif kind == "spell" then
|
|
rec.name = C_Spell and C_Spell.GetSpellName and C_Spell.GetSpellName(id)
|
|
elseif kind == "item" then
|
|
rec.name = C_Item and C_Item.GetItemNameByID and C_Item.GetItemNameByID(id)
|
|
elseif kind == "equipmentset" then
|
|
rec.name = id
|
|
end
|
|
rec.icon = rec.icon or GetActionTexture(slot)
|
|
return rec
|
|
end
|
|
|
|
function P.Same(a, b)
|
|
if a == nil or b == nil then return a == b end
|
|
if a.t ~= b.t then return false end
|
|
if a.t == "macro" then return a.name == b.name end
|
|
return a.id == b.id
|
|
end
|
|
|
|
-- Put a stored record on the cursor. Returns true when the cursor holds it.
|
|
local function Pickup(rec)
|
|
ClearCursor()
|
|
if rec.t == "spell" then
|
|
if C_Spell and C_Spell.PickupSpell then pcall(C_Spell.PickupSpell, rec.id) end
|
|
elseif rec.t == "item" then
|
|
if C_Item and C_Item.PickupItem then pcall(C_Item.PickupItem, rec.id) end
|
|
elseif rec.t == "macro" then
|
|
local index = MacroIndexByName(rec.name)
|
|
if index then PickupMacro(index) end
|
|
elseif rec.t == "equipmentset" then
|
|
local setID = C_EquipmentSet and C_EquipmentSet.GetEquipmentSetID(rec.name)
|
|
if setID then pcall(C_EquipmentSet.PickupEquipmentSet, setID) end
|
|
end
|
|
return GetCursorInfo() ~= nil
|
|
end
|
|
|
|
function P.CaptureAll()
|
|
local actions = {}
|
|
for slot = 1, P.NUM_BARS * P.BAR_SIZE do actions[slot] = Capture(slot) end
|
|
return actions
|
|
end
|
|
|
|
function P.Icon(rec)
|
|
if not rec then return end
|
|
if rec.t == "spell" and C_Spell and C_Spell.GetSpellTexture then return C_Spell.GetSpellTexture(rec.id) or rec.icon end
|
|
if rec.t == "item" and C_Item and C_Item.GetItemIconByID then return C_Item.GetItemIconByID(rec.id) or rec.icon end
|
|
return rec.icon
|
|
end
|
|
|
|
-------------------------------------------------------------------------------- profiles
|
|
function P.Profiles() local _, char = P.DB(); return char.profiles end
|
|
function P.Get(name) return P.Profiles()[name] end
|
|
|
|
function P.SortedNames()
|
|
local names = {}
|
|
for name in pairs(P.Profiles()) do names[#names + 1] = name end
|
|
table.sort(names, function(a, b)
|
|
local x, y = P.DeviceIndex(a), P.DeviceIndex(b)
|
|
if x and y then return x < y end
|
|
if x or y then return x ~= nil end
|
|
return a:lower() < b:lower()
|
|
end)
|
|
return names
|
|
end
|
|
|
|
function P.Save(name, quiet)
|
|
if not name or not name:match("%S") then return end
|
|
local profiles = P.Profiles()
|
|
local profile = profiles[name] or {bars = {}}
|
|
profile.actions = P.CaptureAll()
|
|
profile.talents = P.TalentSplit() or profile.talents
|
|
profile.saved = time()
|
|
for bar = 1, P.NUM_BARS do if profile.bars[bar] == nil then profile.bars[bar] = true end end
|
|
profiles[name] = profile
|
|
if not quiet then Print("saved " .. P.DisplayName(name) .. ".", 0.3, 1, 0.3) end
|
|
if P.OnChanged then P.OnChanged() end
|
|
return profile
|
|
end
|
|
|
|
function P.Delete(name)
|
|
P.Profiles()[name] = nil
|
|
if P.OnChanged then P.OnChanged() end
|
|
end
|
|
|
|
function P.BarIsEmpty(profile, bar)
|
|
for i = 1, P.BAR_SIZE do if profile.actions[(bar - 1) * P.BAR_SIZE + i] then return false end end
|
|
return true
|
|
end
|
|
|
|
local pending
|
|
-- Apply an action table to the real bars. opts.full ignores the skip options (Undo / restore put every slot back).
|
|
local function ApplyActions(profile, opts)
|
|
local _, _, o = P.DB()
|
|
local changed, missing = 0, 0
|
|
for bar = 1, P.NUM_BARS do
|
|
local skip = not opts.full and (profile.bars and profile.bars[bar] == false or (o.emptyBars and P.BarIsEmpty(profile, bar)))
|
|
if not skip then
|
|
for i = 1, P.BAR_SIZE do
|
|
local slot = (bar - 1) * P.BAR_SIZE + i
|
|
local want, have = profile.actions[slot], Capture(slot)
|
|
if not P.Same(want, have) then
|
|
if want == nil then
|
|
if opts.full or not o.emptyButtons then PickupAction(slot); ClearCursor(); changed = changed + 1 end
|
|
elseif Pickup(want) then
|
|
PlaceAction(slot); ClearCursor(); changed = changed + 1
|
|
else
|
|
ClearCursor(); missing = missing + 1
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
return changed, missing
|
|
end
|
|
|
|
function P.Apply(name, quiet)
|
|
local profile = P.Get(name)
|
|
if not profile then Print(string.format("no profile named '%s'.", tostring(name)), 1, 0.3, 0.3); return end
|
|
if InCombatLockdown() then
|
|
pending = name
|
|
Print("in combat; " .. P.DisplayName(name) .. " will be applied when combat ends.", 1, 0.8, 0.2)
|
|
return
|
|
end
|
|
local _, char, o = P.DB()
|
|
char.undo = {actions = P.CaptureAll(), name = name} -- SAS "Undo": the bars as they were before this swap
|
|
local changed, missing = ApplyActions(profile, {})
|
|
local equipped
|
|
if o.equip and profile.equipmentSet and C_EquipmentSet then
|
|
local setID = C_EquipmentSet.GetEquipmentSetID(profile.equipmentSet)
|
|
if setID then equipped = pcall(C_EquipmentSet.UseEquipmentSet, setID) and profile.equipmentSet
|
|
else Print("equipment set '" .. profile.equipmentSet .. "' no longer exists.", 1, 0.5, 0.2) end
|
|
end
|
|
if not quiet or missing > 0 or equipped then
|
|
Print(string.format("applied %s: %d action%s changed%s%s.", P.DisplayName(name), changed, changed == 1 and "" or "s",
|
|
missing > 0 and string.format(", %d not available (spell not known or item not in bags)", missing) or "",
|
|
equipped and (", equipped '" .. equipped .. "'") or ""), 0.3, 1, 0.3)
|
|
end
|
|
char.lastApplied = name
|
|
if P.OnChanged then P.OnChanged() end
|
|
end
|
|
|
|
function P.CanUndo() local _, char = P.DB(); return char.undo ~= nil end
|
|
function P.Undo()
|
|
local _, char = P.DB()
|
|
if not char.undo then Print("nothing to undo.", 1, 0.5, 0.2); return end
|
|
if InCombatLockdown() then Print("cannot change action bars in combat.", 1, 0.3, 0.3); return end
|
|
local undo = char.undo; char.undo = nil
|
|
local changed, missing = ApplyActions(undo, {full = true})
|
|
Print(string.format("undid %s: %d action%s restored%s.", P.DisplayName(undo.name or "?"), changed, changed == 1 and "" or "s",
|
|
missing > 0 and string.format(", %d not available", missing) or ""), 0.3, 1, 0.3)
|
|
if P.OnChanged then P.OnChanged() end
|
|
end
|
|
|
|
-- SAS "Auto restore actions": put the bars back to how they were at the last logout (a character played on
|
|
-- several computers). Runs once per login, out of combat.
|
|
local function AutoRestore()
|
|
local _, char, o = P.DB()
|
|
if not o.autoRestore or not char.logout or InCombatLockdown() then return end
|
|
local changed, missing = ApplyActions({actions = char.logout}, {full = true})
|
|
if o.autoRestoreWarn and (changed > 0 or missing > 0) then
|
|
Print(string.format("auto restore: %d action%s restored to your last logout%s.", changed, changed == 1 and "" or "s",
|
|
missing > 0 and string.format(", %d not available", missing) or ""), 1, 0.8, 0.2)
|
|
end
|
|
end
|
|
|
|
-- Editor support: the cursor's content as a stored record (nil + reason when it cannot go on an action bar).
|
|
function P.RecordFromCursor()
|
|
local kind, a, b, c = GetCursorInfo()
|
|
if not kind then return end
|
|
if kind == "spell" then
|
|
local id = c or b
|
|
if type(id) ~= "number" then return nil, "spell" end
|
|
return {t = "spell", id = id, name = C_Spell and C_Spell.GetSpellName and C_Spell.GetSpellName(id),
|
|
icon = C_Spell and C_Spell.GetSpellTexture and C_Spell.GetSpellTexture(id)}
|
|
elseif kind == "item" then
|
|
return {t = "item", id = a, name = C_Item and C_Item.GetItemNameByID and C_Item.GetItemNameByID(a),
|
|
icon = C_Item and C_Item.GetItemIconByID and C_Item.GetItemIconByID(a)}
|
|
elseif kind == "macro" then
|
|
local name, icon = GetMacroInfo(a)
|
|
if not name then return nil, "macro" end
|
|
return {t = "macro", id = a, name = name, icon = icon}
|
|
elseif kind == "equipmentset" then
|
|
local setID = C_EquipmentSet and C_EquipmentSet.GetEquipmentSetID(a)
|
|
local _, icon = setID and C_EquipmentSet.GetEquipmentSetInfo(setID)
|
|
return {t = "equipmentset", id = a, name = a, icon = icon}
|
|
end
|
|
return nil, kind
|
|
end
|
|
P.PickupRecord = Pickup
|
|
P.CaptureSlot = Capture
|
|
|
|
function P.Known(rec)
|
|
if not rec then return true end
|
|
if rec.t == "spell" then
|
|
if C_SpellBook and C_SpellBook.IsSpellKnown then return C_SpellBook.IsSpellKnown(rec.id) end
|
|
return IsSpellKnown == nil or IsSpellKnown(rec.id)
|
|
elseif rec.t == "item" then
|
|
return not (C_Item and C_Item.GetItemCount) or C_Item.GetItemCount(rec.id) > 0
|
|
elseif rec.t == "macro" then
|
|
return MacroIndexByName(rec.name) ~= nil
|
|
end
|
|
return true
|
|
end
|
|
|
|
-- Store an edited action table under a name (keeps the profile's talents and equipment link).
|
|
function P.Store(name, actions, bars)
|
|
if not name or not name:match("%S") then return end
|
|
local profiles = P.Profiles()
|
|
local profile = profiles[name] or {}
|
|
profile.actions, profile.bars, profile.saved = actions, bars, time()
|
|
profiles[name] = profile
|
|
Print("saved " .. P.DisplayName(name) .. ".", 0.3, 1, 0.3)
|
|
if P.OnChanged then P.OnChanged() end
|
|
return profile
|
|
end
|
|
|
|
-- Sets of the account's other characters (SAS "Load other character's set").
|
|
function P.OtherCharacters()
|
|
local db = P.DB()
|
|
local mine, list = CharKey(), {}
|
|
for key, char in pairs(db.chars) do
|
|
if key ~= mine and next(char.profiles or {}) then list[#list + 1] = key end
|
|
end
|
|
table.sort(list)
|
|
return list
|
|
end
|
|
function P.OtherProfiles(key) local db = P.DB(); return db.chars[key] and db.chars[key].profiles or {} end
|
|
|
|
-------------------------------------------------------------------------------- equipment sets
|
|
function P.EquipmentSetNames()
|
|
local names = {}
|
|
if not (C_EquipmentSet and C_EquipmentSet.GetEquipmentSetIDs) then return names end
|
|
for _, setID in ipairs(C_EquipmentSet.GetEquipmentSetIDs() or {}) do
|
|
local name = C_EquipmentSet.GetEquipmentSetInfo(setID)
|
|
if name then names[#names + 1] = name end
|
|
end
|
|
table.sort(names)
|
|
return names
|
|
end
|
|
|
|
function P.EquippedSetName()
|
|
if not (C_EquipmentSet and C_EquipmentSet.GetEquipmentSetIDs) then return end
|
|
for _, setID in ipairs(C_EquipmentSet.GetEquipmentSetIDs() or {}) do
|
|
local name, _, _, isEquipped = C_EquipmentSet.GetEquipmentSetInfo(setID)
|
|
if isEquipped then return name end
|
|
end
|
|
end
|
|
|
|
function P.SetEquipment(name, setName)
|
|
local profile = P.Get(name)
|
|
if profile then profile.equipmentSet = setName; if P.OnChanged then P.OnChanged() end end
|
|
end
|
|
|
|
-------------------------------------------------------------------------------- slash commands
|
|
local function PromptName(title, default, onAccept)
|
|
StaticPopupDialogs.OCTO_SPEC_PROFILES_NAME = {
|
|
text = "%s", button1 = ACCEPT, button2 = CANCEL, hasEditBox = 1, maxLetters = 30,
|
|
OnShow = function(self) self.EditBox:SetText(self.data.default or ""); self.EditBox:HighlightText() end,
|
|
OnAccept = function(self) self.data.onAccept(self.EditBox:GetText()) end,
|
|
EditBoxOnEnterPressed = function(self) local p = self:GetParent(); p.data.onAccept(self:GetText()); p:Hide() end,
|
|
EditBoxOnEscapePressed = function(self) self:GetParent():Hide() end,
|
|
timeout = 0, whileDead = 1, hideOnEscape = 1,
|
|
}
|
|
StaticPopup_Show("OCTO_SPEC_PROFILES_NAME", title, nil, {default = default, onAccept = onAccept})
|
|
end
|
|
P.PromptName = PromptName
|
|
|
|
function P.PromptSpecName(n)
|
|
PromptName("Name for the Goblin Brainwashing Device's " .. P.ORDINALS[n] .. " Specialization:", P.SpecName(n), function(text)
|
|
if text and text:match("%S") then
|
|
P.SetSpecName(n, text)
|
|
Print(string.format("Specialization %d is now named '%s'.", n, P.SpecName(n)), 0.3, 1, 0.3)
|
|
if P.OnChanged then P.OnChanged() end
|
|
end
|
|
end)
|
|
end
|
|
|
|
SLASH_OCTOSPECPROFILES1, SLASH_OCTOSPECPROFILES2 = "/sas", "/specprofiles"
|
|
SlashCmdList.OCTOSPECPROFILES = function(msg)
|
|
local command, rest = (msg or ""):match("^%s*(%S*)%s*(.-)%s*$")
|
|
command = command:lower()
|
|
if command == "swap" or command == "apply" or command == "load" then
|
|
local n = tonumber(rest)
|
|
P.Apply(n and P.DeviceProfileName(n) or rest)
|
|
elseif command == "save" and rest ~= "" then
|
|
local n = tonumber(rest)
|
|
P.Save(n and P.DeviceProfileName(n) or rest)
|
|
elseif command == "undo" then
|
|
P.Undo()
|
|
elseif command == "device" or command == "specs" then
|
|
if P.ToggleWindow then P.ToggleWindow() end
|
|
elseif command == "" or command == "show" then
|
|
if P.ToggleSets then P.ToggleSets() elseif P.ToggleWindow then P.ToggleWindow() end
|
|
else
|
|
Print("/sas - action sets window; /sas device - Device specs; /sas save <name|1-4>; /sas swap <name|1-4>; /sas undo.")
|
|
end
|
|
end
|
|
|
|
-- GNS commands: /gns lists the names, /gns <1-4> renames.
|
|
SLASH_OCTOGNS1, SLASH_OCTOGNS2 = "/gns", "/goblinname"
|
|
SlashCmdList.OCTOGNS = function(msg)
|
|
local n = tonumber((msg or ""):match("^%s*(%d+)"))
|
|
if n then
|
|
if n >= 1 and n <= P.DEVICE_SPECS then P.PromptSpecName(n) else Print("use a specialization number between 1 and 4.", 1, 0.3, 0.3) end
|
|
return
|
|
end
|
|
Print("Goblin Brainwashing Device names (/gns <1-4> to rename):")
|
|
for i = 1, P.DEVICE_SPECS do DEFAULT_CHAT_FRAME:AddMessage(string.format(" Spec %d: %s", i, P.SpecName(i)), 0.8, 0.8, 0.8) end
|
|
end
|
|
|
|
local events = CreateFrame("Frame")
|
|
events:RegisterEvent("PLAYER_LOGIN")
|
|
events:RegisterEvent("PLAYER_REGEN_ENABLED")
|
|
events:RegisterEvent("PLAYER_LOGOUT")
|
|
events:RegisterEvent("PLAYER_ENTERING_WORLD")
|
|
local restored
|
|
events:SetScript("OnEvent", function(_, event, initialLogin)
|
|
if event == "PLAYER_LOGIN" then P.DB()
|
|
elseif event == "PLAYER_LOGOUT" then local _, char = P.DB(); char.logout = P.CaptureAll()
|
|
elseif event == "PLAYER_ENTERING_WORLD" and not restored then
|
|
restored = true
|
|
C_Timer.After(3, function() pcall(AutoRestore) end)
|
|
elseif event == "PLAYER_REGEN_ENABLED" and pending then
|
|
local name = pending; pending = nil; P.Apply(name)
|
|
end
|
|
end)
|