Module:FriendNavigator

From Japari Library, the Kemono Friends Wiki
Jump to navigation Jump to search

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

local getArgument = require('Module:Arguments').getArgument

local p = {}

function capitalFirst(str) -- Allows capitalization of the first letter of each word in a string; adapted from (https://stackoverflow.com/questions/20284515/capitalize-first-letter-of-every-word-in-lua)
    return (str:gsub("(%l)(%w*)", function(a,b) return string.upper(a)..b end))
end

function trim(s) -- Allows removing of whitespace from inputs; adapted from (https://www.lua.org/manual/2.4/node32.html)
	local l = 1
	while string.sub(s,l,l) == ' ' do
	l = l+1
	end
	local r = string.len(s)
	while string.sub(s,r,r) == ' ' do
	r = r-1
	end
	return string.sub(s,l,r)
end

function p.Main(frame)
	local args = frame.args
	local baseFriend = mw.title.getCurrentTitle().rootText
	local addLinks = ''
	
	function exists(media)
	if mw.title.makeTitle(0, baseFriend .. '/' .. media).exists == true then
		addLinks = addLinks .. '\n|style="display: inline-block; background:#f9f9f9"|[[' .. baseFriend .. '/' .. media .. '|' .. media .. ']]'
	end
	end
	
	exists('Anime')
	exists('Season 2')
	exists('Manga')
	
	if mw.title.makeTitle(0, baseFriend .. '/Festival').exists == true then
		addLinks = addLinks .. '\n|style="display: inline-block; background:#f9f9f9"|[[' .. baseFriend .. '/Festival|Festival]]'
		if mw.title.makeTitle(0, baseFriend .. '/Festival (Costume)').exists == true then 
			addLinks = addLinks .. ' ([[' .. baseFriend .. '/Festival (Costume)|Costume]])'
		end
	end
	
	if mw.title.makeTitle(0, baseFriend .. '/Pavilion (Gen 2)').exists == true then
		pavGen2 = '[[' .. baseFriend .. '/Pavilion (Gen 2)|Gen 2]]'
	else
		pavGen2 = ''
	end
	
	if mw.title.makeTitle(0, baseFriend .. '/Pavilion (EX)').exists == true then
		pavEX = '[[' .. baseFriend .. '/Pavilion (EX)|EX]]'
	else
		pavEX = ''
	end
	
	if mw.title.makeTitle(0, baseFriend .. '/Pavilion (Gen 2)').exists == true or mw.title.makeTitle(0, baseFriend .. '/Pavilion (EX)').exists == true then
		pavExtra = true
	end
	
	if pavGen2 ~= '' and pavEX ~= '' then
		bothPavExtra = ' • '
	else
		bothPavExtra = ''
	end
	
	if mw.title.makeTitle(0, baseFriend .. '/Pavilion').exists == true then
		addLinks = addLinks .. '\n|style="display: inline-block; background:#f9f9f9"|[[' .. baseFriend .. '/Pavilion|Pavilion]]'
	elseif pavExtra == true then 
		addLinks = addLinks .. '\n|style="display: inline-block; background:#f9f9f9"|Pavilion'
	end
	
	if pavExtra == true then
		addLinks = addLinks .. ' (' .. pavEX .. bothPavExtra .. pavGen2 .. ')'
	end
	
	if mw.title.makeTitle(0, baseFriend .. '/KF3 (V2)').exists == true then
		kf3V2	 = '[[' .. baseFriend .. '/KF3 (V2)|V2]]'
	else
		kf3V2 = ''
	end
	
	if mw.title.makeTitle(0, baseFriend .. '/KF3 (V3)').exists == true then
		kf3V3 = '[[' .. baseFriend .. '/KF3 (V3)|V3]]'
	else
		kf3V3 = ''
	end
	
	if mw.title.makeTitle(0, baseFriend .. '/KF3 (V2)').exists == true or mw.title.makeTitle(0, baseFriend .. '/KF3 (V3)').exists == true then
		kf3Extra = true
	end
	
	if kf3V2 ~= '' and kf3V3 ~= '' then
		bothKF3Extra = ' • '
	else
		bothKF3Extra = ''
	end
	
	if mw.title.makeTitle(0, baseFriend .. '/KF3').exists == true then
		addLinks = addLinks .. '\n|style="display: inline-block; background:#f9f9f9"|[[' .. baseFriend .. '/KF3|KF3]]'
	elseif kf3Extra == true then 
		addLinks = addLinks .. '\n|style="display: inline-block; background:#f9f9f9"|KF3'
	end
	
	if kf3Extra == true then
		addLinks = addLinks .. ' (' .. kf3V2 .. bothKF3Extra .. kf3V3 .. ')'
	end
	
	exists('Kingdom')
	exists('Nexon Game')
	exists('Stage Play')
	exists('KemoV')
	exists('Pachislot')
	exists('Gallery')
		
		local output = '{| class=wikitable style="border: 1px none; background:none"\n|style="display: inline-block; background:#f9f9f9"|[[' .. baseFriend .. ']]' .. addLinks .. '\n|}'
		return output
end
return p