Module:icons

Revision as of 13:49, 9 June 2026 by Mex (talk | contribs)

Documentation for this module may be created at Module:icons/doc

local p = {}

function p.main(frame)
	local args = p.getArgs(frame)
	local title = mw.title.new(args[1])
	local text = title:getContent()
	local games = p.extractGames(text)
	local text = {}
	local games2 = { "iii", "vc", "sa", "iv" }
	for i,game in ipairs(games2) do
		if p.inArray(games, game) then
			table.insert(text, frame:expandTemplate{title = "icon-"..game})
		else
			table.insert(text, frame:expandTemplate{title = "icon-placeholder"})
		end
	end
	return table.concat(text, " ")
end

function p.getArgs(frame)
	if p.argsCache then
		return p.argsCache
	else
		local args = frame:getParent().args
		p.argsCache = args
		return args
	end
end

function p.extractGames(text)
    local games = text:match("|%s*games%s*=%s*([^|]+)")
    if not games then
        return nil
    end

    games = games:match("^%s*(.-)%s*$") -- trim

    local result = {}
    for game in games:gmatch("%S+") do
        table.insert(result, game)
    end

    return result
end

function p.inArray(array, value)
    for i,v in ipairs(array) do
        if v == value then
            return true
        end
    end
    return false
end

return p