Module:GetEffect: Difference between revisions
Appearance
imported>Ziebster No edit summary |
imported>Ziebster No edit summary |
||
| Line 44: | Line 44: | ||
return num .. percent | return num .. percent | ||
end | end | ||
-- Check if it's a range format in the key: stat to upper (optional (paren)) | -- Check if it's a range format in the key: stat to ( < )upper (optional (paren or condition)) | ||
local range_stat, | local range_stat, to_part, less_than, upper, condition = key:match('^([%w%.]+)%s+(to)%s*(<)?%s*([%w%.]+)%s*(%b()|[%w%.]+)?$') | ||
if range_stat then | if range_stat and to_part and upper then | ||
debugOutput = debugOutput .. 'Range in key match: range_stat=' .. range_stat .. ', | debugOutput = debugOutput .. 'Range in key match: range_stat=' .. range_stat .. ', to_part=' .. to_part .. ', less_than=' .. (less_than or '') .. ', upper=' .. upper .. ', condition=' .. (condition or '') .. '\n' | ||
local normRangeStat = range_stat:lower() | local normRangeStat = range_stat:lower() | ||
if normRangeStat == normalizedStat then | if normRangeStat == normalizedStat then | ||
| Line 54: | Line 54: | ||
num = num:sub(2) | num = num:sub(2) | ||
end | end | ||
local range = num .. percent .. ' ' .. | local range = num .. percent .. ' ' .. to_part .. ' ' .. (less_than or '') .. upper | ||
return mw.text.trim(range) | return mw.text.trim(range) | ||
end | end | ||
Revision as of 22:01, 9 February 2026
local p = {}
function p.getEffect(frame)
local pageName = frame.args[1] or mw.title.getCurrentTitle().text
local statName = frame.args[2]
local page = mw.title.new(pageName)
if not page then
return 'Page not found'
end
local content = page:getContent()
local effect = content:match('|%s*effects%s*=%s*(.-)\n%s*|') or content:match('|%s*effects%s*=%s*(.-)%s*}}') or ''
effect = mw.text.trim(effect)
if not statName or statName == '' then
-- Return full effect if no stat specified
return effect
end
-- Normalize statName for case-insensitive matching
local normalizedStat = statName:lower()
local debugOutput = 'Debug Info:\n'
debugOutput = debugOutput .. 'Extracted effect: ' .. effect .. '\n'
debugOutput = debugOutput .. 'Normalized stat: ' .. normalizedStat .. '\n'
-- Split the effect into comma-separated parts
local parts = mw.text.split(effect, ',')
for _, part in ipairs(parts) do
part = mw.text.trim(part)
debugOutput = debugOutput .. 'Part: ' .. part .. '\n'
-- Try standard pattern: +number%? stat (e.g., +15 W.PWR, +15% CRIT, +1.5 Speed)
local num, percent, key = part:match('^([+-]?[%d%.]+)(%%?)%s+(.*)$')
if num and key then
debugOutput = debugOutput .. 'Standard match: num=' .. num .. ', percent=' .. (percent or '') .. ', key=' .. key .. '\n'
local normKey = mw.text.trim(key):lower()
if normKey == normalizedStat then
-- Strip leading '+' if present
if num:sub(1,1) == '+' then
num = num:sub(2)
end
return num .. percent
end
-- Check if it's a range format in the key: stat to ( < )upper (optional (paren or condition))
local range_stat, to_part, less_than, upper, condition = key:match('^([%w%.]+)%s+(to)%s*(<)?%s*([%w%.]+)%s*(%b()|[%w%.]+)?$')
if range_stat and to_part and upper then
debugOutput = debugOutput .. 'Range in key match: range_stat=' .. range_stat .. ', to_part=' .. to_part .. ', less_than=' .. (less_than or '') .. ', upper=' .. upper .. ', condition=' .. (condition or '') .. '\n'
local normRangeStat = range_stat:lower()
if normRangeStat == normalizedStat then
-- Strip leading '+' if present
if num:sub(1,1) == '+' then
num = num:sub(2)
end
local range = num .. percent .. ' ' .. to_part .. ' ' .. (less_than or '') .. upper
return mw.text.trim(range)
end
end
else
debugOutput = debugOutput .. 'Standard match: no match\n'
end
end
-- If not found, return debug output instead of empty string
return debugOutput
end
return p