diff --git a/js/game/model/CountingGameLevel.ts b/js/game/model/CountingGameLevel.ts index f662c01d..b4bc1552 100644 --- a/js/game/model/CountingGameLevel.ts +++ b/js/game/model/CountingGameLevel.ts @@ -17,6 +17,8 @@ import PlayObjectType from '../../../../counting-common/js/common/model/PlayObje import dotRandom from '../../../../dot/js/dotRandom.js'; import BooleanProperty from '../../../../axon/js/BooleanProperty.js'; import numberPlayStrings from '../../numberPlayStrings.js'; +import IReadOnlyProperty from '../../../../axon/js/IReadOnlyProperty.js'; +import Enumeration from '../../../../phet-core/js/Enumeration.js'; // constants const LEVEL_INPUT_RANGE = 10; @@ -24,8 +26,10 @@ const LEVEL_INPUT_RANGE = 10; class CountingGameLevel extends NumberPlayGameLevel { public readonly objectsPlayArea: OnesPlayArea; - public readonly playObjectTypeProperty: EnumerationProperty; - public readonly isObjectsRepresentationProperty: BooleanProperty; + private readonly _playObjectTypeProperty: EnumerationProperty; + public readonly playObjectTypeProperty: IReadOnlyProperty; + private readonly _isObjectsRepresentationProperty: BooleanProperty; + public readonly isObjectsRepresentationProperty: IReadOnlyProperty; public readonly groupObjects: boolean; constructor( levelNumber: number ) { @@ -42,11 +46,14 @@ class CountingGameLevel extends NumberPlayGameLevel { } ); // the object type of the current challenge - this.playObjectTypeProperty = new EnumerationProperty( PlayObjectType, CountingGameLevel.getRandomPlayObjectType() ); + // TODO-TS: Use updated enumeration pattern for Property when PlayObjectType is converted. See https://github.com/phetsims/number-play/issues/80 + this._playObjectTypeProperty = new EnumerationProperty( PlayObjectType, CountingGameLevel.getRandomPlayObjectType() ); + this.playObjectTypeProperty = this._playObjectTypeProperty; // whether the current representation of the challengeNumber are objects. Always use objects as the first representation // of the current challenge - this.isObjectsRepresentationProperty = new BooleanProperty( true ); + this._isObjectsRepresentationProperty = new BooleanProperty( true ); + this.isObjectsRepresentationProperty = this._isObjectsRepresentationProperty; } /** @@ -60,8 +67,8 @@ class CountingGameLevel extends NumberPlayGameLevel { public reset(): void { super.reset(); - this.playObjectTypeProperty.reset(); - this.isObjectsRepresentationProperty.reset(); + this._playObjectTypeProperty.reset(); + this._isObjectsRepresentationProperty.reset(); } public step( dt: number ): void { @@ -72,8 +79,8 @@ class CountingGameLevel extends NumberPlayGameLevel { */ public newChallenge(): void { super.newChallenge(); - this.playObjectTypeProperty.value = CountingGameLevel.getRandomPlayObjectType(); - this.isObjectsRepresentationProperty.value = !this.isObjectsRepresentationProperty.value; + this._playObjectTypeProperty.value = CountingGameLevel.getRandomPlayObjectType(); + this._isObjectsRepresentationProperty.value = !this._isObjectsRepresentationProperty.value; } } diff --git a/js/game/model/NumberPlayGameLevel.ts b/js/game/model/NumberPlayGameLevel.ts index 57e8dcb1..301ae8a0 100644 --- a/js/game/model/NumberPlayGameLevel.ts +++ b/js/game/model/NumberPlayGameLevel.ts @@ -19,7 +19,7 @@ abstract class NumberPlayGameLevel { public readonly scoreProperty: NumberProperty; public readonly isChallengeSolvedProperty: BooleanProperty; public readonly challengeRange: Range; - public readonly challengeNumberProperty: NumberProperty; + public readonly challengeNumberProperty: NumberProperty; // TODO-TS: This should be IReadOnlyProperty. See https://github.com/phetsims/number-play/issues/81. private oldChallengeNumberOne: number; private oldChallengeNumberTwo: number; public readonly numberOfAnswerButtonPressesProperty: NumberProperty; diff --git a/js/game/model/Subitizer.ts b/js/game/model/Subitizer.ts index b8c6ad61..ad5f95bc 100644 --- a/js/game/model/Subitizer.ts +++ b/js/game/model/Subitizer.ts @@ -126,18 +126,21 @@ class Subitizer { private readonly challengeNumberProperty: NumberProperty; private readonly isChallengeSolvedProperty: BooleanProperty; public readonly isShapeVisibleProperty: BooleanProperty; - public readonly pointsProperty: Property; + private readonly _pointsProperty: Property; + public readonly pointsProperty: IReadOnlyProperty; private readonly randomOrPredetermined: boolean; private timeSinceShapeVisible: number; public readonly objectSize: number; public readonly isInputEnabledProperty: BooleanProperty; private timeToShowShapeProperty: IReadOnlyProperty; - public readonly objectTypeProperty: Property; + private readonly _objectTypeProperty: Property; + public readonly objectTypeProperty: IReadOnlyProperty; private isDelayStarted: boolean; private timeSinceDelayStarted: number; public readonly isLoadingBarAnimatingProperty: BooleanProperty; public static SUBITIZER_BOUNDS: Bounds2; - public readonly isPlayButtonVisibleProperty: BooleanProperty; + private readonly _isPlayButtonVisibleProperty: BooleanProperty; + public readonly isPlayButtonVisibleProperty: IReadOnlyProperty; constructor( challengeNumberProperty: NumberProperty, isChallengeSolvedProperty: BooleanProperty, @@ -148,7 +151,8 @@ class Subitizer { this.isChallengeSolvedProperty = isChallengeSolvedProperty; // whether the play button is visible - this.isPlayButtonVisibleProperty = new BooleanProperty( true ); + this._isPlayButtonVisibleProperty = new BooleanProperty( true ); + this.isPlayButtonVisibleProperty = this._isPlayButtonVisibleProperty; // whether the loading bar is animating. This can also be used to stop an existing animation. this.isLoadingBarAnimatingProperty = new BooleanProperty( false ); @@ -157,10 +161,11 @@ class Subitizer { this.isShapeVisibleProperty = new BooleanProperty( false ); // the points of the current shape - this.pointsProperty = new Property( [ Vector2.ZERO ], { + this._pointsProperty = new Property( [ Vector2.ZERO ], { valueType: Array, arrayElementType: Vector2 } ); + this.pointsProperty = this._pointsProperty; // if true, make random or predetermined shapes. if false, only make arranged shapes. this.randomOrPredetermined = randomOrPredetermined; @@ -183,7 +188,8 @@ class Subitizer { this.isInputEnabledProperty = new BooleanProperty( false ); // the object type of the current shape - this.objectTypeProperty = new StringEnumerationProperty( SubitizeObjectTypeValues, 'dog' ); + this._objectTypeProperty = new StringEnumerationProperty( SubitizeObjectTypeValues, 'dog' ); + this.objectTypeProperty = this._objectTypeProperty; // how long the shape is visible when shown, in seconds. This is a derived Property instead of a constant because // the time that the shape is shown is increased if the user gets the answer wrong multiple times. @@ -256,7 +262,7 @@ class Subitizer { this.isLoadingBarAnimatingProperty.reset(); this.resetDelay(); this.resetShapeVisible(); - this.isPlayButtonVisibleProperty.reset(); + this._isPlayButtonVisibleProperty.reset(); this.isInputEnabledProperty.reset(); } } @@ -298,8 +304,8 @@ class Subitizer { `${challengeNumber}: ${points.length}` ); // two of the same shapes in a row are not allowed - if ( !Subitizer.arePointsEqual( this.pointsProperty.value, points ) ) { - this.pointsProperty.value = points; + if ( !Subitizer.arePointsEqual( this._pointsProperty.value, points ) ) { + this._pointsProperty.value = points; } else { this.setNewPoints(); @@ -310,13 +316,13 @@ class Subitizer { * Sets this.objectTypeProperty with a new object type for the current challenge. */ private setRandomPlayObjectType(): void { - this.objectTypeProperty.value = dotRandom.sample( SubitizeObjectTypeValues.slice() ); + this._objectTypeProperty.value = dotRandom.sample( SubitizeObjectTypeValues.slice() ); } public reset(): void { this.isShapeVisibleProperty.reset(); this.isInputEnabledProperty.reset(); - this.isPlayButtonVisibleProperty.reset(); + this._isPlayButtonVisibleProperty.reset(); } /**