Skip to content

Commit

Permalink
dispose levelCompletedNode, #78
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Mar 6, 2023
1 parent a7bbbe5 commit 9b6e666
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions js/game/view/ResultsNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import GamePhaseNode from './GamePhaseNode.js';

export default class ResultsNode extends GamePhaseNode {

private rewardNode: RPALRewardNode | null; // created on demand
private rewardNode: RPALRewardNode | null; // created dynamically to match the level

public constructor( model: GameModel, layoutBounds: Bounds2, audioPlayer: GameAudioPlayer, tandem: Tandem ) {

Expand All @@ -30,6 +30,9 @@ export default class ResultsNode extends GamePhaseNode {

this.rewardNode = null;

// Created dynamically to match the level
let levelCompletedNode: LevelCompletedNode | null = null;

/*
* Displays the game results, possibly with a 'reward'.
* Unlink is unnecessary because this node exists for the lifetime of the simulation.
Expand All @@ -49,9 +52,9 @@ export default class ResultsNode extends GamePhaseNode {
audioPlayer.gameOverImperfectScore();
}

// game results
// Pseudo-dialog that shows results.
const level = model.levelProperty.value;
this.addChild( new LevelCompletedNode(
levelCompletedNode = new LevelCompletedNode(
level + 1,
model.scoreProperty.value,
model.getPerfectScore( level ),
Expand All @@ -65,14 +68,18 @@ export default class ResultsNode extends GamePhaseNode {
starDiameter: 45,
centerX: layoutBounds.centerX,
centerY: layoutBounds.centerY
} ) );
} );
this.addChild( levelCompletedNode );
}
else {
this.removeAllChildren();
if ( this.rewardNode !== null ) {
if ( this.rewardNode ) {
this.rewardNode.dispose();
this.rewardNode = null;
}
if ( levelCompletedNode ) {
levelCompletedNode.dispose();
levelCompletedNode = null;
}
this.rewardNode = null;
}
} );
}
Expand Down

0 comments on commit 9b6e666

Please sign in to comment.