Skip to content

Commit

Permalink
Use ScreenIdentifierValues for Projectile screenIdentifier, add to CO…
Browse files Browse the repository at this point in the history
…DAP wrapper - see #314
  • Loading branch information
matthew-blackman committed Apr 24, 2024
1 parent b81909b commit 945fe5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion js/common/model/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import ProjectileType, { CANNONBALL, PIANO, PUMPKIN } from './ProjectileType.js'
import { Color } from '../../../../scenery/js/imports.js';
import PDLPreferences from '../PDLPreferences.js';
import StringUnionProperty from '../../../../axon/js/StringUnionProperty.js';
import { screenIdentifierForScreenTandemName } from './ScreenIdentifier.js';

const launchSoundClip = new SoundClip( launch_mp3, { initialOutputLevel: 0.2 } );
soundManager.addSoundGenerator( launchSoundClip );
Expand Down Expand Up @@ -304,6 +305,7 @@ export default abstract class Field extends PhetioObject {

const screenPhetioID = window.phetio.PhetioIDUtils.getScreenID( this.phetioID );
const screenTandemName = window.phetio.PhetioIDUtils.getComponentName( screenPhetioID );
const screenIdentifier = screenIdentifierForScreenTandemName( screenTandemName );

const launcher = this.launcherProperty.value;

Expand All @@ -322,7 +324,7 @@ export default abstract class Field extends PhetioObject {
}

return new Projectile(
screenTandemName,
screenIdentifier,
this.identifier,
sampleNumber,
this.launcherOrientationProperty.value,
Expand Down
6 changes: 6 additions & 0 deletions js/common/model/ScreenIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@
*/
export const ScreenIdentifierValues = [ 'variability', 'sources', 'measures', 'sampling' ] as const;

export const screenIdentifierForScreenTandemName = ( screenTandemName: string ): ScreenIdentifier => {
const screenTandemNameTrimmed: ScreenIdentifier = screenTandemName.replace( 'Screen', '' ) as ScreenIdentifier;
assert && assert( ScreenIdentifierValues.includes( screenTandemNameTrimmed ), `Invalid screenTandemName: ${screenTandemName}` );
return screenTandemNameTrimmed;
};

export type ScreenIdentifier = typeof ScreenIdentifierValues[number];

0 comments on commit 945fe5f

Please sign in to comment.