Sonolus Wiki

22. Options

In this chapter, we will add options to make our engine more versatile.

Speed

One of the most used option in rhythm game is variable speed, it gives player the ability to speed up/slow down a level to make it more challenging/easier to practice with.

Let's add speed option to engine options:

export const optionsDefinition = {
    speed: {
        name: Text.Speed,
        standard: true,
        type: 'slider',
        def: 1,
        min: 0.5,
        max: 2,
        step: 0.05,
        unit: Text.PercentageUnit,
    },
} satisfies Record<string, EngineConfigurationOption>
export const optionsDefinition = {
    speed: {
        name: Text.Speed,
        standard: true,
        type: 'slider',
        def: 1,
        min: 0.5,
        max: 2,
        step: 0.05,
        unit: Text.PercentageUnit,
    },
}

Amazingly, that's all we need to do. Sonolus knows about the special option name NameText.LevelSpeed and will automatically adjust the BGM speed to match, as well as all BPM values in BPM change. Because we have written our engine code entirely based on BPM and beats, it works without any further modification.

Note Size

We may also offer a note size option, so that players can adjust it to their liking.

Let's add note size option to engine options:

export const optionsDefinition = {
    // ...
    noteSize: {
        name: Text.NoteSize,
        type: 'slider',
        def: 1,
        min: 0.1,
        max: 2,
        step: 0.05,
        unit: Text.PercentageUnit,
    },
} satisfies Record<string, EngineConfigurationOption>
export const optionsDefinition = {
    // ...
    noteSize: {
        name: Text.NoteSize,
        type: 'slider',
        def: 1,
        min: 0.1,
        max: 2,
        step: 0.05,
        unit: Text.PercentageUnit,
    },
}

With that, let's use the value of note size option and adjust note radius:

export class Initialization extends Archetype {
    preprocess() {
        const noteRadius = 0.2 * options.noteSize
        // ...
    }

    // ...
}
export class Initialization extends Archetype {
    preprocess() {
        const noteRadius = 0.2 * options.noteSize
        // ...
    }

    // ...
}