Skip to content

Commit d28067a

Browse files
committed
Fix #32 - Add addProcessors and addAssemblages methods to add lists of elements.
1 parent 23f3d59 commit d28067a

File tree

6 files changed

+84
-4
lines changed

6 files changed

+84
-4
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Current
44

5+
- Add `addProcessors` and `addAssemblages` methods to add lists of elements (#32)[https://github.com/adngdb/entity-system-js/issues/32].
56
- Add an `addComponents` method to add a list of components at once (#31)[https://github.com/adngdb/entity-system-js/issues/31].
67

78
## 1.5.0 (June 21, 2019)

docs/api.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ Add a list of components to known components.
5959

6060
### Params:
6161

62-
* **Array** *components* - Array of objects containing the metadata and data of components. Requires that each object has `name` used to identify it, and `data` to describe it.
62+
* **Array** *components* - Array of objects containing the metadata and data of components. Requires that each object has `name` used to identify
63+
it, and `data` to describe it.
6364

6465
### Return:
6566

@@ -179,6 +180,18 @@ Add an assemblage to the list of known assemblages.
179180

180181
* **object** - this
181182

183+
## addAssemblages(assemblages)
184+
185+
Add a list of assemblages to known assemblages.
186+
187+
### Params:
188+
189+
* **Array** *assemblages* - An array of assemblages to add. Require that each object has a `name` property to use as identifier.
190+
191+
### Return:
192+
193+
* **object** - this
194+
182195
## removeAssemblage(id)
183196

184197
Remove an assemblage from the list of known assemblages.
@@ -216,6 +229,18 @@ Add a processor to the list of known processors.
216229

217230
* **object** - this
218231

232+
## addProcessors(processors)
233+
234+
Add a list of processors to known processors.
235+
236+
### Params:
237+
238+
* **Array** *processors* - An array of processors to manage.
239+
240+
### Return:
241+
242+
* **object** - this
243+
219244
## removeProcessor(processor)
220245

221246
Remove a processor from the list of known processors.

entity-manager.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entity-manager.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/entity-manager.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ class EntityManager {
199199
/**
200200
* Add a list of components to known components.
201201
*
202-
* @param {Array} components - Array of objects containing the metadata and data of components. Requires that each object has `name` used to identify it, and `data` to describe it.
202+
* @param {Array} components - Array of objects containing the metadata and
203+
* data of components. Requires that each object has `name` used to identify
204+
* it, and `data` to describe it.
203205
* @return {object} - this
204206
*/
205207
addComponents(components) {
@@ -431,6 +433,18 @@ class EntityManager {
431433
return this;
432434
}
433435

436+
/**
437+
* Add a list of assemblages to known assemblages.
438+
*
439+
* @param {Array} assemblages - An array of assemblages to add. Require that
440+
* each object has a `name` property to use as identifier.
441+
* @return {object} - this
442+
*/
443+
addAssemblages(assemblages) {
444+
assemblages.forEach(a => this.assemblages[a.name] = a);
445+
return this;
446+
}
447+
434448
/**
435449
* Remove an assemblage from the list of known assemblages.
436450
*
@@ -481,6 +495,17 @@ class EntityManager {
481495
return this;
482496
}
483497

498+
/**
499+
* Add a list of processors to known processors.
500+
*
501+
* @param {Array} processors - An array of processors to manage.
502+
* @return {object} - this
503+
*/
504+
addProcessors(processors) {
505+
processors.forEach(processor => this.processors.push(processor));
506+
return this;
507+
}
508+
484509
/**
485510
* Remove a processor from the list of known processors.
486511
*

test/test_entity-manager.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,18 @@ define(function (require) {
589589
});
590590
});
591591

592+
describe('#addAssemblages()', function () {
593+
it('can add a list of assemblages', function () {
594+
var manager = new EntityManager();
595+
596+
var FakeAssemblage = {
597+
name: 'Fake',
598+
};
599+
manager.addAssemblages([SoldierAssemblage, FakeAssemblage]);
600+
expect(Object.keys(manager.assemblages)).to.deep.equal(['Soldier', 'Fake']);
601+
});
602+
});
603+
592604
describe('#removeAssemblage()', function () {
593605
it('can remove an existing assemblage', function () {
594606
var manager = prepareManager();
@@ -657,6 +669,23 @@ define(function (require) {
657669
});
658670
});
659671

672+
describe('#addProcessors()', function () {
673+
it('adds a list of processors', function () {
674+
var manager = prepareManager();
675+
expect(manager.processors).to.have.length(0);
676+
677+
var processorA = {
678+
update: function () {},
679+
};
680+
var processorB = {
681+
update: function () {},
682+
};
683+
manager.addProcessors([processorA, processorB]);
684+
685+
expect(manager.processors).to.have.length(2);
686+
});
687+
});
688+
660689
describe('#removeProcessor()', function () {
661690
it('removes the processor from the list of processors', function () {
662691
var manager = prepareManager();

0 commit comments

Comments
 (0)