Skip to content

Commit

Permalink
Add userControllable option to UserMovableModelElement, see #307
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisklus committed Jan 9, 2020
1 parent 7d4a56a commit 9140b12
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 44 deletions.
37 changes: 21 additions & 16 deletions js/common/model/UserMovableModelElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,12 @@ define( require => {
constructor( initialPosition, options ) {

options = merge( {
tandem: Tandem.REQUIRED
tandem: Tandem.REQUIRED,
userControllable: true
}, options );

super( initialPosition, options );

// @public {BooleanProperty}
this.userControlledProperty = new BooleanProperty( false, {
tandem: options.tandem.createTandem( 'userControlledProperty' ),
phetioReadOnly: true,
phetioDocumentation: 'whether the element is being directly held or moved by a user'
} );

// @protected {HorizontalSurface|null} - The surface upon which this model element is resting. This is null if the
// element is not resting on a movable surface. This should only be set through the getter/setter methods below.
this.supportingSurface = null;
Expand All @@ -51,14 +45,25 @@ define( require => {
// the view
this.tandem = options.tandem;

// update internal state when the user picks up this model element
this.userControlledProperty.link( userControlled => {
if ( userControlled ) {
// create userControlledProperty unless opted out
if ( options.userControllable ) {

// the user has picked up this model element, so it is no longer sitting on any surface
this.clearSupportingSurface();
}
} );
// @public {BooleanProperty}
this.userControlledProperty = new BooleanProperty( false, {
tandem: options.tandem.createTandem( 'userControlledProperty' ),
phetioReadOnly: true,
phetioDocumentation: 'whether the element is being directly held or moved by a user'
} );

// update internal state when the user picks up this model element
this.userControlledProperty.link( userControlled => {
if ( userControlled ) {

// the user has picked up this model element, so it is no longer sitting on any surface
this.clearSupportingSurface();
}
} );
}

// @private - observer that moves this model element if and when the surface that is supporting it moves
this.surfaceMotionObserver = position => {
Expand All @@ -72,7 +77,7 @@ define( require => {
*/
reset() {
this.clearSupportingSurface();
this.userControlledProperty.reset();
this.userControlledProperty && this.userControlledProperty.reset();
this.verticalVelocityProperty.reset();
super.reset();
}
Expand Down
26 changes: 0 additions & 26 deletions js/phet-io/energy-forms-and-changes-phet-io-elements-baseline.js
Original file line number Diff line number Diff line change
Expand Up @@ -5279,19 +5279,6 @@ window.phet.phetio.phetioElementsBaseline = assert &&
"phetioStudioControl": true,
"phetioTypeName": "NumberPropertyIO"
},
"energyFormsAndChanges.systemsScreen.model.energyUsers.beakerHeater.thermometer.userControlledProperty": {
"phetioDocumentation": "whether the element is being directly held or moved by a user",
"phetioDynamicElement": false,
"phetioEventType": "MODEL",
"phetioFeatured": false,
"phetioHighFrequency": false,
"phetioIsArchetype": false,
"phetioPlayback": false,
"phetioReadOnly": true,
"phetioState": true,
"phetioStudioControl": true,
"phetioTypeName": "PropertyIO<BooleanIO>"
},
"energyFormsAndChanges.systemsScreen.model.energyUsers.beakerHeater.waterBeaker": {
"phetioDocumentation": "beaker that contains water",
"phetioDynamicElement": false,
Expand Down Expand Up @@ -5344,19 +5331,6 @@ window.phet.phetio.phetioElementsBaseline = assert &&
"phetioStudioControl": true,
"phetioTypeName": "NumberPropertyIO"
},
"energyFormsAndChanges.systemsScreen.model.energyUsers.beakerHeater.waterBeaker.userControlledProperty": {
"phetioDocumentation": "whether the element is being directly held or moved by a user",
"phetioDynamicElement": false,
"phetioEventType": "MODEL",
"phetioFeatured": false,
"phetioHighFrequency": false,
"phetioIsArchetype": false,
"phetioPlayback": false,
"phetioReadOnly": true,
"phetioState": true,
"phetioStudioControl": true,
"phetioTypeName": "PropertyIO<BooleanIO>"
},
"energyFormsAndChanges.systemsScreen.model.energyUsers.fan.activeProperty": {
"phetioDocumentation": "whether the system element is active. system elements are active when visible on the screen",
"phetioDynamicElement": false,
Expand Down
6 changes: 4 additions & 2 deletions js/systems/model/BeakerHeater.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ define( require => {
BEAKER_HEIGHT,
energyChunksVisibleProperty, {
tandem: this.waterBeakerTandem,
phetioDocumentation: 'beaker that contains water'
phetioDocumentation: 'beaker that contains water',
userControllable: false
}
);

Expand All @@ -109,7 +110,8 @@ define( require => {
this,
new Vector2( BEAKER_WIDTH * 0.45, BEAKER_HEIGHT * 0.6 ), // position is relative, not absolute
true, {
tandem: tandem.createTandem( 'thermometer' )
tandem: tandem.createTandem( 'thermometer' ),
userControllable: false
}
);

Expand Down

0 comments on commit 9140b12

Please sign in to comment.