From 9f1264e0f83d6b1a3d58882048e1ffd02963a87b Mon Sep 17 00:00:00 2001 From: Not-A-Normal-Robot Date: Tue, 26 Nov 2024 10:57:05 +0700 Subject: [PATCH] Add Hz counter to other classic modes --- parts/eventsets/classic_e.lua | 8 +- parts/eventsets/classic_h.lua | 136 ++++++++++++++++++++++++++++++--- parts/eventsets/classic_l.lua | 138 +++++++++++++++++++++++++++++++--- parts/eventsets/classic_u.lua | 136 ++++++++++++++++++++++++++++++--- 4 files changed, 385 insertions(+), 33 deletions(-) diff --git a/parts/eventsets/classic_e.lua b/parts/eventsets/classic_e.lua index 60fc9854e..8f0de5acc 100644 --- a/parts/eventsets/classic_e.lua +++ b/parts/eventsets/classic_e.lua @@ -39,13 +39,13 @@ local function getMistimeColor(t) end local function onMove(P,dir) local D=P.modeData - + if not D.firstMoveTimestamp then D.firstMoveTimestamp=P.stat.time end - + D.lastMoveTimestamp=P.stat.time - + D.displacement=math.abs(P.curX+dir-D.spawnX) end local function createMoveHandler(dir) @@ -154,8 +154,6 @@ return { }, 40,100 ) - - print(P.curX) -- DEBUG end, task=function(P) local D=P.modeData diff --git a/parts/eventsets/classic_h.lua b/parts/eventsets/classic_h.lua index 83fb3196c..9a37cfca7 100644 --- a/parts/eventsets/classic_h.lua +++ b/parts/eventsets/classic_h.lua @@ -23,6 +23,34 @@ local function GetGravity(lvl) lvl<29 and 2 or 1 end +local function getHzColor(hz) + if not hz or hz<10 then return{1,1,1} + elseif hz<15 then return{1,1,0} + elseif hz<18 then return{1,.75,0} + elseif hz<25 then return{1,.5,0} + elseif hz<40 then return{1,0,0} + elseif hz<1e99 then return{.5,0,1} + else return{1,0,1}end +end +local function getMistimeColor(t) + if not t then return {1,1,1} + elseif t<1 then return{0,1,1} + else return {COLOR.hsv(math.max(.4-1/9*math.log(t,8),0),1,1)}end +end +local function onMove(P,dir) + local D=P.modeData + + if not D.firstMoveTimestamp then + D.firstMoveTimestamp=P.stat.time + end + + D.lastMoveTimestamp=P.stat.time + + D.displacement=math.abs(P.curX+dir-D.spawnX) +end +local function createMoveHandler(dir) + return function(P) onMove(P,dir) end +end return { das=16,arr=6, sddas=3,sdarr=3, @@ -38,25 +66,106 @@ return { noTele=true, keyCancel={5,6}, mesDisp=function(P) + local D=P.modeData + setFont(75) - GC.mStr(GetLevelStr(P.modeData.lvl),63,210) + GC.mStr(GetLevelStr(D.lvl),63,210) mText(TEXTOBJ.speedLV,63,290) - PLY.draw.drawProgress(P.stat.row,P.modeData.target) - if P.modeData.drought>7 then - if P.modeData.drought<=14 then - GC.setColor(1,1,1,P.modeData.drought/7-1) + PLY.draw.drawProgress(P.stat.row,D.target) + if D.drought>7 then + if D.drought<=14 then + GC.setColor(1,1,1,D.drought/7-1) else - local gb=P.modeData.drought<=21 and 2-P.modeData.drought/14 or .5 + local gb=D.drought<=21 and 2-D.drought/14 or .5 GC.setColor(1,gb,gb) end setFont(50) - GC.mStr(P.modeData.drought,63,130) + GC.mStr(D.drought,63,130) mDraw(MODES.drought_l.icon,63,200,nil,.5) end + + -- Draw Hz counters + local spawnHz=( + D.firstMoveTimestamp and + D.displacement/(D.lastMoveTimestamp-D.spawnTimestamp) + or nil + ) + local moveHz=( + D.firstMoveTimestamp and + D.displacement/(D.lastMoveTimestamp-D.firstMoveTimestamp) + or nil + ) + local mistime=( + D.firstMoveTimestamp and + 1000*(D.firstMoveTimestamp-D.spawnTimestamp) + or nil + ) + + local spawnHzStr="---" + if spawnHz then + if spawnHz<10 then + spawnHzStr=string.format("%.2f",spawnHz) + elseif spawnHz<100 then + spawnHzStr=string.format("%.1f",spawnHz) + elseif spawnHz<1e99 then + spawnHzStr=string.format("%.0f",spawnHz) + else + spawnHzStr="∞" + end + end + + local moveHzStr="---" + if moveHz then + if moveHz<10 then + moveHzStr=string.format("%.2f",moveHz) + elseif moveHz<100 then + moveHzStr=string.format("%.1f",moveHz) + elseif spawnHz<1e99 then + moveHzStr=string.format("%.0f",moveHz) + else + moveHzStr="∞" + end + end + + local mistimeStr="---" + if mistime then + if mistime<10 then + mistimeStr=string.format("%.2f",mistime) + elseif mistime<100 then + mistimeStr=string.format("%.1f",mistime) + else + mistimeStr=string.format("%.0f",mistime) + end + end + + GC.setColor(getHzColor(spawnHz)) + setFont(50) + GC.mStr(spawnHzStr,30,40) + + GC.setColor(1,1,1) + setFont(24) + GC.mStr("Hz",110,65) + + setFont(20) + GC.mStr( + { + "(",getHzColor(moveHz),moveHzStr,{1,1,1}," Hz - ", + getMistimeColor(mistime),mistimeStr,{1,1,1}," ms)" + }, + 40,100 + ) end, task=function(P) - P.modeData.lvl=18 - P.modeData.target=10 + local D=P.modeData + + D.lvl=18 + D.target=10 + + D.spawnX=0 + D.spawnTimestamp=P.stat.time + D.firstMoveTimestamp=false + D.lastMoveTimestamp=false + D.displacement=0 end, hook_drop=function(P) local D=P.modeData @@ -77,4 +186,13 @@ return { D.target=D.target+10 end end, + hook_spawn=function(P) + local D=P.modeData + D.spawnX=P.curX + D.spawnTimestamp=P.stat.time + D.firstMoveTimestamp=false + D.lastMoveTimestamp=false + end, + hook_left=createMoveHandler(-1), + hook_right=createMoveHandler(1), } diff --git a/parts/eventsets/classic_l.lua b/parts/eventsets/classic_l.lua index 893972bd7..b35b4c017 100644 --- a/parts/eventsets/classic_l.lua +++ b/parts/eventsets/classic_l.lua @@ -23,6 +23,34 @@ local function GetGravity(lvl) lvl<29 and 2 or 1 end +local function getHzColor(hz) + if not hz or hz<10 then return{1,1,1} + elseif hz<15 then return{1,1,0} + elseif hz<18 then return{1,.75,0} + elseif hz<25 then return{1,.5,0} + elseif hz<40 then return{1,0,0} + elseif hz<1e99 then return{.5,0,1} + else return{1,0,1}end +end +local function getMistimeColor(t) + if not t then return {1,1,1} + elseif t<1 then return{0,1,1} + else return {COLOR.hsv(math.max(.4-1/9*math.log(t,8),0),1,1)}end +end +local function onMove(P,dir) + local D=P.modeData + + if not D.firstMoveTimestamp then + D.firstMoveTimestamp=P.stat.time + end + + D.lastMoveTimestamp=P.stat.time + + D.displacement=math.abs(P.curX+dir-D.spawnX) +end +local function createMoveHandler(dir) + return function(P) onMove(P,dir) end +end return { das=16,arr=6, sddas=2,sdarr=2, @@ -38,25 +66,106 @@ return { noTele=true, keyCancel={5,6}, mesDisp=function(P) + local D=P.modeData + setFont(75) - GC.mStr(GetLevelStr(P.modeData.lvl),63,210) + GC.mStr(GetLevelStr(D.lvl),63,210) mText(TEXTOBJ.speedLV,63,290) - PLY.draw.drawProgress(P.stat.row,P.modeData.target) - if P.modeData.drought>7 then - if P.modeData.drought<=14 then - GC.setColor(1,1,1,P.modeData.drought/7-1) + PLY.draw.drawProgress(P.stat.row,D.target) + if D.drought>7 then + if D.drought<=14 then + GC.setColor(1,1,1,D.drought/7-1) else - local gb=P.modeData.drought<=21 and 2-P.modeData.drought/14 or .5 + local gb=D.drought<=21 and 2-D.drought/14 or .5 GC.setColor(1,gb,gb) end setFont(50) - GC.mStr(P.modeData.drought,63,130) + GC.mStr(D.drought,63,130) mDraw(MODES.drought_l.icon,63,200,nil,.5) end + + -- Draw Hz counters + local spawnHz=( + D.firstMoveTimestamp and + D.displacement/(D.lastMoveTimestamp-D.spawnTimestamp) + or nil + ) + local moveHz=( + D.firstMoveTimestamp and + D.displacement/(D.lastMoveTimestamp-D.firstMoveTimestamp) + or nil + ) + local mistime=( + D.firstMoveTimestamp and + 1000*(D.firstMoveTimestamp-D.spawnTimestamp) + or nil + ) + + local spawnHzStr="---" + if spawnHz then + if spawnHz<10 then + spawnHzStr=string.format("%.2f",spawnHz) + elseif spawnHz<100 then + spawnHzStr=string.format("%.1f",spawnHz) + elseif spawnHz<1e99 then + spawnHzStr=string.format("%.0f",spawnHz) + else + spawnHzStr="∞" + end + end + + local moveHzStr="---" + if moveHz then + if moveHz<10 then + moveHzStr=string.format("%.2f",moveHz) + elseif moveHz<100 then + moveHzStr=string.format("%.1f",moveHz) + elseif spawnHz<1e99 then + moveHzStr=string.format("%.0f",moveHz) + else + moveHzStr="∞" + end + end + + local mistimeStr="---" + if mistime then + if mistime<10 then + mistimeStr=string.format("%.2f",mistime) + elseif mistime<100 then + mistimeStr=string.format("%.1f",mistime) + else + mistimeStr=string.format("%.0f",mistime) + end + end + + GC.setColor(getHzColor(spawnHz)) + setFont(50) + GC.mStr(spawnHzStr,30,40) + + GC.setColor(1,1,1) + setFont(24) + GC.mStr("Hz",110,65) + + setFont(20) + GC.mStr( + { + "(",getHzColor(moveHz),moveHzStr,{1,1,1}," Hz - ", + getMistimeColor(mistime),mistimeStr,{1,1,1}," ms)" + }, + 40,100 + ) end, task=function(P) - P.modeData.lvl=19 - P.modeData.target=10 + local D=P.modeData + + D.lvl=19 + D.target=10 + + D.spawnX=0 + D.spawnTimestamp=P.stat.time + D.firstMoveTimestamp=false + D.lastMoveTimestamp=false + D.displacement=0 end, hook_drop=function(P) local D=P.modeData @@ -75,5 +184,14 @@ return { end D.target=D.target+10 end - end + end, + hook_spawn=function(P) + local D=P.modeData + D.spawnX=P.curX + D.spawnTimestamp=P.stat.time + D.firstMoveTimestamp=false + D.lastMoveTimestamp=false + end, + hook_left=createMoveHandler(-1), + hook_right=createMoveHandler(1), } diff --git a/parts/eventsets/classic_u.lua b/parts/eventsets/classic_u.lua index 72cfc184d..6f80201ed 100644 --- a/parts/eventsets/classic_u.lua +++ b/parts/eventsets/classic_u.lua @@ -4,6 +4,34 @@ local function GetLevelStr(lvl) lvl=lvl%256 return list[lvl] end +local function getHzColor(hz) + if not hz or hz<10 then return{1,1,1} + elseif hz<15 then return{1,1,0} + elseif hz<18 then return{1,.75,0} + elseif hz<25 then return{1,.5,0} + elseif hz<40 then return{1,0,0} + elseif hz<1e99 then return{.5,0,1} + else return{1,0,1}end +end +local function getMistimeColor(t) + if not t then return {1,1,1} + elseif t<1 then return{0,1,1} + else return {COLOR.hsv(math.max(.4-1/9*math.log(t,8),0),1,1)}end +end +local function onMove(P,dir) + local D=P.modeData + + if not D.firstMoveTimestamp then + D.firstMoveTimestamp=P.stat.time + end + + D.lastMoveTimestamp=P.stat.time + + D.displacement=math.abs(P.curX+dir-D.spawnX) +end +local function createMoveHandler(dir) + return function(P) onMove(P,dir) end +end return { das=16,arr=6, sddas=1,sdarr=1, @@ -19,25 +47,106 @@ return { noTele=true, keyCancel={5,6}, mesDisp=function(P) + local D=P.modeData + setFont(75) - GC.mStr(GetLevelStr(P.modeData.lvl),63,210) + GC.mStr(GetLevelStr(D.lvl),63,210) mText(TEXTOBJ.speedLV,63,290) - PLY.draw.drawProgress(P.stat.row,P.modeData.target) - if P.modeData.drought>7 then - if P.modeData.drought<=14 then - GC.setColor(1,1,1,P.modeData.drought/7-1) + PLY.draw.drawProgress(P.stat.row,D.target) + if D.drought>7 then + if D.drought<=14 then + GC.setColor(1,1,1,D.drought/7-1) else - local gb=P.modeData.drought<=21 and 2-P.modeData.drought/14 or .5 + local gb=D.drought<=21 and 2-D.drought/14 or .5 GC.setColor(1,gb,gb) end setFont(50) - GC.mStr(P.modeData.drought,63,130) + GC.mStr(D.drought,63,130) mDraw(MODES.drought_l.icon,63,200,nil,.5) end + + -- Draw Hz counters + local spawnHz=( + D.firstMoveTimestamp and + D.displacement/(D.lastMoveTimestamp-D.spawnTimestamp) + or nil + ) + local moveHz=( + D.firstMoveTimestamp and + D.displacement/(D.lastMoveTimestamp-D.firstMoveTimestamp) + or nil + ) + local mistime=( + D.firstMoveTimestamp and + 1000*(D.firstMoveTimestamp-D.spawnTimestamp) + or nil + ) + + local spawnHzStr="---" + if spawnHz then + if spawnHz<10 then + spawnHzStr=string.format("%.2f",spawnHz) + elseif spawnHz<100 then + spawnHzStr=string.format("%.1f",spawnHz) + elseif spawnHz<1e99 then + spawnHzStr=string.format("%.0f",spawnHz) + else + spawnHzStr="∞" + end + end + + local moveHzStr="---" + if moveHz then + if moveHz<10 then + moveHzStr=string.format("%.2f",moveHz) + elseif moveHz<100 then + moveHzStr=string.format("%.1f",moveHz) + elseif spawnHz<1e99 then + moveHzStr=string.format("%.0f",moveHz) + else + moveHzStr="∞" + end + end + + local mistimeStr="---" + if mistime then + if mistime<10 then + mistimeStr=string.format("%.2f",mistime) + elseif mistime<100 then + mistimeStr=string.format("%.1f",mistime) + else + mistimeStr=string.format("%.0f",mistime) + end + end + + GC.setColor(getHzColor(spawnHz)) + setFont(50) + GC.mStr(spawnHzStr,30,40) + + GC.setColor(1,1,1) + setFont(24) + GC.mStr("Hz",110,65) + + setFont(20) + GC.mStr( + { + "(",getHzColor(moveHz),moveHzStr,{1,1,1}," Hz - ", + getMistimeColor(mistime),mistimeStr,{1,1,1}," ms)" + }, + 40,100 + ) end, task=function(P) - P.modeData.lvl=29 - P.modeData.target=10 + local D=P.modeData + + D.lvl=29 + D.target=10 + + D.spawnX=0 + D.spawnTimestamp=P.stat.time + D.firstMoveTimestamp=false + D.lastMoveTimestamp=false + D.displacement=0 end, hook_drop=function(P) local D=P.modeData @@ -49,4 +158,13 @@ return { D.target=D.target+10 end end, + hook_spawn=function(P) + local D=P.modeData + D.spawnX=P.curX + D.spawnTimestamp=P.stat.time + D.firstMoveTimestamp=false + D.lastMoveTimestamp=false + end, + hook_left=createMoveHandler(-1), + hook_right=createMoveHandler(1), }