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