Module:GameShortened: Difference between revisions

From Inkipedia, the Splatoon wiki
m (docs)
(added string.upper so input can be case insensitive (mainly for abbreviations as input e.g., s, s2, etc.))
Line 4: Line 4:
-- and `default` will be set to nil.
-- and `default` will be set to nil.
function p.getGame(arg, default)
function p.getGame(arg, default)
    local OE = "OE"
--Allows input to be case insensitive
    local SO = "SO"
arg = string.upper(arg)
    local SR = "SR"
    local S = "S"
    local S2 = "S2"
    local S3 = "S3"


    local abbrev = {
local OE = "OE"
        ['OE'] = OE,
local SO = "SO"
        ['Octo Expansion'] = OE,
local SR = "SR"
        ['SR'] = SR,
local S = "S"
        ['Salmon Run'] = SR,
local S2 = "S2"
        ['SO'] = SO,
local S3 = "S3"
        ['Side Order'] = SO,
        ['S'] = S,
--All names are in uppercase because of string.upper (for case insensitivity)
        ['S1'] = S,
local abbrev = {
        ['Splatoon'] = S,
['OE'] = OE,
        ['Splatoon 1'] = S,
['OCTO EXPANSION'] = OE,
        ['S2'] = S2,
['SR'] = SR,
        ['Splatoon 2'] = S2,
['SALMON RUN'] = SR,
        ['S3'] = S3,
['SO'] = SO,
        ['Splatoon 3'] = S3,
['SIDE ORDER'] = SO,
    }
['S'] = S,
   
['S1'] = S,
    -- return the abbreviation from the game arg.
['SPLATOON'] = S,
    -- If arg is nil then a default will be used.
['SPLATOON 1'] = S,
    return abbrev[arg] or default or "S"
['S2'] = S2,
['SPLATOON 2'] = S2,
['S3'] = S3,
['SPLATOON 3'] = S3,
}
 
-- return the abbreviation from the game arg.
-- If arg is nil then a default will be used.
return abbrev[arg] or default or "S"
end
end


-- main to extract arg from frame
-- main to extract arg from frame
function p.main(frame)
function p.main(frame)
    local args = frame:getParent().args
local args = frame:getParent().args
    local arg = args['game'] or args[1]
local arg = args['game'] or args[1]
    local default = args['default'] or args[2] -- or nil
local default = args['default'] or args[2] -- or nil
    return p.getGame(arg, default)
return p.getGame(arg, default)
end
end


return p
return p

Revision as of 13:13, 2 February 2024

Helper template that transforms the game argument into the shortened S form. For template chaining and code reduction. Will also help us when new game/expansions/formats are created.

If the game is not matched, the default argument is used instead if specified, otherwise "S".

Usage

game Named or first positional, optional The game that the cost belongs to. The following values are handled:
  • Octo Expansion -> OE
  • Side Order -> SO
  • Salmon Run -> SR
  • Splatoon -> S
  • Splatoon 1 -> S
  • Splatoon 2 -> S2
  • Splatoon 3 -> S3
  • OE -> OE
  • SO -> SO
  • SR -> SR
  • S -> S
  • S2 -> S2
  • S3 -> S3

If game is not specified, the default argument will be used instead.

default Named or second positional, optional If the game argument was not matched, uses this instead.
  • Defaults to "S".
Typical usage

{{GameShortened|<game>|<default>}}

{{GameShortened|Octo Expansion}} -> OE

Chained in another template that has the game parameter

{{GameShortened|{{{game|}}}}} -> S

Using the default parameter

{{GameShortened|Splatoon 3|S}} -> S3

{{GameShortened|game=Splatoon 2|default=Splatoon}} -> S2

In files

[[File:{{GameShortened|Splatoon 3}}_Icon_Big_Run.svg|link=Big Run|30px]] -> S3 Icon Big Run.svg

[[File:{{GameShortened|game=Splatoon 2|default=Splatoon 3}}_Splatfest_Logo.svg|link=Splatfest|30px]] -> S2 Splatfest Logo.svg

See Also


local p = {}

-- Note in Lua calling p.getGame(game) is acceptable,
-- and `default` will be set to nil.
function p.getGame(arg, default)
	--Allows input to be case insensitive
	arg = string.upper(arg)

	local OE = "OE"
	local SO = "SO"
	local SR = "SR"
	local S = "S"
	local S2 = "S2"
	local S3 = "S3"
	
	--All names are in uppercase because of string.upper (for case insensitivity)
	local abbrev = {
		['OE'] = OE,
		['OCTO EXPANSION'] = OE,
		['SR'] = SR,
		['SALMON RUN'] = SR,
		['SO'] = SO,
		['SIDE ORDER'] = SO,
		['S'] = S,
		['S1'] = S,
		['SPLATOON'] = S,
		['SPLATOON 1'] = S,
		['S2'] = S2,
		['SPLATOON 2'] = S2,
		['S3'] = S3,
		['SPLATOON 3'] = S3,
	}

	-- return the abbreviation from the game arg.
	-- If arg is nil then a default will be used.
	return abbrev[arg] or default or "S"
end

-- main to extract arg from frame
function p.main(frame)
	local args = frame:getParent().args
	local arg = args['game'] or args[1]
	local default = args['default'] or args[2] -- or nil
	return p.getGame(arg, default)
end

return p