mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-15 23:50:38 +00:00
Ports from retail's Blizzard_ObjectAPI, SharedXML, SharedXMLBase and
FrameXMLUtil, in Blizzard's own text, from the _forever_ build:
- ObjectCache.lua and SpellBookItemLocation.lua (ObjectAPI).
- TypeUtil.lua: ValueToBoolean and StringToBoolean.
- SortUtil.lua: SortUtil.CreateSortManager and the comparators.
- Sequencer.lua, Spline.lua (Catmull-Rom splines), TaggableObject.lua,
ObjectUpdater.lua and ExportUtil.lua (base64 export/import streams).
- AnimationSystem.lua: SetUpAnimation and CancelAnimations.
- SmoothStatusBar.lua: SmoothStatusBarMixin.
- MixinUtil.lua: DrawLine, LineMixin, SparseGridMixin,
DoublyLinkedListMixin, DirtiableMixin, DirtyPhaseMixin and more. 1.12
has no global wipe, so the file reads table.wipe, as the other ports do.
FrameDeltaLerp now takes retail's three arguments and reads the frame
time from GetTickTime(). The old form needed a fourth elapsed argument,
so SmoothStatusBar's per-frame ticker would have errored. Nothing else
called it.
DebugTools drops its private StringToBoolean copy and calls the global
one from TypeUtil for the /framestack arguments.
FadingFrame.lua is not ported: 1.12's own FrameXML defines the same
FadingFrame_* names with no-argument `this` signatures, and ZoneText
calls FadingFrame_OnUpdate() every frame.
Verified in game: StringToBoolean, ValueToBoolean and
SpellBookItemLocation return the expected values, a 2D spline's midpoint
is (5, 10), an export stream round-trips 200 and 9, the sort manager
orders {3,1,2}, the linked list enumerates 0 1 2, ObjectUpdater,
Sequencer and SetUpAnimation finish, a smoothed status bar reaches 100,
and /framestack still opens.
77 lines
2.7 KiB
Lua
77 lines
2.7 KiB
Lua
-- Backport of retail's Blizzard_FrameXMLUtil/AnimationSystem.lua.
|
|
|
|
--[[ animTable = { --Note that only consistent data should be in here. These tables are meant to be shared across "sessions" of animations. Put changing data in the frame.
|
|
totalTime = number, --Time to complete the animation in seconds.
|
|
updateFunc = function, --The function called to do the actual change. Takes self, elapsed fraction. Usually frame.SetPoint, frame.SetAlpha, ect.
|
|
getPosFunc = function, --The function returning the data being passed into updateFunc. For example. might return .18 if updateFunc is frame.SetAlpha.
|
|
--]]
|
|
local AnimatingFrames = {};
|
|
|
|
local AnimUpdateFrame = CreateFrame("Frame");
|
|
|
|
local function Animation_UpdateFrame(self, animElapsed, animTable)
|
|
local totalTime = animTable.totalTime
|
|
if ( animElapsed and (animElapsed < totalTime)) then --Should be animating
|
|
local elapsedFraction = self.animReverse and (1-animElapsed/totalTime) or (animElapsed/totalTime);
|
|
animTable.updateFunc(self, animTable.getPosFunc(self, elapsedFraction));
|
|
else --Just finished animating
|
|
animTable.updateFunc(self, animTable.getPosFunc(self, self.animReverse and 0 or 1));
|
|
self.animating = false;
|
|
|
|
AnimatingFrames[self][animTable.updateFunc] = 0; --We use 0 instead of nil'ing out because we don't want to mess with 'next' (used in pairs)
|
|
|
|
if ( self.animPostFunc ) then
|
|
self.animPostFunc(self);
|
|
end
|
|
|
|
end
|
|
end
|
|
|
|
local totalElapsed = 0;
|
|
local function Animation_OnUpdate(self, elapsed)
|
|
totalElapsed = totalElapsed + elapsed;
|
|
local isAnyFrameAnimating = false;
|
|
for frame, frameTable in pairs(AnimatingFrames) do
|
|
for _, animTable in pairs(frameTable) do
|
|
if ( animTable ~= 0 ) then
|
|
Animation_UpdateFrame(frame, totalElapsed - frame.animStartTime, animTable);
|
|
isAnyFrameAnimating = true;
|
|
end
|
|
end
|
|
end
|
|
if ( not isAnyFrameAnimating ) then
|
|
table.wipe(AnimatingFrames);
|
|
AnimUpdateFrame:SetScript("OnUpdate", nil);
|
|
end
|
|
end
|
|
|
|
function SetUpAnimation(frame, animTable, postFunc, reverse)
|
|
if ( type(animTable.updateFunc) == "string" ) then
|
|
animTable.updateFunc = frame[animTable.updateFunc];
|
|
end
|
|
if ( not AnimatingFrames[frame] ) then
|
|
AnimatingFrames[frame] = {};
|
|
end
|
|
|
|
AnimatingFrames[frame][animTable.updateFunc] = animTable;
|
|
|
|
frame.animStartTime = totalElapsed;
|
|
frame.animReverse = reverse;
|
|
frame.animPostFunc = postFunc;
|
|
frame.animating = true;
|
|
|
|
animTable.updateFunc(frame, animTable.getPosFunc(frame, frame.animReverse and 1 or 0));
|
|
|
|
AnimUpdateFrame:SetScript("OnUpdate", Animation_OnUpdate);
|
|
end
|
|
|
|
function CancelAnimations(frame)
|
|
local anims = AnimatingFrames[frame];
|
|
if ( anims ) then
|
|
for k, v in pairs(anims) do
|
|
anims[k] = 0;
|
|
end
|
|
frame.animating = false;
|
|
end
|
|
end
|