Module:PM item: Difference between revisions
From the Super Mario Wiki, the Mario encyclopedia
Jump to navigationJump to search
mNo edit summary |
mNo edit summary |
||
(8 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
local GAME_ALIASES = { | |||
PMTTYD = "TTYD", | |||
PMSS = "SS", | |||
PMCS = "CS", | |||
PMTOK = "TOK", | |||
PMTTYDNS = "TTYDNS", | |||
["1"] = "PM", | |||
["2"] = "TTYD", | |||
["3"] = "SPM", | |||
["4"] = "SS", | |||
["5"] = "CS", | |||
["6"] = "TOK", | |||
["7"] = "TTYDNS", | |||
} | |||
local DEFAULT_IMAGE_SIZES = { | |||
PM = nil, | |||
TTYD = "25x25px", | |||
SPM = nil, | |||
SS = "50x50px", | |||
CS = "50x50px", | |||
TOK = "50x50px", | |||
TTYDNS = "25x25px", | |||
} | |||
local IMAGE_PREFIXES = { | |||
PM = "PaperMario Items ", | |||
TTYD = nil, | |||
SPM = nil, | |||
SS = nil, | |||
CS = "PMCS Item ", | |||
TOK = nil, | |||
TTYDNS = nil, | |||
} | |||
local IMAGE_SUFFIXES = { | |||
PM = nil, | |||
TTYD = " TTYD", | |||
SPM = " SPM", | |||
SS = " Sticker PMSS", | |||
CS = nil, | |||
TOK = " PMTOK icon", | |||
TTYDNS = " PMTTYDNS icon", | |||
} | |||
local p = {} | local p = {} | ||
Line 4: | Line 49: | ||
local args = frame.args | local args = frame.args | ||
local game = args.game or "PM" | local game = args.game or "PM" | ||
game = GAME_ALIASES[game] or game | |||
local item = args[2] or args[1] | local item = args[2] or args[1] | ||
local link = args.link or args[1] | local link = args.link or args[1] | ||
local text = args.text or item | local text = args.text or item | ||
local imageSize = args.size or DEFAULT_IMAGE_SIZES[game] | |||
local imagePrefix = IMAGE_PREFIXES[game] or "" | |||
local imageSuffix = IMAGE_SUFFIXES[game] or "" | |||
local | local imageBase = args.item or item | ||
imageBase = string.gsub(imageBase, "é", "e") | |||
imageBase = string.gsub(imageBase, "×", "x") | |||
imageBase = string.gsub(imageBase, " [-] ", " ") | |||
imageBase = string.gsub(imageBase, "[.,'?!]", "") | |||
imageBase = string.gsub(imageBase, '"', "") | |||
if game == "PM" then | if game == "PM" then | ||
imageBase = string.gsub(imageBase, " ", "") | |||
end | end | ||
Line 58: | Line 80: | ||
if color ~= nil and color ~= "" then | if color ~= nil and color ~= "" then | ||
wikitext = frame:expandTemplate { | wikitext = frame:expandTemplate { | ||
title = "color | title = "color link", | ||
args = { link | args = { color, link, text } | ||
} | } | ||
else | else | ||
Line 85: | Line 107: | ||
end | end | ||
return frame:expandTemplate { title = ' | return frame:expandTemplate { title = 'nw', args = { wikitext } } | ||
end | end | ||
return p | return p |
Latest revision as of 17:28, December 31, 2024
This module creates a page link related to Paper Mario with an associated item image on the left side.
Parameters
Name | Usage |
---|---|
{{{1}}}
|
Set the defaults for {{{item}}} , {{{link}}} , and {{{text}}}
|
{{{item}}} or {{{2}}}
|
Set the item to be displayed |
{{{size}}}
|
Set the item image size |
{{{right}}}
|
Set the position of the item image |
{{{link}}}
|
Set the page to link |
{{{text}}}
|
Set the text to be displayed |
{{{color}}}
|
Set the text color |
{{{wikitext}}}
|
Override {{{text}}}
|
{{{sep}}}
|
Set the separator between the item image and text |
{{{game}}}
|
PM (default), TTYD , TTYDNS , SPM , CS , or TOK
|
See also
- {{PM item}}
- {{PMTTYD item}}
- {{SPM item}}
local GAME_ALIASES = {
PMTTYD = "TTYD",
PMSS = "SS",
PMCS = "CS",
PMTOK = "TOK",
PMTTYDNS = "TTYDNS",
["1"] = "PM",
["2"] = "TTYD",
["3"] = "SPM",
["4"] = "SS",
["5"] = "CS",
["6"] = "TOK",
["7"] = "TTYDNS",
}
local DEFAULT_IMAGE_SIZES = {
PM = nil,
TTYD = "25x25px",
SPM = nil,
SS = "50x50px",
CS = "50x50px",
TOK = "50x50px",
TTYDNS = "25x25px",
}
local IMAGE_PREFIXES = {
PM = "PaperMario Items ",
TTYD = nil,
SPM = nil,
SS = nil,
CS = "PMCS Item ",
TOK = nil,
TTYDNS = nil,
}
local IMAGE_SUFFIXES = {
PM = nil,
TTYD = " TTYD",
SPM = " SPM",
SS = " Sticker PMSS",
CS = nil,
TOK = " PMTOK icon",
TTYDNS = " PMTTYDNS icon",
}
local p = {}
function p.link(frame)
local args = frame.args
local game = args.game or "PM"
game = GAME_ALIASES[game] or game
local item = args[2] or args[1]
local link = args.link or args[1]
local text = args.text or item
local imageSize = args.size or DEFAULT_IMAGE_SIZES[game]
local imagePrefix = IMAGE_PREFIXES[game] or ""
local imageSuffix = IMAGE_SUFFIXES[game] or ""
local imageBase = args.item or item
imageBase = string.gsub(imageBase, "é", "e")
imageBase = string.gsub(imageBase, "×", "x")
imageBase = string.gsub(imageBase, " [-] ", " ")
imageBase = string.gsub(imageBase, "[.,'?!]", "")
imageBase = string.gsub(imageBase, '"', "")
if game == "PM" then
imageBase = string.gsub(imageBase, " ", "")
end
local image = "[[File:" .. imagePrefix .. imageBase .. imageSuffix .. ".png"
if imageSize ~= nil then
image = image .. "|" .. imageSize
end
image = image .. "|link=" .. link .. "]]"
local wikitext = args.wikitext
if wikitext == nil and text ~= "" then
local color = args.color
if link ~= "" then
if color ~= nil and color ~= "" then
wikitext = frame:expandTemplate {
title = "color link",
args = { color, link, text }
}
else
wikitext = "[[" .. link .. "|" .. text .. "]]"
end
else
if color ~= nil and color ~= "" then
wikitext = '<span style="color:' .. color .. '">' .. text .. '</span>'
else
wikitext = text
end
end
end
if wikitext ~= nil then
local sep = args.sep or " "
local right = args.right
if right ~= nil and right ~= "" then
wikitext = wikitext .. sep .. image
else
wikitext = image .. sep .. wikitext
end
else
wikitext = image
end
return frame:expandTemplate { title = 'nw', args = { wikitext } }
end
return p