This commit is contained in:
Bunny67
2020-08-06 17:41:52 +03:00
parent 5a7277a5a3
commit 969ef6edf8
16 changed files with 221 additions and 129 deletions
+20 -50
View File
@@ -16,16 +16,17 @@ local last_update = GetTime();
local function UpdateAnimations()
WeakAuras.StartProfileSystem("animations");
local errorHandler = WeakAuras.IsOptionsOpen() and noopErrorHandler or geterrorhandler()
for groupId, groupRegion in pairs(pending_controls) do
pending_controls[groupId] = nil;
for groupUid, groupRegion in pairs(pending_controls) do
pending_controls[groupUid] = nil;
groupRegion:DoPositionChildren();
end
local time = GetTime();
local elapsed = time - last_update;
last_update = time;
local num = 0;
for id, anim in pairs(animations) do
WeakAuras.StartProfileAura(anim.name);
for key, anim in pairs(animations) do
WeakAuras.StartProfileUID(anim.auraUID);
num = num + 1;
local finished = false;
if(anim.duration_type == "seconds") then
@@ -70,7 +71,7 @@ local function UpdateAnimations()
end
local progress = anim.inverse and (1 - anim.progress) or anim.progress;
progress = anim.easeFunc(progress, anim.easeStrength or 3)
WeakAuras.ActivateAuraEnvironment(anim.name, anim.cloneId, anim.region.state, anim.region.states);
WeakAuras.ActivateAuraEnvironment(anim.region)
if(anim.translateFunc) then
if (anim.region.SetOffsetAnim) then
local ok, x, y = pcall(anim.translateFunc, progress, 0, 0, anim.dX, anim.dY);
@@ -163,40 +164,29 @@ local function UpdateAnimations()
if(anim.region.ColorAnim) then
anim.region:ColorAnim(nil);
end
animations[id] = nil;
animations[key] = nil;
end
if(anim.loop) then
WeakAuras.Animate(anim.namespace, anim.data, anim.type, anim.anim, anim.region, anim.inverse, anim.onFinished, anim.loop, anim.cloneId);
WeakAuras.Animate(anim.namespace, anim.auraUID, anim.type, anim.anim, anim.region, anim.inverse, anim.onFinished, anim.loop, anim.region.cloneId);
elseif(anim.onFinished) then
anim.onFinished();
end
end
WeakAuras.StopProfileAura(anim.name);
WeakAuras.StopProfileUID(anim.auraUID);
end
-- XXX: I tried to have animations only update if there are actually animation data to animate upon.
-- This caused all start animations to break, and I couldn't figure out why.
-- May revisit at a later time.
--[[
if(num == 0) then
WeakAuras.debug("Animation stopped", 3);
frame:SetScript("OnUpdate", nil);
updatingAnimations = nil;
updatingAnimations = nil;
end
]]--
WeakAuras.StopProfileSystem("animations");
end
function Private.RegisterGroupForPositioning(id, region)
pending_controls[id] = region
function Private.RegisterGroupForPositioning(uid, region)
pending_controls[uid] = region
updatingAnimations = true
frame:SetScript("OnUpdate", UpdateAnimations)
end
function WeakAuras.Animate(namespace, data, type, anim, region, inverse, onFinished, loop, cloneId)
local id = data.id;
function WeakAuras.Animate(namespace, uid, type, anim, region, inverse, onFinished, loop, cloneId)
local auraDisplayName = WeakAuras.UIDtoID(uid)
local key = tostring(region);
local valid;
if(anim and anim.type == "custom" and (anim.use_translate or anim.use_alpha or (anim.use_scale and region.Scale) or (anim.use_rotate and region.Rotate) or (anim.use_color and region.Color))) then
@@ -251,7 +241,7 @@ function WeakAuras.Animate(namespace, data, type, anim, region, inverse, onFinis
anim.translateFunc = anim_function_strings[anim.translateType]
end
if (anim.translateFunc) then
translateFunc = WeakAuras.LoadFunction("return " .. anim.translateFunc, id, "translate animation");
translateFunc = WeakAuras.LoadFunction("return " .. anim.translateFunc, auraDisplayName, "translate animation");
else
if (region.SetOffsetAnim) then
region:SetOffsetAnim(0, 0);
@@ -272,7 +262,7 @@ function WeakAuras.Animate(namespace, data, type, anim, region, inverse, onFinis
anim.alphaFunc = anim_function_strings[anim.alphaType]
end
if (anim.alphaFunc) then
alphaFunc = WeakAuras.LoadFunction("return " .. anim.alphaFunc, id, "alpha animation");
alphaFunc = WeakAuras.LoadFunction("return " .. anim.alphaFunc, auraDisplayName, "alpha animation");
else
if (region.SetAnimAlpha) then
region:SetAnimAlpha(nil);
@@ -293,7 +283,7 @@ function WeakAuras.Animate(namespace, data, type, anim, region, inverse, onFinis
anim.scaleFunc = anim_function_strings[anim.scaleType]
end
if (anim.scaleFunc) then
scaleFunc = WeakAuras.LoadFunction("return " .. anim.scaleFunc, id, "scale animation");
scaleFunc = WeakAuras.LoadFunction("return " .. anim.scaleFunc, auraDisplayName, "scale animation");
else
region:Scale(1, 1);
end
@@ -306,7 +296,7 @@ function WeakAuras.Animate(namespace, data, type, anim, region, inverse, onFinis
anim.rotateFunc = anim_function_strings[anim.rotateType]
end
if (anim.rotateFunc) then
rotateFunc = WeakAuras.LoadFunction("return " .. anim.rotateFunc, id, "rotate animation");
rotateFunc = WeakAuras.LoadFunction("return " .. anim.rotateFunc, auraDisplayName, "rotate animation");
else
region:Rotate(startRotation);
end
@@ -319,7 +309,7 @@ function WeakAuras.Animate(namespace, data, type, anim, region, inverse, onFinis
anim.colorFunc = anim_function_strings[anim.colorType]
end
if (anim.colorFunc) then
colorFunc = WeakAuras.LoadFunction("return " .. anim.colorFunc, id, "color animation");
colorFunc = WeakAuras.LoadFunction("return " .. anim.colorFunc, auraDisplayName, "color animation");
else
region:ColorAnim(nil);
end
@@ -331,7 +321,7 @@ function WeakAuras.Animate(namespace, data, type, anim, region, inverse, onFinis
duration = WeakAuras.ParseNumber(anim.duration) or 0;
progress = 0;
if(namespace == "display" and type == "main" and not onFinished and not anim.duration_type == "relative") then
local data = WeakAuras.GetData(id);
local data = WeakAuras.GetDataByUID(uid);
if(data and data.parent) then
local parentRegion = WeakAuras.regions[data.parent].region;
if(parentRegion and parentRegion.controlledRegions) then
@@ -385,11 +375,9 @@ function WeakAuras.Animate(namespace, data, type, anim, region, inverse, onFinis
animation.type = type
animation.loop = loop
animation.onFinished = onFinished
animation.name = id
animation.cloneId = cloneId or ""
animation.namespace = namespace;
animation.data = data;
animation.anim = anim;
animation.auraUID = uid
if not(updatingAnimations) then
frame:SetScript("OnUpdate", UpdateAnimations);
@@ -406,16 +394,6 @@ function WeakAuras.Animate(namespace, data, type, anim, region, inverse, onFinis
end
end
function WeakAuras.IsAnimating(region)
local key = tostring(region);
local anim = animations[key];
if(anim) then
return anim.type;
else
return nil;
end
end
function WeakAuras.CancelAnimation(region, resetPos, resetAlpha, resetScale, resetRotation, resetColor, doOnFinished)
local key = tostring(region);
local anim = animations[key];
@@ -460,11 +438,3 @@ function WeakAuras.CancelAnimation(region, resetPos, resetAlpha, resetScale, res
return false;
end
end
function Private.RenameAnimations(oldid, newid)
for key, animation in pairs(animations) do
if animation.name == oldid then
animation.name = newid;
end
end
end
+4
View File
@@ -192,6 +192,10 @@ function WeakAuras.ClearAuraEnvironment(id)
environment_initialized[id] = nil;
end
function WeakAuras.ActivateAuraEnvironmentForRegion(region, onlyConfig)
WeakAuras.ActivateAuraEnvironment(region.id, region.cloneId, region.state, region.states, onlyConfig)
end
function WeakAuras.ActivateAuraEnvironment(id, cloneId, state, states, onlyConfig)
local data = WeakAuras.GetData(id)
local region = WeakAuras.GetRegion(id, cloneId)
+26 -14
View File
@@ -158,7 +158,7 @@ local function CreateTestForCondition(uid, input, allConditionsTemplate, usedSta
end
end
if (trigger and variable and value) then
if (trigger and variable) then
usedStates[trigger] = true;
local conditionTemplate = allConditionsTemplate[trigger] and allConditionsTemplate[trigger][variable];
@@ -203,27 +203,29 @@ local function CreateTestForCondition(uid, input, allConditionsTemplate, usedSta
uid, testFunctionNumber, trigger);
end
end
elseif (cType == "number" and op) then
elseif cType == "alwaystrue" then
check = "true"
elseif (cType == "number" and value and op) then
local v = tonumber(value)
if (v) then
check = stateCheck .. stateVariableCheck .. "state[" .. trigger .. "]." .. variable .. op .. v;
end
elseif (cType == "timer" and op) then
elseif (cType == "timer" and value and op) then
if (op == "==") then
check = stateCheck .. stateVariableCheck .. "abs(state[" .. trigger .. "]." ..variable .. "- now -" .. value .. ") < 0.05";
else
check = stateCheck .. stateVariableCheck .. "state[" .. trigger .. "]." .. variable .. "- now" .. op .. value;
end
elseif (cType == "select" and op) then
elseif (cType == "select" and value and op) then
if (tonumber(value)) then
check = stateCheck .. stateVariableCheck .. "state[" .. trigger .. "]." .. variable .. op .. tonumber(value);
else
check = stateCheck .. stateVariableCheck .. "state[" .. trigger .. "]." .. variable .. op .. "'" .. value .. "'";
end
elseif (cType == "bool") then
elseif (cType == "bool" and value) then
local rightSide = value == 0 and "false" or "true";
check = stateCheck .. stateVariableCheck .. "state[" .. trigger .. "]." .. variable .. "==" .. rightSide
elseif (cType == "string") then
elseif (cType == "string" and value) then
if(op == "==") then
check = stateCheck .. stateVariableCheck .. "state[" .. trigger .. "]." .. variable .. " == [[" .. value .. "]]";
elseif (op == "find('%s')") then
@@ -244,14 +246,19 @@ local function CreateTestForCondition(uid, input, allConditionsTemplate, usedSta
return check, recheckCode;
end
local function CreateCheckCondition(uid, ret, condition, conditionNumber, allConditionsTemplate, debug)
local function CreateCheckCondition(uid, ret, condition, conditionNumber, allConditionsTemplate, nextIsLinked, debug)
local usedStates = {};
local check, recheckCode = CreateTestForCondition(uid, condition.check, allConditionsTemplate, usedStates);
if (check) then
ret = ret .. " state = region.states\n"
ret = ret .. " if (" .. check .. ") then\n";
ret = ret .. " newActiveConditions[" .. conditionNumber .. "] = true;\n";
ret = ret .. " end\n";
if condition.linked and conditionNumber > 1 then
ret = ret .. " elseif (" .. check .. ") then\n";
else
ret = ret .. " if (" .. check .. ") then\n";
end
ret = ret .. " newActiveConditions[" .. conditionNumber .. "] = true;\n";
if not nextIsLinked then
ret = ret .. " end\n";
end
end
if (recheckCode) then
ret = ret .. recheckCode;
@@ -474,6 +481,10 @@ local globalConditions =
["customcheck"] = {
display = L["Custom Check"],
type = "customcheck"
},
["alwaystrue"] = {
display = L["Always True"],
type = "alwaystrue"
}
}
@@ -500,6 +511,7 @@ local function ConstructConditionFunction(data)
if (debug) then ret = ret .. " print('check conditions for:', region.id, region.cloneId)\n"; end
ret = ret .. " local id = region.id\n";
ret = ret .. " local cloneId = region.cloneId or ''\n";
ret = ret .. " local state = region.states\n"
ret = ret .. " local activatedConditions = WeakAuras.GetActiveConditions(id, cloneId)\n";
ret = ret .. " wipe(newActiveConditions)\n";
ret = ret .. " local recheckTime;\n"
@@ -507,11 +519,12 @@ local function ConstructConditionFunction(data)
local normalConditionCount = data.conditions and #data.conditions;
-- First Loop gather which conditions are active
ret = ret .. " if (not hideRegion) then\n"
ret = ret .. " if (not hideRegion) then\n"
if (data.conditions) then
WeakAuras.conditionHelpers[data.uid] = nil
for conditionNumber, condition in ipairs(data.conditions) do
ret = CreateCheckCondition(data.uid, ret, condition, conditionNumber, allConditionsTemplate, debug)
local nextIsLinked = data.conditions[conditionNumber + 1] and data.conditions[conditionNumber + 1].linked
ret = CreateCheckCondition(data.uid, ret, condition, conditionNumber, allConditionsTemplate, nextIsLinked, debug)
end
end
ret = ret .. " end\n";
@@ -574,7 +587,6 @@ function Private.LoadConditionFunction(data)
end
function Private.RunConditions(region, id, hideRegion)
-- TODO rename show
if (checkConditions[id]) then
checkConditions[id](region, hideRegion);
end
+6
View File
@@ -55,6 +55,12 @@ end
function WeakAuras.StopProfileAura()
end
function WeakAuras.StartProfileUID()
end
function WeakAuras.StopProfileUID()
end
-- If WeakAuras shuts down due to being installed on the wrong target, keep the bindings from erroring
function WeakAuras.StartProfile()
end
+12
View File
@@ -272,6 +272,14 @@ local function StopProfileAura(id)
StopProfiling(profileData.auras, id)
end
local function StartProfileUID(uid)
StartProfiling(profileData.auras, WeakAuras.UIDtoID(uid))
end
local function StopProfileUID(uid)
StopProfiling(profileData.auras, WeakAuras.UIDtoID(uid))
end
function WeakAuras.ProfileRenameAura(oldid, id)
profileData.auras[id] = profileData.auras[id]
profileData.auras[oldid] = nil
@@ -324,8 +332,10 @@ function WeakAuras.StartProfile(startType)
WeakAuras.StartProfileSystem = StartProfileSystem
WeakAuras.StartProfileAura = StartProfileAura
WeakAuras.StartProfileUID = StartProfileUID
WeakAuras.StopProfileSystem = StopProfileSystem
WeakAuras.StopProfileAura = StopProfileAura
WeakAuras.StopProfileUID = StopProfileUID
end
local function doNothing()
@@ -344,8 +354,10 @@ function WeakAuras.StopProfile()
WeakAuras.StartProfileSystem = doNothing
WeakAuras.StartProfileAura = doNothing
WeakAuras.StartProfileUID = doNothing
WeakAuras.StopProfileSystem = doNothing
WeakAuras.StopProfileAura = doNothing
WeakAuras.StopProfileUID = doNothing
currentProfileState = nil
RealTimeProfilingWindow:UnregisterAllEvents()
+6 -3
View File
@@ -1025,7 +1025,7 @@ local function modify(parent, region, data)
self.needToPosition = false
if #self.sortedChildren > 0 then
if animate then
Private.RegisterGroupForPositioning(data.id, self)
Private.RegisterGroupForPositioning(data.uid, self)
else
self:DoPositionChildren()
end
@@ -1044,7 +1044,10 @@ local function modify(parent, region, data)
type(pos[2]) == "number" and pos[2] or 0,
type(pos[3]) ~= "boolean" and true or pos[3]
local controlPoint = regionData.controlPoint
local controlPoint = type(regionData) == "table" and regionData.controlPoint
if not controlPoint then
break
end
controlPoint:ClearAnchorPoint()
controlPoint:SetAnchorPoint(
data.selfPoint,
@@ -1134,7 +1137,7 @@ local function modify(parent, region, data)
}
end
-- update animated expand & collapse for this child
WeakAuras.Animate("controlPoint", data, "controlPoint", anim, regionData.controlPoint, true)
WeakAuras.Animate("controlPoint", data.uid, "controlPoint", anim, regionData.controlPoint, true)
end
end
regionData.xOffset = x
+6 -9
View File
@@ -265,10 +265,7 @@ end
local function RunCode(self, func)
if func and not WeakAuras.IsOptionsOpen() then
WeakAuras.ActivateAuraEnvironment(self.id, self.cloneId, self.state, self.states);
local ok, ret = pcall(func);
if not ok then
geterrorhandler()(ret)
end
xpcall(func, geterrorhandler());
WeakAuras.ActivateAuraEnvironment(nil);
end
end
@@ -716,7 +713,7 @@ function WeakAuras.regionPrototype.AddExpandFunction(data, region, cloneId, pare
local inGroup = parentRegionType == "group";
local startMainAnimation = function()
WeakAuras.Animate("display", data, "main", data.animation.main, region, false, nil, true, cloneId);
WeakAuras.Animate("display", data.uid, "main", data.animation.main, region, false, nil, true, cloneId);
end
function region:OptionsClosed()
@@ -772,7 +769,7 @@ function WeakAuras.regionPrototype.AddExpandFunction(data, region, cloneId, pare
region:SetScript("OnUpdate", nil)
WeakAuras.PerformActions(data, "finish", region);
if (not WeakAuras.Animate("display", data, "finish", data.animation.finish, region, false, hideRegion, nil, cloneId)) then
if (not WeakAuras.Animate("display", data.uid, "finish", data.animation.finish, region, false, hideRegion, nil, cloneId)) then
hideRegion();
end
@@ -797,7 +794,7 @@ function WeakAuras.regionPrototype.AddExpandFunction(data, region, cloneId, pare
WeakAuras.ApplyFrameLevel(region)
region:Show();
WeakAuras.PerformActions(data, "start", region);
if not(WeakAuras.Animate("display", data, "start", data.animation.start, region, true, startMainAnimation, nil, cloneId)) then
if not(WeakAuras.Animate("display", data.uid, "start", data.animation.start, region, true, startMainAnimation, nil, cloneId)) then
startMainAnimation();
end
parent:ActivateChild(data.id, cloneId);
@@ -814,7 +811,7 @@ function WeakAuras.regionPrototype.AddExpandFunction(data, region, cloneId, pare
region:SetScript("OnUpdate", nil)
WeakAuras.PerformActions(data, "finish", region);
if (not WeakAuras.Animate("display", data, "finish", data.animation.finish, region, false, hideRegion, nil, cloneId)) then
if (not WeakAuras.Animate("display", data.uid, "finish", data.animation.finish, region, false, hideRegion, nil, cloneId)) then
hideRegion();
end
@@ -851,7 +848,7 @@ function WeakAuras.regionPrototype.AddExpandFunction(data, region, cloneId, pare
WeakAuras.ApplyFrameLevel(region)
region:Show();
WeakAuras.PerformActions(data, "start", region);
if not(WeakAuras.Animate("display", data, "start", data.animation.start, region, true, startMainAnimation, nil, cloneId)) then
if not(WeakAuras.Animate("display", data.uid, "start", data.animation.start, region, true, startMainAnimation, nil, cloneId)) then
startMainAnimation();
end
+5 -3
View File
@@ -1498,6 +1498,10 @@ function WeakAuras.GetDataByUID(uid)
return WeakAuras.GetData(UIDtoID[uid])
end
function WeakAuras.UIDtoID(uid)
return UIDtoID[uid]
end
function WeakAuras.Delete(data)
local id = data.id;
if(data.parent) then
@@ -1665,8 +1669,6 @@ function WeakAuras.Rename(data, newid)
end
end
Private.RenameAnimations(oldid, newid)
if (WeakAuras.mouseFrame) then
WeakAuras.mouseFrame:rename(oldid, newid);
end
@@ -2647,7 +2649,7 @@ function WeakAuras.SetRegion(data, cloneId)
clonePool[regionType] = clonePool[regionType] or {};
end
if(anim_cancelled) then
WeakAuras.Animate("display", data, "main", data.animation.main, region, false, nil, true, cloneId);
WeakAuras.Animate("display", data.uid, "main", data.animation.main, region, false, nil, true, cloneId);
end
return region;
end