Module:Spell
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Spell/doc
local p = {}
function p.tags(frame)
local tags = frame.args[1]
local sep = ","
local result = {}
for tag in string.gmatch(tags, "([^"..sep.."]+)") do
table.insert(result, '<span>' .. mw.text.trim(tag) .. '</span>')
end
return table.concat(result, ' ')
end
function p.base(frame)
local args = frame.args
local base = args['Base']
local result = {}
-- Iterate through each stat
for stat in string.gmatch(base, "[^,]+") do
-- Trim whitespace
stat = mw.text.trim(stat)
-- Match and capture the name, value, and effect using pattern matching
local name, value, effect = string.match(stat, "^(.-)%s*([%d%-%%%+]+)%s*(.*)$")
-- Default values if not matched correctly
name = name or ""
value = value or ""
effect = effect or ""
-- Insert the formatted div into the result table
table.insert(result, string.format('<div style="display:flex;"><span style="color: #ff4800;">%s</span><span style="color: #f9f9f9; padding-left: 10px;">%s %s</span></div>', name, value, effect))
end
-- Return the concatenated result
return table.concat(result, "\n")
end
function p.synergy(frame)
local args = frame.args
local spellName = args['Name']
local result = {}
local hasSynergy = false
for i = 1, 4 do
local synergy = args['Synergy' .. i]
if synergy and synergy ~= '' then
hasSynergy = true
local name, value, effect = string.match(synergy, "^(.-):%s*([%+%-]?%d+%.?%d*%%?)%s*(.+)$")
if name and value and effect then
name = mw.text.trim(name)
value = mw.text.trim(value)
effect = mw.text.trim(effect)
table.insert(result, string.format('<div style="display:flex; align-items: center; margin-bottom: 5px;"><span style="color: #ff4800;">%s</span><span style="color: #f9f9f9; padding-left: 10px;">%s %s</span></div>', name, value, effect))
end
end
end
if hasSynergy then
table.insert(result, 1, string.format('<div style="color: #02ff00; margin-bottom: 5px">%s receives bonus effects:</div>', spellName))
end
return table.concat(result, '')
end
function p.speed(frame)
local scalingType = frame.args['Speed_Scaling']
if scalingType == 'Faster Cast Rate' then
return '<div style="display:flex;"><span style="border: 1px solid #595551">[[File:Tooltip_Faster_Cast_Rate.png|25px|25px|alt=Cast Rate Icon]]</span><span style="margin-left: 5px">Faster Cast Rate</span></div>'
elseif scalingType == 'Attack Speed' then
return '<div style="display:flex;"><span style="border: 1px solid #595551">[[File:Tooltip_Attack_Speed.png|25px|25px|alt=Attack Speed Icon]]</span><span style="margin-left: 5px">Attack Speed</span></div>'
else
return ''
end
end
function p.icons(frame)
local icons = {
{param = 'Mana', file = 'Tooltip_Mana_Cost.png'},
{param = 'Movement', file = 'Tooltip_Movement_Penalty.png'},
{param = 'Range', file = 'Tooltip_Pixel_Range.png'},
{param = 'Cooldown', file = 'Tooltip_Cooldown.png'},
{param = 'Duration', file = 'Tooltip_Duration.png'},
{param = 'Chance', file = 'Tooltip_Proc_Chance.png'}
}
local result = {}
for _, icon in ipairs(icons) do
local value = frame.args[icon.param]
if value and value ~= '' then
table.insert(result, string.format('<div style="display:flex; align-items: center; margin-bottom: 2px;"><span>%s</span><span style="margin-left: 5px;"><div style="border: 1px solid #595551">[[File:%s|25px|25px|alt=%s Icon]]</div></span></div>', mw.text.trim(value), icon.file, icon.param))
end
end
return table.concat(result, '')
end
return p