Skip to content

Commit

Permalink
Move visibility properties to view, see: #72
Browse files Browse the repository at this point in the history
  • Loading branch information
marlitas committed Jul 29, 2022
1 parent a97e70b commit c46e1a8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
17 changes: 1 addition & 16 deletions js/intro/model/IntroModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ export default class IntroModel extends MeanShareAndBalanceModel {
public readonly dragRange = new Range( MeanShareAndBalanceConstants.CUP_RANGE_MIN, MeanShareAndBalanceConstants.CUP_RANGE_MAX );
public readonly cupRange = new Range( MeanShareAndBalanceConstants.CUP_RANGE_MIN, MeanShareAndBalanceConstants.CUP_RANGE_MAX );

public readonly predictMeanVisibleProperty: Property<boolean>;
public readonly meanVisibleProperty: Property<boolean>;
public readonly tickMarksVisibleProperty: Property<boolean>;

public readonly numberOfCupsProperty: Property<number>;
public readonly meanPredictionProperty: Property<number>;
public readonly meanProperty: IReadOnlyProperty<number>;
Expand All @@ -53,15 +49,7 @@ export default class IntroModel extends MeanShareAndBalanceModel {
const options = optionize<IntroModelOptions, SelfOptions, MeanShareAndBalanceModelOptions>()( {}, providedOptions );
super( options );

this.predictMeanVisibleProperty = new BooleanProperty( false, {
tandem: options.tandem.createTandem( 'predictMeanVisibleProperty' )
} );
this.meanVisibleProperty = new BooleanProperty( false, {
tandem: options.tandem.createTandem( 'meanVisibleProperty' )
} );
this.tickMarksVisibleProperty = new BooleanProperty( false, {
tandem: options.tandem.createTandem( 'tickMarksVisibleProperty' )
} );

this.meanPredictionProperty = new NumberProperty( 0, {
tandem: options.tandem.createTandem( 'meanPredictionProperty' ),
phetioDocumentation: 'Indicates where the user predicted the mean would be, or the default value at startup',
Expand Down Expand Up @@ -308,9 +296,6 @@ export default class IntroModel extends MeanShareAndBalanceModel {
// Short circuit changeWaterLevel during reset.
this.isResetting.set( true );

this.predictMeanVisibleProperty.reset();
this.meanVisibleProperty.reset();
this.tickMarksVisibleProperty.reset();
this.numberOfCupsProperty.reset();
this.meanPredictionProperty.reset();

Expand Down
11 changes: 6 additions & 5 deletions js/intro/view/IntroControlPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
*/
import { Node, Text } from '../../../../scenery/js/imports.js';
import VerticalCheckboxGroup from '../../../../sun/js/VerticalCheckboxGroup.js';
import IntroModel from '../model/IntroModel.js';
import meanShareAndBalance from '../../meanShareAndBalance.js';
import meanShareAndBalanceStrings from '../../meanShareAndBalanceStrings.js';
import MeanShareAndBalanceConstants from '../../common/MeanShareAndBalanceConstants.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import Property from '../../../../axon/js/Property.js';

export default class IntroControlPanel extends Node {
public constructor( model: IntroModel, tandem: Tandem ) {
public constructor( tickMarksVisibleProperty: Property<boolean>, meanVisibleProperty: Property<boolean>,
predictMeanVisibleProperty: Property<boolean>, tandem: Tandem ) {

const predictMeanText = new Text( meanShareAndBalanceStrings.predictMean, {
fontSize: 15,
Expand All @@ -28,17 +29,17 @@ export default class IntroControlPanel extends Node {
const introOptionsCheckboxGroupTandem = tandem.createTandem( 'introOptionsCheckboxGroup' );
const introOptionsCheckboxGroup = new VerticalCheckboxGroup( [ {
node: predictMeanText,
property: model.predictMeanVisibleProperty,
property: predictMeanVisibleProperty,
tandem: introOptionsCheckboxGroupTandem.createTandem( 'predictMeanCheckbox' ),
options: { accessibleName: meanShareAndBalanceStrings.predictMean }
}, {
node: meanText,
property: model.meanVisibleProperty,
property: meanVisibleProperty,
tandem: introOptionsCheckboxGroupTandem.createTandem( 'showMeanCheckbox' ),
options: { accessibleName: meanShareAndBalanceStrings.mean }
}, {
node: tickMarksText,
property: model.tickMarksVisibleProperty,
property: tickMarksVisibleProperty,
tandem: introOptionsCheckboxGroupTandem.createTandem( 'tickMarksCheckbox' ),
options: { accessibleName: meanShareAndBalanceStrings.tickMarks }
} ], {
Expand Down
31 changes: 26 additions & 5 deletions js/intro/view/IntroScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,34 @@ import WaterCup3DNode from './WaterCup3DNode.js';
import MeanShareAndBalanceConstants from '../../common/MeanShareAndBalanceConstants.js';
import MeanShareAndBalanceColors from '../../common/MeanShareAndBalanceColors.js';
import IntroControlPanel from './IntroControlPanel.js';
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';

type SelfOptions = EmptySelfOptions;

type LevelingOutScreenViewOptions = SelfOptions & MeanShareAndBalanceScreenViewOptions;

export default class IntroScreenView extends MeanShareAndBalanceScreenView {
private readonly pipeNodes: PipeNode[];
public readonly predictMeanVisibleProperty: Property<boolean>;
public readonly meanVisibleProperty: Property<boolean>;
public readonly tickMarksVisibleProperty: Property<boolean>;

public constructor( model: IntroModel, providedOptions: LevelingOutScreenViewOptions ) {

const options = optionize<LevelingOutScreenViewOptions, SelfOptions, MeanShareAndBalanceScreenViewOptions>()( {}, providedOptions );

super( model, options );

this.predictMeanVisibleProperty = new BooleanProperty( false, {
tandem: options.tandem.createTandem( 'predictMeanVisibleProperty' )
} );
this.meanVisibleProperty = new BooleanProperty( false, {
tandem: options.tandem.createTandem( 'meanVisibleProperty' )
} );
this.tickMarksVisibleProperty = new BooleanProperty( false, {
tandem: options.tandem.createTandem( 'tickMarksVisibleProperty' )
} );

const modelViewTransform2DCups = ModelViewTransform2.createSinglePointScaleInvertedYMapping( new Vector2( 0, 0 ), new Vector2( 0, MeanShareAndBalanceConstants.CUPS_2D_CENTER_Y ), MeanShareAndBalanceConstants.CUP_HEIGHT );
const modelViewTransform3DCups = ModelViewTransform2.createSinglePointScaleInvertedYMapping( new Vector2( 0, 0 ), new Vector2( 0, MeanShareAndBalanceConstants.CUPS_3D_CENTER_Y ), MeanShareAndBalanceConstants.CUP_HEIGHT );

Expand Down Expand Up @@ -68,7 +82,7 @@ export default class IntroScreenView extends MeanShareAndBalanceScreenView {
model.meanPredictionProperty, model.dragRange,
model.numberOfCupsProperty, () => model.getActive2DCups(),
modelViewTransform2DCups, {
visibleProperty: model.predictMeanVisibleProperty,
visibleProperty: this.predictMeanVisibleProperty,
valueProperty: model.meanPredictionProperty,

// Constant range
Expand Down Expand Up @@ -98,15 +112,15 @@ export default class IntroScreenView extends MeanShareAndBalanceScreenView {

// TODO: Better way of matching indices or tandems?
const index = model.waterCup2DArray.indexOf( cupModel );
const cupNode = new WaterCup2DNode( cupModel, modelViewTransform2DCups, model.meanProperty, model.tickMarksVisibleProperty,
model.meanVisibleProperty, { tandem: options.tandem.createTandem( `waterCup2DNode${index}` ) } );
const cupNode = new WaterCup2DNode( cupModel, modelViewTransform2DCups, model.meanProperty, this.tickMarksVisibleProperty,
this.meanVisibleProperty, { tandem: options.tandem.createTandem( `waterCup2DNode${index}` ) } );
waterCupLayerNode.addChild( cupNode );
centerWaterCupLayerNode();
} );

model.waterCup3DArray.forEach( cupModel => {
const index = model.waterCup3DArray.indexOf( cupModel );
const cupNode = new WaterCup3DNode( model.tickMarksVisibleProperty, model.changeWaterLevel.bind( model ), cupModel, modelViewTransform3DCups,
const cupNode = new WaterCup3DNode( this.tickMarksVisibleProperty, model.changeWaterLevel.bind( model ), cupModel, modelViewTransform3DCups,
{ tandem: options.tandem.createTandem( `waterCup3DNode${index}` ) } );
waterCupLayerNode.addChild( cupNode );
centerWaterCupLayerNode();
Expand All @@ -123,7 +137,7 @@ export default class IntroScreenView extends MeanShareAndBalanceScreenView {
model.numberOfCupsProperty.link( centerWaterCupLayerNode );

// Configure layout
const controlPanel = new IntroControlPanel( model, options.tandem );
const controlPanel = new IntroControlPanel( this.tickMarksVisibleProperty, this.meanVisibleProperty, this.predictMeanVisibleProperty, options.tandem );
this.controlsVBox.addChild( controlPanel );
this.numberSpinnerVBox.children = [ numberOfCupsText, numberOfCupsNumberSpinner ];

Expand All @@ -147,6 +161,13 @@ export default class IntroScreenView extends MeanShareAndBalanceScreenView {
super.step( dt );
this.pipeNodes.forEach( pipeNode => pipeNode.step( dt ) );
}

public override reset(): void {
super.reset();
this.predictMeanVisibleProperty.reset();
this.meanVisibleProperty.reset();
this.tickMarksVisibleProperty.reset();
}
}

meanShareAndBalance.register( 'IntroScreenView', IntroScreenView );

0 comments on commit c46e1a8

Please sign in to comment.