Module:Shop: Difference between revisions

From Inkipedia, the Splatoon wiki
(added display text (which can be different from given name) and support for S3 Inkopolis Ammo Knights (Donny & Shelly))
(Renamed vaguely-named "main" frame object to "invokeFromTemplate" and added another frame object "requireFromModule" for calls from another module. This was implemented on this module's temporary substitute Module:Shop/new.)
 
(4 intermediate revisions by 2 users not shown)
Line 7: Line 7:
},
},
["S3"] = {
["S3"] = {
["Crab-N-Go"] = "S3 Icon Staff.png",
["SplatNet 3"] = "SplatNet 3 Shop.svg",
["SplatNet 3"] = "SplatNet 3 Shop.svg",
["Ammo Knights (Splatsville)"] = "S3 Icon Ammo Knights.png",
["Ammo Knights (Inkopolis)"] = "S3 Icon Shelly Donny Solo.png",
["Ammo Knights (Inkopolis)"] = "S3 Icon Ammo Knights Inkopolis.png",
["Ammo Knights (Duo)"] = "S3 Icon Shelly Donny Duo.png",
},
},
}
}
Line 25: Line 26:
}
}


function p.main(frame)
function p.requireFromModule(frame)
local args = frame:getParent().args
return p.getShopIcon(
local game = args["game"]
frame.game,
local name = args["name"]
frame.name,
local icononly = args["icononly"]
frame.icononly,
local size = args["size"]
frame.size or 24
)
end
 
function p.invokeFromTemplate(frame)
local game = frame:getParent().args.game
local name = frame:getParent().args.name
local icononly = frame:getParent().args.icononly
local size = frame:getParent().args.size or 24
return p.getShopIcon(game, name, icononly, size)
return p.getShopIcon(game, name, icononly, size)
end
end


function p.getShopIcon(game, name, icononly, size)
function p.getShopIcon(game, name, icononly, size)
string.upper(game)
game = string.upper(game)
local fileName = specificFileName[game][name] or string.format("%s Icon %s.png", game, name)
local fileName = specificFileName[game][name] or string.format("%s Icon %s.png", game, name)
local link = specificLink[name] or name
local link = specificLink[name] or name
local displayText = specificDisplayText[name] or name
local displayText = specificDisplayText[name] or name
local result
local result
if not size then size = 24 end
result = string.format("[[File:%s|%dpx|link=%s]]", fileName, size, link)
result = string.format("[[File:%s|%dpx|link=%s]]", fileName, size, link)

Latest revision as of 16:38, 8 March 2024

Displays an inline shop icon with a link text.

Parameters

game Named, required. The abbreviation of icon's game of origin. Must be one of the following:
  • S for Splatoon.
  • S2 for Splatoon 2.
  • S3 for Splatoon 3.
name Named, required. The English name of the shop.
  • Ammo Knights (Inkopolis) (while game=S3) for Shelly/Donny solo icon.
  • Ammo Knights (Duo) (while game=S3) for Shelly and Donny pair icon.
icononly Named, optional. If present and "true", the link text will be omitted.
size Named, optional. The width of the icon in pixels (do not include px). Defaults to 24 if absent.

Examples

Markup

{{Shop|game=S|name=Ammo Knights}}<br />
{{Shop|game=S3|name=Naut Couture}}<br />
{{Shop|game=S3|name=Ammo Knights|icononly=true|size=64}}<br />
{{Shop|game=S3|name=Ammo Knights (Inkopolis)|size=48}}

Output

Ammo Knights
Naut Couture

Ammo Knights


local p = {}

local specificFileName	=	{
	["S"]	=	{},
	["S2"]	=	{
		["SplatNet 2"]	=	"S2 Icon SplatNet Gear Shop.png",
	},
	["S3"]	=	{
		["Crab-N-Go"]					=	"S3 Icon Staff.png",
		["SplatNet 3"]					=	"SplatNet 3 Shop.svg",
		["Ammo Knights (Inkopolis)"]	=	"S3 Icon Shelly Donny Solo.png",
		["Ammo Knights (Duo)"]			=	"S3 Icon Shelly Donny Duo.png",
	},
}

local specificLink	=	{
	["Ammo Knights (Splatsville)"]	=	"Ammo Knights",
	["Ammo Knights (Inkopolis)"]	=	"Ammo Knights",
	["SplatNet 2"]					=	"SplatNet 2#Shop",
	["SplatNet 3"]					=	"SplatNet 3#Shop",
}

local specificDisplayText	=	{
	["Ammo Knights (Splatsville)"]	=	"Ammo Knights",
	["Ammo Knights (Inkopolis)"]	=	"Ammo Knights",
}

function p.requireFromModule(frame)
	return p.getShopIcon(
		frame.game,
		frame.name,
		frame.icononly,
		frame.size or 24
	)
end

function p.invokeFromTemplate(frame)
	local game		= frame:getParent().args.game
	local name		= frame:getParent().args.name
	local icononly	= frame:getParent().args.icononly
	local size		= frame:getParent().args.size or 24
	return p.getShopIcon(game, name, icononly, size)
end

function p.getShopIcon(game, name, icononly, size)
	game = string.upper(game)
	local fileName		= specificFileName[game][name] or string.format("%s Icon %s.png", game, name)
	local link			= specificLink[name] or name
	local displayText	= specificDisplayText[name] or name
	local result
	
	result = string.format("[[File:%s|%dpx|link=%s]]", fileName, size, link)
	if not icononly then result = result..string.format(" [[%s|%s]]", link, displayText) end
	
	return result
end

return p