Revert ClassicAPI nameplate creation hook after crashes
This commit is contained in:
+42
-64
@@ -1,6 +1,6 @@
|
||||
local _G = ShaguTweaks.GetGlobalEnv()
|
||||
local GetExpansion = ShaguTweaks.GetExpansion
|
||||
local API = ShaguTweaks.API
|
||||
local GetUnitData = ShaguTweaks.GetUnitData
|
||||
|
||||
local NAMEPLATE_OBJECTORDER = { "border", "glow", "name", "level", "levelicon", "raidicon" }
|
||||
local NAMEPLATE_TYPE = "Button"
|
||||
@@ -10,7 +10,7 @@ if GetExpansion() == "tbc" then
|
||||
end
|
||||
|
||||
local function IsNamePlate(frame)
|
||||
if not frame or frame:GetObjectType() ~= NAMEPLATE_TYPE then return nil end
|
||||
if frame:GetObjectType() ~= NAMEPLATE_TYPE then return nil end
|
||||
local regions = frame:GetRegions()
|
||||
|
||||
if not regions then return nil end
|
||||
@@ -22,76 +22,54 @@ local function IsNamePlate(frame)
|
||||
end
|
||||
|
||||
local registry = {}
|
||||
local initialized = 0
|
||||
local parentcount, childs, plate
|
||||
ShaguTweaks.libnameplate = CreateFrame("Frame", nil, UIParent)
|
||||
ShaguTweaks.libnameplate.OnInit = {}
|
||||
ShaguTweaks.libnameplate.OnShow = {}
|
||||
ShaguTweaks.libnameplate.OnUpdate = {}
|
||||
ShaguTweaks.libnameplate:SetScript("OnUpdate", function()
|
||||
parentcount = WorldFrame:GetNumChildren()
|
||||
if initialized < parentcount then
|
||||
childs = { WorldFrame:GetChildren() }
|
||||
for i = initialized + 1, parentcount do
|
||||
plate = childs[i]
|
||||
|
||||
local function InitializePlate(plate)
|
||||
if not plate or registry[plate] or not IsNamePlate(plate) then return end
|
||||
if IsNamePlate(plate) and not registry[plate] then
|
||||
plate.healthbar = plate:GetChildren()
|
||||
for i, object in pairs({plate:GetRegions()}) do
|
||||
if plate and NAMEPLATE_OBJECTORDER[i] then
|
||||
plate[NAMEPLATE_OBJECTORDER[i]] = object
|
||||
end
|
||||
end
|
||||
|
||||
plate.healthbar = plate:GetChildren()
|
||||
for i, object in pairs({plate:GetRegions()}) do
|
||||
if plate and NAMEPLATE_OBJECTORDER[i] then
|
||||
plate[NAMEPLATE_OBJECTORDER[i]] = object
|
||||
end
|
||||
end
|
||||
-- run OnInit functions
|
||||
for id, func in pairs(ShaguTweaks.libnameplate.OnInit) do
|
||||
func(plate)
|
||||
end
|
||||
|
||||
-- Run one-time decorators after the native plate objects are exposed.
|
||||
for _, func in pairs(ShaguTweaks.libnameplate.OnInit) do
|
||||
func(plate)
|
||||
end
|
||||
-- register OnUpdate functions
|
||||
local oldUpdate = plate:GetScript("OnUpdate")
|
||||
plate:SetScript("OnUpdate", function(self, elapsed)
|
||||
if oldUpdate then oldUpdate(self, elapsed) end
|
||||
for id, func in pairs(ShaguTweaks.libnameplate.OnUpdate) do
|
||||
func(self, elapsed)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Keep the historical callback surface for modules that genuinely need
|
||||
-- per-frame plate work. ClassicAPI only replaces plate discovery below.
|
||||
local oldUpdate = plate:GetScript("OnUpdate")
|
||||
plate:SetScript("OnUpdate", function(self, elapsed)
|
||||
if oldUpdate then oldUpdate(self, elapsed) end
|
||||
for _, func in pairs(ShaguTweaks.libnameplate.OnUpdate) do
|
||||
func(self, elapsed)
|
||||
end
|
||||
end)
|
||||
-- register OnShow functions
|
||||
local oldShow = plate:GetScript("OnShow")
|
||||
plate:SetScript("OnShow", function(self)
|
||||
if oldShow then oldShow(self) end
|
||||
for id, func in pairs(ShaguTweaks.libnameplate.OnShow) do
|
||||
func(self)
|
||||
end
|
||||
end)
|
||||
|
||||
local oldShow = plate:GetScript("OnShow")
|
||||
plate:SetScript("OnShow", function(self)
|
||||
if oldShow then oldShow(self) end
|
||||
for _, func in pairs(ShaguTweaks.libnameplate.OnShow) do
|
||||
func(self)
|
||||
end
|
||||
end)
|
||||
|
||||
registry[plate] = plate
|
||||
end
|
||||
|
||||
-- ClassicAPI exposes the native nameplate lifecycle directly. Prefer its
|
||||
-- NAME_PLATE_CREATED event so Lua no longer walks every WorldFrame child on
|
||||
-- every rendered frame just to discover newly allocated nameplates.
|
||||
local useCreatedEvent = API and API.eventutils and _G.C_EventUtils
|
||||
and _G.C_EventUtils.IsEventValid("NAME_PLATE_CREATED")
|
||||
|
||||
if useCreatedEvent then
|
||||
ShaguTweaks.libnameplate:RegisterEvent("NAME_PLATE_CREATED")
|
||||
ShaguTweaks.libnameplate:SetScript("OnEvent", function()
|
||||
if event == "NAME_PLATE_CREATED" then
|
||||
InitializePlate(arg1)
|
||||
end
|
||||
end)
|
||||
else
|
||||
-- Legacy fallback for plain 1.12 / older ClassicAPI builds. Preserve the
|
||||
-- original WorldFrame scan exactly where no lifecycle event exists.
|
||||
local initialized = 0
|
||||
local parentcount, childs, plate
|
||||
|
||||
ShaguTweaks.libnameplate:SetScript("OnUpdate", function()
|
||||
parentcount = WorldFrame:GetNumChildren()
|
||||
if initialized < parentcount then
|
||||
childs = { WorldFrame:GetChildren() }
|
||||
for i = initialized + 1, parentcount do
|
||||
plate = childs[i]
|
||||
InitializePlate(plate)
|
||||
registry[plate] = plate
|
||||
end
|
||||
|
||||
initialized = parentcount
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
initialized = parentcount
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user