from retail

This commit is contained in:
NoM0Re
2025-01-07 15:03:14 +01:00
parent 7a185106f2
commit 74a1a856ac
9 changed files with 115 additions and 72 deletions
+11 -6
View File
@@ -1,5 +1,6 @@
if not WeakAuras.IsLibsOK() then return end if not WeakAuras.IsLibsOK() then return end
local AddonName, Private = ... local AddonName, Private = ...
local L = WeakAuras.L
-- Animations -- Animations
local animations = {} local animations = {}
@@ -14,7 +15,6 @@ local updatingAnimations;
local last_update = GetTime(); local last_update = GetTime();
local function UpdateAnimations() local function UpdateAnimations()
Private.StartProfileSystem("animations"); Private.StartProfileSystem("animations");
local errorHandler = WeakAuras.IsOptionsOpen() and noopErrorHandler or geterrorhandler()
for groupUid, groupRegion in pairs(pending_controls) do for groupUid, groupRegion in pairs(pending_controls) do
pending_controls[groupUid] = nil; pending_controls[groupUid] = nil;
groupRegion:DoPositionChildren(); groupRegion:DoPositionChildren();
@@ -72,6 +72,7 @@ local function UpdateAnimations()
progress = anim.easeFunc(progress, anim.easeStrength or 3) progress = anim.easeFunc(progress, anim.easeStrength or 3)
Private.ActivateAuraEnvironmentForRegion(anim.region) Private.ActivateAuraEnvironmentForRegion(anim.region)
if(anim.translateFunc) then if(anim.translateFunc) then
local errorHandler = WeakAuras.IsOptionsOpen() and noopErrorHandler or Private.GetErrorHandlerUid(anim.auraUID, L["Slide Animation"])
if (anim.region.SetOffsetAnim) then if (anim.region.SetOffsetAnim) then
local ok, x, y = pcall(anim.translateFunc, progress, 0, 0, anim.dX, anim.dY); local ok, x, y = pcall(anim.translateFunc, progress, 0, 0, anim.dX, anim.dY);
if not ok then if not ok then
@@ -90,6 +91,7 @@ local function UpdateAnimations()
end end
end end
if(anim.alphaFunc) then if(anim.alphaFunc) then
local errorHandler = WeakAuras.IsOptionsOpen() and noopErrorHandler or Private.GetErrorHandlerUid(anim.auraUID, L["Fade Animation"])
local ok, alpha = pcall(anim.alphaFunc, progress, anim.startAlpha, anim.dAlpha); local ok, alpha = pcall(anim.alphaFunc, progress, anim.startAlpha, anim.dAlpha);
if not ok then if not ok then
errorHandler(alpha) errorHandler(alpha)
@@ -102,6 +104,7 @@ local function UpdateAnimations()
end end
end end
if(anim.scaleFunc) then if(anim.scaleFunc) then
local errorHandler = WeakAuras.IsOptionsOpen() and noopErrorHandler or Private.GetErrorHandlerUid(anim.auraUID, L["Zoom Animation"])
local ok, scaleX, scaleY = pcall(anim.scaleFunc, progress, 1, 1, anim.scaleX, anim.scaleY); local ok, scaleX, scaleY = pcall(anim.scaleFunc, progress, 1, 1, anim.scaleX, anim.scaleY);
if not ok then if not ok then
errorHandler(scaleX) errorHandler(scaleX)
@@ -115,6 +118,7 @@ local function UpdateAnimations()
end end
end end
if(anim.rotateFunc and anim.region.Rotate) then if(anim.rotateFunc and anim.region.Rotate) then
local errorHandler = WeakAuras.IsOptionsOpen() and noopErrorHandler or Private.GetErrorHandlerUid(anim.auraUID, L["Rotate Animation"])
local ok, rotate = pcall(anim.rotateFunc, progress, anim.startRotation, anim.rotate); local ok, rotate = pcall(anim.rotateFunc, progress, anim.startRotation, anim.rotate);
if not ok then if not ok then
errorHandler(rotate) errorHandler(rotate)
@@ -123,6 +127,7 @@ local function UpdateAnimations()
end end
end end
if(anim.colorFunc and anim.region.ColorAnim) then if(anim.colorFunc and anim.region.ColorAnim) then
local errorHandler = WeakAuras.IsOptionsOpen() and noopErrorHandler or Private.GetErrorHandlerUid(anim.auraUID, L["Color Animation"])
local startR, startG, startB, startA = anim.region:GetColor(); local startR, startG, startB, startA = anim.region:GetColor();
startR, startG, startB, startA = startR or 1, startG or 1, startB or 1, startA or 1; startR, startG, startB, startA = startR or 1, startG or 1, startB or 1, startA or 1;
local ok, r, g, b, a = pcall(anim.colorFunc, progress, startR, startG, startB, startA, anim.colorR, anim.colorG, anim.colorB, anim.colorA); local ok, r, g, b, a = pcall(anim.colorFunc, progress, startR, startG, startB, startA, anim.colorR, anim.colorG, anim.colorB, anim.colorA);
@@ -240,7 +245,7 @@ function Private.Animate(namespace, uid, type, anim, region, inverse, onFinished
anim.translateFunc = anim_function_strings[anim.translateType] anim.translateFunc = anim_function_strings[anim.translateType]
end end
if (anim.translateFunc) then if (anim.translateFunc) then
translateFunc = WeakAuras.LoadFunction("return " .. anim.translateFunc, auraDisplayName, "translate animation"); translateFunc = WeakAuras.LoadFunction("return " .. anim.translateFunc);
else else
if (region.SetOffsetAnim) then if (region.SetOffsetAnim) then
region:SetOffsetAnim(0, 0); region:SetOffsetAnim(0, 0);
@@ -261,7 +266,7 @@ function Private.Animate(namespace, uid, type, anim, region, inverse, onFinished
anim.alphaFunc = anim_function_strings[anim.alphaType] anim.alphaFunc = anim_function_strings[anim.alphaType]
end end
if (anim.alphaFunc) then if (anim.alphaFunc) then
alphaFunc = WeakAuras.LoadFunction("return " .. anim.alphaFunc, auraDisplayName, "alpha animation"); alphaFunc = WeakAuras.LoadFunction("return " .. anim.alphaFunc);
else else
if (region.SetAnimAlpha) then if (region.SetAnimAlpha) then
region:SetAnimAlpha(nil); region:SetAnimAlpha(nil);
@@ -282,7 +287,7 @@ function Private.Animate(namespace, uid, type, anim, region, inverse, onFinished
anim.scaleFunc = anim_function_strings[anim.scaleType] anim.scaleFunc = anim_function_strings[anim.scaleType]
end end
if (anim.scaleFunc) then if (anim.scaleFunc) then
scaleFunc = WeakAuras.LoadFunction("return " .. anim.scaleFunc, auraDisplayName, "scale animation"); scaleFunc = WeakAuras.LoadFunction("return " .. anim.scaleFunc);
else else
region:Scale(1, 1); region:Scale(1, 1);
end end
@@ -295,7 +300,7 @@ function Private.Animate(namespace, uid, type, anim, region, inverse, onFinished
anim.rotateFunc = anim_function_strings[anim.rotateType] anim.rotateFunc = anim_function_strings[anim.rotateType]
end end
if (anim.rotateFunc) then if (anim.rotateFunc) then
rotateFunc = WeakAuras.LoadFunction("return " .. anim.rotateFunc, auraDisplayName, "rotate animation"); rotateFunc = WeakAuras.LoadFunction("return " .. anim.rotateFunc);
else else
region:Rotate(startRotation); region:Rotate(startRotation);
end end
@@ -308,7 +313,7 @@ function Private.Animate(namespace, uid, type, anim, region, inverse, onFinished
anim.colorFunc = anim_function_strings[anim.colorType] anim.colorFunc = anim_function_strings[anim.colorType]
end end
if (anim.colorFunc) then if (anim.colorFunc) then
colorFunc = WeakAuras.LoadFunction("return " .. anim.colorFunc, auraDisplayName, "color animation"); colorFunc = WeakAuras.LoadFunction("return " .. anim.colorFunc);
else else
region:ColorAnim(nil); region:ColorAnim(nil);
end end
+3 -3
View File
@@ -269,7 +269,7 @@ function Private.ActivateAuraEnvironment(id, cloneId, state, states, onlyConfig)
if(actions and actions.do_custom and actions.custom) then if(actions and actions.do_custom and actions.custom) then
local func = Private.customActionsFunctions[id]["init"] local func = Private.customActionsFunctions[id]["init"]
if func then if func then
xpcall(func, geterrorhandler()) xpcall(func, Private.GetErrorHandlerId(id, "init"))
end end
end end
end end
@@ -425,11 +425,11 @@ function env_getglobal(k)
end end
local function_cache = {} local function_cache = {}
function WeakAuras.LoadFunction(string, id, inTrigger) function WeakAuras.LoadFunction(string)
if function_cache[string] then if function_cache[string] then
return function_cache[string] return function_cache[string]
else else
local loadedFunction, errorString = loadstring(string, "Error in: " .. (id or "Unknown") .. (inTrigger and ("':'".. inTrigger) or "")) local loadedFunction, errorString = loadstring(string)
if errorString then if errorString then
print(errorString) print(errorString)
else else
+5 -5
View File
@@ -151,7 +151,7 @@ end
function WeakAuras.CallCustomConditionTest(uid, testFunctionNumber, ...) function WeakAuras.CallCustomConditionTest(uid, testFunctionNumber, ...)
local ok, result = pcall(WeakAuras.conditionHelpers[uid].customTestFunctions[testFunctionNumber], ...) local ok, result = pcall(WeakAuras.conditionHelpers[uid].customTestFunctions[testFunctionNumber], ...)
if not ok then if not ok then
geterrorhandler()(result) Private.GetErrorHandlerUid(uid, L["Condition Custom Text"])
elseif (ok) then elseif (ok) then
return result return result
end end
@@ -223,7 +223,7 @@ local function CreateTestForCondition(uid, input, allConditionsTemplate, usedSta
end end
elseif (cType == "customcheck") then elseif (cType == "customcheck") then
if value then if value then
local customCheck = WeakAuras.LoadFunction("return " .. value, Private.UIDtoID(uid), "conditions custom check") local customCheck = WeakAuras.LoadFunction("return " .. value)
if customCheck then if customCheck then
WeakAuras.conditionHelpers[uid] = WeakAuras.conditionHelpers[uid] or {} WeakAuras.conditionHelpers[uid] = WeakAuras.conditionHelpers[uid] or {}
WeakAuras.conditionHelpers[uid].customTestFunctions = WeakAuras.conditionHelpers[uid].customTestFunctions or {} WeakAuras.conditionHelpers[uid].customTestFunctions = WeakAuras.conditionHelpers[uid].customTestFunctions or {}
@@ -295,7 +295,7 @@ local function CreateTestForCondition(uid, input, allConditionsTemplate, usedSta
fn = fn:format(input.op_range, input.range, op, value) fn = fn:format(input.op_range, input.range, op, value)
end end
if fn then if fn then
local customCheck = WeakAuras.LoadFunction(fn, Private.UIDtoID(uid), "conditions range check") local customCheck = WeakAuras.LoadFunction(fn)
if customCheck then if customCheck then
WeakAuras.conditionHelpers[uid] = WeakAuras.conditionHelpers[uid] or {} WeakAuras.conditionHelpers[uid] = WeakAuras.conditionHelpers[uid] or {}
WeakAuras.conditionHelpers[uid].customTestFunctions = WeakAuras.conditionHelpers[uid].customTestFunctions or {} WeakAuras.conditionHelpers[uid].customTestFunctions = WeakAuras.conditionHelpers[uid].customTestFunctions or {}
@@ -517,7 +517,7 @@ function Private.LoadConditionPropertyFunctions(data)
else else
prefix, suffix = "return function()", "\nend"; prefix, suffix = "return function()", "\nend";
end end
local customFunc = WeakAuras.LoadFunction(prefix .. custom .. suffix, id, "condition"); local customFunc = WeakAuras.LoadFunction(prefix .. custom .. suffix);
if (customFunc) then if (customFunc) then
WeakAuras.customConditionsFunctions[id][conditionNumber] = WeakAuras.customConditionsFunctions[id][conditionNumber] or {}; WeakAuras.customConditionsFunctions[id][conditionNumber] = WeakAuras.customConditionsFunctions[id][conditionNumber] or {};
WeakAuras.customConditionsFunctions[id][conditionNumber].changes = WeakAuras.customConditionsFunctions[id][conditionNumber].changes or {}; WeakAuras.customConditionsFunctions[id][conditionNumber].changes = WeakAuras.customConditionsFunctions[id][conditionNumber].changes or {};
@@ -697,7 +697,7 @@ function Private.LoadConditionFunction(data)
CancelTimers(data.uid) CancelTimers(data.uid)
local checkConditionsFuncStr = ConstructConditionFunction(data); local checkConditionsFuncStr = ConstructConditionFunction(data);
local checkCondtionsFunc = checkConditionsFuncStr and WeakAuras.LoadFunction(checkConditionsFuncStr, data.id, "condition checks"); local checkCondtionsFunc = checkConditionsFuncStr and WeakAuras.LoadFunction(checkConditionsFuncStr);
checkConditions[data.uid] = checkCondtionsFunc; checkConditions[data.uid] = checkCondtionsFunc;
end end
+30 -30
View File
@@ -457,7 +457,7 @@ function Private.EndEvent(id, triggernum, force, state)
end end
end end
local function RunOverlayFuncs(event, state) local function RunOverlayFuncs(event, state, id)
state.additionalProgress = state.additionalProgress or {}; state.additionalProgress = state.additionalProgress or {};
local changed = false; local changed = false;
for i, overlayFunc in ipairs(event.overlayFuncs) do for i, overlayFunc in ipairs(event.overlayFuncs) do
@@ -465,7 +465,7 @@ local function RunOverlayFuncs(event, state)
local additionalProgress = state.additionalProgress[i]; local additionalProgress = state.additionalProgress[i];
local ok, a, b, c = pcall(overlayFunc, event.trigger, state); local ok, a, b, c = pcall(overlayFunc, event.trigger, state);
if (not ok) then if (not ok) then
geterrorhandler()(a) Private.GetErrorHandlerId(id, L["Overlay %s"]:format(i))
additionalProgress.min = nil; additionalProgress.min = nil;
additionalProgress.max = nil; additionalProgress.max = nil;
additionalProgress.direction = nil; additionalProgress.direction = nil;
@@ -522,7 +522,7 @@ local function callFunctionForActivateEvent(func, trigger, fallback, errorHandle
end end
end end
function Private.ActivateEvent(id, triggernum, data, state, errorHandler) function Private.ActivateEvent(id, triggernum, data, state)
local changed = state.changed or false; local changed = state.changed or false;
if (state.show ~= true) then if (state.show ~= true) then
state.show = true; state.show = true;
@@ -553,7 +553,7 @@ function Private.ActivateEvent(id, triggernum, data, state, errorHandler)
elseif (data.durationFunc) then elseif (data.durationFunc) then
local ok, arg1, arg2, arg3, inverse = pcall(data.durationFunc, data.trigger); local ok, arg1, arg2, arg3, inverse = pcall(data.durationFunc, data.trigger);
if not ok then if not ok then
errorHandler(arg1); Private.GetErrorHandlerId(id, L["Duration Function"])
arg1 = 0; arg1 = 0;
arg2 = 0; arg2 = 0;
else else
@@ -619,10 +619,10 @@ function Private.ActivateEvent(id, triggernum, data, state, errorHandler)
end end
end end
local name = callFunctionForActivateEvent(data.nameFunc, data.trigger, state.name, errorHandler) local name = callFunctionForActivateEvent(data.nameFunc, data.trigger, state.name, Private.GetErrorHandlerId(id, L["Name Function"]))
local icon = callFunctionForActivateEvent(data.iconFunc, data.trigger, state.icon, errorHandler) local icon = callFunctionForActivateEvent(data.iconFunc, data.trigger, state.icon, Private.GetErrorHandlerId(id, L["Icon Function"]))
local texture = callFunctionForActivateEvent(data.textureFunc, data.trigger, state.texture, errorHandler) local texture = callFunctionForActivateEvent(data.textureFunc, data.trigger, state.texture, Private.GetErrorHandlerId(id, L["Texture Function"]))
local stacks = callFunctionForActivateEvent(data.stacksFunc, data.trigger, state.stacks, errorHandler) local stacks = callFunctionForActivateEvent(data.stacksFunc, data.trigger, state.stacks, Private.GetErrorHandlerId(id, L["Stacks Function"]))
if (state.name ~= name) then if (state.name ~= name) then
state.name = name; state.name = name;
@@ -642,7 +642,7 @@ function Private.ActivateEvent(id, triggernum, data, state, errorHandler)
end end
if (data.overlayFuncs) then if (data.overlayFuncs) then
RunOverlayFuncs(data, state); RunOverlayFuncs(data, state, id);
else else
state.additionalProgress = nil; state.additionalProgress = nil;
end end
@@ -658,7 +658,7 @@ end
local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2, ...) local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2, ...)
local optionsEvent = event == "OPTIONS"; local optionsEvent = event == "OPTIONS";
local errorHandler = (optionsEvent and data.ignoreOptionsEventErrors) and ignoreErrorHandler or geterrorhandler() local errorHandler = (optionsEvent and data.ignoreOptionsEventErrors) and ignoreErrorHandler or Private.GetErrorHandlerId(id, L["Trigger %s"]:format(triggernum))
local updateTriggerState = false; local updateTriggerState = false;
local unitForUnitTrigger local unitForUnitTrigger
@@ -675,7 +675,7 @@ local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2
end end
for key, state in pairs(allStates) do for key, state in pairs(allStates) do
if (type(state) ~= "table") then if (type(state) ~= "table") then
errorHandler(string.format(L["Error in aura '%s' in %s. trigger. All States table contains a non table at key: '%s'."], id, triggernum, key)) errorHandler(string.format(L["All States table contains a non table at key: '%s'."], key))
wipe(allStates) wipe(allStates)
return return
end end
@@ -687,7 +687,7 @@ local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2
elseif (ok and returnValue) or optionsEvent then elseif (ok and returnValue) or optionsEvent then
for id, state in pairs(allStates) do for id, state in pairs(allStates) do
if (state.changed) then if (state.changed) then
if (Private.ActivateEvent(id, triggernum, data, state, errorHandler)) then if (Private.ActivateEvent(id, triggernum, data, state)) then
updateTriggerState = true; updateTriggerState = true;
end end
end end
@@ -721,7 +721,7 @@ local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2
if not ok then if not ok then
errorHandler(returnValue) errorHandler(returnValue)
elseif (ok and returnValue) or optionsEvent then elseif (ok and returnValue) or optionsEvent then
if(Private.ActivateEvent(id, triggernum, data, state, errorHandler)) then if(Private.ActivateEvent(id, triggernum, data, state)) then
updateTriggerState = true; updateTriggerState = true;
end end
else else
@@ -735,7 +735,7 @@ local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2
if not ok then if not ok then
errorHandler(returnValue) errorHandler(returnValue)
elseif (ok and returnValue) or optionsEvent then elseif (ok and returnValue) or optionsEvent then
if(Private.ActivateEvent(id, triggernum, data, state, errorHandler)) then if(Private.ActivateEvent(id, triggernum, data, state)) then
updateTriggerState = true; updateTriggerState = true;
end end
else else
@@ -748,7 +748,7 @@ local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2
elseif (ok and returnValue) or optionsEvent then elseif (ok and returnValue) or optionsEvent then
allStates[""] = allStates[""] or {}; allStates[""] = allStates[""] or {};
local state = allStates[""]; local state = allStates[""];
if(Private.ActivateEvent(id, triggernum, data, state, errorHandler)) then if(Private.ActivateEvent(id, triggernum, data, state)) then
updateTriggerState = true; updateTriggerState = true;
end end
else else
@@ -1391,7 +1391,7 @@ function GenericTrigger.Add(data, region)
triggerFuncStr = ConstructFunction(prototype, trigger); triggerFuncStr = ConstructFunction(prototype, trigger);
statesParameter = prototype.statesParameter; statesParameter = prototype.statesParameter;
triggerFunc = WeakAuras.LoadFunction(triggerFuncStr, id); triggerFunc = WeakAuras.LoadFunction(triggerFuncStr);
durationFunc = prototype.durationFunc; durationFunc = prototype.durationFunc;
nameFunc = prototype.nameFunc; nameFunc = prototype.nameFunc;
@@ -1455,7 +1455,7 @@ function GenericTrigger.Add(data, region)
end end
end end
else -- CUSTOM else -- CUSTOM
triggerFunc = WeakAuras.LoadFunction("return "..(trigger.custom or ""), id); triggerFunc = WeakAuras.LoadFunction("return "..(trigger.custom or ""));
if (trigger.custom_type == "stateupdate") then if (trigger.custom_type == "stateupdate") then
tsuConditionVariables = WeakAuras.LoadFunction("return function() return \n" .. (trigger.customVariables or "") .. "\n end"); tsuConditionVariables = WeakAuras.LoadFunction("return function() return \n" .. (trigger.customVariables or "") .. "\n end");
if not tsuConditionVariables then if not tsuConditionVariables then
@@ -1464,35 +1464,35 @@ function GenericTrigger.Add(data, region)
end end
if(trigger.custom_type == "status" or trigger.custom_type == "event" and trigger.custom_hide == "custom") then if(trigger.custom_type == "status" or trigger.custom_type == "event" and trigger.custom_hide == "custom") then
untriggerFunc = WeakAuras.LoadFunction("return "..(untrigger.custom or ""), id); untriggerFunc = WeakAuras.LoadFunction("return "..(untrigger.custom or ""));
if (not untriggerFunc) then if (not untriggerFunc) then
untriggerFunc = trueFunction; untriggerFunc = trueFunction;
end end
end end
if(trigger.custom_type ~= "stateupdate" and trigger.customDuration and trigger.customDuration ~= "") then if(trigger.custom_type ~= "stateupdate" and trigger.customDuration and trigger.customDuration ~= "") then
durationFunc = WeakAuras.LoadFunction("return "..trigger.customDuration, id); durationFunc = WeakAuras.LoadFunction("return "..trigger.customDuration);
end end
if(trigger.custom_type ~= "stateupdate") then if(trigger.custom_type ~= "stateupdate") then
overlayFuncs = {}; overlayFuncs = {};
for i = 1, 7 do for i = 1, 7 do
local property = "customOverlay" .. i; local property = "customOverlay" .. i;
if (trigger[property] and trigger[property] ~= "") then if (trigger[property] and trigger[property] ~= "") then
overlayFuncs[i] = WeakAuras.LoadFunction("return ".. trigger[property], id); overlayFuncs[i] = WeakAuras.LoadFunction("return ".. trigger[property]);
end end
end end
end end
if(trigger.custom_type ~= "stateupdate" and trigger.customName and trigger.customName ~= "") then if(trigger.custom_type ~= "stateupdate" and trigger.customName and trigger.customName ~= "") then
nameFunc = WeakAuras.LoadFunction("return "..trigger.customName, id); nameFunc = WeakAuras.LoadFunction("return "..trigger.customName);
end end
if(trigger.custom_type ~= "stateupdate" and trigger.customIcon and trigger.customIcon ~= "") then if(trigger.custom_type ~= "stateupdate" and trigger.customIcon and trigger.customIcon ~= "") then
iconFunc = WeakAuras.LoadFunction("return "..trigger.customIcon, id); iconFunc = WeakAuras.LoadFunction("return "..trigger.customIcon);
end end
if(trigger.custom_type ~= "stateupdate" and trigger.customTexture and trigger.customTexture ~= "") then if(trigger.custom_type ~= "stateupdate" and trigger.customTexture and trigger.customTexture ~= "") then
textureFunc = WeakAuras.LoadFunction("return "..trigger.customTexture, id); textureFunc = WeakAuras.LoadFunction("return "..trigger.customTexture);
end end
if(trigger.custom_type ~= "stateupdate" and trigger.customStacks and trigger.customStacks ~= "") then if(trigger.custom_type ~= "stateupdate" and trigger.customStacks and trigger.customStacks ~= "") then
stacksFunc = WeakAuras.LoadFunction("return "..trigger.customStacks, id); stacksFunc = WeakAuras.LoadFunction("return "..trigger.customStacks);
end end
if((trigger.custom_type == "status" or trigger.custom_type == "stateupdate") and trigger.check == "update") then if((trigger.custom_type == "status" or trigger.custom_type == "stateupdate") and trigger.check == "update") then
@@ -4098,7 +4098,7 @@ function GenericTrigger.CreateFallbackState(data, triggernum, state)
if (event.nameFunc) then if (event.nameFunc) then
local ok, name = pcall(event.nameFunc, firstTrigger); local ok, name = pcall(event.nameFunc, firstTrigger);
if not ok then if not ok then
geterrorhandler()(name) Private.GetErrorHandlerUid(data.uid, L["Name Function (fallback state)"])
state.name = nil state.name = nil
else else
state.name = name or nil state.name = name or nil
@@ -4107,7 +4107,7 @@ function GenericTrigger.CreateFallbackState(data, triggernum, state)
if (event.iconFunc) then if (event.iconFunc) then
local ok, icon = pcall(event.iconFunc, firstTrigger); local ok, icon = pcall(event.iconFunc, firstTrigger);
if not ok then if not ok then
geterrorhandler()(icon) Private.GetErrorHandlerUid(data.uid, L["Icon Function (fallback state)"])
state.icon = nil state.icon = nil
else else
state.icon = icon or nil state.icon = icon or nil
@@ -4117,7 +4117,7 @@ function GenericTrigger.CreateFallbackState(data, triggernum, state)
if (event.textureFunc ) then if (event.textureFunc ) then
local ok, texture = pcall(event.textureFunc, firstTrigger); local ok, texture = pcall(event.textureFunc, firstTrigger);
if not ok then if not ok then
geterrorhandler()(texture) Private.GetErrorHandlerUid(data.uid, L["Texture Function (fallback state)"])
state.texture = nil state.texture = nil
else else
state.texture = texture or nil state.texture = texture or nil
@@ -4127,7 +4127,7 @@ function GenericTrigger.CreateFallbackState(data, triggernum, state)
if (event.stacksFunc) then if (event.stacksFunc) then
local ok, stacks = pcall(event.stacksFunc, firstTrigger); local ok, stacks = pcall(event.stacksFunc, firstTrigger);
if not ok then if not ok then
geterrorhandler()(stacks) Private.GetErrorHandlerUid(data.uid, L["Stacks Function (fallback state)"])
state.stacks = nil state.stacks = nil
else else
state.stacks = stacks or nil state.stacks = stacks or nil
@@ -4137,7 +4137,7 @@ function GenericTrigger.CreateFallbackState(data, triggernum, state)
if (event.durationFunc) then if (event.durationFunc) then
local ok, arg1, arg2, arg3, inverse = pcall(event.durationFunc, firstTrigger); local ok, arg1, arg2, arg3, inverse = pcall(event.durationFunc, firstTrigger);
if not ok then if not ok then
geterrorhandler()(arg1) Private.GetErrorHandlerUid(data.uid, L["Duration Function (fallback state)"])
state.progressType = "timed"; state.progressType = "timed";
state.duration = 0; state.duration = 0;
state.expirationTime = math.huge; state.expirationTime = math.huge;
@@ -4180,7 +4180,7 @@ function GenericTrigger.CreateFallbackState(data, triggernum, state)
state.total = nil; state.total = nil;
end end
if (event.overlayFuncs) then if (event.overlayFuncs) then
RunOverlayFuncs(event, state); RunOverlayFuncs(event, state, data.id);
end end
Private.ActivateAuraEnvironment(nil); Private.ActivateAuraEnvironment(nil);
end end
+7 -6
View File
@@ -2,6 +2,7 @@ if not WeakAuras.IsLibsOK() then return end
local AddonName, Private = ... local AddonName, Private = ...
local WeakAuras = WeakAuras local WeakAuras = WeakAuras
local L = WeakAuras.L
local SharedMedia = LibStub("LibSharedMedia-3.0") local SharedMedia = LibStub("LibSharedMedia-3.0")
local default = { local default = {
@@ -317,13 +318,13 @@ local sorters = {
end, end,
custom = function(data) custom = function(data)
local sortStr = data.customSort or "" local sortStr = data.customSort or ""
local sortFunc = WeakAuras.LoadFunction("return " .. sortStr, data.id, "custom sort") or noop local sortFunc = WeakAuras.LoadFunction("return " .. sortStr) or noop
return function(a, b) return function(a, b)
Private.ActivateAuraEnvironment(data.id) Private.ActivateAuraEnvironment(data.id)
local ok, result = pcall(sortFunc, a, b) local ok, result = pcall(sortFunc, a, b)
Private.ActivateAuraEnvironment() Private.ActivateAuraEnvironment()
if not ok then if not ok then
geterrorhandler()(result) Private.GetErrorHandlerId(data.id, L["Custom Sort"])
else else
return result return result
end end
@@ -398,12 +399,12 @@ local anchorers = {
end, end,
["CUSTOM"] = function(data) ["CUSTOM"] = function(data)
local anchorStr = data.customAnchorPerUnit or "" local anchorStr = data.customAnchorPerUnit or ""
local anchorFunc = WeakAuras.LoadFunction("return " .. anchorStr, data.id, "custom frame anchor") or noop local anchorFunc = WeakAuras.LoadFunction("return " .. anchorStr) or noop
return function(frames, activeRegions) return function(frames, activeRegions)
Private.ActivateAuraEnvironment(data.id) Private.ActivateAuraEnvironment(data.id)
local ok, ret = pcall(anchorFunc, frames, activeRegions) local ok, ret = pcall(anchorFunc, frames, activeRegions)
if not ok then if not ok then
geterrorhandler()(ret) Private.GetErrorHandlerUid(data.uid, L["Custom Anchor"])
end end
Private.ActivateAuraEnvironment() Private.ActivateAuraEnvironment()
end end
@@ -763,13 +764,13 @@ local growers = {
end, end,
CUSTOM = function(data) CUSTOM = function(data)
local growStr = data.customGrow or "" local growStr = data.customGrow or ""
local growFunc = WeakAuras.LoadFunction("return " .. growStr, data.id, "custom grow") or noop local growFunc = WeakAuras.LoadFunction("return " .. growStr) or noop
return function(newPositions, activeRegions) return function(newPositions, activeRegions)
Private.ActivateAuraEnvironment(data.id) Private.ActivateAuraEnvironment(data.id)
local ok, ret = pcall(growFunc, newPositions, activeRegions) local ok, ret = pcall(growFunc, newPositions, activeRegions)
Private.ActivateAuraEnvironment() Private.ActivateAuraEnvironment()
if not ok then if not ok then
geterrorhandler()(ret) Private.GetErrorHandlerId(data.id, L["Custom Sort"])
wipe(newPositions) wipe(newPositions)
end end
end end
+3 -3
View File
@@ -253,7 +253,7 @@ end
local function RunCode(self, func) local function RunCode(self, func)
if func and not WeakAuras.IsOptionsOpen() then if func and not WeakAuras.IsOptionsOpen() then
Private.ActivateAuraEnvironment(self.id, self.cloneId, self.state, self.states); Private.ActivateAuraEnvironment(self.id, self.cloneId, self.state, self.states);
xpcall(func, geterrorhandler()); xpcall(func, Private.GetErrorHandlerId(self.id, L["Custom Condition Code"]));
Private.ActivateAuraEnvironment(nil); Private.ActivateAuraEnvironment(nil);
end end
end end
@@ -276,7 +276,7 @@ local function UpdatePosition(self)
local ok, ret = pcall(self.SetPoint, self, self.anchorPoint, self.relativeTo, self.relativePoint, xOffset, yOffset); local ok, ret = pcall(self.SetPoint, self, self.anchorPoint, self.relativeTo, self.relativePoint, xOffset, yOffset);
if not ok then if not ok then
geterrorhandler()(ret) Private.GetErrorHandlerId(self.id, L["Update Position"])
end end
end end
@@ -541,7 +541,7 @@ function WeakAuras.regionPrototype.modify(parent, region, data)
region:SetOffsetAnim(0, 0); region:SetOffsetAnim(0, 0);
if data.anchorFrameType == "CUSTOM" and data.customAnchor then if data.anchorFrameType == "CUSTOM" and data.customAnchor then
region.customAnchorFunc = WeakAuras.LoadFunction("return " .. data.customAnchor, data.id, "custom anchor") region.customAnchorFunc = WeakAuras.LoadFunction("return " .. data.customAnchor)
else else
region.customAnchorFunc = nil region.customAnchorFunc = nil
end end
+1 -1
View File
@@ -195,7 +195,7 @@ local function modify(parent, region, data)
local customTextFunc = nil local customTextFunc = nil
if(Private.ContainsCustomPlaceHolder(data.displayText) and data.customText) then if(Private.ContainsCustomPlaceHolder(data.displayText) and data.customText) then
customTextFunc = WeakAuras.LoadFunction("return "..data.customText, region.id, "custom text") customTextFunc = WeakAuras.LoadFunction("return "..data.customText)
end end
local Update local Update
+1 -1
View File
@@ -192,7 +192,7 @@ local function modify(parent, region, parentData, data, first)
end end
if containsCustomText and parentData.customText and parentData.customText ~= "" then if containsCustomText and parentData.customText and parentData.customText ~= "" then
parent.customTextFunc = WeakAuras.LoadFunction("return "..parentData.customText, parentData.id, "custom text") parent.customTextFunc = WeakAuras.LoadFunction("return "..parentData.customText)
else else
parent.customTextFunc = nil parent.customTextFunc = nil
end end
+54 -17
View File
@@ -63,6 +63,46 @@ function WeakAuras.InternalVersion()
return internalVersion; return internalVersion;
end end
do
local currentErrorHandlerId
local currentErrorHandlerUid
local currentErrorHandlerContext
local function waErrorHandler(errorMessage)
local prefix = ""
local data
if currentErrorHandlerId then
data = WeakAuras.GetData(currentErrorHandlerId)
elseif currentErrorHandlerUid then
data = Private.GetDataByUID(currentErrorHandlerUid)
end
if data then
Private.AuraWarnings.UpdateWarning(data.uid, "LuaError", "error",
L["This aura has caused a Lua error."] .. "\n" .. L["Install the addons BugSack and BugGrabber for detailed error logs."], true)
prefix = L["Lua error in aura '%s': %s"]:format(data.id, currentErrorHandlerContext or L["unknown location"]) .. "\n"
else
prefix = L["Lua error"] .. "\n"
end
prefix = prefix .. L["WeakAuras Version: %s"]:format(WeakAuras.versionString) .. "\n"
local version = data and (data.semver or data.version)
if version then
prefix = prefix .. L["Aura Version: %s"]:format(version) .. "\n"
end
geterrorhandler()(prefix .. errorMessage)
end
function Private.GetErrorHandlerId(id, context)
currentErrorHandlerUid = nil
currentErrorHandlerId = id
currentErrorHandlerContext = context
return waErrorHandler
end
function Private.GetErrorHandlerUid(uid, context)
currentErrorHandlerUid = uid
currentErrorHandlerId = nil
currentErrorHandlerContext = context
return waErrorHandler
end
end
function Private.LoadOptions(msg) function Private.LoadOptions(msg)
if not(IsAddOnLoaded("WeakAurasOptions")) then if not(IsAddOnLoaded("WeakAurasOptions")) then
if not WeakAuras.IsLoginFinished() then if not WeakAuras.IsLoginFinished() then
@@ -796,30 +836,30 @@ local function LoadCustomActionFunctions(data)
if (data.actions) then if (data.actions) then
if (data.actions.init and data.actions.init.do_custom and data.actions.init.custom) then if (data.actions.init and data.actions.init.do_custom and data.actions.init.custom) then
local func = WeakAuras.LoadFunction("return function() "..(data.actions.init.custom).."\n end", id, "initialization"); local func = WeakAuras.LoadFunction("return function() "..(data.actions.init.custom).."\n end");
Private.customActionsFunctions[id]["init"] = func; Private.customActionsFunctions[id]["init"] = func;
end end
if (data.actions.start) then if (data.actions.start) then
if (data.actions.start.do_custom and data.actions.start.custom) then if (data.actions.start.do_custom and data.actions.start.custom) then
local func = WeakAuras.LoadFunction("return function() "..(data.actions.start.custom).."\n end", id, "show action"); local func = WeakAuras.LoadFunction("return function() "..(data.actions.start.custom).."\n end");
Private.customActionsFunctions[id]["start"] = func; Private.customActionsFunctions[id]["start"] = func;
end end
if (data.actions.start.do_message and data.actions.start.message_custom) then if (data.actions.start.do_message and data.actions.start.message_custom) then
local func = WeakAuras.LoadFunction("return "..(data.actions.start.message_custom), id, "show message"); local func = WeakAuras.LoadFunction("return "..(data.actions.start.message_custom));
Private.customActionsFunctions[id]["start_message"] = func; Private.customActionsFunctions[id]["start_message"] = func;
end end
end end
if (data.actions.finish) then if (data.actions.finish) then
if (data.actions.finish.do_custom and data.actions.finish.custom) then if (data.actions.finish.do_custom and data.actions.finish.custom) then
local func = WeakAuras.LoadFunction("return function() "..(data.actions.finish.custom).."\n end", id, "hide action"); local func = WeakAuras.LoadFunction("return function() "..(data.actions.finish.custom).."\n end");
Private.customActionsFunctions[id]["finish"] = func; Private.customActionsFunctions[id]["finish"] = func;
end end
if (data.actions.finish.do_message and data.actions.finish.message_custom) then if (data.actions.finish.do_message and data.actions.finish.message_custom) then
local func = WeakAuras.LoadFunction("return "..(data.actions.finish.message_custom), id, "hide message"); local func = WeakAuras.LoadFunction("return "..(data.actions.finish.message_custom));
Private.customActionsFunctions[id]["finish_message"] = func; Private.customActionsFunctions[id]["finish_message"] = func;
end end
end end
@@ -2605,11 +2645,11 @@ local function pAdd(data, simpleChange)
loadEvents["SCAN_ALL"][id] = true loadEvents["SCAN_ALL"][id] = true
local loadForOptionsFuncStr = ConstructFunction(load_prototype, data.load, true); local loadForOptionsFuncStr = ConstructFunction(load_prototype, data.load, true);
local loadFunc = WeakAuras.LoadFunction(loadFuncStr, id, "load"); local loadFunc = WeakAuras.LoadFunction(loadFuncStr);
local loadForOptionsFunc = WeakAuras.LoadFunction(loadForOptionsFuncStr, id, "options load"); local loadForOptionsFunc = WeakAuras.LoadFunction(loadForOptionsFuncStr);
local triggerLogicFunc; local triggerLogicFunc;
if data.triggers.disjunctive == "custom" then if data.triggers.disjunctive == "custom" then
triggerLogicFunc = WeakAuras.LoadFunction("return "..(data.triggers.customTriggerLogic or ""), id, "trigger combination"); triggerLogicFunc = WeakAuras.LoadFunction("return "..(data.triggers.customTriggerLogic or ""));
end end
LoadCustomActionFunctions(data); LoadCustomActionFunctions(data);
@@ -2668,7 +2708,7 @@ function WeakAuras.Add(data, takeSnapshot, simpleChange)
end end
local ok, ret = pcall(WeakAuras.PreAdd, data) local ok, ret = pcall(WeakAuras.PreAdd, data)
if not ok then if not ok then
geterrorhandler()(ret) Private.GetErrorHandlerUid(data.uid, "PreAdd")
elseif ok then elseif ok then
pAdd(data, simpleChange) pAdd(data, simpleChange)
end end
@@ -3177,7 +3217,7 @@ function Private.PerformActions(data, when, region)
local func = Private.customActionsFunctions[data.id][when] local func = Private.customActionsFunctions[data.id][when]
if func then if func then
Private.ActivateAuraEnvironment(region.id, region.cloneId, region.state, region.states); Private.ActivateAuraEnvironment(region.id, region.cloneId, region.state, region.states);
xpcall(func, geterrorhandler()); xpcall(func, Private.GetErrorHandlerId(data.id, L["Custom Action"]));
Private.ActivateAuraEnvironment(nil); Private.ActivateAuraEnvironment(nil);
end end
end end
@@ -3854,7 +3894,7 @@ local function evaluateTriggerStateTriggers(id)
if (triggerState[id].disjunctive == "custom" and triggerState[id].triggerLogicFunc) then if (triggerState[id].disjunctive == "custom" and triggerState[id].triggerLogicFunc) then
local ok, returnValue = pcall(triggerState[id].triggerLogicFunc, triggerState[id].triggers); local ok, returnValue = pcall(triggerState[id].triggerLogicFunc, triggerState[id].triggers);
if not ok then if not ok then
geterrorhandler()(returnValue) Private.GetErrorHandlerId(id, L["Custom Trigger Combination"])
result = false result = false
else else
result = returnValue result = returnValue
@@ -4073,7 +4113,7 @@ function Private.RunCustomTextFunc(region, customFunc)
local custom = {pcall(customFunc, expirationTime or math.huge, duration or 0, progress, dur, name, icon, stacks)} local custom = {pcall(customFunc, expirationTime or math.huge, duration or 0, progress, dur, name, icon, stacks)}
if not custom[1] then if not custom[1] then
geterrorhandler()(custom[2]) Private.GetErrorHandlerId(region.id, L["Custom Text Function"])
else else
table.remove(custom, 1) table.remove(custom, 1)
end end
@@ -4882,7 +4922,7 @@ local function GetAnchorFrame(data, region, parent)
Private.StartProfileSystem("custom region anchor") Private.StartProfileSystem("custom region anchor")
Private.StartProfileAura(region.id) Private.StartProfileAura(region.id)
Private.ActivateAuraEnvironment(region.id, region.cloneId, region.state) Private.ActivateAuraEnvironment(region.id, region.cloneId, region.state)
local ok, frame = xpcall(region.customAnchorFunc, geterrorhandler()) local ok, frame = xpcall(region.customAnchorFunc, Private.GetErrorHandlerId(region.id, L["Custom Anchor"]))
Private.ActivateAuraEnvironment() Private.ActivateAuraEnvironment()
Private.StopProfileSystem("custom region anchor") Private.StopProfileSystem("custom region anchor")
Private.StopProfileAura(region.id) Private.StopProfileAura(region.id)
@@ -4915,12 +4955,9 @@ function Private.AnchorFrame(data, region, parent, force)
if not anchorParent then return end if not anchorParent then return end
if (data.anchorFrameParent or data.anchorFrameParent == nil if (data.anchorFrameParent or data.anchorFrameParent == nil
or data.anchorFrameType == "SCREEN" or data.anchorFrameType == "MOUSE") then or data.anchorFrameType == "SCREEN" or data.anchorFrameType == "MOUSE") then
local errorhandler = function(text)
geterrorhandler()(L["'ERROR: Anchoring %s': \n"]:format(data.id) .. text)
end
local ok, ret = pcall(region.SetParent, region, anchorParent); local ok, ret = pcall(region.SetParent, region, anchorParent);
if not ok then if not ok then
errorhandler(ret) Private.GetErrorHandlerId(data.id, L["Anchoring"])
end end
else else
region:SetParent(parent or WeakAurasFrame); region:SetParent(parent or WeakAurasFrame);