Skip to content

Commit

Permalink
Only convex lens & flat mirror, no radio buttons to select optic shape,
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Feb 22, 2022
1 parent b0b442f commit ab13550
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 35 deletions.
7 changes: 2 additions & 5 deletions js/common/model/Optic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ const FLAT_MIRROR_FINITE_FOCAL_LENGTH = FLAT_MIRROR_FINITE_RADIUS_OF_CURVATURE /

type OpticOptions = {

// initial shape of the optic, 'convex' or 'concave'
opticShape: OpticShape,

// supported values of OpticShape, radio buttons will be created left-to-right in this order
// supported values of OpticShape, radio buttons will be created left-to-right in this order, default is [0]
opticShapes: OpticShape[]

// range of diameter, in cm
Expand Down Expand Up @@ -136,7 +133,7 @@ abstract class Optic extends PhetioObject {

this.sign = options.sign;

this.opticShapeProperty = new Property( options.opticShape, {
this.opticShapeProperty = new Property( options.opticShapes[ 0 ], {
validValues: options.opticShapes,
tandem: options.tandem.createTandem( 'opticShapeProperty' ),
phetioType: Property.PropertyIO( StringIO ),
Expand Down
7 changes: 5 additions & 2 deletions js/common/view/OpticShapeRadioButtonGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class OpticShapeRadioButtonGroup extends RectangularRadioButtonGroup<OpticShape>

// A radio button for each shape supported by the optic
assert && assert( optic.opticShapeProperty.validValues ); // {OpticShape[]|undefined}
const items = optic.opticShapeProperty.validValues!.map(
const validValues = optic.opticShapeProperty.validValues!;

const items = validValues.map(
( opticShape: OpticShape ) => {
return {
value: opticShape,
Expand All @@ -56,7 +58,8 @@ class OpticShapeRadioButtonGroup extends RectangularRadioButtonGroup<OpticShape>
buttonContentXMargin: 14,
buttonContentYMargin: 5,
touchAreaXDilation: 4,
touchAreaYDilation: 5
touchAreaYDilation: 5,
visible: ( validValues.length > 1 ) // hide if we only have 1 choice
}, providedOptions ) );
}
}
Expand Down
29 changes: 19 additions & 10 deletions js/lens/LensScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,32 @@ import LensNode from './view/LensNode.js';
import LensScreenView from './view/LensScreenView.js';

type LensScreenOptions = {
isBasicsVersion?: boolean,
tandem: Tandem
};

class LensScreen extends Screen<LensModel, LensScreenView> {

constructor( options: LensScreenOptions ) {
constructor( providedOptions: LensScreenOptions ) {

const options = merge( {
isBasicsVersion: false,
name: geometricOpticsStrings.screen.lens,
homeScreenIcon: createScreenIcon(),
showUnselectedHomeScreenIconFrame: true,
backgroundColorProperty: GOColors.screenBackgroundColorProperty,
keyboardHelpNode: new GOKeyboardHelpContent( true /* isLens */ )
}, providedOptions );

super(
() => new LensModel( { tandem: options.tandem.createTandem( 'model' ) } ),
model => new LensScreenView( model, { tandem: options.tandem.createTandem( 'view' ) } ),
merge( {
name: geometricOpticsStrings.screen.lens,
homeScreenIcon: createScreenIcon(),
showUnselectedHomeScreenIconFrame: true,
backgroundColorProperty: GOColors.screenBackgroundColorProperty,
keyboardHelpNode: new GOKeyboardHelpContent( true /* isLens */ )
}, options )
() => new LensModel( {
isBasicsVersion: options.isBasicsVersion,
tandem: options.tandem.createTandem( 'model' )
} ),
model => new LensScreenView( model, {
tandem: options.tandem.createTandem( 'view' )
} ),
options
);
}

Expand Down
4 changes: 2 additions & 2 deletions js/lens/model/Lens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Utils from '../../../../dot/js/Utils.js';
const DIRECT_INDEX_OF_REFRACTION = 1.5;

type LensOptions = {
isBasicsVersion: boolean,
tandem: Tandem
};

Expand All @@ -43,8 +44,7 @@ class Lens extends Optic {
const focalLengthModelsTandem = providedOptions.tandem.createTandem( 'focalLengthModels' );

const options = merge( {
opticShape: 'convex',
opticShapes: [ 'convex', 'concave' ], // radio buttons will be created left-to-right in this order
opticShapes: providedOptions.isBasicsVersion ? [ 'convex' ] : [ 'convex', 'concave' ],
diameterRange: GOConstants.DIAMETER_RANGE, // in cm
sign: 1,
directFocalLengthModelOptions: {
Expand Down
4 changes: 4 additions & 0 deletions js/lens/model/LensModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Vector2 from '../../../../dot/js/Vector2.js';
import OpticalObjectChoice from '../../common/model/OpticalObjectChoice.js';

type LensModelOptions = {
isBasicsVersion?: boolean,
tandem: Tandem
};

Expand All @@ -27,6 +28,8 @@ class LensModel extends GOModel {

const options = merge( {

isBasicsVersion: false,

// optical object choices, in the order that they will appear in OpticalObjectChoiceComboBox
opticalObjectChoices: [
OpticalObjectChoice.PENCIL,
Expand All @@ -46,6 +49,7 @@ class LensModel extends GOModel {

// super is responsible for resetting the lens
const lens = new Lens( {
isBasicsVersion: options.isBasicsVersion,
tandem: providedOptions.tandem.createTandem( 'lens' )
} );

Expand Down
37 changes: 23 additions & 14 deletions js/mirror/MirrorScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import { Node } from '../../../scenery/js/imports.js';
import Screen from '../../../joist/js/Screen.js';
import ScreenIcon from '../../../joist/js/ScreenIcon.js';
import merge from '../../../phet-core/js/merge.js';
Expand All @@ -19,26 +18,36 @@ import MirrorModel from './model/MirrorModel.js';
import MirrorNode from './view/MirrorNode.js';
import MirrorScreenView from './view/MirrorScreenView.js';
import GOKeyboardHelpContent from '../common/view/GOKeyboardHelpContent.js';
import { OpticShape } from '../common/model/OpticShape.js';

type MirrorScreenOptions = {
homeScreenIcon?: Node,
isBasicsVersion?: boolean,
tandem: Tandem
};

class MirrorScreen extends Screen<MirrorModel, MirrorScreenView> {

constructor( options: MirrorScreenOptions ) {
constructor( providedOptions: MirrorScreenOptions ) {

const isBasicsVersion = ( providedOptions.isBasicsVersion || false );

const options = merge( {
name: geometricOpticsStrings.screen.mirror,
homeScreenIcon: createScreenIcon( isBasicsVersion ? 'flat' : 'concave' ),
showUnselectedHomeScreenIconFrame: true,
backgroundColorProperty: GOColors.screenBackgroundColorProperty,
keyboardHelpNode: new GOKeyboardHelpContent( false /* isLens */ )
}, providedOptions );

super(
() => new MirrorModel( { tandem: options.tandem.createTandem( 'model' ) } ),
model => new MirrorScreenView( model, { tandem: options.tandem.createTandem( 'view' ) } ),
merge( {
name: geometricOpticsStrings.screen.mirror,
homeScreenIcon: createScreenIcon(),
showUnselectedHomeScreenIconFrame: true,
backgroundColorProperty: GOColors.screenBackgroundColorProperty,
keyboardHelpNode: new GOKeyboardHelpContent( false /* isLens */ )
}, options )
() => new MirrorModel( {
isBasicsVersion: isBasicsVersion,
tandem: options.tandem.createTandem( 'model' )
} ),
model => new MirrorScreenView( model, {
tandem: options.tandem.createTandem( 'view' )
} ),
options
);
}

Expand All @@ -48,8 +57,8 @@ class MirrorScreen extends Screen<MirrorModel, MirrorScreenView> {
}
}

function createScreenIcon(): ScreenIcon {
return new ScreenIcon( MirrorNode.createIconNode( 'concave' ), {
function createScreenIcon( opticShape: OpticShape ): ScreenIcon {
return new ScreenIcon( MirrorNode.createIconNode( opticShape ), {
fill: GOColors.screenBackgroundColorProperty
} );
}
Expand Down
4 changes: 2 additions & 2 deletions js/mirror/model/Mirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import GOConstants from '../../common/GOConstants.js';
const INDEX_OF_REFRACTION = 2;

type MirrorOptions = {
isBasicsVersion: boolean,
tandem: Tandem
};

Expand All @@ -38,8 +39,7 @@ class Mirror extends Optic {
const focalLengthModelsTandem = providedOptions.tandem.createTandem( 'focalLengthModels' );

const options = merge( {
opticShape: 'concave',
opticShapes: [ 'concave', 'convex', 'flat' ], // radio buttons will be created left-to-right in this order
opticShapes: providedOptions.isBasicsVersion ? [ 'flat' ] : [ 'concave', 'convex', 'flat' ],
diameterRange: GOConstants.DIAMETER_RANGE, // in cm
sign: -1,
directFocalLengthModelOptions: {
Expand Down
2 changes: 2 additions & 0 deletions js/mirror/model/MirrorModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Mirror from './Mirror.js';
import OpticalObjectChoice from '../../common/model/OpticalObjectChoice.js';

type MirrorOptions = {
isBasicsVersion: boolean,
tandem: Tandem
}

Expand Down Expand Up @@ -48,6 +49,7 @@ class MirrorModel extends GOModel {

// super is responsible for resetting the mirror
const mirror = new Mirror( {
isBasicsVersion: options.isBasicsVersion,
tandem: options.tandem.createTandem( 'mirror' )
} );

Expand Down

0 comments on commit ab13550

Please sign in to comment.