Skip to content

Commit

Permalink
Improve cleanup logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jankuss committed Jan 25, 2021
1 parent 49d4f7c commit b7017fe
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/objects/room/parts/Stair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class Stair extends PIXI.Container implements IRoomPart {

destroy() {
super.destroy();
this.removeChildren();
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/objects/room/parts/StairCorner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ export class StairCorner extends PIXI.Container implements IRoomPart {
this._container?.destroy();
}

destroyed(): void {
destroy() {
super.destroy();
this.destroySprites();
}

registered(): void {
this.updateSprites();
}

private _createStairBoxFront(index: number): PIXI.DisplayObject[] {
const baseXLeft = +stairBase * index;
const baseYLeft = -stairBase * index * 1.5;
Expand Down
5 changes: 5 additions & 0 deletions src/objects/room/parts/Tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export class Tile extends PIXI.Container implements IRoomPart {
this._updateSprites();
}

destroy() {
super.destroy();
this._destroySprites();
}

private _destroySprites() {
this._sprites.forEach((sprite) => sprite.destroy());
this._sprites = [];
Expand Down
3 changes: 1 addition & 2 deletions src/objects/room/parts/TileCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ export class TileCursor extends PIXI.Container implements HitDetectionElement {

destroy() {
super.destroy();
console.log("DESTROYED");

this._node.remove();
this._graphics.destroy();
}

private _createGraphics() {
Expand Down
6 changes: 6 additions & 0 deletions src/objects/room/parts/WallLeft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ export class WallLeft extends PIXI.Container implements IRoomPart {
this._update();
}

destroy() {
super.destroy();
this._hitAreaElement?.destroy();
this.removeChildren();
}

protected _update() {
if (this._hitAreaElement != null) {
this.props.hitAreaContainer.removeChild(this._hitAreaElement);
Expand Down

0 comments on commit b7017fe

Please sign in to comment.