Skip to content

Commit

Permalink
implement assemblages
Browse files Browse the repository at this point in the history
  • Loading branch information
sz-piotr committed Dec 17, 2017
1 parent 6fbd65c commit 0a1600e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"system"
],
"license": "MIT",
"version": "0.7.0",
"version": "0.7.1",
"main": "lib/ouyo.js",
"repository": {
"type": "git",
Expand Down
8 changes: 6 additions & 2 deletions src/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions test/Game.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})

0 comments on commit 0a1600e

Please sign in to comment.