Professor Layton Wiki
Advertisement
Professor Layton Wiki

This Lua Module is used to automatically expand one or more Game codes to their full form.

A list of valid game codes and their expanded forms is available on Module:Gamecodes/data.

Invoke-able functions[]

expand[]

The expand function expands a single game code and is used by {{Game}}. This function expects a single game code and will return the expanded version if the game code is valid. All invalid game codes will return the literal text "Invalid Game Code". If a second argument is provided with any value, the short form of the game will be returned. In all other cases, the full name is returned.

Examples
Input Output
CV Professor Layton and the Curious Village
param1: CV, param2: short Curious Village
Some text Invalid Game Code

For more examples and usage see {{Game}}.

expandListInfobox[]

The expandListInfobox function expands and links a list of game codes. It is used on various infobox templates.

The function accepts both a comma separated string of codes and a wikilist of any text.

  • If a comma separated list is given, the function will return a list of all valid game codes, in a pre-defined order. Invalid game codes are ignored.
  • If a list is given, the function will replace all list items with a valid game code by their expanded form. All list items that do not have a (valid) game code will be returned unaltered. The order of the list items is preserved in this mode.
Examples
Input Output
CV Curious Village
UF,CV
UF,other text Unwound Future
* UF
* other text
* CV

local p = {}
 
--- Expands a single game code, used by {{Game}}
function p.expand(frame)
	local a
	if frame == mw.getCurrentFrame() then
		a = frame:getParent().args
	else
		a = type(frame) == 'string' and {frame} or frame	
	end
	if not a[1] then return 'Invalid Game Code' end
 
	local GC = a[1]:upper()
	local data = mw.loadData('Module:Gamecodes/data')
	if not data[GC] then return 'Invalid Game Code' end
 
	local key = a[2] == nil and 'name' or 'short'
	return data[GC][key]
end
 
--- Expands a list of gamecodes, used by some Infoboxes
function p.expandListInfobox(frame)
	local a
	if type(frame) == 'string' then
		a = mw.text.trim(frame)
		if not a or a == '' then return end
	else
		a = frame:getParent().args[1]
		if not a then return end
		a = mw.text.trim(a)
		if a == '' then return end
	end
	
	local buffer = {}
	
	if(a:sub(1, 1) == '*') then
		local data = mw.loadData('Module:Gamecodes/data')
		
		local rows = mw.text.split(a, "\n", true);
		
		for i=1,#rows do
			buffer[#buffer+1] = rows[i]:gsub(
				"^\*%s*(.-)%s*$",
				function(match)
					local d = data[match]
					if d then
						return "''[[" .. d.name .. '|' .. d.short .. "]]''"
					else
						return match
					end
				end, 1
			)
		end
	else
		if a:find("%[") then
			return a -- Contains links, so probably not game codes
		end
	 
		local data = mw.loadData('Module:Gamecodes/data')
		local o = { 'CV', 'DB', 'UF', 'LS', 'ED', 'MM', 'AL', 'VS', 'DM', 'MC', 'MJ', 'MSF', 'NWS' } -- Change order here if needed
	 
		local t = {}
		a:gsub('([^,%s]+)', function(match) t[match:upper()] = true end)
	 
		for i=1,#o do
			local k = o[i]
			if t[k] then
				local d = data[k]
				buffer[#buffer+1] = "''[[" .. d.name .. '|' .. d.short .. "]]''"
			end
		end
	end
	
	if(#buffer == 0) then return "" end
	if(#buffer == 1) then return buffer[1] end
 
	return "* " .. table.concat(buffer,'\n* ')
end
 
return p
Advertisement