diff --git a/package.json b/package.json index f0a8fe9..c7b3020 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "system" ], "license": "MIT", - "version": "0.7.0", + "version": "0.7.1", "main": "lib/ouyo.js", "repository": { "type": "git", diff --git a/src/Game.js b/src/Game.js index 427a918..40f6b5d 100644 --- a/src/Game.js +++ b/src/Game.js @@ -3,6 +3,8 @@ import { assert, map, forEach, forEach2 } from './utils' import { createComponent } from './component' import { defaultTicker } from './ticker' +const doNothing = () => {} + export class Game { constructor (registerUpdate = defaultTicker) { this.changed = [] @@ -93,9 +95,11 @@ export class Game { this.removed.length = 0 } - createEntity () { + createEntity (assemblage = doNothing) { assert(this.started, 'Entities cannot be created before the game is started.') - return new Entity(this.componentCount, this.onEntityChange) + const entity = new Entity(this.componentCount, this.onEntityChange) + assemblage(entity) + return entity } removeEntity (entity) { diff --git a/test/Game.test.js b/test/Game.test.js index 697fa8d..de5e64d 100644 --- a/test/Game.test.js +++ b/test/Game.test.js @@ -195,4 +195,11 @@ describe('Game', () => { { type: 'customevent', x: 1, timeDelta: 0 } ]) }) + + test('createEntity works with assemblages', () => { + const assemblage = jest.fn() + const game = new Game(onTick) + game.start(game => game.createEntity(assemblage)) + expect(assemblage).toHaveBeenCalled() + }) })