From 7b27ca3ed603f55da1f7504562a962eaed198153 Mon Sep 17 00:00:00 2001 From: Casey Raethke Date: Wed, 6 Nov 2024 21:02:27 -0600 Subject: [PATCH] Address LuaLS diagnostics --- .pkgmeta | 1 + LanguageServerOverrides.lua | 14 +++++++++++ RatingBuster.lua | 22 ++++++++++------- libs/StatLogic/StatLogic.lua | 43 +++++++++++++++------------------- libs/StatLogic/TBC_Logic.lua | 10 -------- libs/StatLogic/Wrath_Logic.lua | 12 ---------- 6 files changed, 48 insertions(+), 54 deletions(-) create mode 100644 LanguageServerOverrides.lua diff --git a/.pkgmeta b/.pkgmeta index 7d14862..65c993d 100644 --- a/.pkgmeta +++ b/.pkgmeta @@ -44,6 +44,7 @@ ignore: - ./*.txt - *.jpg - scripts + - LanguageServerOverrides.lua - **/libs/**/*.rockspec - **/libs/**/changelog.* - **/libs/**/CHANGELOG.* diff --git a/LanguageServerOverrides.lua b/LanguageServerOverrides.lua new file mode 100644 index 0000000..2dcce02 --- /dev/null +++ b/LanguageServerOverrides.lua @@ -0,0 +1,14 @@ +---@meta + +---@class ClassicGameTooltip : GameTooltip +local ClassicGameTooltip = {} + +---@return integer +function ClassicGameTooltip:NumLines() end + +---@return Frame? +function ClassicGameTooltip:GetOwner() end + +---@param school 1|2|3|4|5|6|7 +---@return number +function GetSpellCritChance(school) end \ No newline at end of file diff --git a/RatingBuster.lua b/RatingBuster.lua index 711a491..c0ed18b 100644 --- a/RatingBuster.lua +++ b/RatingBuster.lua @@ -1116,13 +1116,17 @@ local options = { order = 5, get = function(info) local db = RatingBuster.db:GetNamespace("AlwaysBuffed") - return db.profile[info[#info]] + if db then + return db.profile[info[#info]] + end end, set = function(info, v) local db = RatingBuster.db:GetNamespace("AlwaysBuffed") - db.profile[info[#info]] = v - RatingBuster:ClearCache() - StatLogic:InvalidateEvent("UNIT_AURA", "player") + if db then + db.profile[info[#info]] = v + RatingBuster:ClearCache() + StatLogic:InvalidateEvent("UNIT_AURA", "player") + end end, args = { description = { @@ -1683,8 +1687,9 @@ do if not StatLogic.StatModIgnoresAlwaysBuffed[modName] then for _, mod in ipairs(mods) do if mod.aura and (not mod.rune or showRunes) then - local name, _, icon = GetSpellInfo(mod.aura) - if name then + local spellInfo = C_Spell.GetSpellInfo(mod.aura) + if spellInfo then + local name, icon = spellInfo.name, spellInfo.iconID local option = { type = 'toggle', name = "|T"..icon..":25:25:-2:0|t"..name, @@ -1695,7 +1700,7 @@ do -- If it's a spell the player knows, use the highest rank for the description local spellId = mod.spellid or mod.known or mod.aura if IsPlayerSpell(spellId) then - spellId = select(7,GetSpellInfo(name)) or spellId + spellId = C_Spell.GetSpellIDForSpellIdentifier(name) or spellId end local spell = Spell:CreateFromSpellID(spellId) spell:ContinueOnSpellLoad(function() @@ -2022,6 +2027,7 @@ local scanningTooltipOwners = { ["UIParent"] = true, } +---@param tooltip ClassicGameTooltip function RatingBuster.ProcessTooltip(tooltip) -- Do nothing if the tooltip is being used as a hidden scanning tooltip if tooltip:GetAnchorType() == "ANCHOR_NONE" and (not tooltip:GetOwner() or scanningTooltipOwners[tooltip:GetOwner():GetName()]) then @@ -4010,7 +4016,7 @@ function RatingBuster:PerformanceProfile() for i = INVSLOT_FIRST_EQUIPPED, INVSLOT_LAST_EQUIPPED do GameTooltip:SetOwner(UIParent, "ANCHOR_PRESERVE") GameTooltip:SetInventoryItem("player", i) - self.ProcessTooltip(GameTooltip) + self.ProcessTooltip(GameTooltip --[[@as ClassicGameTooltip]]) GameTooltip:Hide() end diff --git a/libs/StatLogic/StatLogic.lua b/libs/StatLogic/StatLogic.lua index eba5d20..92b0b1c 100644 --- a/libs/StatLogic/StatLogic.lua +++ b/libs/StatLogic/StatLogic.lua @@ -18,7 +18,7 @@ function StatLogic:argCheck(argument, number, ...) end -- Tooltip with syntactic sugar ----@class StatLogicTooltip : GameTooltip +---@class StatLogicTooltip : ClassicGameTooltip local tip = CreateFrame("GameTooltip", "StatLogicTooltip", nil, "GameTooltipTemplate") --[[@as GameTooltip]] tip:SetOwner(WorldFrame, "ANCHOR_NONE") @@ -77,6 +77,7 @@ local pairs = pairs local ipairs = ipairs local type = type local GetInventoryItemLink = GetInventoryItemLink +local GetSpellName = C_Spell.GetSpellName local IsUsableSpell = IsUsableSpell local UnitStat = UnitStat local GetShapeshiftForm = GetShapeshiftForm @@ -89,7 +90,7 @@ local tocversion = select(4, GetBuildInfo()) --------------- -- metatable for stat tables local statTableMetatable = { - __index = function(t, k) + __index = function(_, k) if k ~= "subclassID" then return 0 end @@ -163,8 +164,9 @@ end ---@class StatTable ---@field link string ----@field numLines number +---@field numLines integer ---@field inventoryType string +---@field subclassID Enum.ItemWeaponSubclass? ---@field [Stat] number -- New table @@ -720,7 +722,7 @@ do for _, mods in pairs(modList) do for _, mod in ipairs(mods) do if mod.aura then -- if we got a buff - local name = GetSpellInfo(mod.aura) + local name = GetSpellName(mod.aura) if name then local aura = {} if not mod.tab and mod.rank then @@ -966,7 +968,7 @@ addon.StatModValidators = { }, aura = { validate = function(case, statModName) - return not not StatLogic:GetAuraInfo(GetSpellInfo(case.aura), StatLogic.StatModIgnoresAlwaysBuffed[statModName]) + return not not StatLogic:GetAuraInfo(GetSpellName(case.aura), StatLogic.StatModIgnoresAlwaysBuffed[statModName]) end, events = { ["UNIT_AURA"] = "player", @@ -1098,7 +1100,7 @@ addon.StatModValidators = { subclassID = select(7, C_Item.GetItemInfoInstant(weapon)) end end - return subclassID and case.weapon[subclassID] + return subclassID and case.weapon[subclassID] or false end, events = { ["UNIT_INVENTORY_CHANGED"] = "player", @@ -1296,11 +1298,11 @@ do newValue = case.value end elseif case.aura and case.rank then - local aura = StatLogic:GetAuraInfo(GetSpellInfo(case.aura)) + local aura = StatLogic:GetAuraInfo(GetSpellName(case.aura)) local rank = aura.rank newValue = case.rank[rank] elseif case.aura and case.stack then - local aura = StatLogic:GetAuraInfo(GetSpellInfo(case.aura)) + local aura = StatLogic:GetAuraInfo(GetSpellName(case.aura)) newValue = case.stack * aura.stacks elseif case.regen then newValue = case.regen(level) @@ -1309,7 +1311,7 @@ do elseif case.level then newValue = case.level[level] elseif case.tooltip then - local aura = StatLogic:GetAuraInfo(GetSpellInfo(case.aura)) + local aura = StatLogic:GetAuraInfo(GetSpellName(case.aura)) newValue = aura.tooltip end @@ -1467,9 +1469,9 @@ end local function GetTotalWeaponSkill(unit) if addon.class == "DRUID" and ( - StatLogic:GetAuraInfo(GetSpellInfo(768), true) - or StatLogic:GetAuraInfo(GetSpellInfo(5487), true) - or StatLogic:GetAuraInfo(GetSpellInfo(9634), true) + StatLogic:GetAuraInfo(GetSpellName(768), true) + or StatLogic:GetAuraInfo(GetSpellName(5487), true) + or StatLogic:GetAuraInfo(GetSpellName(9634), true) ) then return UnitLevel("player") * 5 else @@ -2106,7 +2108,7 @@ function StatLogic:GetDiffID(item, ignoreEnchant, ignoreGems, ignoreExtraSockets if inventoryType == "INVTYPE_WEAPON" then linkDiff1 = GetInventoryItemLink("player", 16) or "NOITEM" -- If player can Dual Wield, calculate offhand difference - if IsUsableSpell(GetSpellInfo(674)) then -- ["Dual Wield"] + if IsUsableSpell(GetSpellName(674)) then -- ["Dual Wield"] local _, _, _, _, _, _, _, _, eqItemType = C_Item.GetItemInfo(linkDiff1) -- If 2h is equipped, copy diff1 to diff2 if eqItemType == "INVTYPE_2HWEAPON" and not HasTitansGrip() then @@ -2300,7 +2302,7 @@ if GetCurrentRegion() == 1 or GetCurrentRegion() == 72 and GetLocale() == "enUS" end) local sending = false - local function cleanUp(delay) + local function cleanUp() -- Wait to see if whispers failed to send C_Timer.After(2, function() if not failure then @@ -2316,17 +2318,10 @@ if GetCurrentRegion() == 1 or GetCurrentRegion() == 72 and GetLocale() == "enUS" local function SendStoredData() if failure or sending or UnitName("player") == target then return end local data = RatingBuster.conversion_data.global - local send = false - for i = 0, 4 do - if data[i] then - send = true - break - end - end - if send then + if data and next(data) then sending = true local serialized = LibStub("LibSerialize"):Serialize(data) - local encoded = codec:Encode(serialized) + local encoded = codec and codec:Encode(serialized) or "" LibStub("AceComm-3.0"):SendCommMessage(prefix, encoded, "WHISPER", target, "BULK", cleanUp, true) end end @@ -2386,7 +2381,7 @@ if GetCurrentRegion() == 1 or GetCurrentRegion() == 72 and GetLocale() == "enUS" --@debug@ local receive = {} function receive:OnCommReceived(_, message) - local decoded = codec:Decode(message) + local decoded = codec and codec:Decode(message) if not decoded then return end local success, data = LibStub("LibSerialize"):Deserialize(decoded) if not success then return end diff --git a/libs/StatLogic/TBC_Logic.lua b/libs/StatLogic/TBC_Logic.lua index 05f88e2..b633132 100644 --- a/libs/StatLogic/TBC_Logic.lua +++ b/libs/StatLogic/TBC_Logic.lua @@ -1341,11 +1341,6 @@ elseif addon.class == "WARLOCK" then }, }, ["MOD_PET_STA"] = { - -- Blessing of Kings - --{ - -- ["value"] = 0.1, - -- ["condition"] = "UnitBuff('pet', GetSpellInfo(20217)) or UnitBuff('pet', GetSpellInfo(25898))", - --}, -- Warlock: Fel Stamina (Rank 3) - 2,9 -- Increases the Stamina of your Imp, Voidwalker, Succubus, and Felhunter and Felguard by 5%/10%/15% and increases your maximum health and mana by 1%/2%/3%. { @@ -1377,11 +1372,6 @@ elseif addon.class == "WARLOCK" then }, }, ["MOD_PET_INT"] = { - -- Blessing of Kings - --{ - -- ["value"] = 0.1, - -- ["condition"] = "UnitBuff('pet', GetSpellInfo(20217)) or UnitBuff('pet', GetSpellInfo(25898))", - --}, -- Warlock: Fel Intellect (Rank 3) - 2,6 -- Increases the Stamina and Intellect of your Imp, Voidwalker, Succubus, Felhunter and Felguard by 15% and increases your maximum health and mana by 1%/2%/3%. { diff --git a/libs/StatLogic/Wrath_Logic.lua b/libs/StatLogic/Wrath_Logic.lua index 64ea4b7..563d321 100644 --- a/libs/StatLogic/Wrath_Logic.lua +++ b/libs/StatLogic/Wrath_Logic.lua @@ -2699,13 +2699,6 @@ elseif addon.class == "WARLOCK" then }, }, ["MOD_PET_STA"] = { - -- 3.3.0 Imp stam total 233: pet base 118, player base 90, pet sta from player sta 0.75, pet kings 1.1, fel vitality 1.15 - -- /dump floor((118+floor(90*0.75))*1.1)*1.05 = 233.45 match - -- /dump (118+floor(90*0.75))*1.1*1.05 = 224.025 wrong - --{ - -- ["value"] = 0.1, -- BoK, BoSanc - -- ["condition"] = "UnitBuff('pet', GetSpellInfo(20217)) or UnitBuff('pet', GetSpellInfo(25898)) or UnitBuff('pet', GetSpellInfo(20911)) or UnitBuff('pet', GetSpellInfo(25899))", - --}, -- Warlock: Fel Vitality (Rank 3) - 2,7 -- Increases the Stamina and Intellect of your Imp, Voidwalker, Succubus, Felhunter and Felguard by 15% and increases your maximum health and mana by 1%/2%/3%. { @@ -2737,11 +2730,6 @@ elseif addon.class == "WARLOCK" then }, }, ["MOD_PET_INT"] = { - -- Blessings on pet - --{ - -- ["value"] = 0.1, - -- ["condition"] = "UnitBuff('pet', GetSpellInfo(20217)) or UnitBuff('pet', GetSpellInfo(25898)) or UnitBuff('pet', GetSpellInfo(20911)) or UnitBuff('pet', GetSpellInfo(25899))", - --}, -- Warlock: Fel Vitality (Rank 3) - 2,7 -- Increases the Stamina and Intellect of your Imp, Voidwalker, Succubus, Felhunter and Felguard by 15% and increases your maximum health and mana by 1%/2%/3%. {