Refactor progress handling

probably some regressions
This commit is contained in:
NoM0Re
2025-01-22 03:37:10 +01:00
parent a643b275ba
commit 23c7da5ea6
29 changed files with 2037 additions and 1263 deletions
+129 -10
View File
@@ -71,6 +71,17 @@ local function compareValues(a, b, propertytype)
and a[2] == b[2]
and a[3] == b[3]
and a[4] == b[4];
elseif propertytype == "progressSource" then
if type(a) == "table" and type(b) == "table" then
local triggerA, propertyA, triggerB, propertyB = a[1], a[2], b[1], b[2]
if triggerA ~= triggerB or propertyA ~= propertyB then
return false
end
if triggerA == 0 then
return a[3] == b[3] and a[4] == b[4]
end
return true
end
end
return a == b;
end
@@ -139,15 +150,36 @@ local function descIfSubset(data, reference, totalAuraCount)
return "";
end
local function descIfNoValue(data, object, variable, type, values)
local function descIfNoValue(data, object, variable, propertyType, values)
if (data.controlledChildren) then
if (object["same" .. variable] == false) then
local desc = "";
for id, reference in pairs(object.references) do
if (type == "list" and values) then
if propertyType == "list" and values then
desc = desc .."|cFFE0E000".. id .. ": |r" .. (values[reference[variable]] or "") .. "\n";
elseif propertyType == "progressSource" then
desc = desc .."|cFFE0E000".. id .. ": |r"
local progressSource = reference[variable]
if type(progressSource) == "table" then
local trigger = progressSource[1]
if trigger == 0 then
desc = desc .. L["Manual with %i/%i"]:format(progressSource[3] or 0, progressSource[4] or 100)
else
local p = OptionsPrivate.Private.GetProgressValueConstant(progressSource)
local description = values[p] or ""
if type(description) == "string" then
desc = desc .. description
elseif type(description) == "table"
and type(description[1]) == "string"
and type(description[2]) == "string"
then
desc = desc .. description[1] .. " " .. description[2]
end
end
end
desc = desc .."\n"
else
desc = desc .."|cFFE0E000".. id .. ": |r" .. (valueToString(reference[variable], type) or "") .. "\n";
desc = desc .."|cFFE0E000".. id .. ": |r" .. (valueToString(reference[variable], propertyType) or "") .. "\n";
end
end
return desc;
@@ -298,6 +330,7 @@ local function addControlsForChange(args, order, data, conditionVariable, totalA
order = order + 1;
local setValue;
local setValueTable
local setValueColor;
local setValueComplex;
local setValueColorComplex;
@@ -313,6 +346,17 @@ local function addControlsForChange(args, order, data, conditionVariable, totalA
conditions[i].changes[j].value = v;
WeakAuras.ClearAndUpdateOptions(data.id)
end
setValueTable = function(info, v)
for id, reference in pairs(conditions[i].changes[j].references) do
local auraData = WeakAuras.GetData(id)
local conditionIndex = conditions[i].check.references[id].conditionIndex
auraData[conditionVariable][conditionIndex].changes[reference.changeIndex].value = CopyTable(v)
WeakAuras.Add(auraData)
OptionsPrivate.ClearOptions(auraData.id)
end
conditions[i].changes[j].value = CopyTable(v)
WeakAuras.ClearAndUpdateOptions(data.id)
end
setValueColor = function(info, r, g, b, a)
for id, reference in pairs(conditions[i].changes[j].references) do
local auraData = WeakAuras.GetData(id);
@@ -332,7 +376,11 @@ local function addControlsForChange(args, order, data, conditionVariable, totalA
conditions[i].changes[j].value[4] = a;
WeakAuras.ClearAndUpdateOptions(data.id)
end
setValueTable = function(info, v)
conditions[i].changes[j].value = CopyTable(v)
WeakAuras.Add(data)
WeakAuras.ClearAndUpdateOptions(data.id)
end
setValueComplex = function(property)
return function(info, v)
for id, reference in pairs(conditions[i].changes[j].references) do
@@ -531,21 +579,92 @@ local function addControlsForChange(args, order, data, conditionVariable, totalA
set = setValueColor
}
order = order + 1;
elseif (propertyType == "list") then
elseif (propertyType == "list" or property == "progressSource") then
local values = property and allProperties.propertyMap[property] and allProperties.propertyMap[property].values;
args["condition" .. i .. "value" .. j] = {
type = "select",
width = WeakAuras.normalWidth,
values = values,
name = blueIfNoValue(data, conditions[i].changes[j], "value", L["Differences"]),
desc = descIfNoValue(data, conditions[i].changes[j], "value", propertyType, values),
name = blueIfNoValue(data, conditions[i].changes[j], "value", L["Differences"], ""),
desc = descIfNoValue(data, conditions[i].changes[j], "value", propertyType, values),
order = order,
get = function()
return conditions[i].changes[j].value;
end,
set = setValue
set = setValue,
}
order = order + 1;
order = order + 1
if propertyType == "progressSource" then
args["condition" .. i .. "value" .. j].control = "WeakAurasTwoColumnDropdown"
args["condition" .. i .. "value" .. j].set = setValueTable
args["condition" .. i .. "value" .. j].get = function()
local v = conditions[i].changes[j].value
return OptionsPrivate.Private.GetProgressValueConstant(v)
end
args["condition" .. i .. "progressSourceWarning" .. j] = {
type = "description",
width = WeakAuras.doubleWidth,
name = L["Note: This progress source does not provide a total value/duration. A total value/duration must be set via \"Set Maximum Progress\""],
order = order,
hidden = function()
local v = conditions[i].changes[j].value
local progressSource = OptionsPrivate.Private.AddProgressSourceMetaData(data, v)
-- Auto progress, Manual Progress or the progress source has a total property
if progressSource[2] == "auto" or progressSource[1] == 0 or progressSource[4] ~= nil then
return true
end
return false
end
}
order = order + 1
local function hiddenManual()
local v = conditions[i].changes[j].value
local progressSource = OptionsPrivate.Private.AddProgressSourceMetaData(data, v)
if progressSource[1] == 0 then
return false
end
return true
end
args["condition" .. i .. "progressSoruceManualValue" .. j] = {
type = "range",
control = "WeakAurasSpinBox",
width = WeakAuras.normalWidth,
name = L["Value"],
order = order,
min = 0,
softMax = 100,
bigStep = 1,
hidden = hiddenManual,
get = function()
local v = conditions[i].changes[j].value
return v and type(v[3]) == "number" and v[3] or 0
end,
set = setValueComplex(3)
}
order = order + 1
args["condition" .. i .. "progressSoruceManualTotal" .. j] = {
type = "range",
control = "WeakAurasSpinBox",
width = WeakAuras.normalWidth,
name = L["Total"],
order = order,
min = 0,
softMax = 100,
bigStep = 1,
hidden = hiddenManual,
get = function()
local v = conditions[i].changes[j].value
return v and type(v[4]) == "number" and v[4] or 100
end,
set = setValueComplex(4)
}
order = order + 1
end
elseif (propertyType == "sound") then
args["condition" .. i .. "value" .. j .. "sound_type"] = {
type = "select",
@@ -2455,7 +2574,7 @@ local function buildAllPotentialProperties(data, category)
allProperties.propertyMap[k].type = "incompatible";
end
if (allProperties.propertyMap[k].type == "list") then
if (allProperties.propertyMap[k].type == "list" or allProperties.propertyMap[k].type == "progressSource" ) then
-- Merge value lists
for key, value in pairs(v.values) do
if (allProperties.propertyMap[k].values[key] == nil) then