Skip to content

Commit

Permalink
factor out GOSim.ts, phetsims/geometric-optics-basics#2
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Feb 23, 2022
1 parent 3ec6690 commit 3aaf5c8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 22 deletions.
52 changes: 52 additions & 0 deletions js/GOSim.ts
Original file line number Diff line number Diff line change
@@ -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;
30 changes: 8 additions & 22 deletions js/geometric-optics-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );

0 comments on commit 3aaf5c8

Please sign in to comment.