FANDOM


local Categorizer = {}
local getArgs = require('Module:Arguments').getArgs
local getGames = require('Module:Gamedata')
 
local function makeInvokeFunction(funcName)
	-- makes a function that can be returned from #invoke, using
	-- [[Module:Arguments]].
	return function (frame)
		local args = getArgs(frame, {parentOnly = true})
		return Categorizer[funcName](args)
	end
end
 
local function cate( category, sortkey )
	if not mw.title.getCurrentTitle():inNamespace('') then 
		return ''
	end
	if sortkey then sortkey = '|' .. sortkey else sortkey = '' end
	return '[[Category:' .. category  .. sortkey .. ']]'
end
 
local function get_prop(args)
	local prop = {}
	for k, v in pairs(t) do
		for _, name in ipairs(v) do
			if args[name] then
				prop[k] = args[name]
				break
			end
		end
		prop[k] = prop[k] or v.default
	end
	return prop
end
 
Categorizer.game = makeInvokeFunction('_game')
 
function Categorizer._game(args)
	local result = { cate('Games') }
	local game = args[1] or args.class or args.game or args.Game or ''
	local gameg -- Game general style
	if getGames.games[game].fallback then
		gameg = getGames.games[game].fallback -- e.g. 'p3f' and 'p3p' will fall back to 'p3' if applicable.
		else gameg = game
	end
 
 
	if gameg == 'mt1' or gameg == 'mt2' then
		table.insert(result, cate('Megami Tensei Series'))
	elseif gameg == 'smt1' or gameg == 'smt2' or gameg == 'smtif' or gameg == 'smt3' or gameg == 'smt9' or gameg == 'smtim' or gameg == 'smtsj' or gameg == 'smt4' or gameg == 'ldx2' then
		table.insert(result, cate('Shin Megami Tensei Series'))
	elseif gameg == 'lb1' or gameg == 'lb2' or gameg == 'alb' or gameg == 'lb3' or gameg == 'lbs' or gameg == 'lbnt1' or gameg == 'lbnt2' or gameg == 'lbnt3' then
		table.insert(result, cate('Last Bible Series'))
	elseif gameg == 'majin1' or gameg == 'majin2' then
		table.insert(result, cate('Majin Tensei Series'))
	elseif gameg == 'smtds' or gameg == 'sh' or gameg == 'raidou1' or gameg == 'raidou2' then
		table.insert(result, cate('Devil Summoner'))
	elseif gameg == 'p1' or gameg == 'p2is' or gameg == 'p2ep' or gameg == 'p3' or gameg == 'pts' or gameg == 'p4' or gameg == 'pq' or gameg == 'p5' then
		table.insert(result, cate('Persona Series'))
	elseif gameg == 'childred' or gameg == 'childblack' or gameg == 'childwhite' or gameg == 'childlight' or gameg == 'childfire' or gameg == 'childice' or gameg == 'childmessiah' then
		table.insert(result, cate('Devil Children'))
	elseif gameg == 'ddsaga1' or gameg == 'ddsaga2' then
		table.insert(result, cate('Digital Devil Saga'))
	elseif gameg == 'desu1' or gameg == 'desu2' then
		table.insert(result, cate('Devil Survivor Series'))
	end
	if gameg == 'childred' or gameg == 'childblack'
		then table.insert(result, cate('Devil Children Red/Black Book','!'))
	elseif gameg == 'childmessiah' then
		table.insert(result, cate('Messiah Riser','!'))
	elseif gameg == '' then
	elseif gameg then
		table.insert(result, cate(gamen,'!'))
	end
	return result
end
 
Categorizer.char = makeInvokeFunction('_char')
 
function Categorizer._char(args)
	local result = {}
	local game = args[1] or args.class or args.game or args.Game or ''
	local gameg
	if getGames.games[game].fallback then
		gameg = getGames.games[game].fallback
		else gameg = game
	end
	local gamen = getGames.games[game].name
	local gamegn = getGames.games[gameg].name
 
	if args.Part == 'both' or args.Part == 'Both' then
	    if game == 'p2is' then
		    table.insert(result, cate(getGames.games['p2is'].name .. ' Characters'))
		    table.insert(result, cate(getGames.games['p2ep'].name .. ' Characters'))
    	elseif game == 'smtds' then
	    	table.insert(result, cate(gamen .. ' Characters'))
		    table.insert(result, cate(getGames.games['sh'].name .. ' Characters'))
    	elseif game == 'raidou1' then
	    	table.insert(result, cate(gamen .. ' Characters'))
		    table.insert(result, cate(getGames.games['raidou2'].name .. ' Characters'))
    	elseif game == 'desu2' then
	    	table.insert(result, cate(gamen .. ' Characters'))
		    table.insert(result, cate(getGames.games['desu2rb'].name .. ' Characters'))
		end
    elseif args.Part == 'All' or args.Part == 'all' then
        if game == 'p3' then
    		table.insert(result, cate(gamen .. ' Characters'))
		    table.insert(result, cate(getGames.games['p3f'].name .. ' Characters'))
		    table.insert(result, cate(getGames.games['p3p'].name .. ' Characters'))
	    elseif game == 'p4' then
		    table.insert(result, cate(gamen .. ' Characters'))
		    table.insert(result, cate(getGames.games['p4g'].name .. ' Characters'))
		    table.insert(result, cate(getGames.games['p4a'].name .. ' Characters'))
		    table.insert(result, cate(getGames.games['p4d'].name .. ' Characters'))
	    end
	elseif gamen ~= nil then
		table.insert(result, cate(gamen .. ' Characters'))
	end
	if args.alignment == 'Law' then
	    table.insert(result, cate('Law-Aligned Characters'))
	elseif args.alignment == 'Neutral' then
	    table.insert(result, cate('Neutral-Aligned Characters'))
	elseif args.alignment == 'Chaos' then
	    table.insert(result, cate('Chaos-Aligned Characters'))
	 end
	 return table.concat(result)
end
 
return Categorizer
Community content is available under CC-BY-SA unless otherwise noted.