Difference between revisions of "Module:FPS diff"

From ALttP Speedrunning Wiki
Jump to: navigation, search
 
(8 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
local SNES_fps = 60.0988
 
local SNES_fps = 60.0988
local frames_per_hour = 60 * 60 * 60
+
local frames_per_hour = 60 * 60
  
 
local color_lose = '#FF0000'
 
local color_lose = '#FF0000'
Line 18: Line 18:
 
end
 
end
  
local diff = SNES_fps - fps * frames_per_hour
+
local diff = (SNES_fps - fps) * frames_per_hour
  
 
local sign
 
local sign
Line 34: Line 34:
 
end
 
end
  
 +
diff = math.floor(math.abs(diff))
 +
 +
local diff_seconds = math.floor(diff/60)
 +
local diff_frames = diff%60
 +
 
local ret = mw.html.create('span')
 
local ret = mw.html.create('span')
 
:css({
 
:css({
 
color = color
 
color = color
 
})
 
})
:wikitext(sign..diff)
+
:wikitext(string.format('%s% 2ds%02df', sign, diff_seconds, diff_frames))
  
 
return ret
 
return ret
 +
end
 +
 +
function p.snes_fps()
 +
return SNES_fps
 
end
 
end
  
 
return p
 
return p

Latest revision as of 11:40, 19 May 2019

Documentation for this module may be created at diff/doc&action=edit&redlink=1 Module:FPS diff/doc

local p = {}

local SNES_fps = 60.0988
local frames_per_hour = 60 * 60

local color_lose = '#FF0000'
local color_same = '#0000FF'
local color_gain = '#00AA00'

function p.main(frame)
	local args = frame:getParent().args
	local fps = args.fps or nil

	if fps then
		fps = tonumber(fps, 10)
	else
		fps = SNES_fps
	end

	local diff = (SNES_fps - fps) * frames_per_hour

	local sign
	local color

	if diff > 0 then -- >0 means the snes has more frames per hour, so this system is losing
		sign = '−'
		color = color_lose
	elseif diff < 0 then
		sign = '+'
		color = color_gain
	else
		sign = '±'
		color = color_same
	end

	diff = math.floor(math.abs(diff))

	local diff_seconds = math.floor(diff/60)
	local diff_frames = diff%60
	
	local ret = mw.html.create('span')
					:css({
							color = color
						})
					:wikitext(string.format('%s% 2ds%02df', sign, diff_seconds, diff_frames))

	return ret
end

function p.snes_fps()
	return SNES_fps
end

return p