WeakAuras.Mixin

This commit is contained in:
Bunny67
2020-09-06 11:33:12 +03:00
parent e9957582cb
commit 47e81f3d70
10 changed files with 48 additions and 30 deletions
-1
View File
@@ -42,7 +42,6 @@ ignore = {
globals = {
-- compat
"tInvert",
"CreateFromMixins",
"Round",
"tIndexOf",
"IsInGroup",
+4 -4
View File
@@ -63,7 +63,7 @@ local storeMethods = {
Set = function(self, id, data)
if data ~= nil and type(id) == "string" then
if not self.stores[id] then
self.stores[id] = WeakAuras:Mixin({}, subStoreMethods)
self.stores[id] = WeakAuras.Mixin({}, subStoreMethods)
end
self.stores[id]:Set(data)
return self.stores[id]
@@ -93,16 +93,16 @@ local prototype = {
if type(store.stores) ~= "table" then
store.stores = {}
end
WeakAuras:Mixin(store, storeMethods)
WeakAuras.Mixin(store, storeMethods)
store:Validate()
return store, store
end,
Update = nil, -- This is the initial version! No need for Update yet.
Open = function(self, image)
local store = image
WeakAuras:Mixin(store, storeMethods)
WeakAuras.Mixin(store, storeMethods)
for _, subStore in pairs(store.stores) do
WeakAuras:Mixin(subStore, subStoreMethods)
WeakAuras.Mixin(subStore, subStoreMethods)
end
store:Validate()
return store
+10
View File
@@ -75,3 +75,13 @@ function WeakAuras.CountWagoUpdates()
-- XXX this is to work around the Companion app trying to use our stuff!
return 0
end
function WeakAuras.Mixin(object, ...)
for i = 1, select("#", ...) do
local mixin = select(i, ...)
for k, v in pairs(mixin) do
object[k] = v
end
end
return object
end
+24
View File
@@ -1,3 +1,27 @@
local assert = assert
local ipairs = ipairs
local next = next
local pairs = pairs
local select = select
local function Mixin(object, ...)
for i = 1, select("#", ...) do
local mixin = select(i, ...);
for k, v in pairs(mixin) do
object[k] = v;
end
end
return object;
end
local function CreateFromMixins(...)
return Mixin({}, ...)
end
local function nop()
end
ObjectPoolMixin = {};
function ObjectPoolMixin:OnLoad(creationFunc, resetterFunc)
+1 -1
View File
@@ -80,7 +80,7 @@ local controlPointFunctions = {
local function createControlPoint(self)
local controlPoint = CreateFrame("FRAME", nil, self.parent)
WeakAuras:Mixin(controlPoint, controlPointFunctions)
WeakAuras.Mixin(controlPoint, controlPointFunctions)
controlPoint:SetWidth(16)
controlPoint:SetHeight(16)
+4 -3
View File
@@ -1113,12 +1113,13 @@ local function scamCheck(codes, data)
end
end
local ignoredForDiffChecking = CreateFromMixins(WeakAuras.internal_fields, WeakAuras.non_transmissable_fields)
local internalFields = WeakAuras.internal_fields
local nonTransmissableFields = WeakAuras.non_transmissable_fields
local deleted = {} -- magic value
local function recurseDiff(ours, theirs)
local diff, seen, same = {}, {}, true
for key, ourVal in pairs(ours) do
if not ignoredForDiffChecking[key] then
if not (internalFields[key] or nonTransmissableFields[key]) then
seen[key] = true
local theirVal = theirs[key]
if type(ourVal) == "table" and type(theirVal) == "table" then
@@ -1139,7 +1140,7 @@ local function recurseDiff(ours, theirs)
end
end
for key, theirVal in pairs(theirs) do
if not seen[key] and not ignoredForDiffChecking[key] then
if not seen[key] and not (internalFields[key] or nonTransmissableFields[key]) then
diff[key] = theirVal
same = false
end
+1 -1
View File
@@ -1930,7 +1930,7 @@ function WeakAuras.RepairDatabase(loginAfter)
-- set db version to current code version
db.dbVersion = WeakAuras.InternalVersion()
-- reinstall snapshots from history
local newDB = WeakAuras:Mixin({}, db.displays)
local newDB = WeakAuras.Mixin({}, db.displays)
coroutine.yield()
for id, data in pairs(db.displays) do
local snapshot = WeakAuras.GetMigrationSnapshot(data.uid)
-16
View File
@@ -1,6 +1,5 @@
local ipairs = ipairs
local pairs = pairs
local select = select
local ceil, floor = math.ceil, math.floor
local format = string.format
@@ -27,21 +26,6 @@ function tInvert(tbl)
return inverted;
end
local function Mixin(object, ...)
for i = 1, select("#", ...) do
local mixin = select(i, ...);
for k, v in pairs(mixin) do
object[k] = v;
end
end
return object;
end
function CreateFromMixins(...)
return Mixin({}, ...)
end
function Round(value)
if value < 0 then
return ceil(value - .5);
+3 -3
View File
@@ -437,20 +437,20 @@ local function GetGenericTriggerOptions(data, triggernum)
}
if (triggerType == "custom") then
WeakAuras:Mixin(options, GetCustomTriggerOptions(data, triggernum, trigger));
WeakAuras.Mixin(options, GetCustomTriggerOptions(data, triggernum, trigger));
elseif (triggerType == "status" or triggerType == "event") then
local prototypeOptions;
local trigger, untrigger = data.triggers[triggernum].trigger, data.triggers[triggernum].untrigger;
if(WeakAuras.event_prototypes[trigger.event]) then
prototypeOptions = WeakAuras.ConstructOptions(WeakAuras.event_prototypes[trigger.event], data, 10, triggernum);
if (trigger.event == "Combat Log") then
WeakAuras:Mixin(prototypeOptions, combatLogOptions);
WeakAuras.Mixin(prototypeOptions, combatLogOptions);
end
else
print("|cFF8800FFWeakAuras|r: No prototype for", trigger.event);
end
if (prototypeOptions) then
WeakAuras:Mixin(options, prototypeOptions);
WeakAuras.Mixin(options, prototypeOptions);
end
end
@@ -282,7 +282,7 @@ local function createOptions(parentData, data, index, subIndex)
anchors = {}
for index, childId in ipairs(parentData.controlledChildren) do
local childData = WeakAuras.GetData(childId)
WeakAuras:Mixin(anchors, WeakAuras.GetAnchorsForData(childData, "point"))
WeakAuras.Mixin(anchors, WeakAuras.GetAnchorsForData(childData, "point"))
end
else
anchors = WeakAuras.GetAnchorsForData(parentData, "point")