From 22d74e1aea017b570b99dc8c92526563bb653de4 Mon Sep 17 00:00:00 2001 From: tillvit Date: Tue, 30 Jan 2024 22:58:26 -0500 Subject: [PATCH] Fix toBeat fromBeat calculation with non 0-beat scrolls --- app/src/chart/ChartRenderer.ts | 35 ++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/app/src/chart/ChartRenderer.ts b/app/src/chart/ChartRenderer.ts index 969aa997..dae9ac39 100644 --- a/app/src/chart/ChartRenderer.ts +++ b/app/src/chart/ChartRenderer.ts @@ -625,13 +625,20 @@ export class ChartRenderer extends Container { a => a.beat ) + if ( + this.getVisualBeat() - Options.chart.maxDrawBeatsBack < + scrolls[0]?.beat + ) { + scrollIndex = -1 + } + while ( - scrolls[scrollIndex]?.beat < - this.getVisualBeat() + Options.chart.maxDrawBeats + scrolls[scrollIndex]?.beat ?? + 0 < this.getVisualBeat() + Options.chart.maxDrawBeats ) { const scroll = scrolls[scrollIndex] - const scrollStartYPos = this.getYPosFromBeat(scroll.beat) + const scrollStartYPos = this.getYPosFromBeat(scroll?.beat ?? 0) const scrollEndBeat = scrolls[scrollIndex + 1]?.beat ?? @@ -639,7 +646,7 @@ export class ChartRenderer extends Container { const scrollEndYPos = this.getYPosFromBeat(scrollEndBeat) if ( - scroll.value * sign > 0 && + (scroll?.value ?? 1) * sign > 0 && scrollEndYPos > upperBound && (scrollStartYPos < upperBound || !scrolls[scrollIndex - 1] || @@ -649,7 +656,7 @@ export class ChartRenderer extends Container { ) break if ( - scroll.value * sign < 0 && + (scroll?.value ?? 1) * sign < 0 && scrollEndYPos < lowerBound && (scrollStartYPos > lowerBound || !scrolls[scrollIndex - 1] || @@ -669,6 +676,7 @@ export class ChartRenderer extends Container { (pixelsToEffectiveBeats / Math.abs(scrollValue)) * Options.chart.zoom const start = Options.chart.reverse ? upperBound : lowerBound const end = Options.chart.reverse ? lowerBound : upperBound + if (scrollValue * sign > 0) { if ( scrolls[scrollIndex - 1]?.value == 0 && @@ -731,13 +739,20 @@ export class ChartRenderer extends Container { a => a.beat ) + if ( + this.getVisualBeat() - Options.chart.maxDrawBeatsBack < + scrolls[0]?.beat + ) { + scrollIndex = -1 + } + while ( - scrolls[scrollIndex]?.beat > - this.getVisualBeat() - Options.chart.maxDrawBeatsBack + scrolls[scrollIndex]?.beat ?? + 0 > this.getVisualBeat() - Options.chart.maxDrawBeatsBack ) { const scroll = scrolls[scrollIndex] - const scrollStartYPos = this.getYPosFromBeat(scroll.beat) + const scrollStartYPos = this.getYPosFromBeat(scroll?.beat ?? 0) const scrollEndBeat = scrolls[scrollIndex + 1]?.beat ?? @@ -745,7 +760,7 @@ export class ChartRenderer extends Container { const scrollEndYPos = this.getYPosFromBeat(scrollEndBeat) if ( - scroll.value * sign > 0 && + (scroll?.value ?? 1) * sign > 0 && scrollStartYPos < lowerBound && (scrollEndYPos > lowerBound || !scrolls[scrollIndex + 1] || @@ -755,7 +770,7 @@ export class ChartRenderer extends Container { ) break if ( - scroll.value * sign < 0 && + (scroll?.value ?? 1) * sign < 0 && scrollStartYPos > upperBound && (scrollEndYPos < upperBound || !scrolls[scrollIndex + 1] ||