FANDOM


local utils = require('Module:Utils')
local yesno = require('Dev:Yesno')
 
local categorize = utils.categorize(0)
 
local p = {}
 
local genres = {'Building', 'Horror', 'Town and city', 'Military', 'Comedy', 'Fighting', 'Medieval', 'Adventure', 'Sci-fi', 'FPS', 'Naval', 'RPG', 'Sports', 'Western'}
 
function p._format_genre(args)
	local genre_name = args.genre or 'All' -- Assume 'All' if no genre was given.
	local genre_string = genre_name:lower() -- Use the lowercase string for comparisons.
	if genre_string == 'all' then
		return "[[File:All icon.png|link=Genre#Current genres]] All"
	else
		for _, genre in next, genres do
			if genre:lower() == genre_string then
				return "[[File:" .. genre .. " icon.png|link=Genre]] " .. genre .. (args["category suffix"] and (categorize(genre .. " " .. args["category suffix"])) or "")
			end
		end
		-- If the function didn't return in the loop, the genre string corresponded to none of the recognized genres.
		return error("Invalid genre")
	end
end
 
p.format_genre = utils.make_wrapper_function(p._format_genre)
 
function p._enumerate_genres(args)
	local output = ""
	if args.genres then
		-- If there are multiple genres, list them.
		-- Otherwise, we want to format the only genre without putting it in a list.
		if args.genres:find('/') or args.genres:find(',') then
			for genre in args.genres:gmatch('%s*([^/,]+)') do
				output = output .. "\n* " .. p._format_genre {genre = genre, ["category suffix"] = args["category suffix"]}
			end
			output = output:sub(2) -- Remove the initial newline.
		else
			output = p._format_genre {genre = args.genres, ["category suffix"] = args["category suffix"]}
		end
	else
		-- If no genres were specified, default to 'All'.
		output = p._format_genre {genre = 'All', ["category suffix"] = args["category suffix"]}
	end
	return output
end
 
p.enumerate_genres = utils.make_wrapper_function(p._enumerate_genres)
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.