Skip to content

Commit

Permalink
Improve type hierarchy. See #99 and #102.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luisav1 committed Dec 17, 2021
1 parent cba53e9 commit b9005b2
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 40 deletions.
6 changes: 0 additions & 6 deletions js/game/model/CountingGameLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ class CountingGameLevel extends NumberPlayGameLevel {
this._isObjectsRepresentationProperty.reset();
}

/**
* @param dt - in seconds
*/
public step( dt: number ): void {
}

/**
* Sets up a new challenge for this level.
*/
Expand Down
7 changes: 6 additions & 1 deletion js/game/model/NumberPlayGameLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,16 @@ abstract class NumberPlayGameLevel {
} );
}

protected reset(): void {
public reset(): void {
this.isChallengeSolvedProperty.reset();
this.scoreProperty.reset();
}

/**
* @param dt - in seconds. No-op because not all subclasses need a step function.
*/
public step( dt: number ): void {}

/**
* Sets up a new challenge for this level.
* TODO-TS: why can't this be protected if i only want sub-class implementations to call it? See https://github.com/phetsims/number-play/issues/81.
Expand Down
7 changes: 4 additions & 3 deletions js/game/model/NumberPlayGameModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import SubitizeGameLevel from './SubitizeGameLevel.js';
import CountingGameLevel from './CountingGameLevel.js';
import NumberPlayQueryParameters from '../../common/NumberPlayQueryParameters.js';
import NumberPlayConstants from '../../common/NumberPlayConstants.js';
import NumberPlayGameLevel from './NumberPlayGameLevel.js';

class NumberPlayGameModel {

public readonly subitizeLevels: SubitizeGameLevel[];
public readonly countingLevels: CountingGameLevel[];
public readonly levels: Array<SubitizeGameLevel | CountingGameLevel>;
public readonly levelProperty: Property<SubitizeGameLevel | CountingGameLevel | null>
public readonly levels: Array<NumberPlayGameLevel>;
public readonly levelProperty: Property<NumberPlayGameLevel| null>

constructor( tandem: Tandem ) {

Expand All @@ -36,7 +37,7 @@ class NumberPlayGameModel {
this.levels = [ ...this.countingLevels, ...this.subitizeLevels ];

// the selected game level - null means 'no selection' so that the view returns to the level-selection UI
this.levelProperty = new Property<SubitizeGameLevel | CountingGameLevel | null>( null, {
this.levelProperty = new Property<NumberPlayGameLevel | null>( null, {
validValues: [ null, ...this.levels ]
} );
}
Expand Down
7 changes: 0 additions & 7 deletions js/game/model/SubitizeGameLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ class SubitizeGameLevel extends NumberPlayGameLevel {
this.subitizer.newChallenge();
}

/**
* Calls reset on super type - no need to reset the subitizer because that happens everytime the user enters the level
*/
public reset(): void {
super.reset();
}

/**
* @param dt - in seconds
*/
Expand Down
8 changes: 2 additions & 6 deletions js/game/view/CountingGameLevelNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Property from '../../../../axon/js/Property.js';
import Bounds2 from '../../../../dot/js/Bounds2.js';
import CountingGameLevel from '../model/CountingGameLevel.js';
import numberPlay from '../../numberPlay.js';
import SubitizeGameLevel from '../model/SubitizeGameLevel.js';
import NumberPlayGameAnswerButtons from './NumberPlayGameAnswerButtons.js';
import NumberPlayConstants from '../../common/NumberPlayConstants.js';
import OnesPlayAreaNode from '../../common/view/OnesPlayAreaNode.js';
Expand All @@ -21,6 +20,7 @@ import EnumerationProperty from '../../../../axon/js/EnumerationProperty.js';
import GroupingLinkingType from '../../../../counting-common/js/common/model/GroupingLinkingType.js';
import TenFrameNode from '../../common/view/TenFrameNode.js';
import NumberPlayColors from '../../common/NumberPlayColors.js';
import NumberPlayGameLevel from '../model/NumberPlayGameLevel.js';

// constants
const RECTANGLE_WIDTH = 550;
Expand All @@ -33,7 +33,7 @@ class CountingGameLevelNode extends NumberPlayGameLevelNode<CountingGameLevel> {
protected readonly answerButtons: NumberPlayGameAnswerButtons;

constructor( level: CountingGameLevel,
levelProperty: Property<SubitizeGameLevel | CountingGameLevel | null>,
levelProperty: Property<NumberPlayGameLevel | null>,
layoutBounds: Bounds2,
visibleBoundsProperty: Property<Bounds2> ) {

Expand Down Expand Up @@ -122,10 +122,6 @@ class CountingGameLevelNode extends NumberPlayGameLevelNode<CountingGameLevel> {
tenFramePanel.visible = !isObjects;
} );
}

public reset(): void {
super.reset();
}
}

numberPlay.register( 'CountingGameLevelNode', CountingGameLevelNode );
Expand Down
5 changes: 2 additions & 3 deletions js/game/view/NumberPlayGameAnswerButtons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import { Color, ColorProperty, HBox, Node, Rectangle, Text } from '../../../../scenery/js/imports.js';
import RectangularPushButton from '../../../../sun/js/buttons/RectangularPushButton.js';
import numberPlay from '../../numberPlay.js';
import SubitizeGameLevel from '../model/SubitizeGameLevel.js';
import NumberProperty from '../../../../axon/js/NumberProperty.js';
import CountingGameLevel from '../model/CountingGameLevel.js';
import merge from '../../../../phet-core/js/merge.js';
import NumberPlayConstants from '../../common/NumberPlayConstants.js';
import NumberPlayGameLevel from '../model/NumberPlayGameLevel.js';

// types
type AnswerButtonsOptions = {
Expand All @@ -45,7 +44,7 @@ class NumberPlayGameAnswerButtons extends Node {
private readonly buttonListener: ( index: number ) => void;
public static BUTTON_DIMENSION: Dimension2;

constructor( level: SubitizeGameLevel | CountingGameLevel,
constructor( level: NumberPlayGameLevel,
pointAwardedNodeVisibleProperty: BooleanProperty,
rightAnswerCallback: () => void,
wrongAnswerCallback: () => void,
Expand Down
6 changes: 2 additions & 4 deletions js/game/view/NumberPlayGameLevelNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import { Color, ColorProperty, HBox, Node, Path, RichText, Text } from '../../../../scenery/js/imports.js';
import InfiniteStatusBar from '../../../../vegas/js/InfiniteStatusBar.js';
import numberPlay from '../../numberPlay.js';
import SubitizeGameLevel from '../model/SubitizeGameLevel.js';
import FaceNode from '../../../../scenery-phet/js/FaceNode.js';
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import StarNode from '../../../../scenery-phet/js/StarNode.js';
import ArrowShape from '../../../../scenery-phet/js/ArrowShape.js';
import RectangularPushButton from '../../../../sun/js/buttons/RectangularPushButton.js';
import Animation from '../../../../twixt/js/Animation.js';
import Easing from '../../../../twixt/js/Easing.js';
import CountingGameLevel from '../model/CountingGameLevel.js';
import NumberPlayGameLevel from '../model/NumberPlayGameLevel.js';
import NumberPlayGameAnswerButtons from './NumberPlayGameAnswerButtons.js';
import StringUtils from '../../../../phetcommon/js/util/StringUtils.js';
Expand Down Expand Up @@ -49,7 +47,7 @@ abstract class NumberPlayGameLevelNode<T extends NumberPlayGameLevel> extends No
public static GAME_AREA_NODE_BOTTOM_MARGIN_Y: number;

protected constructor( level: T,
levelProperty: Property<SubitizeGameLevel | CountingGameLevel | null>,
levelProperty: Property<NumberPlayGameLevel | null>,
layoutBounds: Bounds2,
visibleBoundsProperty: Property<Bounds2>,
providedOptions?: StatusBarOptions ) {
Expand Down Expand Up @@ -145,7 +143,7 @@ abstract class NumberPlayGameLevelNode<T extends NumberPlayGameLevel> extends No
this.addChild( newChallengeButton );
}

protected reset(): void {
public reset(): void {
this.pointAwardedNodeVisibleProperty.reset();
this.answerButtons.reset();
}
Expand Down
5 changes: 2 additions & 3 deletions js/game/view/NumberPlayGameLevelSelectionNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ import numberPlay from '../../numberPlay.js';
import numberPlayStrings from '../../numberPlayStrings.js';
import NumberPlayGameModel from '../model/NumberPlayGameModel.js';
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import SubitizeGameLevel from '../model/SubitizeGameLevel.js';
import CountingGameLevel from '../model/CountingGameLevel.js';
import NumberPlayColors from '../../common/NumberPlayColors.js';
import subitizeGameIcon1 from '../../../images/subitize_game_icon_1_png.js';
import countingGameIcon1 from '../../../images/counting_game_icon_1_png.js';
import subitizeGameIcon2 from '../../../images/subitize_game_icon_2_png.js';
import countingGameIcon2 from '../../../images/counting_game_icon_2_png.js';
import NumberPlayGameLevel from '../model/NumberPlayGameLevel.js';

// types
type GameLevelToButtonImageType = {
Expand Down Expand Up @@ -60,7 +59,7 @@ class NumberPlayGameLevelSelectionNode extends Node {
this.addChild( titleText );

// creates a level-selection button for each level
const createLevelSelectionButton = ( level: SubitizeGameLevel | CountingGameLevel, baseColor: ColorProperty ) => {
const createLevelSelectionButton = ( level: NumberPlayGameLevel, baseColor: ColorProperty ) => {
return new LevelSelectionButton( new Image( GAME_LEVEL_TO_BUTTON_IMAGE[ level.gameName ][ level.levelNumber ] ),
level.scoreProperty, {
iconToScoreDisplayYSpace: 0,
Expand Down
4 changes: 3 additions & 1 deletion js/game/view/NumberPlayGameScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import NumberPlayGameModel from '../model/NumberPlayGameModel.js';
import NumberPlayGameLevelSelectionNode from './NumberPlayGameLevelSelectionNode.js';
import SubitizeGameLevelNode from './SubitizeGameLevelNode.js';
import CountingGameLevelNode from './CountingGameLevelNode.js';
import NumberPlayGameLevelNode from './NumberPlayGameLevelNode.js';
import NumberPlayGameLevel from '../model/NumberPlayGameLevel.js';

// constants
const TRANSITION_OPTIONS = {
Expand All @@ -27,7 +29,7 @@ const TRANSITION_OPTIONS = {

class NumberPlayGameScreenView extends ScreenView {

private readonly levelNodes: Array<SubitizeGameLevelNode | CountingGameLevelNode>;
private readonly levelNodes: Array<NumberPlayGameLevelNode<NumberPlayGameLevel>>;

constructor( model: NumberPlayGameModel, tandem: Tandem ) {

Expand Down
8 changes: 2 additions & 6 deletions js/game/view/SubitizeGameLevelNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import numberPlay from '../../numberPlay.js';
import SubitizeGameLevel from '../model/SubitizeGameLevel.js';
import NumberPlayGameLevelNode from './NumberPlayGameLevelNode.js';
import SubitizerNode from './SubitizerNode.js';
import CountingGameLevel from '../model/CountingGameLevel.js';
import NumberPlayGameAnswerButtons from './NumberPlayGameAnswerButtons.js';
import NumberPlayColors from '../../common/NumberPlayColors.js';
import NumberPlayGameLevel from '../model/NumberPlayGameLevel.js';

class SubitizeGameLevelNode extends NumberPlayGameLevelNode<SubitizeGameLevel> {

protected readonly answerButtons: NumberPlayGameAnswerButtons;

constructor( level: SubitizeGameLevel,
levelProperty: Property<SubitizeGameLevel | CountingGameLevel | null>,
levelProperty: Property<NumberPlayGameLevel | null>,
layoutBounds: Bounds2,
visibleBoundsProperty: Property<Bounds2> ) {

Expand Down Expand Up @@ -54,10 +54,6 @@ class SubitizeGameLevelNode extends NumberPlayGameLevelNode<SubitizeGameLevel> {
subitizerNode.bottom = this.answerButtons.top - NumberPlayGameLevelNode.GAME_AREA_NODE_BOTTOM_MARGIN_Y;
this.addChild( subitizerNode );
}

public reset(): void {
super.reset();
}
}

numberPlay.register( 'SubitizeGameLevelNode', SubitizeGameLevelNode );
Expand Down

0 comments on commit b9005b2

Please sign in to comment.