Skip to content

10 Repetição

Neste capítulo, implementaremos a lógica de repetição do Note.

Julgamento e Precisão

O replay recria a jogabilidade gravada no modo de observação.

Para conseguir isso, precisamos de informações de julgamento e precisão:

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

    import = this.defineImport({
        // ...
        judgment: { name: EngineArchetypeDataName.Judgment, type: DataType<Judgment> },
        accuracy: { name: EngineArchetypeDataName.Accuracy, type: Number },
    })

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

    import = this.defineImport({
        // ...
        judgment: { name: EngineArchetypeDataName.Judgment, type: Number },
        accuracy: { name: EngineArchetypeDataName.Accuracy, type: Number },
    })

    // ...
}

Tempo de Desaparecimento

Com precisão, podemos ajustar o tempo de desaparecimento de acordo:

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

    despawnTime() {
        return replay.isReplay
            ? timeScaleChanges.at(this.targetTime + this.import.accuracy).scaledTime
            : this.visualTime.max
    }

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

    despawnTime() {
        return replay.isReplay
            ? timeScaleChanges.at(this.targetTime + this.import.accuracy).scaledTime
            : this.visualTime.max
    }

    // ...
}

SFX

Da mesma forma, podemos ajustar os efeitos sonoros com base no julgamento e na precisão:

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

    preprocess() {
        // ...

        if (replay.isReplay) {
            const hitTime = this.targetTime + this.import.accuracy

            switch (this.import.judgment) {
                case Judgment.Perfect:
                    effect.clips.perfect.schedule(hitTime, 0.02)
                    break
                case Judgment.Great:
                    effect.clips.great.schedule(hitTime, 0.02)
                    break
                case Judgment.Good:
                    effect.clips.good.schedule(hitTime, 0.02)
                    break
            }
        } else {
            effect.clips.perfect.schedule(this.targetTime, 0.02)
        }

        // ...
    }

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

    preprocess() {
        // ...

        if (replay.isReplay) {
            const hitTime = this.targetTime + this.import.accuracy

            switch (this.import.judgment) {
                case Judgment.Perfect:
                    effect.clips.perfect.schedule(hitTime, 0.02)
                    break
                case Judgment.Great:
                    effect.clips.great.schedule(hitTime, 0.02)
                    break
                case Judgment.Good:
                    effect.clips.good.schedule(hitTime, 0.02)
                    break
            }
        } else {
            effect.clips.perfect.schedule(this.targetTime, 0.02)
        }

        // ...
    }

    // ...
}

Efeito de Partícula

Por fim, devemos pular a reprodução do efeito de partícula se o jogador não acertou a nota:

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

    terminate() {
        // ...
        if (replay.isReplay && !this.import.judgment) return

        // ...
    }

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

    terminate() {
        // ...
        if (replay.isReplay && !this.import.judgment) return

        // ...
    }

    // ...
}