Skip to content

Commit

Permalink
When going back to a challenge, reselect the previously-selected grou…
Browse files Browse the repository at this point in the history
…p (if any), see #43
  • Loading branch information
jonathanolson committed Jan 11, 2019
1 parent d0c1dc0 commit 114a820
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion js/building/model/BuildingModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,16 @@ define( require => {
useDeepEquality: true
} );

// @public {Property.<Group|null>} - We'll only show controls for this group
// @public {Property.<Group|null>} - We'll only show controls for this group (and track the previous value)
this.selectedGroupProperty = new Property( null );
this.previouslySelectedGroupProperty = new Property( null );

// Hook up the correct values for previouslySelectedGroupProperty (no need to unlink due to same lifetime)
this.selectedGroupProperty.lazyLink( ( newValue, oldValue ) => {
if ( oldValue ) {
this.previouslySelectedGroupProperty.value = oldValue;
}
} );

// @public {EnumerationMap.<Array.<Stack>>} - The stacks for groups
this.groupStacksMap = new EnumerationMap( BuildingType, type => ( {
Expand Down
10 changes: 10 additions & 0 deletions js/game/model/FractionChallenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ define( require => {
return bestTarget;
}

/**
* If nothing is selected, try to select the most-previously-selected group.
* @public
*/
selectPreviouslySelectedGroup() {
if ( this.previouslySelectedGroupProperty.value && !this.selectedGroupProperty.value ) {
this.selectedGroupProperty.value = this.previouslySelectedGroupProperty.value;
}
}

// REVIEW: Incomplete parameter documentation
/**
* Handles moving a Group into the collection area (Target).
Expand Down
3 changes: 3 additions & 0 deletions js/game/view/BuildingGameScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ define( require => {
lastChallengeNode = null;
let transition;
if ( challenge ) {
// See https://github.com/phetsims/fractions-common/issues/43
challenge.selectPreviouslySelectedGroup();

const challengeNode = new FractionChallengeNode( challenge, this.layoutBounds, model.nextLevel.bind( model ), model.incorrectAttemptEmitter );
lastChallengeNode = challengeNode;
if ( allLevelsCompletedNode ) {
Expand Down

0 comments on commit 114a820

Please sign in to comment.