From 2c788797c8eea58b2ad7878c0f20854f352d774a Mon Sep 17 00:00:00 2001 From: Rob Anderson Date: Tue, 26 Nov 2024 17:03:22 -0700 Subject: [PATCH] Fix lua error, better support Lifetime honor --- Features/Currency.lua | 58 ++++++++++--------- GameTesting/IntegrationTest.lua | 23 +------- GameTesting/TestMode.lua | 22 ++----- .../LootDisplayRow/LootDisplayRow.lua | 2 + spec/Features/Currency_spec.lua | 32 +++++++--- spec/common_stubs.lua | 6 ++ 6 files changed, 70 insertions(+), 73 deletions(-) diff --git a/Features/Currency.lua b/Features/Currency.lua index 9a9478b..73ea131 100644 --- a/Features/Currency.lua +++ b/Features/Currency.lua @@ -15,13 +15,30 @@ function Currency.Element:new(...) element.isLink = true - local t - element.key, t, element.icon, element.quantity, element.totalCount, element.quality, element.totalEarned, element.cappedQuantity = - ... + local currencyLink, currencyInfo, basicInfo = ... + + if not currencyLink or not currencyInfo or not basicInfo then + return + end + + element.key = currencyInfo.currencyID + element.icon = currencyInfo.iconFileID + element.quantity = basicInfo.displayAmount + element.totalCount = currencyInfo.quantity + element.quality = currencyInfo.quality + element.totalEarned = currencyInfo.totalEarned + element.cappedQuantity = currencyInfo.maxQuantity + + if element.key == Constants.CurrencyConsts.ACCOUNT_WIDE_HONOR_CURRENCY_ID then + element.totalCount = UnitHonorLevel("player") + element.cappedQuantity = UnitHonorMax("player") + element.totalEarned = UnitHonor("player") + currencyLink = currencyLink:gsub(currencyInfo.name, _G.LIFETIME_HONOR) + end element.textFn = function(existingQuantity, truncatedLink) if not truncatedLink then - return t + return currencyLink end return truncatedLink .. " x" .. ((existingQuantity or 0) + element.quantity) end @@ -36,13 +53,15 @@ function Currency.Element:new(...) numerator = element.totalCount percentage = element.totalCount / element.cappedQuantity end - local color - if percentage < 0.7 then - color = "|cFFFFFFFF" - elseif percentage >= 0.7 and percentage < 0.9 then - color = "|cFFFF9B00" - else - color = "|cFFFF0000" + local color = "|cFFFFFFFF" + if element.key ~= Constants.CurrencyConsts.ACCOUNT_WIDE_HONOR_CURRENCY_ID then + if percentage < 0.7 then + color = "|cFFFFFFFF" + elseif percentage >= 0.7 and percentage < 0.9 then + color = "|cFFFF9B00" + else + color = "|cFFFF0000" + end end return " " .. color .. numerator .. " / " .. element.cappedQuantity .. "|r" @@ -120,16 +139,7 @@ function Currency:Process(eventName, currencyType, quantityChange) self:fn(function() local basicInfo = C_CurrencyInfo.GetBasicCurrencyInfo(currencyType, quantityChange) - local e = self.Element:new( - info.currencyID, - C_CurrencyInfo.GetCurrencyLink(currencyType), - info.iconFileID, - basicInfo.displayAmount, - info.quantity, - info.quality, - info.totalEarned, - info.maxQuantity - ) + local e = self.Element:new(C_CurrencyInfo.GetCurrencyLink(currencyType), info, basicInfo) e:Show() end) end @@ -146,12 +156,6 @@ function Currency:PERKS_PROGRAM_CURRENCY_AWARDED(eventName, quantityChange) self:Process(eventName, currencyType, quantityChange) end --- Handle Lifetime Honor --- LIFETIME_HONOR --- Constants.CurrencyConsts.ACCOUNT_WIDE_HONOR_CURRENCY_ID --- print(UnitHonorLevel("player")) --- print(UnitHonor("player") .. "/" .. UnitHonorMax("player")) - hiddenCurrencies = { [2918] = true, [2919] = true, diff --git a/GameTesting/IntegrationTest.lua b/GameTesting/IntegrationTest.lua index 90827d2..1e8f0f8 100644 --- a/GameTesting/IntegrationTest.lua +++ b/GameTesting/IntegrationTest.lua @@ -92,27 +92,10 @@ local function runCurrencyIntegrationTest() local module = G_RLF.RLF:GetModule("Currency") local testObj = TestMode.testCurrencies[2] local amountLooted = 1 - local e = module.Element:new( - testObj.id, - testObj.link, - testObj.icon, - amountLooted, - testObj.quantity, - testObj.quality, - testObj.totalEarned, - testObj.maxQuantity - ) + testObj.basicInfo.displayAmount = amountLooted + local e = module.Element:new(testObj.link, testObj.info, testObj.basicInfo) runTestSafely(e.Show, "LootDisplay: Currency") - e = module.Element:new( - testObj.id, - testObj.link, - testObj.icon, - amountLooted, - testObj.quantity, - testObj.quality, - testObj.totalEarned, - testObj.maxQuantity - ) + e = module.Element:new(testObj.link, testObj.info, testObj.basicInfo) runTestSafely(e.Show, "LootDisplay: Currency Quantity Update") end diff --git a/GameTesting/TestMode.lua b/GameTesting/TestMode.lua index d143892..107fb94 100644 --- a/GameTesting/TestMode.lua +++ b/GameTesting/TestMode.lua @@ -83,13 +83,9 @@ local function initializeTestCurrencies() local basicInfo = C_CurrencyInfo.GetBasicCurrencyInfo(id, 100) if info and link and info.currencyID and info.iconFileID then table.insert(TestMode.testCurrencies, { - id = info.currencyID, link = link, - icon = info.iconFileID, - quantity = info.quantity, - quality = info.quality, - totalEarned = info.totalEarned, - maxQuantity = info.maxQuantity, + info = info, + basicInfo = basicInfo, }) end end @@ -153,8 +149,7 @@ function TestMode:GET_ITEM_INFO_RECEIVED(eventName, itemID, success) end end - G_RLF:ProfileFunction(getItem, "getItem")(itemID) - -- getItem(itemID) + getItem(itemID) if #self.testItems == #testItemIds and not anyPendingRequests() then allItemsInitialized = true @@ -210,16 +205,7 @@ local function generateRandomLoot() local currency = TestMode.testCurrencies[math.random(#TestMode.testCurrencies)] local amountLooted = math.random(1, 500) local module = G_RLF.RLF:GetModule("Currency") - local e = module.Element:new( - currency.id, - currency.link, - currency.icon, - amountLooted, - currency.quantity, - currency.quality, - currency.totalEarned, - currency.maxQuantity - ) + local e = module.Element:new(currency.link, currency.info, currency.basicInfo) e:Show() -- 10% chance to show reputation (least frequent) diff --git a/LootDisplay/LootDisplayFrame/LootDisplayRow/LootDisplayRow.lua b/LootDisplay/LootDisplayFrame/LootDisplayRow/LootDisplayRow.lua index a678425..fc671f8 100644 --- a/LootDisplay/LootDisplayFrame/LootDisplayRow/LootDisplayRow.lua +++ b/LootDisplay/LootDisplayFrame/LootDisplayRow/LootDisplayRow.lua @@ -228,12 +228,14 @@ local function rowHighlightBorder(row) fadeIn:SetFromAlpha(0) fadeIn:SetToAlpha(1) fadeIn:SetDuration(0.2) + fadeIn:SetSmoothing("IN_OUT") local fadeOut = b.HighlightAnimation:CreateAnimation("Alpha") fadeOut:SetFromAlpha(1) fadeOut:SetToAlpha(0) fadeOut:SetDuration(0.2) fadeOut:SetStartDelay(0.3) + fadeOut:SetSmoothing("IN_OUT") fadeOut:SetScript("OnFinished", function() row:ResetHighlightBorder() end) diff --git a/spec/Features/Currency_spec.lua b/spec/Features/Currency_spec.lua index d0c1bbb..f65438e 100644 --- a/spec/Features/Currency_spec.lua +++ b/spec/Features/Currency_spec.lua @@ -71,21 +71,37 @@ describe("Currency module", function() it("shows loot if the currency info is valid", function() ns.db.global.currencyFeed = true + local info = { + currencyID = 123, + description = "An awesome currency", + iconFileID = 123456, + quantity = 5, + quality = 2, + } + local link = "|c12345678|Hcurrency:123|r" + local basicInfo = { + name = "Best Coin", + description = "An awesome currency", + icon = 123456, + quality = 2, + displayAmount = 2, + actualAmount = 2, + } _G.C_CurrencyInfo.GetCurrencyInfo = function() - return { - currencyID = 123, - description = "An awesome currency", - iconFileID = 123456, - quantity = 5, - quality = 2, - } + return info + end + _G.GetCurrencyLink = function(currencyType) + return link + end + _G.GetBasicCurrencyInfo = function(currencyType, quantity) + return basicInfo end local newElement = spy.on(CurrencyModule.Element, "new") CurrencyModule:CURRENCY_DISPLAY_UPDATE(_, 123, 5, 2) - assert.spy(newElement).was.called_with(_, 123, "|c12345678|Hcurrency:123|r", 123456, 2, 5, 2, nil, nil) + assert.spy(newElement).was.called_with(_, "|c12345678|Hcurrency:123|r", info, basicInfo) assert.stub(ns.SendMessage).was.called() end) end) diff --git a/spec/common_stubs.lua b/spec/common_stubs.lua index 37174e7..b15fd29 100644 --- a/spec/common_stubs.lua +++ b/spec/common_stubs.lua @@ -274,6 +274,12 @@ function common_stubs.stub_WoWGlobals(spy) ItemQuality = { Legendary = 5 }, } + _G.Constants = { + CurrencyConsts = { + ACCOUNT_WIDE_HONOR_CURRENCY_ID = 1585, + }, + } + _G.C_CVar = { SetCVar = function() end, }