diff --git a/.luacheckrc b/.luacheckrc index a1f3d8b..00f9eac 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -42,7 +42,6 @@ ignore = { globals = { -- compat "tInvert", - "CreateFromMixins", "Round", "tIndexOf", "IsInGroup", diff --git a/WeakAuras/ArchiveTypes/Repository.lua b/WeakAuras/ArchiveTypes/Repository.lua index 21d950f..a36317f 100644 --- a/WeakAuras/ArchiveTypes/Repository.lua +++ b/WeakAuras/ArchiveTypes/Repository.lua @@ -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 diff --git a/WeakAuras/Init.lua b/WeakAuras/Init.lua index 8cfa0ef..5dee76c 100644 --- a/WeakAuras/Init.lua +++ b/WeakAuras/Init.lua @@ -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 diff --git a/WeakAuras/Pools.lua b/WeakAuras/Pools.lua index e569dc2..d7d120f 100644 --- a/WeakAuras/Pools.lua +++ b/WeakAuras/Pools.lua @@ -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) diff --git a/WeakAuras/RegionTypes/DynamicGroup.lua b/WeakAuras/RegionTypes/DynamicGroup.lua index 4c2ce6b..421a4dc 100644 --- a/WeakAuras/RegionTypes/DynamicGroup.lua +++ b/WeakAuras/RegionTypes/DynamicGroup.lua @@ -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) diff --git a/WeakAuras/Transmission.lua b/WeakAuras/Transmission.lua index 2cc9e72..cee96a3 100644 --- a/WeakAuras/Transmission.lua +++ b/WeakAuras/Transmission.lua @@ -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 diff --git a/WeakAuras/WeakAuras.lua b/WeakAuras/WeakAuras.lua index 08399a1..580dddd 100644 --- a/WeakAuras/WeakAuras.lua +++ b/WeakAuras/WeakAuras.lua @@ -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) diff --git a/WeakAuras/compat.lua b/WeakAuras/compat.lua index 0fd50e1..68731d4 100644 --- a/WeakAuras/compat.lua +++ b/WeakAuras/compat.lua @@ -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); diff --git a/WeakAurasOptions/GenericTrigger.lua b/WeakAurasOptions/GenericTrigger.lua index dc28e00..1b0bdcb 100644 --- a/WeakAurasOptions/GenericTrigger.lua +++ b/WeakAurasOptions/GenericTrigger.lua @@ -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 diff --git a/WeakAurasOptions/SubRegionOptions/SubText.lua b/WeakAurasOptions/SubRegionOptions/SubText.lua index 479bad9..3c1e432 100644 --- a/WeakAurasOptions/SubRegionOptions/SubText.lua +++ b/WeakAurasOptions/SubRegionOptions/SubText.lua @@ -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")