Module:FrameChart: Difference between revisions

From Dustloop Wiki
(Test mw.html)
(Convert html to use mw.html)
Line 2: Line 2:


local currentFrame
local currentFrame
local wikitext
local html


function p.drawFrameData(frame)
function p.drawFrameData(frame)
  currentFrame = 0
currentFrame = 0
  wikitext = "<div class=\"frameChart\">"


  -- Optional field to add title
html = mw.html.create('div')
  local title
html:addClass('frameChart')
  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.
-- Optional field to add title
  local startupIsFirstActive
local title
  if frame.args['startupIsFirstActive'] == nil then
if frame.args['title'] ~= nil then
    startupIsFirstActive = true
title = frame.args['title']
  else
end
    startupIsFirstActive = false
 
  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
-- Startup of move, substract 1 if startupIsFirstActive
  local startup = frame.args['startup']
local startup = frame.args['startup']
  if tonumber(startup) ~= nil then
if tonumber(startup) ~= nil then
    if startupIsFirstActive and tonumber(startup) > 0 then
if startupIsFirstActive and tonumber(startup) > 0 then
      startup = tonumber(startup) - 1
startup = tonumber(startup) - 1
    end
end
  end
end
    
    
  -- Active of move
-- Active of move
  local active = frame.args['active']
local active = frame.args['active']
  -- Inactive of move
-- Inactive of move
  local inactive = frame.args['inactive']
local inactive = frame.args['inactive']
  -- Recovery of move
-- Recovery of move
  local recovery = frame.args['recovery']
local recovery = frame.args['recovery']
  -- Special Recovery of move
-- Special Recovery of move
  local specialRecovery = frame.args['specialRecovery']
local specialRecovery = frame.args['specialRecovery']
  -- How many frames into active frames the inactive period occurs
-- How many frames into active frames the inactive period occurs
  local offset = frame.args['offset']
local offset = frame.args['offset']
  -- Display projectile spawn bar after startup?
-- Display projectile spawn bar after startup?
  local isProjectile = frame.args['isProjectile']
local isProjectile = frame.args['isProjectile']
    
    
  -- Defining FRC / Cancel windows
-- Defining FRC / Cancel windows
  local cIndex = 1
local cIndex = 1
  cList = {}
cList = {}


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


  if frame.args['frcEnd'] ~= nil then
-- Creating list of cancel windows from N potential fields
    cList[cIndex+1] = tonumber(frame.args['frcEnd'])
local index = 1
    cIndex = cIndex + 2
while tonumber(frame.args['cancelStart' .. index]) ~= nil or tonumber(frame.args['cancelEnd' .. index]) ~= nil do
  end
cList[cIndex] = tonumber(frame.args['cancelStart' .. index])
 
cList[cIndex+1] = tonumber(frame.args['cancelEnd' .. index])
  -- Creating list of cancel windows from N potential fields
cIndex = cIndex + 2
  local index = 1
index = index + 1
  while tonumber(frame.args['cancelStart' .. index]) ~= nil or tonumber(frame.args['cancelEnd' .. index]) ~= nil do
end
    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
if title ~= nil then
    wikitext = wikitext .. "<div class=\"frameChart-title\">" .. title .. "</div> "
html
  end
:tag('div')
:addClass('frameChart-title')
:wikitext(title)
:done()
end
    
    
  drawFrame(startup,  "startup")
drawFrame(startup,  "startup")
  if isProjectile ~= nil then
 
    wikitext = wikitext .. "<div class=\"spawn-projectile\"></div>"
if isProjectile ~= nil then
  end
html
  -- Alternate way of inputting multihits, only works for moves with a single gap in active frames
:tag('div')
  if offset ~= nil then
:addClass('spawn-projectile')
    drawFrame(offset,  "active")
end
    drawFrame(inactive, "inactive")
 
    drawFrame(active-offset,  "active")
-- Alternate way of inputting multihits, only works for moves with a single gap in active frames
  else
if offset ~= nil then
    drawFrame(active,  "active")
drawFrame(offset,  "active")
   end
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
    
    
  -- Option for inputting multihits, works for moves with 1+ gaps in the active frames
drawFrame(recovery, "recovery")
  index = 2
drawFrame(specialRecovery, "specialRecovery")
  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")
html
  drawFrame(specialRecovery, "specialRecovery")
:tag('div')
:addClass('frame-data-total')
:wikitext("'''Total:''' " .. currentFrame )
:done()


  wikitext = wikitext .. "<div class=\"frame-data-total\">  '''Total: '''" .. currentFrame .. "</div></div>"
return tostring(html) .. mw.getCurrentFrame():extensionTag{
 
name = 'templatestyles', args = { src = 'Module:FrameChart/styles.css' }
  return wikitext .. mw.getCurrentFrame():extensionTag{
}
name = 'templatestyles', args = { src = 'Module:FrameChart/styles.css' }
  }
end
end


function drawFrame(frames, frameType)
function drawFrame(frames, frameType)
local html = mw.html.create()
if tonumber(frames) ~= nil then
if tonumber(frames) ~= nil then
for i=1, tonumber(frames) do
for i=1, tonumber(frames) do
Line 121: Line 133:
end
end
end
end
wikitext = wikitext .. tostring(html)
end
end



Revision as of 22:01, 19 July 2023

Module:FrameChart is used to generate timelines which represent the given frame data as a set of discrete frames color coded by their classification.

Usage

Any page which uses the FrameChart module should include the template Template:FrameChartKey which explains each of the colored squares generated by the graph.

Creating a frame chart involves defining a number of values for the code to plot on the timeline. If a given value is left out, it will not be drawn.

  • startup - the quantity of startup frames. By default, this includes the first active frame of the move. As is standard for Dustloop.
  • active - the quantity of active frames. Can be multiple sections [2-N].
  • recovery - the quantity of recovery frames after all active frames have ended.
  • inactive - The quantity of frames during which the move is not active which occur in between two sets of active frames. Can be multiple sections [2-N].
  • specialRecovery - The quantity of non-standard recovery frames tied to a move. These include things such as Landing Recovery.
  • offset - The quantity of active frames which occur before the inactive frames. This is used for handling edge cases, or as an alternative syntax to inactive.
  • isProjectile - a bar created after startup frames indicating a projectile was spawned.
  • isStrikeProjectile - a bar created after active frames indicating a projectile was spawned. Used when the attack starts with a strike and is followed up by a projectile
  • frcStart - the first frame which an FRC can occur on.
  • frcEnd - the last frame which an FRC can occur on.
  • cancelStart - the first frame a cancel can occur on, an alternative syntax to frcStart. Can be multiple sections [2-N].
  • cancelEnd - the last frame a cancel can occur on, an alternative syntax to frcEnd. Can be multiple sections [2-N].
  • title - a title for a given FrameChart, most useful when making multiple FrameCharts in one area.
  • startupIsFirstActive - the first active frame is the last frame of startup. True by default as that is the standard. Set to false for cases such as when Active frames are skipped.

Examples

Frame Chart Key

StartupThe time before an attack is active. Written startup values include the first active frame, so the startup on a frame chart will display one less square than the written value. Frames
Active The active frames of an attack refers to the amount of time an attack can hit the opponent. Frames
InactiveFrames in the middle of multi-hit attacks which cannot hit the opponent, but are after the move has become active at least once. Frames
Recovery The recovery of an attack refers to the amount of time an attacker must wait before they may perform another action, even blocking. Frames
Special RecoveryThe recovery of an attack refers to the amount of time an attacker must wait before they may perform another action.Recovery frames which happen under abnormal conditions, such as after landing. Frames
ProjectileIndicates an entity that exists separately from the character has become active. Usually something like a Fireball A projectile which usually travels slowly across the screen in a horizontal path above the ground.. Active
CancelA window in which to cancel a move. Can be varied in usage. Window

Simple

Startup Active Recovery
8 2 10
{{#invoke:FrameChart|drawFrameData
|startup         = 8
|active          = 2
|recovery        = 10
}}
Total: 19

Inactive Frames

Startup Active Recovery
8 2(3)2 10
{{#invoke:FrameChart|drawFrameData
|startup         = 8
|active          = 2
|inactive2       = 3
|active3         = 2
|recovery        = 10
}}
Total: 24

Complex

The following example uses multiple optional features of the framechart: title, frc window, and special recovery.

Startup Active Recovery
8 4 5+10
{{#invoke:FrameChart|drawFrameData
|title           = Complex Example
|startup         = 8
|active          = 4
|recovery        = 5
|specialRecovery = 10
|frcStart        = 9
|frcEnd          = 10
}}
Complex Example
Total: 26

Projectile + Cancel Window

Startup Active Recovery
18 32 Total 51
{{#invoke:FrameChart|drawFrameData
|startup              = 18
|isProjectile         = true
|startupIsFirstActive = false
|recovery             = 33
|cancelStart1         = 20
|cancelEnd1           = 21
|cancelStart2         = 25
|cancelEnd2           = 26
}}
Total: 51

local p = {}

local currentFrame
local html

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
   
	drawFrame(startup,  "startup")

	if isProjectile ~= nil then
	html
		:tag('div')
		:addClass('spawn-projectile')
	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/styles.css' }
	}
end

function drawFrame(frames, frameType)
	if tonumber(frames) ~= nil then
		for i=1, tonumber(frames) do
			currentFrame = currentFrame + 1
			
			html
				:tag('div')
				:addClass('frame-data')
				:addClass('frame-data-' .. frameType)
			
			if checkCancel() then
				html:addClass('frame-data-frc')
			end
			
			html:done()
		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

return p