Skip to content

Instantly share code, notes, and snippets.

@iaincarsberg
Created October 17, 2011 15:43
Show Gist options
  • Save iaincarsberg/1292900 to your computer and use it in GitHub Desktop.
Save iaincarsberg/1292900 to your computer and use it in GitHub Desktop.
Demos of two possible level loading syntaxes.
// Less pretty syntax, super simple to implement, generic reusable implementation
flow.exec(
function () {
new Entity().addComponent('level', this)
},
function (err, level) {
level.addComponent('level-segment', 'something.json', this)
},
function (err, level) {
level.addComponent('level-segment', 'something-else.json', this)
},
function (err, level) {
renderer.draw(level);
}
);
// Nicer syntax, but the implementation is bound to the solution
var map = new Entity()
.addComponent('level')
.addComponent('level-segment', 'something.json')
.addComponent('level-segment', 'something-else.json')
.triggers(function () {
renderer.map(map);
});
new Entity()
.exec(
function (entity) {
entity.addComponent('level', entity, this)
},
function (entity) {
entity.addComponent('level-segment', 'something.json', this)
},
function (entity) {
entity.addComponent('level-segment', 'something-else.json', this)
},
function (entity) {
renderer.draw(entity);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment