Skip to content

Commit

Permalink
Adding initialScreen/homeScreen, see #714
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed May 13, 2021
1 parent 10e2885 commit fd0ce1f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion js/NavigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ define( function( require ) {
},
tandem: options.tandem && options.tandem.createTandem( 'homeButton' )
} );
this.barContents.addChild( this.homeButton );
phet.chipper.queryParameters.homeScreen && this.barContents.addChild( this.homeButton );

/*
* Allocate remaining horizontal space equally for screen buttons, assuming they will be centered in the navbar.
Expand Down
29 changes: 23 additions & 6 deletions js/Sim.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ define( function( require ) {
options = _.extend( {

// whether to show the home screen, or go immediately to the screen indicated by screenIndex
showHomeScreen: true,
showHomeScreen: phet.chipper.queryParameters.homeScreen,

// index of the screen that will be selected at startup
screenIndex: 0,
Expand Down Expand Up @@ -125,13 +125,30 @@ define( function( require ) {
//Default values are to show the home screen with the 1st screen selected
var showHomeScreen = ( _.isUndefined( options.showHomeScreen ) ) ? true : options.showHomeScreen;

var initialScreen = phet.chipper.queryParameters.initialScreen;

//If specifying 'screens' then use 1-based (not zero-based) and "." delimited string such as "1.3.4" to get the 1st, 3rd and 4th screen
if ( phet.chipper.getQueryParameter( 'screens' ) ) {
var screensValueString = phet.chipper.getQueryParameter( 'screens' );
screens = screensValueString.split( '.' ).map( function( screenString ) {
return screens[ parseInt( screenString, 10 ) - 1 ];
var newScreens = [];
phet.chipper.getQueryParameter( 'screens' ).split( '.' ).map( function( screenString ) {
return parseInt( screenString, 10 );
} ).forEach( function( userIndex ) {
var screenIndex = userIndex - 1; // screens query parameter is 1-based
if ( screenIndex < 0 || screenIndex > screens.length - 1 ) {
throw new Error( 'invalid screen index: ' + userIndex );
}
newScreens.push( screens[ screenIndex ] );
} );
options.screenIndex = 0;

// If the user specified an initial screen other than the homescreen and specified a subset of screens
// remap the selected 1-based index from the original screens list to the filtered screens list.
if ( initialScreen !== 0 ) {
var index = _.indexOf( newScreens, screens[ initialScreen - 1 ] );
assert && assert( index !== -1, 'screen not found' );
initialScreen = index + 1;
}

screens = newScreens;
}

//If there is only one screen, do not show the home screen
Expand All @@ -145,7 +162,7 @@ define( function( require ) {
showHomeScreen: showHomeScreen,

// The selected index
screenIndex: options.screenIndex || 0,
screenIndex: initialScreen === 0 ? 0 : initialScreen - 1,

// [read-only] how the home screen and navbar are scaled
scale: 1,
Expand Down

0 comments on commit fd0ce1f

Please sign in to comment.