From 65e1bcfcc86a17040468ac92103a4b61180a1274 Mon Sep 17 00:00:00 2001 From: samreid Date: Mon, 11 Sep 2017 09:13:23 -0600 Subject: [PATCH] Made TNumber nonparametric and moved range/units to NumberProperty, see https://github.com/phetsims/axon/issues/137 --- js/motion/model/Item.js | 15 +++--- js/motion/model/MotionModel.js | 87 +++++++++++++++--------------- js/motion/view/MotionScreenView.js | 8 ++- js/netforce/model/Cart.js | 20 ++++--- js/netforce/model/Knot.js | 13 ++--- js/netforce/model/NetForceModel.js | 49 +++++++++-------- js/netforce/view/GoPauseButton.js | 4 +- 7 files changed, 98 insertions(+), 98 deletions(-) diff --git a/js/motion/model/Item.js b/js/motion/model/Item.js index 4eaa474f..cd7a070a 100644 --- a/js/motion/model/Item.js +++ b/js/motion/model/Item.js @@ -8,19 +8,19 @@ define( function( require ) { 'use strict'; + var NumberProperty = require( 'AXON/NumberProperty' ); var Property = require( 'AXON/Property' ); + var Range = require( 'DOT/Range' ); var TVector2 = require( 'DOT/TVector2' ); var Util = require( 'DOT/Util' ); - var Range = require( 'DOT/Range' ); var Vector2 = require( 'DOT/Vector2' ); var forcesAndMotionBasics = require( 'FORCES_AND_MOTION_BASICS/forcesAndMotionBasics' ); var inherit = require( 'PHET_CORE/inherit' ); // phet-io modules - var TItem = require( 'FORCES_AND_MOTION_BASICS/motion/model/TItem' ); var TAnimationState = require( 'FORCES_AND_MOTION_BASICS/motion/model/TAnimationState' ); + var TItem = require( 'FORCES_AND_MOTION_BASICS/motion/model/TItem' ); var TBoolean = require( 'ifphetio!PHET_IO/types/TBoolean' ); - var TNumber = require( 'ifphetio!PHET_IO/types/TNumber' ); var TString = require( 'ifphetio!PHET_IO/types/TString' ); /** @@ -97,16 +97,15 @@ define( function( require ) { } ); // How much to increase/shrink the original image. Could all be set to 1.0 if images pre-scaled in an external program - this.imageScaleProperty = new Property( imageScale || 1.0, { - tandem: tandem.createTandem( 'imageScaleProperty' ), - phetioValueType: TNumber() + this.imageScaleProperty = new NumberProperty( imageScale || 1.0, { + tandem: tandem.createTandem( 'imageScaleProperty' ) } ); // How much the object grows or shrinks when interacting with it var minValue = homeScale || 1.0; - this.interactionScaleProperty = new Property( homeScale || 1.0, { + this.interactionScaleProperty = new NumberProperty( homeScale || 1.0, { tandem: tandem.createTandem( 'interactionScaleProperty' ), - phetioValueType: TNumber( { range: new Range( minValue, 1.3 ) } ) + range: new Range( minValue, 1.3 ) } ); this.context.directionProperty.link( function( direction ) { diff --git a/js/motion/model/MotionModel.js b/js/motion/model/MotionModel.js index 432ef60f..45140885 100644 --- a/js/motion/model/MotionModel.js +++ b/js/motion/model/MotionModel.js @@ -8,34 +8,34 @@ define( function( require ) { 'use strict'; - var Item = require( 'FORCES_AND_MOTION_BASICS/motion/model/Item' ); - var Property = require( 'AXON/Property' ); + var DerivedProperty = require( 'AXON/DerivedProperty' ); + var Emitter = require( 'AXON/Emitter' ); + var NumberProperty = require( 'AXON/NumberProperty' ); var ObservableArray = require( 'AXON/ObservableArray' ); - var inherit = require( 'PHET_CORE/inherit' ); - var MotionConstants = require( 'FORCES_AND_MOTION_BASICS/motion/MotionConstants' ); - var Vector2 = require( 'DOT/Vector2' ); + var Property = require( 'AXON/Property' ); + var Range = require( 'DOT/Range' ); var Util = require( 'DOT/Util' ); - var waterBucketImage = require( 'image!FORCES_AND_MOTION_BASICS/water-bucket.png' ); - var fridgeImage = require( 'image!FORCES_AND_MOTION_BASICS/fridge.png' ); + var Vector2 = require( 'DOT/Vector2' ); + var forcesAndMotionBasics = require( 'FORCES_AND_MOTION_BASICS/forcesAndMotionBasics' ); + var Item = require( 'FORCES_AND_MOTION_BASICS/motion/model/Item' ); + var MotionConstants = require( 'FORCES_AND_MOTION_BASICS/motion/MotionConstants' ); var crateImage = require( 'image!FORCES_AND_MOTION_BASICS/crate.png' ); - var girlStandingImage = require( 'mipmap!FORCES_AND_MOTION_BASICS/girl-standing.png' ); - var manStandingImage = require( 'mipmap!FORCES_AND_MOTION_BASICS/man-standing.png' ); - var girlSittingImage = require( 'mipmap!FORCES_AND_MOTION_BASICS/girl-sitting.png' ); - var manSittingImage = require( 'mipmap!FORCES_AND_MOTION_BASICS/man-sitting.png' ); + var fridgeImage = require( 'image!FORCES_AND_MOTION_BASICS/fridge.png' ); + var mysteryObjectImage = require( 'image!FORCES_AND_MOTION_BASICS/mystery-object-01.png' ); + var waterBucketImage = require( 'image!FORCES_AND_MOTION_BASICS/water-bucket.png' ); var girlHoldingImage = require( 'mipmap!FORCES_AND_MOTION_BASICS/girl-holding.png,level=1' ); + var girlSittingImage = require( 'mipmap!FORCES_AND_MOTION_BASICS/girl-sitting.png' ); + var girlStandingImage = require( 'mipmap!FORCES_AND_MOTION_BASICS/girl-standing.png' ); var manHoldingImage = require( 'mipmap!FORCES_AND_MOTION_BASICS/man-holding.png' ); + var manSittingImage = require( 'mipmap!FORCES_AND_MOTION_BASICS/man-sitting.png' ); + var manStandingImage = require( 'mipmap!FORCES_AND_MOTION_BASICS/man-standing.png' ); var trashCanImage = require( 'mipmap!FORCES_AND_MOTION_BASICS/trash-can.png' ); - var mysteryObjectImage = require( 'image!FORCES_AND_MOTION_BASICS/mystery-object-01.png' ); - var forcesAndMotionBasics = require( 'FORCES_AND_MOTION_BASICS/forcesAndMotionBasics' ); - var Range = require( 'DOT/Range' ); - var Emitter = require( 'AXON/Emitter' ); - var DerivedProperty = require( 'AXON/DerivedProperty' ); + var inherit = require( 'PHET_CORE/inherit' ); // phet-io modules + var TItem = require( 'FORCES_AND_MOTION_BASICS/motion/model/TItem' ); var TBoolean = require( 'ifphetio!PHET_IO/types/TBoolean' ); var TString = require( 'ifphetio!PHET_IO/types/TString' ); - var TNumber = require( 'ifphetio!PHET_IO/types/TNumber' ); - var TItem = require( 'FORCES_AND_MOTION_BASICS/motion/model/TItem' ); /** * Constructor for the motion model @@ -64,57 +64,57 @@ define( function( require ) { } ); // @public - force applied to the stack of items by the pusher - this.appliedForceProperty = new Property( 0, { + this.appliedForceProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'appliedForceProperty' ), - phetioValueType: TNumber( { units: 'newtons', range: new Range( -500, 500 ) } ) + units: 'newtons', + range: new Range( -500, 500 ) } ); // @public - force applied to the stack of items by friction - this.frictionForceProperty = new Property( 0, { + this.frictionForceProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'frictionForceProperty' ), - phetioValueType: TNumber( { units: 'newtons' } ) + units: 'newtons' } ); // @public - friction of the ground - this.frictionProperty = new Property( frictionValue, { - tandem: tandem.createTandem( 'frictionProperty' ), - phetioValueType: TNumber() + this.frictionProperty = new NumberProperty( frictionValue, { + tandem: tandem.createTandem( 'frictionProperty' ) } ); // @public - sum of all forces acting on the stack of items - this.sumOfForcesProperty = new Property( 0, { + this.sumOfForcesProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'sumOfForcesProperty' ), - phetioValueType: TNumber( { units: 'newtons' } ) + units: 'newtons' } ); // @public - 1-D position of the stack of items - this.positionProperty = new Property( 0, { + this.positionProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'positionProperty' ), - phetioValueType: TNumber( { units: 'meters' } ) + units: 'meters' } ); // @public - speed of the stack of items, in the x direction - this.speedProperty = new Property( 0, { + this.speedProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'speedProperty' ), - phetioValueType: TNumber( { units: 'meters/second' } ) + units: 'meters/second' } ); // @public - elocity is a 1-d vector, where the direction (right or left) is indicated by the sign - this.velocityProperty = new Property( 0, { + this.velocityProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'velocityProperty' ), - phetioValueType: TNumber( { units: 'meters/second' } ) + units: 'meters/second' } ); // @public - 1-d acceleration of the stack of items - this.accelerationProperty = new Property( 0, { + this.accelerationProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'accelerationProperty' ), - phetioValueType: TNumber( { units: 'meters/second/second' } ) + units: 'meters/second/second' } ); // @public {number} - initially to the left of the box by this many meters - this.pusherPositionProperty = new Property( -16, { + this.pusherPositionProperty = new NumberProperty( -16, { tandem: tandem.createTandem( 'pusherPositionProperty' ), - phetioValueType: TNumber( { units: 'meters' } ) + units: 'meters' } ); // @public {boolean} - whether or not forces are visible @@ -182,8 +182,8 @@ define( function( require ) { // @public {number} - time since pusher has fallen over, in seconds // TODO: Should we this have a tandem? It spams the data stream. // TODO: Why is default value 10? - this.timeSinceFallenProperty = new Property( 10, { - phetioValueType: TNumber( { units: 'seconds' } ) + this.timeSinceFallenProperty = new NumberProperty( 10, { + units: 'seconds' } ); // @public {boolean} - whether or not the pusher has fallen over @@ -200,15 +200,14 @@ define( function( require ) { // @public {number} - how long the simulation has been running // TODO: Should we this have a tandem? It spams the data stream. - this.timeProperty = new Property( 0, { - phetioValueType: TNumber( { units: 'seconds' } ) + this.timeProperty = new NumberProperty( 0, { + units: 'seconds' } ); //stack.length is already a property, but mirror it here to easily multilink with it, see usage in MotionScreenView.js //TODO: Perhaps a DerivedProperty would be more suitable instead of duplicating/synchronizing this value - this.stackSizeProperty = new Property( 1, { - tandem: tandem.createTandem( 'stackSizeProperty' ), - phetioValueType: TNumber() + this.stackSizeProperty = new NumberProperty( 1, { + tandem: tandem.createTandem( 'stackSizeProperty' ) } ); // @public {boolean} - is the sim running or paused? diff --git a/js/motion/view/MotionScreenView.js b/js/motion/view/MotionScreenView.js index d4b74693..425a13e2 100644 --- a/js/motion/view/MotionScreenView.js +++ b/js/motion/view/MotionScreenView.js @@ -36,6 +36,7 @@ define( function( require ) { var AccelerometerNode = require( 'FORCES_AND_MOTION_BASICS/motion/view/AccelerometerNode' ); var Property = require( 'AXON/Property' ); var DerivedProperty = require( 'AXON/DerivedProperty' ); + var NumberProperty = require( 'AXON/NumberProperty' ); var ArrowButton = require( 'SUN/buttons/ArrowButton' ); var Util = require( 'DOT/Util' ); var ItemToolboxNode = require( 'FORCES_AND_MOTION_BASICS/motion/view/ItemToolboxNode' ); @@ -44,9 +45,6 @@ define( function( require ) { var Line = require( 'SCENERY/nodes/Line' ); var ForcesAndMotionBasicsQueryParameters = require( 'FORCES_AND_MOTION_BASICS/common/ForcesAndMotionBasicsQueryParameters' ); - // phet-io modules - var TNumber = require( 'ifphetio!PHET_IO/types/TNumber' ); - // constants var DEBUG = false; // adds a line at the bottom of the items to assist with layout var PLAY_PAUSE_BUFFER = 10; // separation between step and reset all button, usedful for i18n @@ -509,9 +507,9 @@ define( function( require ) { } ); //Only update the sum force arrow after both friction and applied force changed, so we don't get partial updates, see https://github.com/phetsims/forces-and-motion-basics/issues/83 - var roundedSumProperty = new Property( roundedAppliedForceProperty.get() + roundedFrictionForceProperty.get(), { + var roundedSumProperty = new NumberProperty( roundedAppliedForceProperty.get() + roundedFrictionForceProperty.get(), { tandem: tandem.createTandem( 'roundedSumProperty' ), - phetioValueType: TNumber( { units: 'newtons' } ) + units: 'newtons' } ); model.stepEmitter.addListener( function() { diff --git a/js/netforce/model/Cart.js b/js/netforce/model/Cart.js index 14df09d7..aa78957b 100644 --- a/js/netforce/model/Cart.js +++ b/js/netforce/model/Cart.js @@ -8,13 +8,10 @@ define( function( require ) { 'use strict'; - var Property = require( 'AXON/Property' ); - var inherit = require( 'PHET_CORE/inherit' ); - var forcesAndMotionBasics = require( 'FORCES_AND_MOTION_BASICS/forcesAndMotionBasics' ); + var NumberProperty = require( 'AXON/NumberProperty' ); var Range = require( 'DOT/Range' ); - - // phet-io modules - var TNumber = require( 'ifphetio!PHET_IO/types/TNumber' ); + var forcesAndMotionBasics = require( 'FORCES_AND_MOTION_BASICS/forcesAndMotionBasics' ); + var inherit = require( 'PHET_CORE/inherit' ); /** * @param {Tandem} tandem @@ -23,16 +20,17 @@ define( function( require ) { function Cart( tandem ) { // @public {number} - 1-D x location of the cart - this.xProperty = new Property( 0, { + this.xProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'xProperty' ), - phetioValueType: TNumber( { units: 'meters', range: new Range( -403, 403 ) } ) + units: 'meters', + range: new Range( -403, 403 ) } ); - // @public {number} - 1-D velocity in MKS - this.vProperty = new Property( 0, { + this.vProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'vProperty' ), - phetioValueType: TNumber( { units: 'meters/second', range: new Range( -6, 6 ) } ) + units: 'meters/second', + range: new Range( -6, 6 ) } ); // @public (read-only) - width from the center of the cart to the wheels, used to determine when a wheel touches diff --git a/js/netforce/model/Knot.js b/js/netforce/model/Knot.js index 1ebd892c..58109abd 100644 --- a/js/netforce/model/Knot.js +++ b/js/netforce/model/Knot.js @@ -8,21 +8,21 @@ define( function( require ) { 'use strict'; + var NumberProperty = require( 'AXON/NumberProperty' ); var Property = require( 'AXON/Property' ); - var inherit = require( 'PHET_CORE/inherit' ); var Vector2 = require( 'DOT/Vector2' ); - var Range = require( 'DOT/Range' ); var forcesAndMotionBasics = require( 'FORCES_AND_MOTION_BASICS/forcesAndMotionBasics' ); + var inherit = require( 'PHET_CORE/inherit' ); // phet-io modules - var TNumber = require( 'ifphetio!PHET_IO/types/TNumber' ); - var TBoolean = require( 'ifphetio!PHET_IO/types/TBoolean' ); var TKnot = require( 'FORCES_AND_MOTION_BASICS/netforce/model/TKnot' ); + var TBoolean = require( 'ifphetio!PHET_IO/types/TBoolean' ); /** * Constructor for the 8 knots that appear along the rope. * * @param {number} x the horizontal position (in meters) of the knot + * // TODO: Fix JSDoc * @param {string} type whether the knot is for red or blue pullers * @param {number} ropeLength - the length of the rope in model coordinates * @param {Tandem} tandem @@ -34,9 +34,10 @@ define( function( require ) { this.type = type; // @public {number} - the 1-D x location of the knot - this.xProperty = new Property( x, { + this.xProperty = new NumberProperty( x, { tandem: tandem.createTandem( 'xProperty' ), - phetioValueType: TNumber( { units: 'meters', range: new Range( ropeStart, ropeLength + ropeStart ) } ) + units: 'meters' + // TODO: Fix range, was buggy during https://github.com/phetsims/axon/issues/137 and hence removed } ); // @public {boolean} - whether or not the know is visible diff --git a/js/netforce/model/NetForceModel.js b/js/netforce/model/NetForceModel.js index 3b424611..a2a99727 100644 --- a/js/netforce/model/NetForceModel.js +++ b/js/netforce/model/NetForceModel.js @@ -9,21 +9,21 @@ define( function( require ) { 'use strict'; // modules + var Emitter = require( 'AXON/Emitter' ); + var NumberProperty = require( 'AXON/NumberProperty' ); var Property = require( 'AXON/Property' ); - var inherit = require( 'PHET_CORE/inherit' ); - var Puller = require( 'FORCES_AND_MOTION_BASICS/netforce/model/Puller' ); - var Knot = require( 'FORCES_AND_MOTION_BASICS/netforce/model/Knot' ); + var Range = require( 'DOT/Range' ); var Vector2 = require( 'DOT/Vector2' ); - var Cart = require( 'FORCES_AND_MOTION_BASICS/netforce/model/Cart' ); var forcesAndMotionBasics = require( 'FORCES_AND_MOTION_BASICS/forcesAndMotionBasics' ); - var Range = require( 'DOT/Range' ); - var Emitter = require( 'AXON/Emitter' ); + var Cart = require( 'FORCES_AND_MOTION_BASICS/netforce/model/Cart' ); + var Knot = require( 'FORCES_AND_MOTION_BASICS/netforce/model/Knot' ); + var Puller = require( 'FORCES_AND_MOTION_BASICS/netforce/model/Puller' ); + var inherit = require( 'PHET_CORE/inherit' ); // phet-io modules + var TNetForceModel = require( 'FORCES_AND_MOTION_BASICS/netforce/model/TNetForceModel' ); var TBoolean = require( 'ifphetio!PHET_IO/types/TBoolean' ); var TString = require( 'ifphetio!PHET_IO/types/TString' ); - var TNumber = require( 'ifphetio!PHET_IO/types/TNumber' ); - var TNetForceModel = require( 'FORCES_AND_MOTION_BASICS/netforce/model/TNetForceModel' ); // constants // puller game will extend to +/- this value - when the cart wheel hits this length, the game is over @@ -54,9 +54,9 @@ define( function( require ) { phetioValueType: TBoolean } ); - this.numberPullersAttachedProperty = new Property( 0, { + this.numberPullersAttachedProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'numberPullersAttachedProperty' ), - phetioValueType: TNumber( { range: new Range( 0, 8 ) } ) + range: new Range( 0, 8 ) } ); // TODO what are the valid values? @@ -71,29 +71,34 @@ define( function( require ) { // phetioValueType: TNumber( 'seconds' ) } ); - this.netForceProperty = new Property( 0, { + this.netForceProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'netForceProperty' ), - phetioValueType: TNumber( { units: 'newtons', range: new Range( -350, 350 ) } ) + units: 'newtons', + range: new Range( -350, 350 ) } ); - this.leftForceProperty = new Property( 0, { + this.leftForceProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'leftForceProperty' ), - phetioValueType: TNumber( { units: 'newtons', range: new Range( -350, 0 ) } ) + units: 'newtons', + range: new Range( -350, 0 ) } ); - this.rightForceProperty = new Property( 0, { + this.rightForceProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'rightForceProperty' ), - phetioValueType: TNumber( { units: 'newtons', range: new Range( 0, 350 ) } ) + units: 'newtons', + range: new Range( 0, 350 ) } ); - this.speedProperty = new Property( 0, { + this.speedProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'speedProperty' ), - phetioValueType: TNumber( { units: 'meters/second', range: new Range( 0, 6 ) } ) + units: 'meters/second', + range: new Range( 0, 6 ) } ); - this.durationProperty = new Property( 0, { + this.durationProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'durationProperty' ), - phetioValueType: TNumber( { units: 'seconds', range: new Range( 0, Number.POSITIVE_INFINITY ) } ) + units: 'seconds', + range: new Range( 0, Number.POSITIVE_INFINITY ) } ); // User settings @@ -421,7 +426,7 @@ define( function( require ) { if ( this.runningProperty.get() ) { - // Increment tug-of-war timer + // Increment tug-of-war timer this.durationProperty.set( this.durationProperty.get() + dt ); // Make the simulation run about as fast as the Java version @@ -451,7 +456,7 @@ define( function( require ) { /** * Update the velocity and position of the cart and the pullers. - * + * * @private * @param {number} newV * @param {number} newX diff --git a/js/netforce/view/GoPauseButton.js b/js/netforce/view/GoPauseButton.js index 5d4966e1..55ed0581 100644 --- a/js/netforce/view/GoPauseButton.js +++ b/js/netforce/view/GoPauseButton.js @@ -97,7 +97,7 @@ define( function( require ) { // When the go button is pressed, indicate which pullers are on which knots and what the net force is. var goButtonPressedEmitter = new Emitter( { tandem: tandem.createTandem( 'goButtonPressedEmitter' ), - phetioArgumentTypes: [ TNumber( { units: 'newtons' } ), TString ] + phetioArgumentTypes: [ TNumber, TString ] } ); var goListener = function() { goButtonPressedEmitter.emit2( model.netForceProperty.get(), JSON.stringify( model.getKnotDescription() ) ); @@ -113,7 +113,7 @@ define( function( require ) { goButton.mutate( { tagName: 'input', inputType: 'button', - accessibleDescription: goButtonDescriptionString, + accessibleDescription: goButtonDescriptionString, descriptionTagName: 'p' } ); goButton.setAccessibleAttribute( 'aria-disabled', !isGoButtonEnabled() );