Module:Sandbox/Mistiryshak4

Jump to navigation Jump to search

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

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

local p = {}

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 input = args[1]:lower()
	local getSkill = mw.loadData('Module:Data/Skill/dx2').skill
	if not getSkill[input] then
		error("Skill \"" .. input .. "\" not defined for Dx2")
	end
	
	header = ''
	
	if getSkill[input] then --if the skill exists, begin table
		header = '{| class="wikitable sortable"\n|-'
	end
	
	--If devil connector active skill
	if getSkill[input].mainapt or getSkill[input].subapt or getSkill[input].maintype or getSkill[input].subtype then
		devconSkill = true
	end
	
	if getSkill[input].armname then --If armament
		armament = true --Used to more easily short-circuit compare armaments stuff later on
		if getSkill[input].use then --If use
			if getSkill[input].hit then
				armaAtkUse = true
			else
				armaHeal = true
			end
		elseif getSkill[input].cost then --If cost
			if not getSkill[input].pow then --If cost, but no power
				armaStatus = true
			else
				armaActive = true --If cost AND power
			end
		elseif getSkill[input].attribute == 'passive' then --If no cost, and it's a passive skill
			armaPassive = true
		else
			armaTalent = true -- If no cost, no power, no use, and it isn't a passive
		end
	end
	
	if devconSkill == true then
		header = header .. '\n!rowspan=2|Name'
	elseif armament then
		header = header .. '\n!colspan='
		if armaActive or armaHeal then
			header = header .. '7|Skill\n!colspan=2|Armament\n|-\n!Name'
		elseif armaTalent or armaPassive then
			header = header .. '2|Skill\n!colspan='
				if armaTalent then
					header = header .. '3|Armament\n|-\n!Name'
				else
					header = header .. '2|Armament\n|-\n!Name'
				end
		elseif armaStatus then
			header = header .. '5|Skill\n!colspan=2|Armament\n|-\n!Name'
		elseif armaAtkUse then
			header = header .. '8|Skill\n!colspan=2|Armament\n|-\n!Name'
		end
	else
		header = header .. '\n!Name'
	end
	
	if getSkill[input].rarity then
		if devconSkill then
			header = header .. '\n!rowspan=2|Rarity'
		else
			header = header .. '\n!Rarity'
		end
	end
	
	if devconSkill then
		header = header .. '\n!rowspan=2|' .. frame:expandTemplate{ title = 'Tt', args = { 'CC(s)', 'Connect Component(s)' } }
	elseif getSkill[input].component then
		header = header .. '\n!' .. frame:expandTemplate{ title = 'Tt', args = { 'CC(s)', 'Connect Component(s)' } }
	end
	
	if devconSkill then
		header = header .. '\n!colspan=2|Aptitude'	
	end
	
	if not devconSkill and getSkill[input].cost then
		header = header .. '\n!Cost'
	end
	
	if getSkill[input].hit then
		if devconSkill then
			header = header .. '\n!rowspan=2|Hit(s)'
		elseif not (getSkill[input].attribute:lower() == 'bad status' and armament) then
			header = header .. '\n!Hit(s)'
		end
	end
	
	if getSkill[input].target then
		header = header .. '\n!Target'
	end
	
	if getSkill[input].pow then
		if devconSkill then
			header = header .. '\n!rowspan=2|Power'
		elseif not (getSkill[input].attribute:lower() == 'healing' and armament) then
			header = header .. '\n!Power'
		end
	end
	
	if getSkill[input].use then
		header = header .. '\n!Use(s)'
	end
	
	if getSkill[input].description then
		if devconSkill then
			header = header .. '\n!rowspan=2 class="unsortable"|Description'
		else
			header = header .. '\n!class="unsortable"|Description'
		end
	end
	
	if getSkill[input].level then
		if devconSkill then
			header = header .. '\n!rowspan=2 class="unsortable"|Max Level'
		else
			header = header .. '\n!class="unsortable"|Max Level'
		end
	end
	
	if not getSkill[input].unique and getSkill[input].skillpoints then
		header = header .. '\n!Skill Point(s)'
	end
	
	if getSkill[input].unique then
		header = header .. '\n!User'
	end
	
	if armament then
		header = header .. '\n!Name\n!Demon'
	end

	if getSkill[input].notes then
		if devconSkill then
			header = header .. '\n!rowspan=2|Notes'
		else
			header = header .. '\n!Notes'
		end
	end
	
	if devconSkill then
		header = header .. '\n|-\n!Main\n!Sub'
	end
	
	local output = header .. '\n|-'
	return output
end

return p