Module:Amiibo

From Inkipedia, the Splatoon wiki
Revision as of 18:31, 5 December 2023 by Slate (talk | contribs) (wrong find?)

Displays an inline amiibo icon with a text link.

Parameters

name Unnamed or named. The English name of the amiibo.
size Unnamed or named, optional. The numeric dimension in pixels for the maximum size of the icon. The default size is 24.
icononly Unnamed, optional. If present, the text label will be omitted.
section Named, optional. The section in the amiibo article to link to. If absent, name will be used.
text Named, optional. The link text. If absent, name will be used for all amiibo, except the Splatoon 2 series, who will exclude the numeral 2.
ext Named, optional. The file extension, e.g. jpg. Will default to png if unspecified or empty.

Examples

Markup

*{{amiibo|Inkling Boy}}
*{{amiibo|Inkling Boy (recolor)}}
*{{amiibo|Inkling Boy 2}}
*{{amiibo|Callie|48}}
*{{amiibo|Inkling Girl|icononly}}
*{{amiibo|Inkling Squid 2|48|icononly}}
*{{amiibo|Inkling Squid 2|text=The ''Splatoon 2'' series Inkling Squid}}
*{{amiibo|Inkling (Yellow)}}
*{{amiibo|Octoling (Blue)}}
*{{amiibo|Smallfry}}
*{{amiibo|Shiver}} {{amiibo|Frye}} {{amiibo|Big Man}}
*{{amiibo|Frye|ext=jpg}}

Output


local p = {}
p.main = function(frame)
    local args = frame.args
    local amiiboName = args['name'] or args[1] or ''
    local size = args['size'] or tonumber(args[2]) or 24
    local section = args['section'] or amiiboName
    local text = args['text'] or nil
    local ext = string.lower(args['ext'] or 'png') or 'png'

    -- Mapping table for amiibo name patterns to image file names
    local amiiboMap = {
        {pattern = "Inkling Girl (Splatoon)", imageName = "S_amiibo_Inkling Girl"},
        {pattern = "Inkling Girl", imageName = "S_amiibo_Inkling Girl"},
        {pattern = "Inkling Boy (Splatoon)", imageName = "S_amiibo_Inkling Boy"},
        {pattern = "Inkling Boy", imageName = "S_amiibo_Inkling Boy"},
        {pattern = "Inkling Squid (Splatoon)", imageName = "S_amiibo_Inkling Squid"},
        {pattern = "Inkling Squid", imageName = "S_amiibo_Inkling Squid"},
        {pattern = "Inkling Girl (recolor)", imageName = "S_amiibo_Inkling Girl"},
        {pattern = "Inkling Boy (recolor)", imageName = "S_amiibo_Inkling Boy"},
        {pattern = "Inkling Squid (recolor)", imageName = "S_amiibo_Inkling Squid"},
        {pattern = "Callie", imageName = "S_amiibo_Callie"},
        {pattern = "Marie", imageName = "S_amiibo_Marie"},
        {pattern = "Inkling Girl (Splatoon 2)", imageName = "S2_amiibo_Inkling Girl 2"},
        {pattern = "Inkling Girl 2", imageName = "S2_amiibo_Inkling Girl 2"},
        {pattern = "Inkling Boy (Splatoon 2)", imageName = "S2_amiibo_Inkling Boy 2"},
        {pattern = "Inkling Boy 2", imageName = "S2_amiibo_Inkling Boy 2"},
        {pattern = "Inkling Squid (Splatoon 2)", imageName = "S2_amiibo_Inkling Squid 2"},
        {pattern = "Inkling Squid 2", imageName = "S2_amiibo_Inkling Squid 2"},
        {pattern = "Octoling Girl", imageName = "S2_amiibo_Octoling Girl"},
        {pattern = "Octoling Boy", imageName = "S2_amiibo_Octoling Boy"},
        {pattern = "Octoling Octopus", imageName = "S2_amiibo_Octoling Octopus"},
        {pattern = "Marina", imageName = "S2_amiibo_Marina"},
        {pattern = "Pearl", imageName = "S2_amiibo_Pearl"},
        {pattern = "Inkling (Yellow)", imageName = "S3_amiibo_Inkling (Yellow)"},
        {pattern = "Octoling (Blue)", imageName = "S3_amiibo_Octoling (Blue)"},
        {pattern = "Smallfry", imageName = "S3_amiibo_Smallfry"},
        {pattern = "Shiver", imageName = "S3_amiibo_Shiver"},
        {pattern = "Frye", imageName = "S3_amiibo_Frye"},
        {pattern = "Big Man", imageName = "S3_amiibo_Big Man"},
        {pattern = "Inkling Girl (Super Smash Bros. Ultimate)", imageName = "SSBU_amiibo_Inkling Girl"}
        -- Add more mappings as needed
    }

    -- Default to amiiboName if not found
    local imageName = amiiboName

    -- Iterate through the map to find the first matching pattern
    for _, mapping in ipairs(amiiboMap) do
        if mw.ustring.find(amiiboName, mapping.pattern) then
            imageName = mapping.imageName
            break
        end
    end

    -- Construct the image link
    local imageLink = string.format('[[File:%s.%s|%dx%dpx|%s|link=amiibo#%s]]',
                                    imageName, ext, size, size, amiiboName,
                                    section)

    local output = mw.html.create('span')
    output:css('width', size .. 'px')
    output:css('height', size .. 'px')
    output:css('text-align', 'center')
    output:css('display', 'inline-block')
    output:wikitext(imageLink)

    -- Append additional text if not icononly
    if args[2] ~= 'icononly' and args[3] ~= 'icononly' and text then
        output:wikitext(' ' ..mw.text.nowiki('[[amiibo#' .. section .. '|' .. text .. ']]'))
    end

    return tostring(output)
end

return p