Marvel Database
Marvel Database

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

-- module for Marvel Database:Race Template
local p = {}
local getArgs = require('Module:Arguments').getArgs 
local h = require("Module:HF")
local design = require('Module:Design')

function p.main(frame)
	local args = getArgs(frame)
	local pagename = mw.title.getCurrentTitle().text
	local page_type = 'Race'
	local value
	local categories = {}
	local output_categories = {}
	local output = {}

	table.insert(output_categories, p.lua_get_outdated_fields(args) )

-- sections
	-- adds 'Quote', 'Overview' section, 'TOC' and 'History' section
	value, categories = design.add_quote_overview_toc_history(args, page_type)
	output_categories = h.join_tables(output_categories, categories)
	output = h.join_tables(output, value)
	
	if not h.isempty(args.Powers) 
	or not h.isempty(args.Abilities) 
	or not h.isempty(args.AvgStrength) 
	or not h.isempty(args.Weaknesses) 
		then
			table.insert( output, design.add_header('Powers and Abilities', 2) )
			table.insert( output, design.add_section('Powers', args.Powers, 3) )
			table.insert( output, design.add_section('Abilities', args.Abilities, 3) )
			table.insert( output, design.add_section('Average Strength Level', args.AvgStrength, 3) )
			table.insert( output, design.add_section('Weaknesses', args.Weaknesses, 3) )
	end

	if not h.isempty(args.Habitat) 
	or not h.isempty(args.Gravity) 
	or not h.isempty(args.Atmosphere) 
	or not h.isempty(args.Population) 
		then
			table.insert( output, design.add_header('Habitat', 2) )
			table.insert( output, design.add_section('Habitat', args.Habitat, 3) )
			table.insert( output, design.add_section('Gravity', args.Gravity, 3) )
			table.insert( output, design.add_section('Atmosphere', args.Atmosphere, 3) )
			table.insert( output, design.add_section('Population', args.Population, 3) )
	end

	if not h.isempty(args.GovernmentType) 
	or not h.isempty(args.TechnologyLevel) 
	or not h.isempty(args.CulturalTraits) 
	or not h.isempty(args.Representatives) 
		then
			table.insert( output, design.add_header('Miscellaneous', 2) )
			table.insert( output, design.add_section('Type of Government', args.GovernmentType, 3) )
			table.insert( output, design.add_section('Level of Technology', args.TechnologyLevel, 3) )
			table.insert( output, design.add_section('Cultural Traits', args.CulturalTraits, 3) )
			table.insert( output, design.add_section('Representatives', args.Representatives, 3) )
	end

	-- adds 'Notes', 'Trivia', 'See Also', 'Recommended Reading' and 'Links and References' sections
	---- links to standard sub-pages/categories - "Appearances", "Minor Appearances", Mentions", "Images", "Quotes" and "Gallery" 
	value, categories = design.add_notes_trivia_see_also_recommended_links_references(args, page_type, pagename)
	output_categories = h.join_tables(output_categories, categories)
	output = h.join_tables(output, value)

--
	output_categories = h.add_categories(output_categories)
	output = table.concat(output)
	
	return frame:preprocess(output)..output_categories
end

--------------------------------------------------------------------------------------------------
function p.lua_get_outdated_fields(args)
	local output = ''
	
	if  not h.isempty(args.Custom)
		or not h.isempty(args.CustomLabel)
		or not h.isempty(args.CustomSection1)
		or not h.isempty(args.CustomText1)
		or not h.isempty(args.CustomSection2)
		or not h.isempty(args.CustomText2)
		or not h.isempty(args.NotesHeader)
		or not h.isempty(args.TriviaHeader)
		or not h.isempty(args.HistoryHeader)
		or not h.isempty(args.SeeAlsoHeader)
		or not h.isempty(args.HabitatHeader)
		or not h.isempty(args.MiscellaneousHeader)
		or not h.isempty(args.PowersAbilitiesHeader)
		or not h.isempty(args.OtherMedia)
		or not h.isempty(args.OtherMediaHeader)
			then output = 'Outdated Fields/Race'
	end
	
	return output	
end


--------------------------------------------------------------------------------------------------
function p.get_characteristics(link1, category1, link2, category2, value2)
	local value
	local category
	local output_categories = {}
	local output = {}

	if link1 ~= ''
		then
			table.insert(output_categories, category1)
			table.insert(output, link1)
	end
	
	if not h.isempty(category2) and h.exists('Category:'..category2)
		then
			table.insert(output_categories, category2)
			table.insert(output, link2)
		else
			table.insert(output, value2)
	end
	
	output = mw.text.listToText(output, ', ', ', ')
	
	return output, output_categories
end


--------------------------------------------------------------------------------------------------
function p.get_value_and_category(value, value_type, value_type2)
	local category = ''
	local output = ''
	
	if not h.isempty(value)
		then 
			if h.in_list({'0', 'none', 'no '..string.lower(value_type), 'n/a', 'no'}, string.lower(value))
				then 
					category = 'Races with No '..value_type
					value = 'None'
				elseif h.in_list({'1', 'one'}, string.lower(value))
					then
						if value_type == 'Eyes'
							then category = 'Races with One Eye'
							else category = 'Races with One '..value_type2
						end
						value = 'One'
				elseif string.lower(value) == 'bald'
					then
						category = 'Bald Races'
						value = 'Bald'
				else
					category = 'Races with '..value..' '..value_type
			end
			output = h.LinkToCategory(category, value)
	end
		
	return output, category
end

--------------------------------------------------------------------------------------------------
function p.get_place_of_origin(frame)
	local args = getArgs(frame)
	local value = args[1]
	local category = ''
	local output = ''
	
	if h.is_link(value) 
		then
			category = h.break_link(value, 1)..'/Races'
			output = value
		elseif h.exists(value)
			then 
				category = value..'/Races'
				output = h.Link(value, value)
		elseif h.exists('Category:'..value)
			then 
				category = value..'/Races'
				output = h.LinkToCategory(value, value)		
		else output = value
	end
	
	if category ~= ''
		then category = h.Category(category)
	end

	return output..category
end


--------------------------------------------------------------------------------------------------
function p.get_origin_categories(frame)
	local list = {
		['alien']			= 'Races of Aliens', 
		['gestalt']			= 'Gestalt Races', 
		['clone']			= 'Races of Clones', 
		['cosmic ray']		= 'Cosmic Ray Exposed Races',
		['cyborg']			= 'Races of Cyborgs', 
		['deity']			= 'Races of Deities', 
		['deities']			= 'Races of Deities', 
		[' god']			= 'Races of Deities', 
		['doppelganger']	= 'Races of Doppelgangers', 
		['gamma ray']		= 'Gamma Ray Exposed Races', 
		['homo superior']	= 'Mutants (Homo superior)', 
		[' ionic']			= 'Ionic Races', 
		['magician']		= 'Races of Magicians', 
		['robot']			= 'Races of Robots', 
		['synthetic']		= 'Races of Robots', 
		['super%-soldier']	= 'Races of Super-Soldiers', 
		['super soldier']	= 'Races of Super-Soldiers', 
		['undead']			= 'Undead Races', 
		['vampire']			= 'Races of Vampires', 
		['werewolf']		= 'Races of Werewolves', 
		['psionic entit']	= 'Races of Psionic Entities', 
	}
	local args = getArgs(frame)
	local value = string.lower(args.Origin)
	local output_categories = {}

	for i, v in pairs(list) do
		if string.find(value, i) ~= nil
			then table.insert(output_categories, v)
		end 
	end

	if string.find(value, 'vampire') ~= nil
		then table.insert(output_categories, 'Undead Races')
	end
	
	table.sort(output_categories)

	return h.add_categories(output_categories)
end


--------------------------------------------------------------------------------------------------
function p.get_special_adaptations_categories(frame)
	local args = getArgs(frame)
	local value = args.SpecialAdaptations
	local output_categories = {}

	if string.find(string.lower(value), 'feathers') ~= nil
		then table.insert(output_categories, 'Races with Feathers')
	end

	return h.add_categories(output_categories)
end


--------------------------------------------------------------------------------------------------
-- for fields 'Eyes', 'Hair', 'Skin', 'NumberOfLimbs', 'NumberOfFingers', 'NumberOfToes', 'NumberOfEyes'
function p.get_physical_characteristics(frame)
	local args = getArgs(frame)
	local field = args[1]
	local link1
	local category1
	local link2
	local category2
	local output_categories = {}
	local output = {}
	
	if h.in_list({'Eyes', 'Hair', 'Skin'}, field)
		then
			link1, category1 = p.get_value_and_category(args[field], field)
			link2, category2 = p.get_value_and_category(args[field..'2'], field)
			output, output_categories = p.get_characteristics(link1, category1, link2, category2, args[field..'2'])
		else -- 'NumberOfLimbs', 'NumberOfFingers', 'NumberOfToes', 'NumberOfEyes'
			link1, category1 = p.get_value_and_category(args['NumberOf'..field], field..'s', field)
			output, output_categories = p.get_characteristics(link1, category1)
	end

	return output..h.add_categories(output_categories)
end


return p