Skip to content

Commit

Permalink
fully set up jack diff debug output
Browse files Browse the repository at this point in the history
good lord this got weird
  • Loading branch information
poco0317 committed Jul 18, 2020
1 parent 1d0270f commit 34e05cc
Showing 1 changed file with 143 additions and 17 deletions.
160 changes: 143 additions & 17 deletions Themes/Til Death/BGAnimations/_calcdisplay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,24 @@ local function fitY2(y, lb, ub)
end

-- restrict the x bounds of the graph to a specific range of percentages
local function getGraphBounds()
local function getGraphBounds(vec)
-- if these vectors are empty, dont restrict
if graphVecs["JS"] == nil or #graphVecs["JS"][1] == 0 then
if vec == nil or #vec[1] == 0 then
return 0, 1
else
-- get the x position of the first and last item, normalize the position, and then convert them to percentages [0,1]
return (fitX(firstSecond / getCurRateValue(), finalSecond / getCurRateValue()) + plotWidth/2) / plotWidth, (fitX(#graphVecs["JS"][1] + firstSecond, finalSecond / getCurRateValue()) + plotWidth/2) / plotWidth
return (fitX(firstSecond / getCurRateValue(), finalSecond / getCurRateValue()) + plotWidth/2) / plotWidth, (fitX(#vec[1] + firstSecond, finalSecond / getCurRateValue()) + plotWidth/2) / plotWidth
end
end

-- restrict the x bounds of the graph to a specific range of percentages
local function getGraphBoundsJack(vec)
-- if these vectors are empty, dont restrict
if vec == nil or #vec == 0 then
return 0, 1
else
-- get the x position of the first and last item, normalize the position, and then convert them to percentages [0,1]
return (fitX(vec[1][1], finalSecond/2 / getCurRateValue()) + plotWidth/2) / plotWidth, (fitX(vec[#vec][1], finalSecond/2 / getCurRateValue()) + plotWidth/2) / plotWidth
end
end

Expand All @@ -90,7 +101,7 @@ end
-- graph percentage to index (dependent on mod/song length)
local function convertPercentToIndexForMods(leftX, rightX)
local percent = leftX / rightX
local lower, upper = getGraphBounds()
local lower, upper = getGraphBounds(graphVecs["JS"])

-- if the percentage given is outside the desired bounds, restrict it to sane bounds
if percent < lower then
Expand All @@ -104,6 +115,53 @@ local function convertPercentToIndexForMods(leftX, rightX)
end
end

-- graph percentage to index (dependent on nerv/jack length)
local function convertPercentToIndexForJack(leftX, rightX, vec)
local percent = leftX / rightX
local lower, upper = getGraphBoundsJack(vec)

-- if the percentage given is outside the desired bounds, restrict it to sane bounds
if percent < lower then
finalIndex = 1
elseif percent > upper then
finalIndex = #vec
else
local timepercent = percent
-- otherwise scale the number to a percentage .. of a percentage
percent = scale(percent, lower, upper, 0, 1)

-- heres the time value of the index we want to end up with but its REALLY likely that wont happen
local intendedtime = finalSecond/2/getCurRateValue() * timepercent
-- but we have to binary search the values to find the true index
-- HAHAHAHAHAHA THIS IS SO BAD BUT IM TRYING TO MAKE IT NOT SO BAD
local searchpoint = notShit.round(percent * #vec)
if searchpoint < 1 then searchpoint = 1 end
if searchpoint > #vec then searchpoint = #vec end
local lastsearchpoint = 0
local lastlastsearchpoint = -1 -- checking this to prevent loops
local lb, ub = 0, #vec
while lastlastsearchpoint ~= searchpoint do
if vec[searchpoint][1] < intendedtime then
lb = searchpoint
lastlastsearchpoint = lastsearchpoint
lastsearchpoint = searchpoint
searchpoint = notShit.round((ub-lb)/2 + lb)
elseif vec[searchpoint][1] > intendedtime then
ub = searchpoint
lastlastsearchpoint = lastsearchpoint
lastsearchpoint = searchpoint
searchpoint = notShit.round((ub-lb)/2 + lb)
else
-- well this would be exceptionally rare to match a float...
return searchpoint
end
end

finalIndex = searchpoint
end
return finalIndex
end

-- transforms the position of the mouse from the cd graph to the calc info graph
local function transformPosition(pos, w, px)
distanceAcrossOriginal = (pos - px) / w
Expand Down Expand Up @@ -264,14 +322,15 @@ local debugGroups = {
-- specify enum names here
-- only CalcDiffValue enums
-- also specify SSR to show all SSRs (recommend to leave a group alone)
-- also specify Jack to show the Jack diffs for both hands
-- miscDebugMods that are also specified under miscToLowerMods can be placed here
local diffGroups = {
{ -- Group 1
NPSBase = true,
MSD = true,
},
{ -- Group 2

Jack = true,
},
{ -- Group 3
TechBase = true,
Expand Down Expand Up @@ -313,7 +372,7 @@ local function updateCoolStuff()
-- double the output because intervals are half seconds
firstSecond = steps:GetFirstSecond() * 2
finalSecond = steps:GetLastSecond() * 2
steplength = (finalSecond - firstSecond)
steplength = (finalSecond - firstSecond) -- this is "doubled" here
end
jackdiffs = {Left = {}, Right = {}}
if steps then
Expand All @@ -330,14 +389,16 @@ local function updateCoolStuff()
-- Jack debug output got hyper convoluted so im trying to make it as sane as possible
-- basically jackdiffs[hand][index] = {row time, diff}
-- this is so we can place the indices based on row time instead of index
-- also keep in mind the row times are already changed for each rate so 1.1 will be smaller than 1.0
-- also all the row times are relative to the first non empty noterow so lets just pad it by the firstsecond/2 too
local jap = steps:GetCalcDebugJack()["JackHand"]
local upperiter = #jap["Left"] > #jap["Right"] and #jap["Left"] or #jap["Right"]
for i = 1, upperiter do
if jap["Left"][i] then
jackdiffs["Left"][#jackdiffs["Left"] + 1] = { jap["Left"][i][1], jap["Left"][i][2] }
jackdiffs["Left"][#jackdiffs["Left"] + 1] = { jap["Left"][i][1] + firstSecond/2/getCurRateValue(), jap["Left"][i][2] }
end
if jap["Right"][i] then
jackdiffs["Right"][#jackdiffs["Right"] + 1] = { jap["Right"][i][1], jap["Right"][i][2] }
jackdiffs["Right"][#jackdiffs["Right"] + 1] = { jap["Right"][i][1] + firstSecond/2/getCurRateValue(), jap["Right"][i][2] }
end
end

Expand Down Expand Up @@ -519,14 +580,6 @@ local function yetAnotherInputCallback(event)
return true
end
end

local CtrlPressed = INPUTFILTER:IsControlPressed()
if tonumber(event.char) and CtrlPressed and enabled then
local num = tonumber(event.char)
if num == 0 then
switchSSRGraph()
end
end
end
return false
end
Expand Down Expand Up @@ -713,8 +766,21 @@ o[#o + 1] = Def.Quad {
if not diffGroups[activeDiffGroup]["SSRS"] then
local index = convertPercentToIndexForMods(mx - leftEnd, rightEnd - leftEnd)
local modText = getDebugModsForIndex(CalcDiffValue, "CalcDiffValue", miscToLowerMods, index, false)

if diffGroups[activeDiffGroup]["Jack"] then
modText = modText .. "\n"
for h = 1,2 do
local hnd = h == 1 and "Left" or "Right"
local hand = h == 1 and "L" or "R"
local index = convertPercentToIndexForJack(mx - leftEnd, rightEnd - leftEnd, jackdiffs[hnd])
local txt = string.format("%s: %5.4f\n", "Jack"..hand, jackdiffs[hnd][index][2])
modText = modText .. txt
end
modText = modText:sub(1, #modText-1) -- remove the end whitespace
end

txt:settext(modText)
else
elseif diffGroups[activeDiffGroup]["SSRS"] then
local ssrindex = convertPercentToIndex(perc)
-- The names here are made under the assumption the skillsets and their positions never change
local ssrAtIndex = {
Expand Down Expand Up @@ -901,6 +967,11 @@ local skillsetColors = {
color("#b0cec2"), -- tech
}

local jackdiffColors = {
color("1,1,0"), -- jack diff left
color(".6,0,.7") -- jack diff right
}

-- these are all CalcDiffValue mods only
-- in the same order
local calcDiffValueColors = {
Expand Down Expand Up @@ -1149,6 +1220,55 @@ local function bottomGraphLineMSD(mod, colorToUse, hand)
}
end

local function bottomGraphLineJack(colorToUse, hand)
return Def.ActorMultiVertex {
InitCommand = function(self)
self:y(plotHeight+5)
end,
DoTheThingCommand = function(self)
if song and enabled then
self:SetVertices({})
self:SetDrawState {Mode = "DrawMode_Quads", First = 1, Num = 0}

if activeDiffGroup == -1 or (diffGroups[activeDiffGroup] and diffGroups[activeDiffGroup]["Jack"]) then
self:visible(true)
else
self:visible(false)
end

local hand = hand == 1 and "Left" or "Right"
local verts = {}
local values = jackdiffs[hand]
if not values or not values[1] then return end

for i = 1, #values do
--local x = fitX(i, #values) -- vector length based positioning
-- if used, final/firstsecond must be halved
-- they need to be halved because the numbers we use here are not half second interval based, but row time instead
local x = fitX(values[i][1], finalSecond / 2 / getCurRateValue()) -- song length based positioning
local y = fitY2(values[i][2], lowerGraphMin, lowerGraphMax)

setOffsetVerts(verts, x, y, colorToUse)
end

self:SetVertices(verts)
self:SetDrawState {Mode = "DrawMode_LineStrip", First = 1, Num = #verts}
else
self:visible(false)
end
end,
UpdateActiveLowerGraphMessageCommand = function(self)
if song and enabled then
if activeDiffGroup == -1 or (diffGroups[activeDiffGroup] and diffGroups[activeDiffGroup]["Jack"]) then
self:visible(true)
else
self:visible(false)
end
end
end
}
end

local function bottomGraphLineSSR(lineNum, colorToUse)
return Def.ActorMultiVertex {
InitCommand = function(self)
Expand Down Expand Up @@ -1257,6 +1377,12 @@ for i = 1,8 do
o[#o+1] = bottomGraphLineSSR(i, skillsetColors[i])
end

-- Jack diff line(s)
for h = 1,2 do
local colr = jackdiffColors[h]
o[#o+1] = bottomGraphLineJack(colr, h)
end

-- a bunch of things for stuff and things
o[#o + 1] = LoadFont("Common Normal") .. {
Name = "Seektext1",
Expand Down

0 comments on commit 34e05cc

Please sign in to comment.