8000 fix: classic currency again by Mctalian · Pull Request #384 · Mctalian/RPGLootFeed · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: classic currency again #384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
.PHONY: all_checks hardcode_string_check missing_translation_check missing_locale_key_check test test-ci local check_untracked_files
.PHONY: all_checks hardcode_string_check missing_translation_check missing_locale_key_check test test-ci test-file test-pattern test-only local check_untracked_files help

all_checks: hardcode_string_check missing_translation_check missing_locale_key_check

# Show available make targets
help:
@echo "Available targets:"
@echo " test - Run all tests with coverage"
@echo " test-only - Run tests tagged with 'only'"
@echo " test-file FILE=... - Run tests for a specific file"
@echo " Example: make test-file FILE=RPGLootFeed_spec/Features/Currency_spec.lua"
@echo " test-pattern PATTERN=... - Run tests matching a pattern"
@echo " Example: make test-pattern PATTERN=\"quantity mismatch\""
@echo " test-ci - Run tests for CI (TAP output)"
@echo " all_checks - Run all code quality checks"
@echo " hardcode_string_check - Check for hardcoded strings"
@echo " missing_translation_check - Check for missing translations"
@echo " missing_locale_key_check - Check for missing locale keys"
@echo " generate_hidden_currencies - Generate hidden currencies list"
@echo " lua_deps - Install Lua dependencies"
@echo " check_untracked_files - Check for untracked git files"
@echo " watch - Watch for changes and build"
@echo " dev - Build for development"
@echo " build - Build for production"

# Variables
ROCKSBIN := $(HOME)/.luarocks/bin

Expand All @@ -25,6 +46,24 @@ test:
test-only:
@$(ROCKSBIN)/busted --tags=only RPGLootFeed_spec

# Run tests for a specific file
# Usage: make test-file FILE=RPGLootFeed_spec/Features/Currency_spec.lua
test-file:
@if [ -z "$(FILE)" ]; then \
echo "Usage: make test-file FILE=path/to/test_file.lua"; \
exit 1; \
fi
@$(ROCKSBIN)/busted --verbose "$(FILE)"

# Run tests matching a specific pattern
# Usage: make test-pattern PATTERN="quantity mismatch"
8000 test-pattern:
@if [ -z "$(PATTERN)" ]; then \
echo "Usage: make test-pattern PATTERN=\"test description\""; \
exit 1; \
fi
@$(ROCKSBIN)/busted --verbose --filter="$(PATTERN)" RPGLootFeed_spec

test-ci:
@rm -rf luacov-html && rm -rf luacov.*out && mkdir -p luacov-html && $(ROCKSBIN)/busted --coverage -o=TAP RPGLootFeed_spec && $(ROCKSBIN)/luacov

Expand Down
226 changes: 109 additions & 117 deletions RPGLootFeed/Features/Currency/Currency.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ local C = LibStub("C_Everywhere")
---@class RLF_Currency: RLF_Module, AceEvent-3.0
local Currency = G_RLF.RLF:NewModule("Currency", "AceEvent-3.0")

--- @param content string
--- @param message string
--- @param id? string
--- @param amount? string|number
function Currency:LogDebug(content, message, id, amount)
G_RLF:LogDebug(message, addonName, self.moduleName, id, content, amount)
end

Currency.Element = {}

--- @param currencyLink string
Expand All @@ -27,6 +35,10 @@ function Currency.Element:new(currencyLink, currencyInfo, basicInfo)
element.isLink = true

if not currencyLink or not currencyInfo or not basicInfo then
Currency:LogDebug(
"Skip showing currency",
"SKIP: Missing currencyLink, currencyInfo, or basicInfo - " .. tostring(currencyLink)
)
return
end

Expand Down Expand Up @@ -93,22 +105,38 @@ local function isHiddenCurrency(id)
return G_RLF.hiddenCurrencies[id] == true
end

local function extractCurrencyAndAmount(message, patterns)
local function extractAmount(message, patterns)
for _, segments in ipairs(patterns) do
local currencyLink, amount = G_RLF:ExtractDynamicsFromPattern(message, segments)
if currencyLink then
return currencyLink, amount
local prePattern, postPattern = unpack(segments)
local preMatchStart, _ = string.find(message, prePattern, 1, true)
if not preMatchStart then
-- If the prePattern is not found, skip to the next pattern
else
local subString = string.sub(message, preMatchStart)
local amount = string.match(subString, prePattern .. "(%d+)" .. postPattern)
if amount and amount ~= "" and tonumber(amount) > 0 then
return tonumber(amount)
end
end
end
return nil, nil
return nil
end

-- Precompute pattern segments to optimize runtime message parsing
local function precomputePatternSegments(patterns)
local function precomputeAmountPatternSegments(patterns)
local computedPatterns = {}
for _, pattern in ipairs(patterns) do
local segments = G_RLF:CreatePatternSegmentsForStringNumber(pattern)
table.insert(computedPatterns, segments)
local _, stringPlaceholderEnd = string.find(pattern, "%%s")
if stringPlaceholderEnd then
local numberPlaceholderStart, numberPlaceholderEnd = string.find(pattern, "%%d", stringPlaceholderEnd + 1)
if numberPlaceholderEnd then
local midPattern = string.sub(pattern, stringPlaceholderEnd + 1, numberPlaceholderStart - 1)
local postPattern = string.sub(pattern, numberPlaceholderEnd + 1)
table.insert(computedPatterns, { midPattern, postPattern })
else
Currency:LogDebug("Invalid pattern", "No number placeholder found in pattern " .. pattern)
end
end
end
return computedPatterns
end
Expand All @@ -123,17 +151,18 @@ function Currency:OnInitialize()

if GetExpansionLevel() < G_RLF.Expansion.BFA then
local currencyConsts = {
CURRENCY_GAINED,
CURRENCY_GAINED_MULTIPLE,
CURRENCY_GAINED_MULTIPLE_BONUS,
}
classicCurrencyPatterns = precomputePatternSegments(currencyConsts)
classicCurrencyPatterns = precomputeAmountPatternSegments(currencyConsts)
else
classicCurrencyPatterns = nil
end
end

function Currency:OnDisable()
if GetExpansionLevel() < G_RLF.Expansion.WOTLK then
G_RLF:LogDebug("OnEnable", addonName, self.moduleName, "Disabled because expansion is below WOTLK")
self:LogDebug("OnEnable", "Disabled because expansion is below WOTLK")
return
end
if GetExpansionLevel() < G_RLF.Expansion.BFA then
Expand All @@ -149,7 +178,7 @@ end

function Currency:OnEnable()
if GetExpansionLevel() < G_RLF.Expansion.WOTLK then
G_RLF:LogDebug("OnEnable", addonName, self.moduleName, "Disabled because expansion is below WOTLK")
self:LogDebug("OnEnable", "Disabled because expansion is below WOTLK")
return
end
if GetExpansionLevel() < G_RLF.Expansion.BFA then
Expand All @@ -160,31 +189,27 @@ function Currency:OnEnable()
if G_RLF:IsRetail() then
self:RegisterEvent("PERKS_PROGRAM_CURRENCY_AWARDED")
end
8000 G_RLF:LogDebug("OnEnable", addonName, self.moduleName)
self:LogDebug("OnEnable", "Currency module is enabled")
end

function Currency:Process(eventName, currencyType, quantityChange)
G_RLF:LogInfo(eventName, "WOWEVENT", self.moduleName, currencyType, eventName, quantityChange)

if currencyType == nil or not quantityChange or quantityChange <= 0 then
G_RLF:LogDebug(
self:LogDebug(
"Skip showing currency",
addonName,
self.moduleName,
currencyType,
"SKIP: Something was missing, don't display",
currencyType,
quantityChange
)
return
end

if isHiddenCurrency(currencyType) then
G_RLF:LogDebug(
self:LogDebug(
"Skip showing currency",
addonName,
self.moduleName,
currencyType,
"SKIP: This is a known hidden currencyType",
currencyType,
quantityChange
)
return
Expand All @@ -193,14 +218,7 @@ function Currency:Process(eventName, currencyType, quantityChange)
---@type CurrencyInfo
local info = C.CurrencyInfo.GetCurrencyInfo(currencyType)
if info == nil or info.description == "" or info.iconFileID == nil then
G_RLF:LogDebug(
"Skip showing currency",
addonName,
self.moduleName,
currencyType,
"SKIP: Description or icon was empty",
quantityChange
)
self:LogDebug("Skip showing currency", "SKIP: Description or icon was empty", currencyType, quantityChange)
return
end

Expand All @@ -218,14 +236,7 @@ function Currency:Process(eventName, currencyType, quantityChange)
if e then
e:Show()
else
G_RLF:LogDebug(
"Skip showing currency",
addonName,
self.moduleName,
currencyType,
"SKIP: Element was nil",
quantityChange
)
self:LogDebug("Skip showing currency", "SKIP: Element was nil", currencyType, quantityChange)
end
end)
end
Expand All @@ -237,103 +248,84 @@ function Currency:CURRENCY_DISPLAY_UPDATE(eventName, ...)
end

---@param msg string
---@return string? currencyLink, number? quantityChange
---@return number? quantityChange
function Currency:ParseCurrencyChangeMessage(msg)
local currencyLink, quantityChange = extractCurrencyAndAmount(msg, classicCurrencyPatterns)
if not currencyLink then
G_RLF:LogDebug(
"Skip showing currency",
addonName,
self.moduleName,
nil,
"SKIP: No currency link found in message",
msg
)
return nil, nil
if not classicCurrencyPatterns or #classicCurrencyPatterns == 0 then
self:LogDebug("Skip showing currency", "SKIP: No classic currency patterns available")
return nil
end

local quantityChange = extractAmount(msg, classicCurrencyPatterns)

quantityChange = quantityChange or 1

return currencyLink, quantityChange
return quantityChange
end

function Currency:CHAT_MSG_CURRENCY(eventName, ...)
local msg = ...
G_RLF:LogInfo(eventName, "WOWEVENT", self.moduleName, nil, msg)

return self:fn(function()
local currencyLink, quantityChange = self:ParseCurrencyChangeMessage(msg)
if not currencyLink or not quantityChange then
G_RLF:LogDebug(
"Skip showing currency",
addonName,
self.moduleName,
nil,
"SKIP: No currency link or quantity change found in message",
msg
)
return
end
local currencyId = G_RLF:ExtractCurrencyID(msg)
if currencyId == 0 or currencyId == nil then
self:LogDebug("Skip showing currency", "SKIP: No currency ID found for links in msg = " .. tostring(msg))
return
end

local currencyInfo = C_CurrencyInfo.GetCurrencyInfoFromLink(currencyLink)
if not currencyInfo then
G_RLF:LogDebug(
"Skip showing currency",
addonName,
self.moduleName,
nil,
"SKIP: No currency info found for currency link = " .. tostring(currencyLink)
)
return
end
if currencyId and isHiddenCurrency(currencyId) then
self:LogDebug(
"Skip showing currency",
"SKIP: This is a known hidden currency " .. tostring(msg),
tostring(currencyId)
)
return
end

if currencyInfo.quantity == 0 then
currencyInfo.quantity = quantityChange
end
local quantityChange = self:ParseCurrencyChangeMessage(msg)
if quantityChange == nil or quantityChange <= 0 then
self:LogDebug(
"Skip showing currency",
"SKIP: there was a problem determining the quantity change " .. tostring(msg),
tostring(currencyId)
)
return
end

if currencyInfo.currencyID == 0 then
local currencyId = G_RLF:ExtractCurrencyID(currencyLink)
if currencyId == 0 or currencyId == nil then
G_RLF:LogDebug(
"Skip showing currency",
addonName,
self.moduleName,
nil,
"SKIP: No currency ID found for currency link = " .. tostring(currencyLink)
)
return
end
currencyInfo.currencyID = currencyId
end
local currencyInfo = C_CurrencyInfo.GetCurrencyInfo(currencyId)
if not currencyInfo then
self:LogDebug("Skip showing currency", "SKIP: No currency info found for msg = " .. msg, tostring(currencyId))
return
end

local basicInfo = C_CurrencyInfo.GetBasicCurrencyInfo(currencyInfo.currencyID, quantityChange)
if not basicInfo then
---@diagnostic disable-next-line: missing-fields
basicInfo = {
displayAmount = quantityChange,
}
end
if currencyInfo.currencyID == 0 then
self:LogDebug(
"Currency info has no ID",
"Overriding " .. tostring(currencyInfo.name) .. " currencyID",
tostring(currencyId)
)
currencyInfo.currencyID = currencyId
end

local currencyId = currencyInfo.currencyID
if currencyId and isHiddenCurrency(currencyId) then
G_RLF:LogDebug(
"Skip showing currency",
addonName,
self.moduleName,
tostring(currencyId),
"SKIP: This is a known hidden currency",
msg
)
return
end
if currencyInfo.quantity == 0 then
self:LogDebug(
"Currency info has no quantity",
"Overriding " .. tostring(currencyInfo.name) .. " quantity to " .. tostring(quantityChange),
tostring(currencyId)
)
currencyInfo.quantity = quantityChange
end

local e = self.Element:new(currencyLink, currencyInfo, basicInfo)
if e then
e:Show()
else
G_RLF:LogDebug("Skip showing currency", addonName, self.moduleName, nil, "SKIP: Element was nil")
end
end)
local basicInfo = {
displayAmount = quantityChange,
}

local currencyLink = GetCurrencyLink(currencyId, currencyInfo.quantity)
local e = self.Element:new(currencyLink, currencyInfo, basicInfo)
if e then
e:Show()
else
self:LogDebug("Skip showing currency", "SKIP: Element was nil", tostring(currencyInfo.currencyID))
end
end

function Currency:PERKS_PROGRAM_CURRENCY_AWARDED(eventName, quantityChange)
Expand Down
Loading
Loading
0