Skip to content

03 Initialization

In this chapter, we will initialize the shared gameplay systems and add the watch progress bar.

Initialization

Watch mode uses the same setup calls as Play mode, but it does not process live player input. The template already defines WatchInitialization as a subclass of WatchArchetype.

Edit guide/watch/initialization.py. Import the setup functions used for buckets, score, UI, and layout. Keep the template's archetype name, then add the preprocess callback so the file contains:

python
from sonolus.script.archetype import WatchArchetype

from guide.lib import archetype_names
from guide.lib.buckets import init_buckets
from guide.lib.layout import init_layout
from guide.lib.note import init_score
from guide.lib.options import Options
from guide.lib.ui import init_ui


class WatchInitialization(WatchArchetype):
    name = archetype_names.INITIALIZATION

    def preprocess(self):
        init_buckets()
        init_score()
        init_ui()
        init_layout(Options.note_size)

These helpers reuse the bucket setup from Play chapter 15, score setup from Play chapter 16, completed UI setup from Play chapter 17, and configurable layout from Play chapter 22.

Do not copy Play's spawning or input callbacks. Watch mode does not process live input. Life setup also waits until WatchNote exists in chapter 05.

Watch mode needs a progress bar so players can see and change the playback position. The Play section already added all required imports to guide/lib/ui.py. Add this block at the end of init_ui, after the secondary metric layout:

python
def init_ui():
    # ...

    ui.progress.update(
        anchor=safe_area().bl + Vec2(0.05, 0.05),
        pivot=Vec2(0, 0),
        dimensions=Vec2(safe_area().w - 0.1, 0.15 * ui.progress_config.scale),
        rotation=0,
        alpha=ui.progress_config.alpha,
        horizontal_align=HorizontalAlign.CENTER,
        background=True,
    )

Reload Watch. The progress bar should appear along the bottom of the screen. The template's temporary time log remains until chapter 04.