Skip to content

Commit

Permalink
Move all StatsScreen-specific parameters into model options - #313
Browse files Browse the repository at this point in the history
  • Loading branch information
UniverseAndMore committed Dec 9, 2022
1 parent 0f82168 commit 6989a50
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 44 deletions.
5 changes: 3 additions & 2 deletions js/common/ProjectileMotionConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ const ProjectileMotionConstants = {
CANNONBALL_DRAG_COEFFICIENT: 0.47,

// productive constraints
MAX_NUMBER_OF_TRAJECTORIES: 150,
RAPID_FIRE_DELTA_TIME: 0.1,
MAX_NUMBER_OF_TRAJECTORIES: 10,
MAX_NUMBER_OF_TRAJECTORIES_STATS: 20,
RAPID_FIRE_DELTA_TIME: 0.2,

//group size
GROUP_SIZE_DEFAULT: 20,
Expand Down
28 changes: 13 additions & 15 deletions js/common/model/ProjectileMotionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const TIME_PER_DATA_POINT = ProjectileMotionConstants.TIME_PER_DATA_POINT; // ms

class ProjectileMotionModel {
/**
* @param {ProjectileObjectType} defaultProjectileObjectType - default object type for the each model
* @param {ProjectileObjectType} defaultProjectileObjectType - default object type for the model
* @param {boolean} defaultAirResistance - default air resistance on value
* @param {ProjectileObjectType[]} possibleObjectTypes - a list of the possible ProjectileObjectTypes for the model
* @param {Tandem} tandem
Expand All @@ -57,20 +57,22 @@ class ProjectileMotionModel {
) {
options = merge(
{
maxProjectiles: ProjectileMotionConstants.MAX_NUMBER_OF_TRAJECTORIES,
defaultCannonHeight: 0,
defaultCannonAngle: 80,
defaultInitialSpeed: 18,
defaultSpeedStandardDeviation: 1,
defaultAngleStandardDeviation: 2,
phetioInstrumentAltitudeProperty: true,
statsScreen: false
defaultSpeedStandardDeviation: 0,
defaultAngleStandardDeviation: 0,
phetioInstrumentAltitudeProperty: true
},
options
);

assert && assert( defaultProjectileObjectType instanceof ProjectileObjectType,
'defaultProjectileObjectType should be a ProjectileObjectType' );

this.maxProjectiles = options.maxProjectiles;

// @public {Target} model for handling scoring ( if/when projectile hits target )
this.target = new Target(
ProjectileMotionConstants.TARGET_X_DEFAULT,
Expand All @@ -95,11 +97,8 @@ class ProjectileMotionModel {
}
);

const speedInitialSD = options.statsScreen ? options.defaultSpeedStandardDeviation : 0;
const angleInitialSD = options.statsScreen ? options.defaultAngleStandardDeviation : 0;

// @public {Property.<number>}
this.initialSpeedStandardDeviationProperty = new NumberProperty( speedInitialSD, {
this.initialSpeedStandardDeviationProperty = new NumberProperty( options.defaultSpeedStandardDeviation, {
tandem: tandem.createTandem( 'initialSpeedStandardDeviationProperty' ),
phetioDocumentation: 'The standard deviation of the launch speed',
units: 'm/s',
Expand All @@ -120,7 +119,7 @@ class ProjectileMotionModel {
);

// @public {Property.<number>}
this.initialAngleStandardDeviationProperty = new NumberProperty( angleInitialSD, {
this.initialAngleStandardDeviationProperty = new NumberProperty( options.defaultAngleStandardDeviation, {
tandem: tandem.createTandem( 'initialAngleStandardDeviationProperty' ),
phetioDocumentation: 'The standard deviation of the launch angle',
units: '\u00B0', // degrees
Expand Down Expand Up @@ -265,10 +264,10 @@ class ProjectileMotionModel {
this.fireEnabledProperty = new DerivedProperty(
[ this.numberOfMovingProjectilesProperty, this.rapidFireModeProperty ],
( numMoving, rapidFireMode ) =>
!rapidFireMode && numMoving < ProjectileMotionConstants.MAX_NUMBER_OF_TRAJECTORIES,
!rapidFireMode && numMoving < this.maxProjectiles,
{
tandem: tandem.createTandem( 'fireEnabledProperty' ),
phetioDocumentation: `The fire button is only enabled if there are less than ${ProjectileMotionConstants.MAX_NUMBER_OF_TRAJECTORIES} projectiles in the air.`,
phetioDocumentation: `The fire button is only enabled if there are less than ${this.maxProjectiles} projectiles in the air.`,
phetioValueType: BooleanIO
}
);
Expand All @@ -294,7 +293,7 @@ class ProjectileMotionModel {
phetioReadOnly: true
} );

// @public {PhetioGroup.<Trajectory>} a group of trajectories, limited to MAX_NUMBER_OF_TRAJECTORIES
// @public {PhetioGroup.<Trajectory>} a group of trajectories, limited to this.maxProjectiles
// Create this after model properties to support the PhetioGroup creating the prototype immediately
this.trajectoryGroup = Trajectory.createGroup( this, tandem.createTandem( 'trajectoryGroup' ) );

Expand Down Expand Up @@ -398,7 +397,7 @@ class ProjectileMotionModel {
limitTrajectories() {
// create a temporary array to hold all trajectories to be disposed, to avoid array mutation of trajectoryGroup while looping
const trajectoriesToDispose = [];
const numTrajectoriesToDispose = this.trajectoryGroup.count - ProjectileMotionConstants.MAX_NUMBER_OF_TRAJECTORIES;
const numTrajectoriesToDispose = this.trajectoryGroup.count - this.maxProjectiles;
if ( numTrajectoriesToDispose > 0 ) {
for ( let i = 0; i < this.trajectoryGroup.count; i++ ) {
const trajectory = this.trajectoryGroup.getElement( i );
Expand Down Expand Up @@ -442,7 +441,6 @@ class ProjectileMotionModel {
}

this.limitTrajectories();
this.updateTrajectoryRanksEmitter.emit(); // increment rank of all trajectories
}

/**
Expand Down
8 changes: 2 additions & 6 deletions js/common/model/Trajectory.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ import NullableIO from '../../../../tandem/js/types/NullableIO.js';
import NumberIO from '../../../../tandem/js/types/NumberIO.js';
import ReferenceIO from '../../../../tandem/js/types/ReferenceIO.js';
import projectileMotion from '../../projectileMotion.js';
import ProjectileMotionConstants from '../ProjectileMotionConstants.js';
import DataPoint from './DataPoint.js';
import ProjectileObjectType from './ProjectileObjectType.js';

// constants
const MAX_NUMBER_OF_TRAJECTORIES = ProjectileMotionConstants.MAX_NUMBER_OF_TRAJECTORIES;

class Trajectory extends PhetioObject {

/**
Expand Down Expand Up @@ -131,8 +127,8 @@ class Trajectory extends PhetioObject {
phetioDocumentation: `${
'The count of how old this projectile trajectory is. Older trajectories have more ' +
'opacity until they are subsequently removed. The most recent trajectory fired has rank 0. ' +
'The second most recent has rank 1. The oldest still on screen has rank '
}${MAX_NUMBER_OF_TRAJECTORIES - 1}`,
'The second most recent has rank 1.'
}`,
phetioReadOnly: true
} );

Expand Down
17 changes: 8 additions & 9 deletions js/common/view/ProjectileMotionScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,22 @@ class ProjectileMotionScreenView extends ScreenView {
* @param {ProjectileMotionViewProperties} viewProperties - Properties that determine which vectors are shown
* @param {Tandem} tandem
* @param {Object} [options]
* @param {boolean} showPaths - show the trajectory paths
*/
constructor(
model,
topRightPanel,
bottomRightPanel,
viewProperties,
tandem,
options,
maxNumberOfTrajectories = ProjectileMotionConstants.MAX_NUMBER_OF_TRAJECTORIES,
constantTrajectoryOpacity = false,
showPaths = true
options
) {
options = merge( {
tandem: tandem,
cannonNodeOptions: {},
addFlatirons: true // if false, then flatirons easteregg will never be shown
addFlatirons: true, // if false, then flatirons easteregg will never be shown
maxTrajectories: ProjectileMotionConstants.MAX_NUMBER_OF_TRAJECTORIES, // max number of trajectories that can be shown
showPaths: true, // if false, trajectory paths will not be drawn
constantTrajectoryOpacity: false // if true, trajectory paths will not be faded when new ones are added
}, options );

super( options );
Expand Down Expand Up @@ -124,9 +123,9 @@ class ProjectileMotionScreenView extends ScreenView {
viewProperties,
addedTrajectory,
transformProperty,
maxNumberOfTrajectories,
constantTrajectoryOpacity,
showPaths
options.maxTrajectories,
options.showPaths,
options.constantTrajectoryOpacity
);

// add the view to scene graph
Expand Down
6 changes: 3 additions & 3 deletions js/common/view/TrajectoryNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class TrajectoryNode extends Node {
viewProperties,
trajectory,
transformProperty,
maxNumberOfTrajectories = ProjectileMotionConstants.MAX_NUMBER_OF_TRAJECTORIES,
constantTrajectoryOpacity = false,
showPath = true
maxNumberOfTrajectories,
showPath,
constantTrajectoryOpacity
) {
super( { pickable: false, preventFit: true } );

Expand Down
10 changes: 6 additions & 4 deletions js/stats/model/StatsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ class StatsModel extends ProjectileMotionModel {
];

super( objectTypes[ 0 ], false, objectTypes, tandem, {
maxProjectiles: ProjectileMotionConstants.MAX_NUMBER_OF_TRAJECTORIES_STATS,
defaultCannonHeight: 2,
defaultCannonAngle: 60,
defaultInitialSpeed: 15,
phetioInstrumentAltitudeProperty: false,
statsScreen: true
defaultSpeedStandardDeviation: 1,
defaultAngleStandardDeviation: 2,
phetioInstrumentAltitudeProperty: false
} );

this.objectTypes = objectTypes;
Expand All @@ -60,10 +62,10 @@ class StatsModel extends ProjectileMotionModel {
this.fireMultipleEnabledProperty = new DerivedProperty(
[ this.numberOfMovingProjectilesProperty, this.groupSizeProperty, this.rapidFireModeProperty ],
( numMoving, groupSize, rapidFireMode ) =>
!rapidFireMode && numMoving + groupSize <= ProjectileMotionConstants.MAX_NUMBER_OF_TRAJECTORIES,
!rapidFireMode && numMoving + groupSize <= ProjectileMotionConstants.MAX_NUMBER_OF_TRAJECTORIES_STATS,
{
tandem: tandem.createTandem( 'fireMultipleEnabledProperty' ),
phetioDocumentation: `The fire-multi button is only enabled if the number of moving projectiles would not exceed ${ProjectileMotionConstants.MAX_NUMBER_OF_TRAJECTORIES}.`,
phetioDocumentation: `The fire-multi button is only enabled if the number of moving projectiles would not exceed ${ProjectileMotionConstants.MAX_NUMBER_OF_TRAJECTORIES_STATS}.`,
phetioValueType: BooleanIO
}
);
Expand Down
11 changes: 6 additions & 5 deletions js/stats/view/StatsScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class StatsScreenView extends ProjectileMotionScreenView {
constructor( model, tandem, options ) {
options = merge( {
addFlatirons: false,
cannonNodeOptions: { preciseCannonDelta: true }
cannonNodeOptions: { preciseCannonDelta: true },
maxTrajectories: ProjectileMotionConstants.MAX_NUMBER_OF_TRAJECTORIES_STATS,
showPaths: false,
constantTrajectoryOpacity: true

}, options );

// contains Properties about vector visibility, used in super class
Expand Down Expand Up @@ -80,10 +84,7 @@ class StatsScreenView extends ProjectileMotionScreenView {
statsPanel,
visibilityProperties,
tandem,
options,
ProjectileMotionConstants.MAX_NUMBER_OF_TRAJECTORIES,
true, //constantTrajectoryOpacity
false //showPaths
options
);

// @private
Expand Down

0 comments on commit 6989a50

Please sign in to comment.