Module:GameShortened: Difference between revisions

From Inkipedia, the Splatoon wiki
 
(Took Lake's implementation from Discord + minor tweaks)
Line 1: Line 1:
return function (game, default)
local g = {}
     if game == "Octo Expansion" or game == "OE" then
 
        return "OE"
function g.main(frame)
     elseif game == "Splatoon" or game == "Splatoon 1" or game == "S" then
     local S1 = "S"
         return "S"
    local S2 = "S2"
    elseif game == "Splatoon 2" or game == "S2" then
    local S3 = "S3"
         return "S2"
    local OE = "OE"
    elseif game == "Splatoon 3" or game == "S3" then
     local abbrev = {
         return "S3"
        ['S'] = S,
     else
        ['S1'] = S,
        return default or "S"
        ['Splatoon'] = S,
     end
        ['Splatoon 1'] = S,
         ['S2'] = S2,
        ['Splatoon 2'] = S2,
         ['S3'] = S3,
        ['Splatoon 3'] = S3,
        ['OE'] = OE,
         ['Octo Expansion'] = OE,
    }
   
     local arg = frame:getParent().args[1] or S1
local default = frame:getParent().args[2] or frame:getParent().args['default'] or S1
     return abbrev[arg] or default
end
end
return g

Revision as of 01:17, 11 August 2023

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}} -> Splatoon

In files

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

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

See Also


local g = {}

function g.main(frame)
    local S1 = "S"
    local S2 = "S2"
    local S3 = "S3"
    local OE = "OE"
    local abbrev = {
        ['S'] = S,
        ['S1'] = S,
        ['Splatoon'] = S,
        ['Splatoon 1'] = S,
        ['S2'] = S2,
        ['Splatoon 2'] = S2,
        ['S3'] = S3,
        ['Splatoon 3'] = S3,
        ['OE'] = OE,
        ['Octo Expansion'] = OE,
    }
    
    local arg = frame:getParent().args[1] or S1
	local default = frame:getParent().args[2] or frame:getParent().args['default'] or S1
    return abbrev[arg] or default
end

return g