diff --git a/js/DynamicStringTest.ts b/js/DynamicStringTest.ts new file mode 100644 index 00000000..35c479af --- /dev/null +++ b/js/DynamicStringTest.ts @@ -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 ); + } + } ); + } +} \ No newline at end of file diff --git a/js/SimDisplay.ts b/js/SimDisplay.ts index fa6b57a5..6ed56d01 100644 --- a/js/SimDisplay.ts +++ b/js/SimDisplay.ts @@ -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'; @@ -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