Skip to content

07 Printing Measures ​

In this chapter, we will implementing printing measures.

Beats ​

To know how many measures to print, we first need to know how many beats are in a level.

Similar to how we obtain duration of a level, we can have a variable storing beats and notes continuously update it.

TypeScript
export const chart = previewData({
    beats: Number,
    // ...
})
JavaScript
export const chart = previewData({
    beats: Number,
    // ...
})
TypeScript
export class Note extends Archetype {
    // ...

    preprocess() {
        chart.beats = Math.max(chart.beats, this.import.beat)
        // ...
    }

    // ...
}
JavaScript
export class Note extends Archetype {
    // ...

    preprocess() {
        chart.beats = Math.max(chart.beats, this.import.beat)
        // ...
    }

    // ...
}

Measures ​

Now we can loop over the beats, and print every 4 beats:

TypeScript
export class Stage extends Archetype {
    // ...

    render() {
        // ...
        this.printMeasures()
    }

    // ...

    printMeasures() {
        for (let i = 4; i <= Math.floor(chart.beats); i += 4) {
            print(
                i / 4 + 1,
                bpmChanges.at(i).time,
                PrintFormat.MeasureCount,
                0,
                PrintColor.Neutral,
                'right',
            )
        }
    }
}
JavaScript
export class Stage extends Archetype {
    // ...

    render() {
        // ...
        this.printMeasures()
    }

    // ...

    printMeasures() {
        for (let i = 4; i <= Math.floor(chart.beats); i += 4) {
            print(
                i / 4 + 1,
                bpmChanges.at(i).time,
                PrintFormat.MeasureCount,
                0,
                PrintColor.Neutral,
                'right',
            )
        }
    }
}