Module:GameFromAbbreviation: Difference between revisions

From Inkipedia, the Splatoon wiki
m (added string.upper (so duplicate entries for lowercase abbreviations are no longer necessary))
(removing "Splatoon" placeholder (I'd rather it errors out) and renamed variables)
Line 1: Line 1:
local p = {}
local p = {}


function p.getFullName(arg, default)
function p.getFullName(abbr, default)
arg = string.upper(arg)
abbr = string.upper(abbr)


     local abbrev = {
     local fullName = {
['OE'] = "Octo Expansion",
['OE'] = "Octo Expansion",
['SR'] = "Salmon Run",
['SR'] = "Salmon Run",
Line 14: Line 14:
     }
     }
      
      
     -- return the full name from the game arg.
     -- If abbr is nil:
     -- If arg is nil then a default or "Splatoon" (whichever is non-nil first) will be used.
     -- If default is defined, then it will be used.
     return abbrev[arg] or default or "Splatoon"
    -- If default is also nil, it errors out (I guess)
     return fullName[abbr] or default
end
end


Line 22: Line 23:
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 game = args['game'] or args[1]
     local default = args['default'] or args[2] -- or nil
     local default = args['default'] or args[2]
     return p.getFullName(arg, default)
     return p.getFullName(game, default)
end
end


return p
return p
--Forked from Module:GameShortened (by Slate)
--Forked from Module:GameShortened (by Slate)

Revision as of 12:15, 2 February 2024

Usage

{{GameFromAbbreviation|<game>|<default>}}

game Named or first positional, required The game's abbreviation (case insensitive). The following abbreviations are handled:
  • OE -> Octo Expansion
  • SO -> Side Order
  • SR -> Salmon Run
  • S S1 -> Splatoon
  • S2 Splatoon 2
  • S3 -> Splatoon 3

If an invalid abbreviation is used, the default argument will be used instead.

default Named or second positional, optional If the game argument was not matched, uses this instead.

See Also


local p = {}

function p.getFullName(abbr, default)
	abbr = string.upper(abbr)

    local fullName = {
		['OE']	= "Octo Expansion",
		['SR']	= "Salmon Run",
		['SO']	= "Side Order",
		['S']	= "Splatoon",
		['S1']	= "Splatoon",
		['S2']	= "Splatoon 2",
		['S3']	= "Splatoon 3",
    }
    
    -- If abbr is nil: 
    -- If default is defined, then it will be used.
    -- If default is also nil, it errors out (I guess)
    return fullName[abbr] or default
end

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

return p
--Forked from Module:GameShortened (by Slate)