Skip to content

Commit

Permalink
https://github.com/phetsims/graphing-lines/issues/144
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Feb 3, 2024
1 parent 83e3c27 commit e4bb5cb
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 14 deletions.
6 changes: 4 additions & 2 deletions js/common/GLQueryParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
import logGlobal from '../../../phet-core/js/logGlobal.js';
import graphingLines from '../graphingLines.js';
import getGameLevelsSchema from '../../../vegas/js/getGameLevelsSchema.js';
import LineGameConstants from '../linegame/LineGameConstants.js';

const NUMBER_OF_GAME_LEVELS = 6;
export { NUMBER_OF_GAME_LEVELS };

const GLQueryParameters = QueryStringMachine.getAll( {

// The levels to show in the Line Game screen.
gameLevels: getGameLevelsSchema( LineGameConstants.NUMBER_OF_GAME_LEVELS ),
gameLevels: getGameLevelsSchema( NUMBER_OF_GAME_LEVELS ),

// Shows the game reward regardless of score.
// For internal use only.
Expand Down
2 changes: 0 additions & 2 deletions js/linegame/LineGameConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ const LineGameConstants = {

ORIGIN_OFFSET: new Vector2( 790, 300 ), // graph (0,0) will be positioned at these view coordinates

NUMBER_OF_GAME_LEVELS: 6,

// fonts
TITLE_FONT: new PhetFont( { size: 40, weight: 'bold' } ),
BUTTON_FONT: new PhetFont( { size: 30, weight: 'bold' } ),
Expand Down
4 changes: 2 additions & 2 deletions js/linegame/model/LineGameModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ChallengeFactory3 from './ChallengeFactory3.js';
import ChallengeFactory4 from './ChallengeFactory4.js';
import ChallengeFactory5 from './ChallengeFactory5.js';
import ChallengeFactory6 from './ChallengeFactory6.js';
import LineGameConstants from '../LineGameConstants.js';
import { NUMBER_OF_GAME_LEVELS } from '../../common/GLQueryParameters.js';

export default class LineGameModel extends BaseGameModel {

Expand All @@ -30,7 +30,7 @@ export default class LineGameModel extends BaseGameModel {
new ChallengeFactory5(),
new ChallengeFactory6()
];
assert && assert( challengeFactories.length === LineGameConstants.NUMBER_OF_GAME_LEVELS );
assert && assert( challengeFactories.length === NUMBER_OF_GAME_LEVELS );

super( challengeFactories, tandem );
}
Expand Down
4 changes: 3 additions & 1 deletion js/linegame/view/BaseGameScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ export default class BaseGameScreenView extends ScreenView {

/**
* @param model
* @param gameLevels - show buttons for these game levels
* @param levelImages - grid of images for the level-selection buttons, ordered by level
* @param rewardNodeFunctions - functions that create nodes for the game reward, ordered by level
* @param tandem
*/
public constructor( model: BaseGameModel,
gameLevels: number[],
levelImages: HTMLImageElement[],
rewardNodeFunctions: RewardNodeFunction[],
tandem: Tandem ) {
Expand All @@ -44,7 +46,7 @@ export default class BaseGameScreenView extends ScreenView {
// sounds
const audioPlayer = new GameAudioPlayer();

this.settingsNode = new SettingsNode( model, this.layoutBounds, levelImages, tandem.createTandem( 'settingsNode' ) );
this.settingsNode = new SettingsNode( model, this.layoutBounds, levelImages, gameLevels, tandem.createTandem( 'settingsNode' ) );
this.playNode = new PlayNode( model, this.layoutBounds, this.visibleBoundsProperty, audioPlayer );
this.resultsNode = new ResultsNode( model, this.layoutBounds, audioPlayer, rewardNodeFunctions );

Expand Down
8 changes: 4 additions & 4 deletions js/linegame/view/LineGameLevelSelectionButtonGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import GraphingLinesStrings from '../../GraphingLinesStrings.js';
import GamePhase from '../model/GamePhase.js';
import LineGameModel from '../model/LineGameModel.js';
import DerivedStringProperty from '../../../../axon/js/DerivedStringProperty.js';
import GLQueryParameters from '../../common/GLQueryParameters.js';
import Tandem from '../../../../tandem/js/Tandem.js';

const BUTTON_WIDTH = 175;
Expand All @@ -31,9 +30,10 @@ export default class LineGameLevelSelectionButtonGroup extends LevelSelectionBut
/**
* @param model
* @param levelImages - images for the level-selection buttons, ordered by level
* @param gameLevels - show buttons for these game levels
* @param tandem
*/
public constructor( model: LineGameModel, levelImages: HTMLImageElement[], tandem: Tandem ) {
public constructor( model: LineGameModel, levelImages: HTMLImageElement[], gameLevels: number[], tandem: Tandem ) {
assert && assert( levelImages.length === model.numberOfLevels, 'one image is required for each game level' );

// To give all button icons the same effective size
Expand All @@ -59,7 +59,7 @@ export default class LineGameLevelSelectionButtonGroup extends LevelSelectionBut
} );
}

const buttonsPerRow = ( GLQueryParameters.gameLevels.length <= 4 ) ? 4 : 3;
const buttonsPerRow = ( gameLevels.length <= 4 ) ? 4 : 3;

super( levelSelectionButtonItems, {

Expand All @@ -78,7 +78,7 @@ export default class LineGameLevelSelectionButtonGroup extends LevelSelectionBut
wrap: true, // start a new row when preferredWidth is reached
justify: 'center' // horizontal justification
},
gameLevels: GLQueryParameters.gameLevels,
gameLevels: gameLevels,
tandem: tandem
} );
}
Expand Down
5 changes: 4 additions & 1 deletion js/linegame/view/LineGameScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import level3_svg from '../../../images/usa/level3_svg.js';
import level4_svg from '../../../images/usa/level4_svg.js';
import level5_svg from '../../../images/usa/level5_svg.js';
import level6_svg from '../../../images/usa/level6_svg.js';
import GLQueryParameters, { NUMBER_OF_GAME_LEVELS } from '../../common/GLQueryParameters.js';
import graphingLines from '../../graphingLines.js';
import LineGameModel from '../model/LineGameModel.js';
import BaseGameScreenView from './BaseGameScreenView.js';
Expand All @@ -24,6 +25,7 @@ export default class LineGameScreenView extends BaseGameScreenView {

// Images for the level-selection buttons, ordered by level
const levelImages = [ level1_svg, level2_svg, level3_svg, level4_svg, level5_svg, level6_svg ];
assert && assert( levelImages.length === NUMBER_OF_GAME_LEVELS );

// functions that create nodes for the game reward, ordered by level
const rewardNodeFunctions = [
Expand All @@ -34,8 +36,9 @@ export default class LineGameScreenView extends BaseGameScreenView {
GLRewardNode.createPaperAirplaneNodes,
GLRewardNode.createAssortedNodes
];
assert && assert( rewardNodeFunctions.length === NUMBER_OF_GAME_LEVELS );

super( model, levelImages, rewardNodeFunctions, tandem );
super( model, GLQueryParameters.gameLevels, levelImages, rewardNodeFunctions, tandem );
}
}

Expand Down
6 changes: 4 additions & 2 deletions js/linegame/view/SettingsNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ export default class SettingsNode extends Node {
* @param model
* @param layoutBounds
* @param levelImages - images for the level-selection buttons, ordered by level
* @param gameLevels - show buttons for these game levels
* @param tandem
*/
public constructor( model: LineGameModel, layoutBounds: Bounds2, levelImages: HTMLImageElement[], tandem: Tandem ) {
public constructor( model: LineGameModel, layoutBounds: Bounds2, levelImages: HTMLImageElement[],
gameLevels: number[], tandem: Tandem ) {

assert && assert( levelImages.length === model.numberOfLevels, 'one image is required for each game level' );

Expand All @@ -38,7 +40,7 @@ export default class SettingsNode extends Node {
} );

// Group of LevelSelectionButtons
const levelSelectionButtonGroup = new LineGameLevelSelectionButtonGroup( model, levelImages,
const levelSelectionButtonGroup = new LineGameLevelSelectionButtonGroup( model, levelImages, gameLevels,
tandem.createTandem( 'levelSelectionButtonGroup' ) );

// title is centered on level-selection buttons
Expand Down

0 comments on commit e4bb5cb

Please sign in to comment.