Sonolus Wiki

22. 选项

在本章中,我们将添加选项以使我们的引擎更加通用化。

速度

节奏游戏中最常用的选项之一是变速,它使玩家能够加速/减速关卡,使其更具挑战性/更容易练习。

让我们在引擎选项中添加速度选项:

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

非常惊人,这就是我们需要做的所有事情。 Sonolus 知道特殊选项名称NameText.LevelSpeed并将自动调整 BGM 速度与之匹配,以及 BPM 变化(BPM change)中的所有 BPM 值。因为我们完全基于 BPM 和节拍编写了我们的引擎代码,所以它无需任何进一步修改即可运行。

音符大小

我们可能还会提供音符大小选项,以便玩家可以根据自己的喜好进行调整。

让我们在引擎选项中添加音符大小选项:

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

有了上面这些以后,我们就要使用音符大小选项的值来调整音符半径:

export class Initialization extends Archetype {
    preprocess() {
        // ...

        note.radius = (noteRadius / h) * options.noteSize

        // ...
    }

    // ...
}
export class Initialization extends Archetype {
    preprocess() {
        // ...

        note.radius = (noteRadius / h) * options.noteSize

        // ...
    }

    // ...
}