Skip to content

22 Options

This chapter adds Speed and Note Size options.

Add the Speed Option

Variable speed is one of the most common options in rhythm games. It lets the player speed up a level for a greater challenge or slow it down for easier practice.

Open guide/lib/options.py. Add the imports below and replace pass in Options with the speed slider:

python
from sonolus.script.options import options, slider_option
from sonolus.script.text import StandardText


@options
class Options:
    speed: float = slider_option(
        name=StandardText.SPEED,
        standard=True,
        default=1,
        min=0.5,
        max=2,
        step=0.05,
        unit=StandardText.PERCENTAGE_UNIT,
    )

name=StandardText.SPEED identifies the slider as Sonolus's speed option. Sonolus then adjusts both background music playback and BPM values to the selected speed. Our Note calculations use beat_to_time and beat_to_bpm, so they receive the adjusted values without further changes.

standard=True has a separate purpose: if the player chooses a value other than the default, Sonolus reports the play as using modified gameplay on the result screen.

Add the Note Size Option

In the same Options class, add a note size slider below speed:

python
@options
class Options:
    # ...

    note_size: float = slider_option(
        name=StandardText.NOTE_SIZE,
        default=1,
        min=0.1,
        max=2,
        step=0.05,
        unit=StandardText.PERCENTAGE_UNIT,
    )

Now open guide/play/initialization.py. Import Options and replace init_layout(1) with init_layout(Options.note_size):

python
from guide.lib.layout import init_layout
from guide.lib.options import Options
from guide.lib.ui import init_ui


class Initialization(PlayArchetype):
    def preprocess(self):
        # ...
        init_ui()
        init_layout(Options.note_size)

    # ...

Checkpoint

Open the level configuration. It should contain Speed and Note Size sliders. Changing Speed should affect the music and chart together. Changing Note Size should affect the note layout without changing note timing.

Continue to Watch Mode.