Skip to content

Commit

Permalink
feat: [#2044] Add Current Graphics Keys to GraphicsComponent (#2072)
Browse files Browse the repository at this point in the history
Closes #2044

## Changes:

- Add Current Graphics Keys to GraphicsComponent #2044
  • Loading branch information
ignoreintuition authored Nov 2, 2021
1 parent 2e600fc commit 9890ad6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Add `SpriteSheet.getSpacingDimensions()` method to retrieve calculated spacing dimensions ([#1788](https://github.com/excaliburjs/Excalibur/issues/1778))
- Add `KeyEvent.value?: string` which is the key value (or "typed" value) that the browser detected. For example, holding Shift and pressing 9 will have a value of `(` which is the typed character.
- Add `KeyEvent.originalEvent?: KeyboardEvent` which exposes the raw keyboard event handled from the browser.

- Added a new getter to GraphicsComponent.ts called currentKeys that will return the names of the graphics shown in all layers
- Added a new getter to GraphicsLayer called currentKeys that will the names of the graphics shown in this layer
### Changed

- `Gif` now supports new graphics component
Expand Down
12 changes: 12 additions & 0 deletions src/engine/Graphics/GraphicsComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ export class GraphicsLayer {
public set offset(value: Vector) {
this._options.offset = value;
}

public get currentKeys(): string {
return this.name ?? 'anonymous';
}
}

export class GraphicsLayers {
Expand Down Expand Up @@ -201,6 +205,14 @@ export class GraphicsLayers {
return this._layers;
}

public currentKeys() {
const graphicsLayerKeys = [];
for (const layer of this._layers) {
graphicsLayerKeys.push(layer.currentKeys);
}
return graphicsLayerKeys;
}

public has(name: string): boolean {
return name in this._layerMap;
}
Expand Down
12 changes: 12 additions & 0 deletions src/spec/GraphicsComponentSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,16 @@ describe('A Graphics ECS Component', () => {

expect(animation.tick).toHaveBeenCalledWith(123, 4);
});

it('currentKeys should return names of graphics show in all layers', () => {
const rect = new ex.Rectangle({
width: 40,
height: 40
});
const sut = new ex.GraphicsComponent();
sut.layers.create({ name: 'background', order: -1 }).show(rect);
const layers = sut.layers.currentKeys();
expect(typeof layers).toBe('object');
expect(layers.length).toBe(2);
});
});

0 comments on commit 9890ad6

Please sign in to comment.