07 Note and Entity Data
In this chapter, we will set up Note and look at how to integrate Entity Data into it.
Note Archetype
Let's first set up 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,
})
Entity Data
Until now we only have Initialization and Stage, both should behave the same across all levels.
However that is not the case for notes: in one level maybe the first note is at 5 second mark, while in another level it could be at 2; one level could have 200 notes, while another could have 30.
How would engine be able to handle varying amount of notes with different information provided by the level? That's where Entity Data comes into play. Each level can specify all the entities and also inject data into them.
Let's define that Note has a time
data, which is simply time of the note in seconds. We can import the data using its name:
TypeScript
export class Note extends Archetype {
import = this.defineImport({
time: { name: 'time', type: Number },
})
}
JavaScript
export class Note extends Archetype {
import = this.defineImport({
time: { name: 'time', type: Number },
})
}
Now we can simply access it. To test it out, let's log it:
TypeScript
export class Note extends Archetype {
// ...
updateParallel() {
debug.log(this.import.time)
}
}
JavaScript
export class Note extends Archetype {
// ...
updateParallel() {
debug.log(this.import.time)
}
}
Lastly, let's add a note entity to our level, also giving it time data:
TypeScript
export const data: LevelData = {
// ...
entities: [
// ...
{
archetype: 'Note',
data: [
{
name: 'time',
value: 2,
},
],
},
],
}
JavaScript
export const data = {
// ...
entities: [
// ...
{
archetype: 'Note',
data: [
{
name: 'time',
value: 2,
},
],
},
],
}