Skip to content

Commit

Permalink
Add stringTest=dynamic, see phetsims/chipper#1319
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Nov 11, 2022
1 parent f251daa commit 2663d3d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
71 changes: 71 additions & 0 deletions js/DynamicStringTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2021-2022, University of Colorado Boulder

import { localizedStrings } from '../../chipper/js/getStringModule.js';

/**
* For testing dynamic layout in sims that may not yet have submitted translations, enabled via ?stringTest=dynamic.
* Please see initialize-globals for the hotkeys.
*
* @author Sam Reid (PhET Interactive Simulations)
* @author Marla Schulz (PhET Interactive Simulations)
*/
export default class DynamicStringTest {

public static init(): void {

let stride = 0;

// Random words of different lengths that can be cycled through
const wordSource = 'Sometimes when Hippopotomonstrosesquippedaliophobia want lyrics you turn to Shakespeare like the following text copied from some work ' +
'To be or not to be that is the question ' +
'Supercalifragilisticexpeladocious tis nobler in the mind to suffer ' +
'The slings and arrows of antidisestablishmentarianism fortune ' +
'Or to take Incomprehensibility against a sea of Floccinaucinihilipilification';
const words = wordSource.split( ' ' );
window.addEventListener( 'keydown', event => {

// check if the keyboard event is a right arrow key
if ( event.keyCode === 39 ) {
localizedStrings.forEach( localizedString => {
localizedString.property.value = localizedString.property.value + localizedString.property.value;
} );
}

// check if the keyboard event is a left arrow key
if ( event.keyCode === 37 ) {
localizedStrings.forEach( localizedString => {
localizedString.property.value = localizedString.property.value.substring( 0, localizedString.property.value.length / 2 );
} );
}

function setStride( newStride: number ): void {
stride = newStride;
console.log( 'stride = ' + stride );
localizedStrings.forEach( ( localizedString, index ) => {
localizedString.property.value = words[ ( index + stride ) % words.length ];
} );
}

// Check if the user press the spacebar
if ( event.keyCode === 32 ) {
stride = 0;
console.log( 'stride = ' + stride );
localizedStrings.forEach( localizedString => localizedString.restoreInitialValue( 'en' ) );
}

// Check if the keyboard event is an up arrow key
if ( event.keyCode === 38 ) {
setStride( stride + 1 );
}

// Check if the keyboard event is an down arrow key
if ( event.keyCode === 40 ) {
let newStride = stride - 1;
if ( newStride < 0 ) {
newStride = words.length - 1;
}
setStride( newStride );
}
} );
}
}
6 changes: 6 additions & 0 deletions js/SimDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import BooleanProperty from '../../axon/js/BooleanProperty.js';
import TProperty from '../../axon/js/TProperty.js';
import DynamicStringTest from './DynamicStringTest.js';
import optionize from '../../phet-core/js/optionize.js';
import StrictOmit from '../../phet-core/js/types/StrictOmit.js';
import { animatedPanZoomSingleton, Display, DisplayOptions, InputFuzzer, KeyboardFuzzer, Node, RendererType, scenery, Utils } from '../../scenery/js/imports.js';
Expand Down Expand Up @@ -151,6 +152,11 @@ export default class SimDisplay extends Display {
scenery.switchLogToString();
}

if ( phet.chipper.queryParameters.stringTest === 'dynamic' ) {

DynamicStringTest.init();
}

this.initializeEvents( {
tandem: Tandem.GENERAL_CONTROLLER.createTandem( 'input' )
} ); // sets up listeners on the document with preventDefault(), and forwards those events to our scene
Expand Down

0 comments on commit 2663d3d

Please sign in to comment.