Skip to content

Commit

Permalink
When the sim is inactive, make it non-interactive, see phetsims/scene…
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Mar 31, 2015
1 parent 005b203 commit 469839f
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions js/Sim.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ define( function( require ) {
if ( phet.chipper.getQueryParameter( 'screens' ) ) {
var screensValueString = phet.chipper.getQueryParameter( 'screens' );
screens = screensValueString.split( '.' ).map( function( screenString ) {
return screens[parseInt( screenString, 10 ) - 1];
return screens[ parseInt( screenString, 10 ) - 1 ];
} );
options.screenIndex = 0;
}
Expand Down Expand Up @@ -261,7 +261,7 @@ define( function( require ) {
document.body.removeChild( document.getElementById( 'sim' ) );
}

sim.rootNode = new Node( {renderer: options.rootRenderer} );
sim.rootNode = new Node( { renderer: options.rootRenderer } );

sim.display = new Display( sim.rootNode, {
allowSceneOverflow: true, // we take up the entire browsable area, so we don't care about clipping
Expand All @@ -272,8 +272,13 @@ define( function( require ) {
accessibility: options.accessibility
} );

// When the sim is inactive, make it non-interactive, see https://github.com/phetsims/scenery/issues/414
this.activeProperty.link( function( active ) {
sim.display.interactive = active;
} );

if ( options.accessibility ) {
this.focusLayer = new FocusLayer( window.TWEEN ? {tweenFactory: window.TWEEN} : {} );
this.focusLayer = new FocusLayer( window.TWEEN ? { tweenFactory: window.TWEEN } : {} );
this.ariaSpeech = new AriaSpeech();

//Adding the accessibility layer directly to the Display's root makes it easy to use local->global bounds.
Expand Down Expand Up @@ -303,7 +308,7 @@ define( function( require ) {
sim.display.scenery.switchLogToString();
}

sim.display.initializeWindowEvents( {batchDOMEvents: this.options.batchEvents} ); // sets up listeners on the document with preventDefault(), and forwards those events to our scene
sim.display.initializeWindowEvents( { batchDOMEvents: this.options.batchEvents } ); // sets up listeners on the document with preventDefault(), and forwards those events to our scene
if ( options.recordInputEventLog ) {
sim.display._input.logEvents = true; // flag Scenery to log all input events
}
Expand Down Expand Up @@ -368,8 +373,8 @@ define( function( require ) {
sim.display.backgroundColor = backgroundColor;
} );

sim.multilink( ['showHomeScreen', 'screenIndex'], function( showHomeScreen, screenIndex ) {
sim.currentScreen = showHomeScreen ? null : screens[screenIndex];
sim.multilink( [ 'showHomeScreen', 'screenIndex' ], function( showHomeScreen, screenIndex ) {
sim.currentScreen = showHomeScreen ? null : screens[ screenIndex ];
sim.updateBackground();
} );

Expand Down Expand Up @@ -397,12 +402,12 @@ define( function( require ) {
sim.rootNode.addChild( screen.view );
} );
sim.rootNode.addChild( sim.navigationBar );
sim.multilink( ['screenIndex', 'showHomeScreen'], function( screenIndex, showHomeScreen ) {
sim.multilink( [ 'screenIndex', 'showHomeScreen' ], function( screenIndex, showHomeScreen ) {
if ( sim.homeScreen ) {
sim.homeScreen.view.setVisible( showHomeScreen );
}
for ( var i = 0; i < screens.length; i++ ) {
screens[i].view.setVisible( !showHomeScreen && screenIndex === i );
screens[ i ].view.setVisible( !showHomeScreen && screenIndex === i );
}
sim.navigationBar.setVisible( !showHomeScreen );
sim.updateBackground();
Expand All @@ -417,7 +422,7 @@ define( function( require ) {
// When moving from a screen to the homescreen, the previous screen should be highlighted
// When the user selects a different screen, show it.
sim.screenIndexProperty.link( function( screenIndex ) {
var newScreenNode = screens[screenIndex].view;
var newScreenNode = screens[ screenIndex ].view;
var oldIndex = currentScreenNode ? sim.rootNode.indexOfChild( currentScreenNode ) : -1;

// Swap out the views if the old one is displayed. if not, we are probably in the home screen
Expand Down Expand Up @@ -543,7 +548,7 @@ define( function( require ) {
if ( isModal ) {
this.barrierStack.remove( node );
}
Input.popFocusContext( node.getTrails()[0] );
Input.popFocusContext( node.getTrails()[ 0 ] );

this.topLayer.removeChild( node );
},
Expand Down Expand Up @@ -707,7 +712,7 @@ define( function( require ) {
if ( !sim.showHomeScreen ) {

// step model and view (both optional)
screen = sim.screens[sim.screenIndex];
screen = sim.screens[ sim.screenIndex ];
if ( screen.model.step ) {
screen.model.step( dt );
}
Expand Down Expand Up @@ -767,14 +772,14 @@ define( function( require ) {
// Make sure requestAnimationFrame is defined
Util.polyfillRequestAnimationFrame();

if ( data.length && data[0].width ) {
sim.resize( data[0].width, data[0].height );
if ( data.length && data[ 0 ].width ) {
sim.resize( data[ 0 ].width, data[ 0 ].height );
}

var startTime = Date.now();

(function animationLoop() {
var frame = data[index++];
var frame = data[ index++ ];

// when we have aready played the last frame
if ( frame === undefined ) {
Expand Down Expand Up @@ -807,7 +812,7 @@ define( function( require ) {

// Update the active screen, but not if the user is on the home screen
if ( !sim.showHomeScreen ) {
sim.screens[sim.screenIndex].model.step( frame.dt ); // use the pre-recorded dt to ensure lack of variation between runs
sim.screens[ sim.screenIndex ].model.step( frame.dt ); // use the pre-recorded dt to ensure lack of variation between runs
}

// If using the TWEEN animation library, then update all of the tweens (if any) before rendering the scene.
Expand Down Expand Up @@ -841,7 +846,7 @@ define( function( require ) {

// protocol-relative URL to the same-origin on a different port, for loading/saving recorded input events and frames
getEventLogLocation: function() {
var host = window.location.host.split( ':' )[0]; // grab the hostname without the port
var host = window.location.host.split( ':' )[ 0 ]; // grab the hostname without the port
return '//' + host + ':8083/' + this.getEventLogName();
},

Expand Down

0 comments on commit 469839f

Please sign in to comment.