diff --git a/js/GOSim.ts b/js/GOSim.ts new file mode 100644 index 00000000..b117ba2d --- /dev/null +++ b/js/GOSim.ts @@ -0,0 +1,52 @@ +// Copyright 2022, University of Colorado Boulder + +/** + * GOSim is the subclass of Sim used by both the 'full' and 'basics' versions of Geometric Optics. + * + * @author Chris Malley (PixelZoom, Inc.) + */ + +import Sim from '../../joist/js/Sim.js'; +import merge from '../../phet-core/js/merge.js'; +import Tandem from '../../tandem/js/Tandem.js'; +import geometricOptics from './geometricOptics.js'; +import LensScreen from './lens/LensScreen.js'; +import MirrorScreen from './mirror/MirrorScreen.js'; +import GOConstants from './common/GOConstants.js'; +import { Node } from '../../scenery/js/imports.js'; + +type GOSimOptions = { + isBasicsVersion?: boolean, + createOptionsDialogContent?: ( tandem: Tandem ) => Node +}; + +class GOSim extends Sim { + + /** + * @param title + * @param providedOptions + */ + constructor( title: string, providedOptions?: GOSimOptions ) { + + const options = merge( { + credits: GOConstants.CREDITS, + + // pdom options + hasKeyboardHelpContent: true + }, providedOptions ); + + super( title, [ + new LensScreen( { + isBasicsVersion: options.isBasicsVersion, + tandem: Tandem.ROOT.createTandem( 'lensScreen' ) + } ), + new MirrorScreen( { + isBasicsVersion: options.isBasicsVersion, + tandem: Tandem.ROOT.createTandem( 'mirrorScreen' ) + } ) + ], options ); + } +} + +geometricOptics.register( 'GOSim', GOSim ); +export default GOSim; \ No newline at end of file diff --git a/js/geometric-optics-main.ts b/js/geometric-optics-main.ts index 3ba568b2..288ea544 100644 --- a/js/geometric-optics-main.ts +++ b/js/geometric-optics-main.ts @@ -3,36 +3,22 @@ /** * Main entry point for the sim. * - * @author Martin Veillette * @author Chris Malley (PixelZoom, Inc.) */ -import Sim from '../../joist/js/Sim.js'; import simLauncher from '../../joist/js/simLauncher.js'; import Tandem from '../../tandem/js/Tandem.js'; import GOGlobalOptionsNode from './common/view/GOGlobalOptionsNode.js'; import geometricOpticsStrings from './geometricOpticsStrings.js'; -import LensScreen from './lens/LensScreen.js'; -import MirrorScreen from './mirror/MirrorScreen.js'; -import GOConstants from './common/GOConstants.js'; - -const simOptions = { - - credits: GOConstants.CREDITS, - - // Creates content for the Options dialog, accessible via the PhET menu - createOptionsDialogContent: ( tandem: Tandem ) => new GOGlobalOptionsNode( { - tandem: tandem - } ), - - // pdom options - hasKeyboardHelpContent: true -}; +import GOSim from './GOSim.js'; simLauncher.launch( () => { - const sim = new Sim( geometricOpticsStrings[ 'geometric-optics' ].title, [ - new LensScreen( { tandem: Tandem.ROOT.createTandem( 'lensScreen' ) } ), - new MirrorScreen( { tandem: Tandem.ROOT.createTandem( 'mirrorScreen' ) } ) - ], simOptions ); + const sim = new GOSim( geometricOpticsStrings[ 'geometric-optics' ].title, { + + // Creates content for the Options dialog, accessible via the PhET menu + createOptionsDialogContent: ( tandem: Tandem ) => new GOGlobalOptionsNode( { + tandem: tandem + } ) + } ); sim.start(); } );