From d2dbaaa6ae71acc80000e7f9cac1d35b27d7829a Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 25 Apr 2021 06:31:50 -0500 Subject: [PATCH] refactor: layer -> list --- packages/physics/src/traits/collider.js | 6 +++--- packages/topdown/src/resources/layer.js | 4 ---- packages/topdown/src/resources/layers.js | 12 ------------ packages/topdown/src/resources/room.js | 4 ---- packages/topdown/test/layer.js | 18 ------------------ 5 files changed, 3 insertions(+), 41 deletions(-) diff --git a/packages/physics/src/traits/collider.js b/packages/physics/src/traits/collider.js index b957df4..d9b0747 100644 --- a/packages/physics/src/traits/collider.js +++ b/packages/physics/src/traits/collider.js @@ -64,8 +64,8 @@ export default (latus) => class Collider extends decorate(Trait) { if (!this.params.activeCollision) { return; } - const {layer} = this.entity; - if (!layer) { + const {list} = this.entity; + if (!list) { return; } const query = Rectangle.compose( @@ -76,7 +76,7 @@ export default (latus) => class Collider extends decorate(Trait) { this.entity.shape.aabb, this.entity.position, ); - const entities = layer.visibleEntities(query); + const entities = list.visibleEntities(query); for (let i = 0; i < entities.length; ++i) { const entity = entities[i]; if ( diff --git a/packages/topdown/src/resources/layer.js b/packages/topdown/src/resources/layer.js index f60637a..dd4742b 100644 --- a/packages/topdown/src/resources/layer.js +++ b/packages/topdown/src/resources/layer.js @@ -155,9 +155,5 @@ export default (latus) => { }; } - visibleEntities(query) { - return this.entityList.visibleEntities(query); - } - }; }; diff --git a/packages/topdown/src/resources/layers.js b/packages/topdown/src/resources/layers.js index 8bd222e..d6cbfd1 100644 --- a/packages/topdown/src/resources/layers.js +++ b/packages/topdown/src/resources/layers.js @@ -124,17 +124,5 @@ export default (latus) => { return this.layers.map((layer) => layer.toNetwork(informed)); } - visibleEntities(query) { - const entities = []; - for (let i = 0; i < this.layers.length; i++) { - const layerVisibleEntities = this.layers[i].visibleEntities(query); - for (let j = 0; j < layerVisibleEntities.length; j++) { - const layerVisibleEntity = layerVisibleEntities[j]; - entities.push(layerVisibleEntity); - } - } - return entities; - } - }; }; diff --git a/packages/topdown/src/resources/room.js b/packages/topdown/src/resources/room.js index c45ec41..79550b1 100644 --- a/packages/topdown/src/resources/room.js +++ b/packages/topdown/src/resources/room.js @@ -117,9 +117,5 @@ export default (latus) => { }; } - visibleEntities(query) { - return this.layers.visibleEntities(query); - } - }; }; diff --git a/packages/topdown/test/layer.js b/packages/topdown/test/layer.js index 690464f..49ca5d8 100644 --- a/packages/topdown/test/layer.js +++ b/packages/topdown/test/layer.js @@ -18,22 +18,4 @@ describe('Layer', () => { expect(Object.keys(layer.entities).length).to.equal(0); expect(layer.tiles.size).to.deep.equal([0, 0]); }); - describe('entity list interaction', () => { - let entity; - let layer; - beforeEach(async () => { - const {Entity, EntityList, Layer} = latus.get('%resources'); - entity = await Entity.load({}); - const entityList = new EntityList(); - entityList.addEntity(entity); - layer = new Layer(); - layer.setEntityList(entityList); - }) - it('delegates to entity list', async () => { - expect(Object.keys(layer.entities).length).to.equal(1); - }); - it('can find entities', async () => { - expect(layer.findEntity(entity.instanceUuid)).to.equal(entity); - }); - }); });