Final Fantasy Wiki
Final Fantasy Wiki

This module implements {{icon}}, and for instructions on how to use {{icon}} see that template page. This documentation page simply explains how to edit the module and its data sets.

The dict GAMES contains the directory of the data modules used by this module, or LOADER_FLAG if the way that game's code is treated is processed manually. It is indexed by classcodes. If the game of classcode ffz is set to LOADER_FLAG one needs to set loaderz["ffz"] to a function which generates the data tables for that game.

By convention, all dict entries should be lowercase. All data modules (except possibly those called by an element of loaderz) should have the naming scheme Module:Icon/data/Game/Category where Category satisfies the capitalization convention that The First Letter Of Every Word Is Capitalized.

Extant data modules[]

Final Fantasy VII Remake[]

World of Final Fantasy[]

Final Fantasy XIV[]

Source code

-- <nowiki>
local p = {}
local getArgs = require('Dev:Arguments').getArgs

-------------- CONSTANTS --------------
-- The value of this constant doesn't matter, except that it cannot equal the name of an article on the FFWiki
local LOADER_FLAG = 30071996 

-- The icon that is returned if something breaks
local ERROR_ICON = {
	["file"] = "Wiki logo.png",
	["name"] = '<strong class="error scribunto-error">Error: Could not find icon in Module:Icon</strong>',
	["link"] = "Module:Icon",

-- Every entry here should either be the URL of a game's data table directory or LOADER_FLAG
-- If it is LOADER_FLAG, the game needs a loader (see the next section)
-- LOADER_FLAG should be used for games with very large data tables to cut down on load times and memory usage
local GAMES = {
	["ffviir"] = "Module:Icon/data/FFVIIR/",
	["woff"] = "Module:Icon/data/WoFF/",
	["ffxiv"] = LOADER_FLAG,

-- Some more constants used by loaders
local FFXIV_DIRECTORY = "Module:Icon/data/FFXIV/"
local FFXIV_ITEM_CATEGORIES = "Module:Icon/data/FFXIV/Item Categories"

-------------- LOADERS --------------
-- Loaders for specific games (these are only necessary for games with FUNCTION_FLAG)
-- A loader is a function that takes (category, icon) and returns the associated data table while NOT loading any other data table.
-- Example: loaderz["ffxiv"]("quests", "la-hee") == mw.loadData("Module:Icon/data/FFXIV/Quests")["la-hee"]
-- This is necessary for games with very large data tables, or with data tables.
-- Loaders can also be used to call databases other than Module:Icon/data.

local loaderz = {} -- loaders is a magic word in Lua, lol

loaderz["ffxiv"] = function(category, icon)
	if category == "Item" then
		-- This case WILL be scrapped once we have XIVAPI integration, as it causes serious performance issues.
		local ffxiv_item_types = mw.loadData(FFXIV_ITEM_CATEGORIES)
		for _, item_type in ipairs(ffxiv_item_types) do
			local d = mw.loadData(FFXIV_DIRECTORY .. item_type)
			if d[icon] then return d[icon] end
		return mw.loadData(FFXIV_DIRECTORY .. category)[icon]

-------------- METHODS --------------
-- Implements {{Icon|1=game|2=category|3=icon}}
function p.main(frame)
    local args = getArgs(frame)
    local game = assert( or args[1], 'Game icons not found')
    local category = assert(args.category or args[2], 'Category not found')
    local icon = assert(args.icon or args[3], 'Icon not found')

	-- Enforce capitalization conventions.
	-- game and icon must be lowercase
	-- category must have the first letter of each word capitalized, and all other letters lowercase
	-- category trick stolen from
	game = game:lower()
	category = string.gsub(category, "(%a)([%w_']*)", function(first, rest)
		return first:upper() .. rest:lower()
	icon = icon:lower()
	local ico = ((GAMES[game] == LOADER_FLAG) and loaderz[game](category, icon))
		or ((not (GAMES[game] == LOADER_FLAG)) and mw.loadData(GAMES[game] .. category)[icon])
    local file = '[[File:' .. ico.file .. '|alt=' .. .. '|20px|link=' .. ( or '') .. ']]'
    local link = ''
    if and not (args[4] == 'nolink') then
        link = ' [[' .. .. '|' .. .. ']]'

    return file .. link

return p
-- </nowiki>