Skip to content

Commit

Permalink
hide game levels in the view, #165
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Aug 22, 2021
1 parent d6273e2 commit 4ad3f56
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
9 changes: 0 additions & 9 deletions js/solveit/model/SolveItModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import Property from '../../../../axon/js/Property.js';
import EqualityExplorerQueryParameters from '../../common/EqualityExplorerQueryParameters.js';
import equalityExplorer from '../../equalityExplorer.js';
import ChallengeGenerator1 from './ChallengeGenerator1.js';
import ChallengeGenerator2 from './ChallengeGenerator2.js';
Expand All @@ -33,14 +32,6 @@ class SolveItModel {
assert && assert( _.every( this.challengeGenerators, ( value, index, array ) => ( index === 0 || array[ index - 1 ].level <= value.level ) ),
'Challenge generators must be ordered by ascending level number.' );

// Filter challenge generators by gameLevels query parameter.
// See https://github.com/phetsims/equality-explorer/issues/165
if ( EqualityExplorerQueryParameters.gameLevels ) {
this.challengeGenerators = _.filter( this.challengeGenerators, challengeGenerator =>
EqualityExplorerQueryParameters.gameLevels.includes( challengeGenerator.level )
);
}

// @public (read-only) {SolveItScene[]} a scene for each challenge generator
this.scenes = _.map( this.challengeGenerators, challengeGenerator => new SolveItScene( challengeGenerator ) );

Expand Down
13 changes: 12 additions & 1 deletion js/solveit/view/LevelSelectionNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Text from '../../../../scenery/js/nodes/Text.js';
import RectangularPushButton from '../../../../sun/js/buttons/RectangularPushButton.js';
import Dialog from '../../../../sun/js/Dialog.js';
import EqualityExplorerConstants from '../../common/EqualityExplorerConstants.js';
import EqualityExplorerQueryParameters from '../../common/EqualityExplorerQueryParameters.js';
import equalityExplorer from '../../equalityExplorer.js';
import equalityExplorerStrings from '../../equalityExplorerStrings.js';
import EqualityExplorerLevelSelectionButton from './EqualityExplorerLevelSelectionButton.js';
Expand All @@ -42,12 +43,22 @@ class LevelSelectionNode extends Node {
maxWidth: 0.65 * layoutBounds.width
};

// Level-selection buttons
// Level-selection buttons, ordered by ascending level number.
const levelSelectionButtons = [];
model.scenes.forEach( scene => {
levelSelectionButtons.push( new EqualityExplorerLevelSelectionButton( scene, model.sceneProperty ) );
} );

// Hide buttons for levels that are not included in gameLevels query parameter.
// We must still create these buttons so that we don't change the PhET-iO API.
// See https://github.com/phetsims/equality-explorer/issues/165
if ( EqualityExplorerQueryParameters.gameLevels ) {
for ( let i = 0; i < levelSelectionButtons.length; i++ ) {
const levelNumber = i + 1;
levelSelectionButtons[ i ].visible = EqualityExplorerQueryParameters.gameLevels.includes( levelNumber );
}
}

// Layout the level-selection buttons horizontally
const levelSelectionButtonsBox = new HBox( {
children: levelSelectionButtons,
Expand Down

0 comments on commit 4ad3f56

Please sign in to comment.