Skip to content

Commit

Permalink
Many bug fixes and attempts to get thermometers to follow blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewadare committed Jun 29, 2016
1 parent 1441eb9 commit 5ab9edd
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
10 changes: 6 additions & 4 deletions js/common/model/ElementFollower.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ define( function( require ) {
var self = this;
// @private - function that gets linked/unlinked when the thermometer is following/unfollwing.
this.followerFunction = function( location ) {
self.followerProperty.set( location.plus( self.offset ) );
// self.followerProperty.set( location.plus( self.offset ) );
self.followerProperty.set( location );
console.log(location, self.followerProperty.get());
};
}

Expand All @@ -52,14 +54,14 @@ define( function( require ) {
},

stopFollowing: function() {
if ( this.locationBeingFollowed !== null ) {
if ( this.locationBeingFollowedProperty.get() !== null ) {
this.locationBeingFollowedProperty.unlink( this.followerFunction );
this.locationBeingFollowed = null;
this.locationBeingFollowedProperty.set( null );
}
},

isFollowing: function() {
return this.locationBeingFollowed !== null;
return this.locationBeingFollowedProperty.get() !== null;
}

} );
Expand Down
4 changes: 2 additions & 2 deletions js/common/model/Thermometer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ define( function( require ) {

step: function( dt ) {
var temperatureAndColor = this.model.getTemperatureAndColorAtLocation( this.position );
this.sensedTemperature = temperatureAndColor.temperature;
this.sensedElementColor = temperatureAndColor.color;
this.sensedTemperatureProperty.set( temperatureAndColor.temperature );
this.sensedElementColorProperty.set( temperatureAndColor.color );
},

reset: function() {
Expand Down
16 changes: 8 additions & 8 deletions js/intro/model/ElementFollowingThermometer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ define( function( require ) {
// extend the scope of this
var self = this;

this.elementFollower = new ElementFollower( this.position );
this.elementFollower = new ElementFollower( this.positionProperty.get() );

// Monitor 'userControlled' in order to see when the user drops this
// thermometer and determine whether or not it was dropped over anything
// that it should stick to.
this.userControlledProperty.link( function( userControlled ) {
if ( userControlled ) {
// stop following anything.
console.log('stop following');
self.elementFollower.stopFollowing();
} else {
// The user has dropped this thermometer. See if it was
// dropped over something that it should follow.
for ( var block in model.getBlockList() ) {
if ( model.getBlockList.hasOwnProperty( block ) ) {
if ( block.getProjectedShape().containsPoint( self.position ) ) {
// stick to this block.
self.elementFollower.follow( block.positionProperty );
}
model.getBlockList().forEach( function( block ) {
if ( block.getProjectedShape().containsPoint( self.position ) ) {
// stick to this block.
console.log( 'sticking?' );
self.elementFollower.follow( block.positionProperty );
}
}
} );
if ( !self.elementFollower.isFollowing() &&
model.beaker.getThermalContactArea().containsPoint( self.position ) ) {
// Stick to the beaker.
Expand Down
2 changes: 1 addition & 1 deletion js/intro/model/EnergyFormsAndChangesIntroModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ define( function( require ) {
modelElement.verticalVelocity = velocity;
}

modelElement.position = new Vector2( modelElement.position.x, proposedYPos );
modelElement.positionProperty.set( new Vector2( modelElement.position.x, proposedYPos ) );
},

getBlockList: function() {
Expand Down
2 changes: 1 addition & 1 deletion js/intro/view/EnergyFormsAndChangesIntroScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ define( function( require ) {
// backLayer.addChild( thermometerBox );
backLayer.addChild( thermometerToolBox );
thermometerToolBoxNodes.forEach( function( thermometerToolBoxNode ) {
thermometerToolBoxNode.setReturnRect( thermometerBox.bounds );
thermometerToolBoxNode.returnRect = thermometerBox.bounds;
} );

// Create a function that updates the Z-order of the blocks when the user controlled state changes.
Expand Down
1 change: 1 addition & 0 deletions js/intro/view/MovableThermometerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ define( function( require ) {

inherit( Object, ThermometerLocationConstraint, {

// Gets applied as a constraint in ThermalElementDragHandler
apply: function( proposedModelPosition ) {
// TODO: These bounds calculations for the constraint should be handled by MovableDragHandler.
var constrainedXPos = Util.clamp( this.modelBounds.minX, proposedModelPosition.x, this.modelBounds.maxX );
Expand Down
1 change: 1 addition & 0 deletions js/intro/view/SensingThermometerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ define( function( require ) {
self.setSensedColor( sensedColor );
} );
thermometer.activeProperty.link( function( active ) {
console.log('active? ', active);
self.setVisible( active );
} );
}
Expand Down
30 changes: 13 additions & 17 deletions js/intro/view/ThermometerToolBoxNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ define( function( require ) {
allowTouchSnag: true,

start: function( event, trail ) {
thermometer.userControlled = true;
thermometer.active = true;
thermometer.userControlledProperty.set( true );
thermometer.activeProperty.set( true );

if ( !parentScreenView ) {

Expand All @@ -62,23 +62,26 @@ define( function( require ) {
assert && assert( parentScreenView, 'unable to find parent screen view' );
}

// Determine the initial position of the new element as a function of the event position and this node's bounds.
var triangleTipGlobal = self.parentToGlobalPoint( self.rightCenter.plus( thermometerNode.getOffsetCenterShaftToTriangleTip() ) );
// Determine the initial position of the new element as a function of
// the event position and this node's bounds.
var triangleTipGlobal = self.parentToGlobalPoint(
self.rightCenter.plus( thermometerNode.getOffsetCenterShaftToTriangleTip() ) );
var initialPosition = parentScreenView.globalToLocalPoint( triangleTipGlobal );

thermometer.position = modelViewTransform.viewToModelPosition( initialPosition );
thermometer.positionProperty.set( modelViewTransform.viewToModelPosition( initialPosition ) );
},

// Handler that moves the shape in model space.
translate: function( translationParams ) {
thermometer.position = thermometer.position.plus( modelViewTransform.viewToModelDelta( translationParams.delta ) );
thermometer.positionProperty.set(
thermometer.position.plus( modelViewTransform.viewToModelDelta( translationParams.delta ) ) );
},

end: function( event, trail ) {
thermometer.userControlled = false;
thermometer.userControlledProperty.set( false );
if ( self.returnRect !== null && thermometerNode.bounds.intersectsBounds( self.returnRect ) ) {
// Released over tool box, so return it.
thermometer.active = false;
thermometer.activeProperty.set( false );
}
}
} ) );
Expand All @@ -87,13 +90,6 @@ define( function( require ) {

energyFormsAndChanges.register( 'ThermometerToolBoxNode', ThermometerToolBoxNode );

return inherit( ThermometerNode, ThermometerToolBoxNode, {
/**
* @public
* @param {Rectangle} returnRect
*/
setReturnRect: function( returnRect ) {
this.returnRect = returnRect;
}
} );
return inherit( ThermometerNode, ThermometerToolBoxNode );
} );

0 comments on commit 5ab9edd

Please sign in to comment.