Module:GetEffect: Difference between revisions
Appearance
imported>Ziebster No edit summary |
imported>Ziebster No edit summary |
||
| Line 3: | Line 3: | ||
function p.getEffect(frame) | function p.getEffect(frame) | ||
local pageName = frame.args[1] or mw.title.getCurrentTitle().text | local pageName = frame.args[1] or mw.title.getCurrentTitle().text | ||
local | local booleanParam = frame.args[2] | ||
local page = mw.title.new(pageName) | local page = mw.title.new(pageName) | ||
| Line 13: | Line 13: | ||
local effect = content:match('|%s*effects%s*=%s*(.-)\n%s*|') or content:match('|%s*effects%s*=%s*(.-)%s*}}') or '' | local effect = content:match('|%s*effects%s*=%s*(.-)\n%s*|') or content:match('|%s*effects%s*=%s*(.-)%s*}}') or '' | ||
effect = mw.text.trim(effect) | effect = mw.text.trim(effect) | ||
effect = effect:gsub("<", "<") | |||
if | if booleanParam == '1' then | ||
-- | -- Parse all stats into a map | ||
local statsMap = {} | |||
local parts = mw.text.split(effect, ',') | |||
for _, part in ipairs(parts) do | |||
part = mw.text.trim(part) | |||
-- 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 | |||
-- Strip leading '+' if present | -- Strip leading '+' if present | ||
if num:sub(1,1) == '+' then | if num:sub(1,1) == '+' then | ||
num = num:sub(2) | num = num:sub(2) | ||
end | end | ||
local value = num .. percent | |||
local normKey = mw.text.trim(key):lower() | |||
-- Check if it's a range format in the key: stat to <number (optional (paren or condition)) | |||
local range_stat, range_part, condition = key:match('^([%w%.]+)%s+(to%s*<[%d%.]+)%s*(%b()|[%w%.]+)?$') | |||
if range_stat then | |||
local normRangeStat = range_stat:lower() | |||
value = num .. percent .. ' ' .. range_part | |||
statsMap[normRangeStat] = mw.text.trim(value) | |||
else | |||
statsMap[normKey] = mw.text.trim(value) | |||
end | end | ||
end | end | ||
end | end | ||
-- Output the 6 stats separated by double || | |||
local results = {} | |||
local allStats = {'w.pwr', 'def', 'crit', 'durability', 'gather speed', 'speed'} | |||
for _, s in ipairs(allStats) do | |||
local value = statsMap[s] or '' | |||
table.insert(results, value) | |||
end | |||
return table.concat(results, '||') | |||
elseif booleanParam == '0' then | |||
-- Return full effect | |||
return effect | |||
end | end | ||
-- If | -- If invalid boolean, return empty string | ||
return '' | return '' | ||
end | end | ||
return p | return p | ||
Revision as of 21:47, 9 February 2026
local p = {}
function p.getEffect(frame)
local pageName = frame.args[1] or mw.title.getCurrentTitle().text
local booleanParam = 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)
effect = effect:gsub("<", "<")
if booleanParam == '1' then
-- Parse all stats into a map
local statsMap = {}
local parts = mw.text.split(effect, ',')
for _, part in ipairs(parts) do
part = mw.text.trim(part)
-- 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
-- Strip leading '+' if present
if num:sub(1,1) == '+' then
num = num:sub(2)
end
local value = num .. percent
local normKey = mw.text.trim(key):lower()
-- Check if it's a range format in the key: stat to <number (optional (paren or condition))
local range_stat, range_part, condition = key:match('^([%w%.]+)%s+(to%s*<[%d%.]+)%s*(%b()|[%w%.]+)?$')
if range_stat then
local normRangeStat = range_stat:lower()
value = num .. percent .. ' ' .. range_part
statsMap[normRangeStat] = mw.text.trim(value)
else
statsMap[normKey] = mw.text.trim(value)
end
end
end
-- Output the 6 stats separated by double ||
local results = {}
local allStats = {'w.pwr', 'def', 'crit', 'durability', 'gather speed', 'speed'}
for _, s in ipairs(allStats) do
local value = statsMap[s] or ''
table.insert(results, value)
end
return table.concat(results, '||')
elseif booleanParam == '0' then
-- Return full effect
return effect
end
-- If invalid boolean, return empty string
return ''
end
return p