Add CoA custom-class Pawn scales for all 21 classes (70+ specs)
release / release (push) Successful in 3s
release / release (push) Successful in 3s
- Pawn/CoAClassSpecData.lua: copied from coa-db/data (source of truth, keyed by UnitClass token, neutral stat keys). - Pawn/CoAScales.lua: registers a scale per class+spec via PawnAddPluginScaleProvider/PawnAddPluginScale; translates neutral keys to Pawn internal (AttackPower→Ap, RangedAttackPower→Rap, Dodge/Parry/Defense→DodgeRating/ParryRating/DefenseRating). Auto-enables the player's class scales on first login via C_Timer.After(0), honouring the same one-shot LastAdded guard used by Wowhead.lua. - Pawn/Pawn.toc: loads CoAClassSpecData.lua early (before Pawn.lua), CoAScales.lua last (after Wowhead.lua); adds PawnCoAScaleProviderOptions to SavedVariables.
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
-- CoAScales.lua — Pawn integration for CoA custom-class stat scales
|
||||
-- Registers one scale per class+spec from CoAClassSpec (CoAClassSpecData.lua).
|
||||
-- Auto-enables all scales for the logged-in player's class on first login.
|
||||
-- Saved in PawnCoAScaleProviderOptions.LastAdded (per SavedVariables).
|
||||
--
|
||||
-- Neutral-key → Pawn-internal-key map used here:
|
||||
-- AttackPower → Ap
|
||||
-- RangedAttackPower → Rap
|
||||
-- Dodge → DodgeRating
|
||||
-- Parry → ParryRating
|
||||
-- Defense → DefenseRating
|
||||
-- All others → unchanged (Agility, Strength, Intellect, Spirit,
|
||||
-- Stamina, SpellPower, CritRating, HitRating,
|
||||
-- HasteRating, ArmorPenetration, Mp5, Armor)
|
||||
------------------------------------------------------------
|
||||
|
||||
local CoAScaleProviderName = "CoAClasses"
|
||||
|
||||
-- Class-token → 6-digit hex colour (roughly matching CoA class colours).
|
||||
-- Fallback "a0a0a0" (grey) for any token not listed.
|
||||
local CoAClassColor = {
|
||||
BARBARIAN = "c69b3a",
|
||||
WITCHDOCTOR = "00ff96",
|
||||
DEMONHUNTER = "a330c9",
|
||||
WITCHHUNTER = "6e95ff",
|
||||
STORMBRINGER = "69ccf0",
|
||||
FLESHWARDEN = "c79c6e",
|
||||
GUARDIAN = "f58cba",
|
||||
MONK = "f0eba0",
|
||||
SONOFARUGAL = "ff0000",
|
||||
RANGER = "abd473",
|
||||
CHRONOMANCER = "40c0e0",
|
||||
NECROMANCER = "556699",
|
||||
PYROMANCER = "ff6600",
|
||||
CULTIST = "9966cc",
|
||||
STARCALLER = "e0d060",
|
||||
SUNCLERIC = "ffe680",
|
||||
TINKER = "aaaaaa",
|
||||
PROPHET = "5a8a00",
|
||||
REAPER = "336699",
|
||||
WILDWALKER = "1aaa55",
|
||||
SPIRITMAGE = "c0a0ff",
|
||||
}
|
||||
|
||||
-- Translate one neutral-key weights table to Pawn internal keys.
|
||||
local function TranslateWeights(neutralWeights)
|
||||
local out = {}
|
||||
for k, v in pairs(neutralWeights) do
|
||||
local pawnKey
|
||||
if k == "AttackPower" then pawnKey = "Ap"
|
||||
elseif k == "RangedAttackPower" then pawnKey = "Rap"
|
||||
elseif k == "Dodge" then pawnKey = "DodgeRating"
|
||||
elseif k == "Parry" then pawnKey = "ParryRating"
|
||||
elseif k == "Defense" then pawnKey = "DefenseRating"
|
||||
else pawnKey = k
|
||||
end
|
||||
out[pawnKey] = v
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
-- Sanitise a string for use as an internal scale name (no double-quotes,
|
||||
-- no spaces — keeps names safe for PawnGetProviderScaleName).
|
||||
local function SafeInternalName(token, specName)
|
||||
local s = token .. "_" .. specName
|
||||
s = s:gsub("[^%w_]", "_")
|
||||
return s
|
||||
end
|
||||
|
||||
-- Build a human-readable localized name for tooltip display.
|
||||
local function LocalizedScaleName(classData, specName)
|
||||
return classData.name .. ": " .. specName
|
||||
end
|
||||
|
||||
------------------------------------------------------------
|
||||
-- Scale provider registration
|
||||
------------------------------------------------------------
|
||||
|
||||
local function CoAScaleProvider_AddScales()
|
||||
if not CoAClassSpec then return end
|
||||
|
||||
for token, classData in pairs(CoAClassSpec) do
|
||||
local color = CoAClassColor[token] or "a0a0a0"
|
||||
for _, spec in ipairs(classData.specs) do
|
||||
local internalName = SafeInternalName(token, spec.name)
|
||||
local localizedName = LocalizedScaleName(classData, spec.name)
|
||||
local pawnWeights = TranslateWeights(spec.weights)
|
||||
pcall(PawnAddPluginScale,
|
||||
CoAScaleProviderName,
|
||||
internalName,
|
||||
localizedName,
|
||||
color,
|
||||
pawnWeights,
|
||||
1
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
------------------------------------------------------------
|
||||
-- Auto-enable scales for the player's class
|
||||
-- Mirror the same C_Timer.After(0) pattern used by Wowhead.lua.
|
||||
-- PawnCoAScaleProviderOptions is a SavedVariable declared in .toc;
|
||||
-- only enable once (LastAdded == 0 means never done).
|
||||
------------------------------------------------------------
|
||||
if not PawnCoAScaleProviderOptions then PawnCoAScaleProviderOptions = {} end
|
||||
if not PawnCoAScaleProviderOptions.LastAdded then PawnCoAScaleProviderOptions.LastAdded = 0 end
|
||||
|
||||
local _lastAdded = PawnCoAScaleProviderOptions.LastAdded
|
||||
C_Timer.After(0, function()
|
||||
local _, playerToken = UnitClass("player")
|
||||
if not playerToken then return end
|
||||
if _lastAdded >= 1 then return end -- already enabled once; honour user's subsequent changes
|
||||
|
||||
local classData = CoAClassSpec and CoAClassSpec[playerToken]
|
||||
if not classData then return end -- vanilla class; nothing to do
|
||||
|
||||
for _, spec in ipairs(classData.specs) do
|
||||
local internalName = SafeInternalName(playerToken, spec.name)
|
||||
local fullName = PawnGetProviderScaleName(CoAScaleProviderName, internalName)
|
||||
pcall(PawnSetScaleVisible, fullName, true)
|
||||
end
|
||||
|
||||
PawnCoAScaleProviderOptions.LastAdded = 1
|
||||
end)
|
||||
|
||||
-- Self-destruct to free memory (matches Wowhead.lua pattern).
|
||||
CoAScaleProvider_AddScales = nil
|
||||
end
|
||||
|
||||
------------------------------------------------------------
|
||||
|
||||
PawnAddPluginScaleProvider(CoAScaleProviderName, "CoA class scales", CoAScaleProvider_AddScales)
|
||||
Reference in New Issue
Block a user