diff --git a/WeakAuras/Modernize.lua b/WeakAuras/Modernize.lua index 5f1038d..7eab34a 100644 --- a/WeakAuras/Modernize.lua +++ b/WeakAuras/Modernize.lua @@ -4,40 +4,40 @@ local L = WeakAuras.L -- Takes as input a table of display data and attempts to update it to be compatible with the current version function Private.Modernize(data) - if (not data.internalVersion or data.internalVersion < 2) then + if not data.internalVersion or data.internalVersion < 2 then WeakAuras.prettyPrint(string.format("Data for '%s' is too old, can't modernize.", data.id)) - data.internalVersion = 2; + data.internalVersion = 2 end -- Version 3 was introduced April 2018 in Legion - if (data.internalVersion < 3) then - if (data.parent) then - local parentData = WeakAuras.GetData(data.parent); - if(parentData and parentData.regionType == "dynamicgroup") then + if data.internalVersion < 3 then + if data.parent then + local parentData = WeakAuras.GetData(data.parent) + if parentData and parentData.regionType == "dynamicgroup" then -- Version 3 allowed for offsets for dynamic groups, before that they were ignored -- Thus reset them in the V2 to V3 upgrade - data.xOffset = 0; - data.yOffset = 0; + data.xOffset = 0 + data.yOffset = 0 end end end -- Version 4 was introduced July 2018 in BfA - if (data.internalVersion < 4) then - if (data.conditions) then + if data.internalVersion < 4 then + if data.conditions then for conditionIndex, condition in ipairs(data.conditions) do - if (condition.check) then + if condition.check then local triggernum = condition.check.trigger; - if (triggernum) then - local trigger; - if (triggernum == 0) then - trigger = data.trigger; - elseif(data.additional_triggers and data.additional_triggers[triggernum]) then - trigger = data.additional_triggers[triggernum].trigger; + if triggernum then + local trigger + if triggernum == 0 then + trigger = data.trigger + elseif data.additional_triggers and data.additional_triggers[triggernum] then + trigger = data.additional_triggers[triggernum].trigger end - if (trigger and trigger.event == "Cooldown Progress (Spell)") then - if (condition.check.variable == "stacks") then - condition.check.variable = "charges"; + if trigger and trigger.event == "Cooldown Progress (Spell)" then + if condition.check.variable == "stacks" then + condition.check.variable = "charges" end end end @@ -67,7 +67,7 @@ function Private.Modernize(data) if data.internalVersion < 6 then if data.triggers then for triggernum, triggerData in ipairs(data.triggers) do - local trigger = triggerData.trigger; + local trigger = triggerData.trigger if trigger and trigger.type == "aura" then if trigger.showOn == "showOnMissing" then trigger.buffShowOn = "showOnMissing" @@ -88,9 +88,7 @@ function Private.Modernize(data) -- Version 7 was introduced September 1 2018 in BfA -- Triggers were cleaned up into a 1-indexed array - if data.internalVersion < 7 then - -- migrate trigger data data.triggers = data.additional_triggers or {} tinsert(data.triggers, 1, { @@ -113,7 +111,9 @@ function Private.Modernize(data) data.disjunctive = nil -- migrate condition trigger references local function recurseRepairChecks(checks) - if not checks then return end + if not checks then + return + end for _, check in pairs(checks) do if check.trigger and check.trigger >= 0 then check.trigger = check.trigger + 1 @@ -137,11 +137,11 @@ function Private.Modernize(data) local function repairCheck(check) if check and check.variable == "buffed" then local trigger = check.trigger and data.triggers[check.trigger] and data.triggers[check.trigger].trigger; - if (trigger) then - if(trigger.buffShowOn == "showOnActive") then - check.variable = "show"; - elseif (trigger.buffShowOn == "showOnMissing") then - check.variable = "show"; + if trigger then + if trigger.buffShowOn == "showOnActive" then + check.variable = "show" + elseif trigger.buffShowOn == "showOnMissing" then + check.variable = "show" check.value = check.value == 0 and 1 or 0; end end @@ -149,15 +149,17 @@ function Private.Modernize(data) end local function recurseRepairChecks(checks) - if not checks then return end + if not checks then + return + end for _, check in pairs(checks) do - repairCheck(check); - recurseRepairChecks(check.checks); + repairCheck(check) + recurseRepairChecks(check.checks) end end for _, condition in pairs(data.conditions) do - repairCheck(condition.check); - recurseRepairChecks(condition.check.checks); + repairCheck(condition.check) + recurseRepairChecks(condition.check.checks) end end @@ -182,7 +184,7 @@ function Private.Modernize(data) local selfPoints = { default = "CENTER", RIGHT = function(data) - if data.align == "LEFT" then + if data.align == "LEFT" then return "TOPLEFT" elseif data.align == "RIGHT" then return "BOTTOMLEFT" @@ -191,7 +193,7 @@ function Private.Modernize(data) end end, LEFT = function(data) - if data.align == "LEFT" then + if data.align == "LEFT" then return "TOPRIGHT" elseif data.align == "RIGHT" then return "BOTTOMRIGHT" @@ -250,11 +252,12 @@ function Private.Modernize(data) if data.internalVersion < 14 then if data.triggers then for triggerId, triggerData in pairs(data.triggers) do - if type(triggerData) == "table" - and triggerData.trigger - and triggerData.trigger.debuffClass - and type(triggerData.trigger.debuffClass) == "string" - and triggerData.trigger.debuffClass ~= "" + if + type(triggerData) == "table" + and triggerData.trigger + and triggerData.trigger.debuffClass + and type(triggerData.trigger.debuffClass) == "string" + and triggerData.trigger.debuffClass ~= "" then local idx = triggerData.trigger.debuffClass data.triggers[triggerId].trigger.debuffClass = { [idx] = true } @@ -324,7 +327,7 @@ function Private.Modernize(data) text_anchorPoint = convertPoint(data.text1Containment, data.text1Point), anchorXOffset = 0, anchorYOffset = 0, - text_shadowColor = { 0, 0, 0, 1}, + text_shadowColor = { 0, 0, 0, 1 }, text_shadowXOffset = 0, text_shadowYOffset = 0, } @@ -343,7 +346,7 @@ function Private.Modernize(data) text_anchorPoint = convertPoint(data.text2Containment, data.text2Point), anchorXOffset = 0, anchorYOffset = 0, - text_shadowColor = { 0, 0, 0, 1}, + text_shadowColor = { 0, 0, 0, 1 }, text_shadowXOffset = 0, text_shadowYOffset = 0, } @@ -370,16 +373,16 @@ function Private.Modernize(data) text1Color = "sub.1.text_color", text1FontSize = "sub.1.text_fontSize", text2Color = "sub.2.text_color", - text2FontSize = "sub.2.text_fontSize" + text2FontSize = "sub.2.text_fontSize", } data.subRegions = data.subRegions or {} tinsert(data.subRegions, text1) - if (usetext2) then + if usetext2 then tinsert(data.subRegions, text2) end - if (data.conditions) then + if data.conditions then for conditionIndex, condition in ipairs(data.conditions) do for changeIndex, change in ipairs(condition.changes) do if propertyRenames[change.property] then @@ -398,7 +401,7 @@ function Private.Modernize(data) HORIZONTAL_INVERSE = { "INNER_LEFT", "INNER_RIGHT" }, HORIZONTAL = { "INNER_RIGHT", "INNER_LEFT" }, VERTICAL_INVERSE = { "INNER_BOTTOM", "INNER_TOP" }, - VERTICAL = {"INNER_TOP", "INNER_BOTTOM"} + VERTICAL = { "INNER_TOP", "INNER_BOTTOM" }, } local positions = orientationToPostion[data.orientation] or { "INNER_LEFT", "INNER_RIGHT" } @@ -415,10 +418,10 @@ function Private.Modernize(data) text_anchorPoint = positions[1], anchorXOffset = 0, anchorYOffset = 0, - text_shadowColor = { 0, 0, 0, 1}, + text_shadowColor = { 0, 0, 0, 1 }, text_shadowXOffset = 1, text_shadowYOffset = -1, - rotateText = data.rotateText + rotateText = data.rotateText, } local text2 = { @@ -433,10 +436,10 @@ function Private.Modernize(data) text_anchorPoint = positions[2], anchorXOffset = 0, anchorYOffset = 0, - text_shadowColor = { 0, 0, 0, 1}, + text_shadowColor = { 0, 0, 0, 1} , text_shadowXOffset = 1, text_shadowYOffset = -1, - rotateText = data.rotateText + rotateText = data.rotateText, } local text3 = { @@ -451,10 +454,10 @@ function Private.Modernize(data) text_anchorPoint = "ICON_CENTER", anchorXOffset = 0, anchorYOffset = 0, - text_shadowColor = { 0, 0, 0, 1}, + text_shadowColor = { 0, 0, 0, 1 }, text_shadowXOffset = 1, text_shadowYOffset = -1, - rotateText = data.rotateText + rotateText = data.rotateText, } data.timer = nil @@ -490,7 +493,7 @@ function Private.Modernize(data) tinsert(data.subRegions, text2) tinsert(data.subRegions, text3) - if (data.conditions) then + if data.conditions then for conditionIndex, condition in ipairs(data.conditions) do for changeIndex, change in ipairs(condition.changes) do if propertyRenames[change.property] then @@ -499,7 +502,6 @@ function Private.Modernize(data) end end end - end end @@ -541,10 +543,10 @@ function Private.Modernize(data) end local propertyRenames = { - borderColor = "sub.".. #data.subRegions..".border_color", + borderColor = "sub." .. #data.subRegions .. ".border_color", } - if (data.conditions) then + if data.conditions then for conditionIndex, condition in ipairs(data.conditions) do for changeIndex, change in ipairs(condition.changes) do if propertyRenames[change.property] then @@ -568,7 +570,7 @@ function Private.Modernize(data) if value then trigger.form = { multi = { [value] = true } } else - trigger.form = { multi = { } } + trigger.form = { multi = {} } end elseif trigger.use_form then trigger.form = { single = value } @@ -604,7 +606,7 @@ function Private.Modernize(data) data.subRegions = data.subRegions or {} -- Need to check if glow is needed - local prefix = "sub.".. #data.subRegions + 1 .. "." + local prefix = "sub." .. #data.subRegions + 1 .. "." -- For Conditions local propertyRenames = { glow = prefix .. "glow", @@ -622,7 +624,7 @@ function Private.Modernize(data) } local needsGlow = data.glow - if (not needsGlow and data.conditions) then + if not needsGlow and data.conditions then for conditionIndex, condition in ipairs(data.conditions) do for changeIndex, change in ipairs(condition.changes) do if propertyRenames[change.property] then @@ -666,7 +668,7 @@ function Private.Modernize(data) data.glowXOffset = nil data.glowYOffset = nil - if (data.conditions) then + if data.conditions then for conditionIndex, condition in ipairs(data.conditions) do for changeIndex, change in ipairs(condition.changes) do if propertyRenames[change.property] then @@ -704,16 +706,10 @@ function Private.Modernize(data) if data.internalVersion < 29 then if data.actions then - if data.actions.start - and data.actions.start.do_glow - and data.actions.start.glow_type == nil - then + if data.actions.start and data.actions.start.do_glow and data.actions.start.glow_type == nil then data.actions.start.glow_type = "buttonOverlay" end - if data.actions.finish - and data.actions.finish.do_glow - and data.actions.finish.glow_type == nil - then + if data.actions.finish and data.actions.finish.do_glow and data.actions.finish.glow_type == nil then data.actions.finish.glow_type = "buttonOverlay" end end @@ -741,8 +737,8 @@ function Private.Modernize(data) sym = sym or symbol if sym == "p" or sym == "t" then data["displayText_format_" .. symbol .. "_format"] = "timed" - data["displayText_format_" .. symbol .. "_time_precision"], data["displayText_format_" .. symbol .. "_time_dynamic"] - = convertLegacyPrecision(sym == "p" and progressPrecision or totalPrecision) + data["displayText_format_" .. symbol .. "_time_precision"], data["displayText_format_" .. symbol .. "_time_dynamic"] = + convertLegacyPrecision(sym == "p" and progressPrecision or totalPrecision) end end seenSymbols[symbol] = symbol @@ -759,8 +755,8 @@ function Private.Modernize(data) sym = sym or symbol if sym == "p" or sym == "t" then subRegionData["text_text_format_" .. symbol .. "_format"] = "timed" - subRegionData["text_text_format_" .. symbol .. "_time_precision"], subRegionData["text_text_format_" .. symbol .. "_time_dynamic"] - = convertLegacyPrecision(sym == "p" and progressPrecision or totalPrecision) + subRegionData["text_text_format_" .. symbol .. "_time_precision"], subRegionData["text_text_format_" .. symbol .. "_time_dynamic"] = + convertLegacyPrecision(sym == "p" and progressPrecision or totalPrecision) end end seenSymbols[symbol] = symbol @@ -770,7 +766,7 @@ function Private.Modernize(data) end if data.actions then - for _, when in ipairs{ "start", "finish" } do + for _, when in ipairs({ "start", "finish" }) do if data.actions[when] then local seenSymbols = {} Private.ParseTextStr(data.actions[when].message, function(symbol) @@ -779,8 +775,8 @@ function Private.Modernize(data) sym = sym or symbol if sym == "p" or sym == "t" then data.actions[when]["message_format_" .. symbol .. "_format"] = "timed" - data.actions[when]["message_format_" .. symbol .. "_time_precision"], data.actions[when]["message_format_" .. symbol .. "_time_dynamic"] - = convertLegacyPrecision(sym == "p" and progressPrecision or totalPrecision) + data.actions[when]["message_format_" .. symbol .. "_time_precision"], data.actions[when]["message_format_" .. symbol .. "_time_dynamic"] = + convertLegacyPrecision(sym == "p" and progressPrecision or totalPrecision) end end seenSymbols[symbol] = symbol @@ -800,8 +796,8 @@ function Private.Modernize(data) sym = sym or symbol if sym == "p" or sym == "t" then change.value["message_format_" .. symbol .. "_format"] = "timed" - change.value["message_format_" .. symbol .. "_time_precision"], change.value["message_format_" .. symbol .. "_time_dynamic"] - = convertLegacyPrecision(sym == "p" and progressPrecision or totalPrecision) + change.value["message_format_" .. symbol .. "_time_precision"], change.value["message_format_" .. symbol .. "_time_dynamic"] = + convertLegacyPrecision(sym == "p" and progressPrecision or totalPrecision) end end seenSymbols[symbol] = symbol @@ -886,15 +882,17 @@ function Private.Modernize(data) end local function recurseRepairChecks(replacements, checks) - if not checks then return end + if not checks then + return + end for _, check in pairs(checks) do - repairCheck(replacements, check); - recurseRepairChecks(replacements, check.checks); + repairCheck(replacements, check) + recurseRepairChecks(replacements, check.checks) end end for _, condition in pairs(data.conditions) do - repairCheck(replacements, condition.check); - recurseRepairChecks(replacements, condition.check.checks); + repairCheck(replacements, condition.check) + recurseRepairChecks(replacements, condition.check.checks) end end end @@ -923,13 +921,11 @@ function Private.Modernize(data) triggerData.trigger.blackauraspellids = nil end end - end -- Introduced in July 2020 in Shadowlands if data.internalVersion < 34 then - if data.regionType == 'dynamicgroup' - and (data.grow == "CIRCLE" or data.grow == "COUNTERCIRCLE") then + if data.regionType == "dynamicgroup" and (data.grow == "CIRCLE" or data.grow == "COUNTERCIRCLE") then if data.arcLength == 360 then data.fullCircle = true else @@ -943,7 +939,7 @@ function Private.Modernize(data) end if data.internalVersion < 39 then - if data.regionType == 'icon' or data.regionType == 'aurabar' then + if data.regionType == "icon" or data.regionType == "aurabar" then if data.auto then data.iconSource = -1 else @@ -954,7 +950,7 @@ function Private.Modernize(data) if data.internalVersion < 40 then data.information = data.information or {} - if data.regionType == 'group' then + if data.regionType == "group" then data.information.groupOffset = true end data.information.ignoreOptionsEventErrors = data.ignoreOptionsEventErrors @@ -1067,7 +1063,7 @@ function Private.Modernize(data) end if data.actions then - for _, when in ipairs{ "start", "finish" } do + for _, when in ipairs({ "start", "finish" }) do if data.actions[when] then fixUp(data.actions[when], "message_format_") end @@ -1085,7 +1081,7 @@ function Private.Modernize(data) end end - if (data.internalVersion < 49) then + if data.internalVersion < 49 then if not data.regionType:match("group") then data.subRegions = data.subRegions or {} -- rename aurabar_bar into subforeground, and subbarmodel into submodel @@ -1113,9 +1109,9 @@ function Private.Modernize(data) local prefix, property = change.property:match("(sub%.%d+%.)(.*)") if prefix and property then if property == "bar_model_visible" then - change.property = prefix.."model_visible" + change.property = prefix .. "model_visible" elseif property == "bar_model_alpha" then - change.property = prefix.."model_alpha" + change.property = prefix .. "model_alpha" end end end @@ -1126,7 +1122,7 @@ function Private.Modernize(data) end end - if (data.internalVersion == 49) then + if data.internalVersion == 49 then -- Version 49 was a dud and contained a broken validation. Try to salvage the data, as -- best as we can. local broken = false @@ -1142,7 +1138,7 @@ function Private.Modernize(data) local subRegionIndex, property = change.property:match("^sub%.(%d+)%.(.*)") if subRegionIndex and property then broken = true - for _, offset in ipairs({-1, 1}) do + for _, offset in ipairs({ -1, 1 }) do local newProperty = "sub." .. subRegionIndex + offset .. "." .. property if properties[newProperty] then change.property = newProperty @@ -1160,7 +1156,7 @@ function Private.Modernize(data) end end - if (data.internalVersion < 51) then + if data.internalVersion < 51 then for _, triggerData in ipairs(data.triggers) do if triggerData.trigger.event == "Threat Situation" then triggerData.trigger.unit = triggerData.trigger.threatUnit @@ -1171,7 +1167,7 @@ function Private.Modernize(data) end end - if (data.internalVersion < 52) then + if data.internalVersion < 52 then local function matchTarget(input) return input == "target" or input == "'target'" or input == "\"target\"" or input == "%t" or input == "'%t'" or input == "\"%t\"" end @@ -1189,18 +1185,12 @@ function Private.Modernize(data) end end - if data.actions.start.do_message - and data.actions.start.message_type == "WHISPER" - and matchTarget(data.actions.start.message_dest) - then + if data.actions.start.do_message and data.actions.start.message_type == "WHISPER" and matchTarget(data.actions.start.message_dest) then data.actions.start.message_dest = "target" data.actions.start.message_dest_isunit = true end - if data.actions.finish.do_message - and data.actions.finish.message_type == "WHISPER" - and matchTarget(data.actions.finish.message_dest) - then + if data.actions.finish.do_message and data.actions.finish.message_type == "WHISPER" and matchTarget(data.actions.finish.message_dest) then data.actions.finish.message_dest = "target" data.actions.finish.message_dest_isunit = true end @@ -1404,5 +1394,5 @@ function Private.Modernize(data) end end - data.internalVersion = max(data.internalVersion or 0, WeakAuras.InternalVersion()); + data.internalVersion = max(data.internalVersion or 0, WeakAuras.InternalVersion()) end