Skip to content

Commit

Permalink
Fix toBeat fromBeat calculation with non 0-beat scrolls
Browse files Browse the repository at this point in the history
  • Loading branch information
tillvit committed Jan 31, 2024
1 parent f0403a2 commit 22d74e1
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions app/src/chart/ChartRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,21 +625,28 @@ export class ChartRenderer extends Container<ChartRendererComponent> {
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 ??
this.getVisualBeat() + Options.chart.maxDrawBeats
const scrollEndYPos = this.getYPosFromBeat(scrollEndBeat)

if (
scroll.value * sign > 0 &&
(scroll?.value ?? 1) * sign > 0 &&
scrollEndYPos > upperBound &&
(scrollStartYPos < upperBound ||
!scrolls[scrollIndex - 1] ||
Expand All @@ -649,7 +656,7 @@ export class ChartRenderer extends Container<ChartRendererComponent> {
)
break
if (
scroll.value * sign < 0 &&
(scroll?.value ?? 1) * sign < 0 &&
scrollEndYPos < lowerBound &&
(scrollStartYPos > lowerBound ||
!scrolls[scrollIndex - 1] ||
Expand All @@ -669,6 +676,7 @@ export class ChartRenderer extends Container<ChartRendererComponent> {
(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 &&
Expand Down Expand Up @@ -731,21 +739,28 @@ export class ChartRenderer extends Container<ChartRendererComponent> {
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 ??
this.getVisualBeat() + Options.chart.maxDrawBeats
const scrollEndYPos = this.getYPosFromBeat(scrollEndBeat)

if (
scroll.value * sign > 0 &&
(scroll?.value ?? 1) * sign > 0 &&
scrollStartYPos < lowerBound &&
(scrollEndYPos > lowerBound ||
!scrolls[scrollIndex + 1] ||
Expand All @@ -755,7 +770,7 @@ export class ChartRenderer extends Container<ChartRendererComponent> {
)
break
if (
scroll.value * sign < 0 &&
(scroll?.value ?? 1) * sign < 0 &&
scrollStartYPos > upperBound &&
(scrollEndYPos < upperBound ||
!scrolls[scrollIndex + 1] ||
Expand Down

0 comments on commit 22d74e1

Please sign in to comment.