Module:FrameChart-PKMNCC

From Mizuumi Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:FrameChart-PKMNCC/doc

--taken from Dustloop, with a new page being made as to not interfere with the other version of this on Mizuumi, and so that we can mess around with editing it if needed.

local p = {}

local currentFrame
local html
local frameChartDataHtml

function drawFrame(frames, frameType)
	if tonumber(frames) ~= nil then
		for i=1, tonumber(frames) do
			currentFrame = currentFrame + 1
			
			local frameDataHtml = mw.html.create('div')
			frameDataHtml
				:addClass('frame-data')
				:addClass('frame-data-' .. frameType)
			
			if checkCancel() then
				frameDataHtml:addClass('frame-data-frc')
			end
			
			frameDataHtml:done()
			frameChartDataHtml:node(frameDataHtml)
		end
	end
end

-- Checks if currentFrame is within one of the cancel/FRC windows
function checkCancel()
	local i = 1
	while cList[i] ~= nil do
		if currentFrame <= cList[i+1] and currentFrame >= cList[i] then
			return true
		end
		i = i + 2
	end
	return false
end

function p.drawFrameData(frame)
	currentFrame = 0

	html = mw.html.create('div')
	html:addClass('frameChart')

	-- Optional field to add title
	local title
	if frame.args['title'] ~= nil then
		title = frame.args['title']
	end

	-- Startup is the first active frame. Sets to true if empty. Otherwise it's false.
	local startupIsFirstActive
	if frame.args['startupIsFirstActive'] == nil then
		startupIsFirstActive = true
	else
		startupIsFirstActive = false
	end
  
	-- Startup of move, substract 1 if startupIsFirstActive
	local startup = frame.args['startup']
	if tonumber(startup) ~= nil then
		if startupIsFirstActive and tonumber(startup) > 0 then
			startup = tonumber(startup) - 1
		end
	end
  
	-- Active of move
	local active = frame.args['active']
	-- Inactive of move
	local inactive = frame.args['inactive']
	-- Recovery of move
	local recovery = frame.args['recovery']
	-- Special Recovery of move
	local specialRecovery = frame.args['specialRecovery']
	-- How many frames into active frames the inactive period occurs
	local offset = frame.args['offset']
	-- Display projectile spawn bar after startup?
	local isProjectile = frame.args['isProjectile']
  
	-- Defining FRC / Cancel windows
	local cIndex = 1
	cList = {}

	-- Supporting frcStart/End as optional arguments
	if frame.args['frcStart'] ~= nil then
		cList[cIndex] = tonumber(frame.args['frcStart'])
	end
	
	if frame.args['frcEnd'] ~= nil then
		cList[cIndex+1] = tonumber(frame.args['frcEnd'])
		cIndex = cIndex + 2
	end

	-- Creating list of cancel windows from N potential fields
	local index = 1
	while tonumber(frame.args['cancelStart' .. index]) ~= nil or tonumber(frame.args['cancelEnd' .. index]) ~= nil do
		cList[cIndex] = tonumber(frame.args['cancelStart' .. index])
		cList[cIndex+1] = tonumber(frame.args['cancelEnd' .. index])
		cIndex = cIndex + 2
		index = index + 1
	end
  

	if title ~= nil then
		html
			:tag('div')
			:addClass('frameChart-title')
			:wikitext(title)
			:done()
	end

	-- Create container for frame data
	frameChartDataHtml = mw.html.create('div')
	frameChartDataHtml:addClass('frameChart-data')
	html:node(frameChartDataHtml)
   
	drawFrame(startup,  "startup")

	if isProjectile ~= nil then
	frameChartDataHtml
		:tag('div')
		:addClass('spawn-projectile')
		:done()
	end

-- Alternate way of inputting multihits, only works for moves with a single gap in active frames
	if offset ~= nil then
		drawFrame(offset,   "active")
		drawFrame(inactive, "inactive")
		drawFrame(active-offset,   "active")
	else
		drawFrame(active,   "active")
	end
  
	-- Option for inputting multihits, works for moves with 1+ gaps in the active frames
	index = 2
	while tonumber(frame.args['active' .. index]) ~= nil or tonumber(frame.args['inactive' .. index]) ~= nil do
		drawFrame(frame.args['active' .. index], "active")
		drawFrame(frame.args['inactive' .. index], "inactive")
		index = index + 1
	end
  
	drawFrame(recovery, "recovery")
	drawFrame(specialRecovery, "specialRecovery")
  
	html
		:tag('div')
		:addClass('frame-data-total')
		:wikitext("'''Total:''' " .. currentFrame )
		:done()

	return tostring(html) .. mw.getCurrentFrame():extensionTag{
		name = 'templatestyles', args = { src = 'Module:FrameChart-PKMNCC/CCstyles.css' }
	}
end

return p