This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
engine.entity('single-step').setComponent('housekeeping', {}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
engine.on('tick:before', (engine) => { | |
todos = [] // reset | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let todos = [] | |
engine.system('gather-todos-for-save', ['data'], (entity, { data }) => { | |
todos_data.push(data) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
engine.on('tick:after', (engine) => { | |
console.log('-'.repeat(40)) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
engine.entity('single-step').setComponent('housekeeping', {}) | |
... | |
engine.system('reset-todos', ['housekeeping'], (entity, { housekeeping }) => { | |
// this code will run once per tick | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// process all entities with data component | |
engine.system('process-all', ['data'], (entity, { data }) => { | |
console.log(`Found entity ${entity} with data ${data}`) | |
}); | |
// all entities with data component and dirty component | |
engine.system('find-dirty', ['data', 'dirty'], (entity, { data, dirty }) => { | |
console.log(`Found dirty entity ${entity}`) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log( | |
e.name, | |
JSON.stringify(e.getComponent('Name')), | |
JSON.stringify(e.getComponent('Address')) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let e = engine.entity('person 1') | |
e.setComponent('Name', {firstname:'John', surname:'Smith'}) | |
e.setComponent('Address', {number: 12, street: 'Bounty Drive', state: 'WA'}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const engine = new Engine(); | |
engine.entity(util.uuid()).setComponent('data', {title:'make lunch', completed:true}) | |
engine.entity(util.uuid()).setComponent('data', {title:'wash dishes', completed:false}) | |
engine.system('report', ['data'], (entity, { data }) => { | |
let is_or_is_not = data.completed ? 'is' : 'is not' | |
console.log(`Todo item ${data.title} has id ${entity.name} and ${is_or_is_not} completed`) | |
}); | |
engine.tick() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TodoItem { | |
constructor(title, completed, id) { | |
this.title = title | |
this.completed = completed | |
this.id = id == undefined ? util.uuid() : id | |
} | |
report() { | |
let is_or_is_not = this.completed ? 'is' : 'is not' | |
console.log(`Todo item ${this.title} ${is_or_is_not} completed`) | |
} |