/
Note.ts
66 lines (48 loc) · 1.54 KB
/
Note.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { EngineArchetypeDataName } from '@sonolus/core'
import { effect } from '../effect.js'
import { note } from '../note.js'
import { skin } from '../skin.js'
export class Note extends Archetype {
hasInput = true
import = this.defineImport({
beat: { name: EngineArchetypeDataName.Beat, type: Number },
})
initialized = this.entityMemory(Boolean)
targetTime = this.entityMemory(Number)
visualTime = this.entityMemory({
min: Number,
max: Number,
})
z = this.entityMemory(Number)
globalPreprocess() {
this.life.set({
perfect: 10,
great: 0,
good: 0,
miss: -100,
})
}
preprocess() {
this.targetTime = bpmChanges.at(this.import.beat).time
this.visualTime.max = timeScaleChanges.at(this.targetTime).scaledTime
this.visualTime.min = this.visualTime.max - 120 / bpmChanges.at(this.import.beat).bpm
effect.clips.perfect.schedule(this.targetTime, 0.02)
this.result.time = this.targetTime
}
spawnTime() {
return this.visualTime.min
}
despawnTime() {
return this.visualTime.max
}
initialize() {
if (this.initialized) return
this.initialized = true
this.z = 1000 - this.targetTime
}
updateParallel() {
const y = Math.unlerp(this.visualTime.min, this.visualTime.max, time.scaled)
const layout = Rect.one.mul(note.radius).scale(1, -1).translate(0, y)
skin.sprites.note.draw(layout, this.z, 1)
}
}