Skip to content

Commit

Permalink
Fix first scroll not inheriting first value
Browse files Browse the repository at this point in the history
  • Loading branch information
tillvit committed Aug 19, 2024
1 parent 6135628 commit 6a9e8a1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
22 changes: 11 additions & 11 deletions app/src/chart/ChartRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,11 @@ export class ChartRenderer extends Container<ChartRendererComponent> {
...this.chart.timingData.getTimingData("SCROLLS"),
]
if (scrolls[0]?.beat != 0)
scrolls.splice(0, 0, { beat: 0, value: 1, type: "SCROLLS" })
scrolls.splice(0, 0, {
beat: 0,
value: scrolls[0]?.value ?? 1,
type: "SCROLLS",
})

let scrollIndex = bsearch(
scrolls,
Expand All @@ -633,8 +637,6 @@ export class ChartRenderer extends Container<ChartRendererComponent> {
const scroll = scrolls[scrollIndex]
scrollIndex++

if (scroll.value == 0) continue

const scrollStartY =
scroll === undefined
? -Infinity * this.getScrollDirection(scrolls[0]?.value ?? 1)
Expand All @@ -656,7 +658,11 @@ export class ChartRenderer extends Container<ChartRendererComponent> {
...this.chart.timingData.getTimingData("SCROLLS"),
]
if (scrolls[0]?.beat != 0)
scrolls.splice(0, 0, { beat: 0, value: 1, type: "SCROLLS" })
scrolls.splice(0, 0, {
beat: 0,
value: scrolls[0]?.value ?? 1,
type: "SCROLLS",
})
let scrollIndex = bsearch(
scrolls,
this.getVisualBeat() + Options.chart.maxDrawBeats,
Expand All @@ -673,8 +679,6 @@ export class ChartRenderer extends Container<ChartRendererComponent> {
const scroll = scrolls[scrollIndex]
scrollIndex--

if (scroll.value == 0) continue

const scrollStartY =
scroll === undefined
? -Infinity * this.getScrollDirection(scrolls[0]?.value ?? 1)
Expand All @@ -699,12 +703,8 @@ export class ChartRenderer extends Container<ChartRendererComponent> {
) {
const scroll = this.findFirstOnScreenScroll()

const speedMult = this.getCurrentSpeedMult()
const pixelsToEffectiveBeats =
100 /
Options.chart.speed /
Math.abs(speedMult) /
64 /
(1 / Math.abs(this.getEffectiveBeatsToPixelsRatio())) *
Options.chart.zoom

const scrollStartY = this.getYPosFromBeat(scroll.beat)
Expand Down
16 changes: 9 additions & 7 deletions app/src/chart/component/edit/Waveform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ export class Waveform extends Sprite implements ChartRendererComponent {
...this.renderer.chart.timingData.getTimingData("SCROLLS"),
]
if (scrolls[0]?.beat != 0)
scrolls.unshift({ type: "SCROLLS", beat: 0, value: 1 })
scrolls.unshift({
type: "SCROLLS",
beat: 0,
value: scrolls[0]?.value ?? 1,
})

const startScrollIndex = scrolls.findIndex(
a => a.beat == startScroll.beat
Expand All @@ -258,7 +262,7 @@ export class Waveform extends Sprite implements ChartRendererComponent {
)) {
if (scroll.value == 0) continue
const pixelsToBeats = pixelsToEffectiveBeats / Math.abs(scroll.value)
if (scroll != startScroll) {
if (scroll.beat != startScroll.beat) {
currentBeat = scroll.beat
} else {
// fix flickering by rounding the current beat to land on a pixel
Expand All @@ -279,7 +283,7 @@ export class Waveform extends Sprite implements ChartRendererComponent {
// Stop if the scroll is off the screen
if (currentYPos < 0) {
// Skip the scroll if we step off the top of the screen
if (scroll.value * scrollDirection < 0) {
if (scrollDirection < 0) {
currentBeat = scrollEndBeat
break
}
Expand All @@ -290,7 +294,7 @@ export class Waveform extends Sprite implements ChartRendererComponent {

if (currentYPos > screenHeight) {
// Skip the scroll if we step off the bottom of the screen
if (scroll.value * scrollDirection > 0) {
if (scrollDirection > 0) {
currentBeat = scrollEndBeat
break
}
Expand All @@ -302,9 +306,7 @@ export class Waveform extends Sprite implements ChartRendererComponent {

// Step by 1 or -1 pixels and get the current beat
currentBeat += pixelsToBeats * Options.chart.waveform.lineHeight
currentYPos +=
(scroll.value * scrollDirection > 0 ? 1 : -1) *
Options.chart.waveform.lineHeight
currentYPos += scrollDirection * Options.chart.waveform.lineHeight

curSec = this.calculateSecond(
currentBeat,
Expand Down
2 changes: 1 addition & 1 deletion app/src/chart/component/timing/TimingTrackContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ export class TimingTrackContainer
TIMING_EVENT_COLORS[event.type] ?? 0x000000,
Math.sin(Date.now() / 320) * 0.4 + 1.5
)
: TIMING_EVENT_COLORS[event.type] ?? 0x000000
: (TIMING_EVENT_COLORS[event.type] ?? 0x000000)
box.selection.alpha = inSelection ? 1 : 0
box.visible =
!inSelection || !this.renderer.chartManager.eventSelection.shift
Expand Down
2 changes: 1 addition & 1 deletion app/src/chart/sm/TimingData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export abstract class TimingData {
cache.unshift({
type: "SCROLLS",
beat: 0,
value: 1,
value: cache[0].value ?? 1,
})
effBeat = cache[0].beat
for (let i = 0; i < cache.length - 1; i++) {
Expand Down

0 comments on commit 6a9e8a1

Please sign in to comment.