05 Nota Vitalícia
Neste capítulo, implementaremos a lógica de tempo de vida do Note.
Nota Arquétipo
Vamos primeiro configurar o Note:
TypeScript
export class Note extends Archetype {}
JavaScript
export class Note extends Archetype {}
TypeScript
export const archetypes = defineArchetypes({
// ...
Note,
})
JavaScript
export const archetypes = defineArchetypes({
// ...
Note,
})
While we are at it, let's also add life:
TypeScript
export class Note extends Archetype {
globalPreprocess() {
this.life.set({
perfect: 10,
great: 0,
good: 0,
miss: -100,
})
}
}
JavaScript
export class Note extends Archetype {
globalPreprocess() {
this.life.set({
perfect: 10,
great: 0,
good: 0,
miss: -100,
})
}
}
Tempos Alvo e Visual
Similar to play mode, we can use note's beat to calculate target and visual times:
TypeScript
export class Note extends Archetype {
import = this.defineImport({
beat: { name: EngineArchetypeDataName.Beat, type: Number },
})
targetTime = this.entityMemory(Number)
visualTime = this.entityMemory(Range)
// ...
preprocess() {
this.targetTime = bpmChanges.at(this.import.beat).time
this.visualTime.copyFrom(
Range.l
.mul(120 / bpmChanges.at(this.import.beat).bpm)
.add(timeScaleChanges.at(this.targetTime).scaledTime),
)
}
}
JavaScript
export class Note extends Archetype {
import = this.defineImport({
beat: { name: EngineArchetypeDataName.Beat, type: Number },
})
targetTime = this.entityMemory(Number)
visualTime = this.entityMemory(Range)
// ...
preprocess() {
this.targetTime = bpmChanges.at(this.import.beat).time
this.visualTime.copyFrom(
Range.l
.mul(120 / bpmChanges.at(this.import.beat).bpm)
.add(timeScaleChanges.at(this.targetTime).scaledTime),
)
}
}
Vida
O tempo de vida de uma nota é simplesmente seu tempo visual:
TypeScript
export class Note extends Archetype {
// ...
spawnTime() {
return this.visualTime.min
}
despawnTime() {
return this.visualTime.max
}
}
JavaScript
export class Note extends Archetype {
// ...
spawnTime() {
return this.visualTime.min
}
despawnTime() {
return this.visualTime.max
}
}