Module:Cost: Difference between revisions
From Inkipedia, the Splatoon wiki
(so far (wip)) |
(rewrote) |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
-- Main for Cost module with the wiki template args | |||
function p.main(frame) | function p.main(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
Line 8: | Line 7: | ||
end | end | ||
function p. | -- Get the full name of a currency type from its abbreviation. | ||
local | -- Remember in Lua you do not have to specify all parameters. | ||
-- If default is not specified then 'nil' is used and returned if not found. | |||
function p.getNameFromAbbreviation(abbreviation, default) | |||
-- Switch logic for different | |||
local currencyTypes = { | |||
cash = "Cash", | |||
pe = "Power Egg", | |||
sss = "Super Sea Snail", | |||
ge = "Golden Egg", | |||
sard = "Sardinium", | |||
ac = "Ability Chunk Generic", | |||
cqp = "CQ Points", | |||
sl = "Sheldon License", | |||
gsl = "Gold Sheldon License", | |||
bs = "Bronze Fish Scale", | |||
ss = "Silver Fish Scale", | |||
gs = "Gold Fish Scale", | |||
} | |||
return currencyTypes[abbreviation] or default | |||
end | end | ||
function p. | -- Get the link text of a currency type from its abbreviation. | ||
-- If default is not specified then 'nil' is used and returned if not found. | |||
function p.getLinkFromAbbreviation(abbreviation, default) | |||
local | -- Switch logic for different | ||
local currencyTypes = { | |||
cash = "Cash", | |||
pe = "Power Egg", | |||
sss = "Super Sea Snail", | |||
ge = "Golden Egg", | |||
sard = "Sardinium", | |||
ac = "Ability chunk", | |||
cqp = "CQ-80#CQ Points", | |||
sl = "Sheldon License", | |||
gsl = "Sheldon License", | |||
bs = "Fish scale", | |||
ss = "Fish scale", | |||
gs = "Fish scale", | |||
} | } | ||
local | return currencyTypes[abbreviation] or default | ||
local | end | ||
function p.getCost(args) | |||
local game = args[1] or 'S' | |||
local quantity = args[2] | |||
local currencyType = args[3] or args['currency'] or 'cash' | |||
local size = tonumber(args[4]) or 24 | |||
local linkDisplay = args[5] or args[4] or '' | |||
local widthStyle = args[6] and ("width:" .. args[6] .. "px;") or '' | |||
local currencyIconName = nil | |||
-- Special cases for currency names based on game type | |||
if currencyType == 'pe' and game == 'S3' then | |||
currencyIconName = "Power Egg Alterna" | |||
elseif currencyType == 'sard' and game == 'S2' then | |||
currencyIconName = "Sardinium Shadow" | |||
else | |||
currencyIconName = p.getNameFromAbbreviation(currencyType, "Cash") | |||
end | |||
-- Constructing file name and link | |||
local fileName = string.format("%s Icon %s.png", game, currencyIconName) | |||
local fileSize = string.format("%dx%dpx", size, size) | |||
local fileLink = p.getLinkFromAbbreviation(currencyType, "Cash") | |||
-- Now let's construct the display name. | |||
-- Dirty hack, for ac, remove 'Generic' | |||
if currencyType == 'ac' then | |||
currencyIconName = "Ability Chunk" | |||
end | end | ||
-- Append 's' for plural forms for the display name if quantity is not '1' | |||
-- Exclude sardinium, cqp, and cash | |||
if quantity ~= '1' and (currencyType ~= 'sard' and currencyType ~= 'cqp' and currencyIconName ~= 'Cash') then | |||
currencyIconName = currencyIconName .. "s" | |||
end | |||
-- Construct the image link | |||
local imageLink = string.format('[[File:%s|%s|%s|link=%s]]', fileName, fileSize, currencyIconName, fileLink) | |||
-- Constructing output with additional span for quantity if provided | |||
local output = mw.html.create('span') | |||
output:css('display', 'inline-block') | |||
:css('text-align', 'right') | |||
:cssText(widthStyle) | |||
:wikitext(imageLink) | |||
if quantity and quantity ~= '' then | |||
local quantityLink = linkDisplay == 'link' and string.format('[[%s|%s]]', fileLink, quantity) or quantity | |||
output:wikitext(' ' .. quantityLink) | |||
end | |||
return | return tostring(output) | ||
end | end | ||
return p | return p |
Revision as of 23:13, 22 December 2023
Displays an inline currency icon with a text link.
Usage
{{Cost|<game>|<price>|<currency>|<size>|<link>|<textwidth>}}
Markup
*{{Cost|S|200}} *{{Cost|S2|200}} *{{Cost|S3|200}} *{{Cost|S|}} *{{Cost|S|1|sss}} *{{Cost|S2||ac}} *{{Cost|S3|160|bs}} *{{Cost|S|200|cash|48}} *{{Cost|S|200|cash|link}} *{{Cost|S|200|cash|48|link}} *{{Cost|S|200|cash|24|link|60}} *{{Cost|S|200|cash|24| |60}}
Output
local p = {} -- Main for Cost module with the wiki template args function p.main(frame) local args = frame:getParent().args return p.getCost(args) end -- Get the full name of a currency type from its abbreviation. -- Remember in Lua you do not have to specify all parameters. -- If default is not specified then 'nil' is used and returned if not found. function p.getNameFromAbbreviation(abbreviation, default) -- Switch logic for different local currencyTypes = { cash = "Cash", pe = "Power Egg", sss = "Super Sea Snail", ge = "Golden Egg", sard = "Sardinium", ac = "Ability Chunk Generic", cqp = "CQ Points", sl = "Sheldon License", gsl = "Gold Sheldon License", bs = "Bronze Fish Scale", ss = "Silver Fish Scale", gs = "Gold Fish Scale", } return currencyTypes[abbreviation] or default end -- Get the link text of a currency type from its abbreviation. -- If default is not specified then 'nil' is used and returned if not found. function p.getLinkFromAbbreviation(abbreviation, default) -- Switch logic for different local currencyTypes = { cash = "Cash", pe = "Power Egg", sss = "Super Sea Snail", ge = "Golden Egg", sard = "Sardinium", ac = "Ability chunk", cqp = "CQ-80#CQ Points", sl = "Sheldon License", gsl = "Sheldon License", bs = "Fish scale", ss = "Fish scale", gs = "Fish scale", } return currencyTypes[abbreviation] or default end function p.getCost(args) local game = args[1] or 'S' local quantity = args[2] local currencyType = args[3] or args['currency'] or 'cash' local size = tonumber(args[4]) or 24 local linkDisplay = args[5] or args[4] or '' local widthStyle = args[6] and ("width:" .. args[6] .. "px;") or '' local currencyIconName = nil -- Special cases for currency names based on game type if currencyType == 'pe' and game == 'S3' then currencyIconName = "Power Egg Alterna" elseif currencyType == 'sard' and game == 'S2' then currencyIconName = "Sardinium Shadow" else currencyIconName = p.getNameFromAbbreviation(currencyType, "Cash") end -- Constructing file name and link local fileName = string.format("%s Icon %s.png", game, currencyIconName) local fileSize = string.format("%dx%dpx", size, size) local fileLink = p.getLinkFromAbbreviation(currencyType, "Cash") -- Now let's construct the display name. -- Dirty hack, for ac, remove 'Generic' if currencyType == 'ac' then currencyIconName = "Ability Chunk" end -- Append 's' for plural forms for the display name if quantity is not '1' -- Exclude sardinium, cqp, and cash if quantity ~= '1' and (currencyType ~= 'sard' and currencyType ~= 'cqp' and currencyIconName ~= 'Cash') then currencyIconName = currencyIconName .. "s" end -- Construct the image link local imageLink = string.format('[[File:%s|%s|%s|link=%s]]', fileName, fileSize, currencyIconName, fileLink) -- Constructing output with additional span for quantity if provided local output = mw.html.create('span') output:css('display', 'inline-block') :css('text-align', 'right') :cssText(widthStyle) :wikitext(imageLink) if quantity and quantity ~= '' then local quantityLink = linkDisplay == 'link' and string.format('[[%s|%s]]', fileLink, quantity) or quantity output:wikitext(' ' .. quantityLink) end return tostring(output) end return p