rsi/utils.lua

12 lines
843 B
Lua
Raw Normal View History

2023-08-27 12:32:38 +00:00
utils={}
function utils.accuracy(beatDivisions, time)
local ticksToPrevDiv=(game.ticker.ticks-1)%beatDivisions
local ticksToNextDiv=beatDivisions-ticksToPrevDiv
local prevDivTime=game.ticker.lastTickTime-ticksToPrevDiv*game.ticker.tickTime
local nextDivTime=game.ticker.lastTickTime+ticksToNextDiv*game.ticker.tickTime
local closest=math.min(math.abs(time-prevDivTime), math.abs(time-nextDivTime))
local halfDivision=beatDivisions/2*game.ticker.tickTime
-- print(math.abs(time-nextDivTime),"to next beat, ",math.abs(time-prevDivTime)," to previous beat. Half division is ",halfDivision,". Closest is ",closest,". The current time is ",time,", and the next division is at ", nextDivTime,", last tick happened at ",game.ticker.lastTickTime," and is tick number ",game.ticker.ticks)
return (halfDivision-closest)/halfDivision -- Math is hard
end