From 0a1600e9f4b3fe9d73c0665467bff76aa2488381 Mon Sep 17 00:00:00 2001 From: sz-piotr Date: Sun, 17 Dec 2017 15:50:50 +0100 Subject: [PATCH] implement assemblages --- package.json | 2 +- src/Game.js | 8 ++++++-- test/Game.test.js | 7 +++++++ 3 files changed, 14 insertions(+), 3 deletions(-) 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() + }) })