Skip to content

Commit

Permalink
Wilder testing of hotkeys in a simulation context, see phetsims/axon#428
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Mar 28, 2024
1 parent b9a90c0 commit 18fe37e
Show file tree
Hide file tree
Showing 6 changed files with 679 additions and 8 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
Wilder
================

"Wilder" is used to demonstrate and test PhET software development patterns.
"Wilder" is an educational simulation in HTML5, by <a href="https://phet.colorado.edu/" target="_blank">PhET
Interactive Simulations</a>
at the University of Colorado Boulder.

By PhET Interactive Simulations
https://phet.colorado.edu/
*This simulation is under development and has not been published.*

NOTE: This repository has dependencies on other repositories. Those repositories much be checked out as siblings to this
repository in your directory structure. See package.json for a list of dependencies.
### Documentation

The <a href="https://github.com/phetsims/phet-info/blob/main/doc/phet-development-overview.md" target="_blank">PhET
Development Overview</a> is the most complete guide to PhET Simulation Development. This guide includes how to obtain
simulation code and its dependencies, notes about architecture & design, how to test and build the sims, as well as
other important information.

### License

Expand Down
1 change: 0 additions & 1 deletion js/WilderStrings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import wilder from './wilder.js';

type StringsType = {
'wilder': {
'title': string;
'titleStringProperty': LocalizedStringProperty;
}
};
Expand Down
75 changes: 75 additions & 0 deletions js/wilder/view/WilderScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import WilderNode from './WilderNode.js';
import WilderModel from '../model/WilderModel.js';
import { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import { globalHotkeyRegistry, Hotkey, Text } from '../../../../scenery/js/imports.js';
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import ABSwitch from '../../../../sun/js/ABSwitch.js';
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';

type WilderScreenViewOptions = PickRequired<PhetioObjectOptions, 'tandem'>;

Expand All @@ -23,6 +27,17 @@ class WilderScreenView extends ScreenView {
wilderNode.center = this.layoutBounds.center;
this.addChild( wilderNode );

// For testing enabled hotkeys
const extraEnabledProperty = new BooleanProperty( false );

const enabledText = new Text( 'Some Hotkeys Enabled', { font: new PhetFont( 16 ) } );
const disabledText = new Text( 'Some Hotkeys Disabled', { font: new PhetFont( 16 ) } );
const enabledSwitch = new ABSwitch( extraEnabledProperty, true, enabledText, false, disabledText, {
centerX: this.layoutBounds.centerX,
bottom: this.layoutBounds.maxY - 10
} );
this.addChild( enabledSwitch );

// Reset All button
const resetAllButton = new ResetAllButton( {
listener: () => {
Expand All @@ -33,6 +48,66 @@ class WilderScreenView extends ScreenView {
tandem: providedOptions.tandem.createTandem( 'resetAllButton' )
} );
this.addChild( resetAllButton );

globalHotkeyRegistry.add( new Hotkey( {
key: 'y',
fire: () => console.log( 'fire: y' )
} ) );

globalHotkeyRegistry.add( new Hotkey( {
key: 't',
fire: () => console.log( 'fire: t' ),
fireOnHold: true,
fireOnHoldTiming: 'browser'
} ) );

globalHotkeyRegistry.add( new Hotkey( {
key: 't',
modifierKeys: [ 'shift' ],
fire: () => console.log( 'fire: shift+t' ),
fireOnHold: true,
fireOnHoldTiming: 'browser'
} ) );

globalHotkeyRegistry.add( new Hotkey( {
key: 'r',
fire: () => console.log( 'fire: r' ),
fireOnHold: true,
fireOnHoldTiming: 'custom',
fireOnHoldCustomInterval: 300
} ) );

resetAllButton.addInputListener( {
hotkeys: [
new Hotkey( {
key: 'x',
fire: () => console.log( 'fire: x' ),
enabledProperty: extraEnabledProperty
} ),
new Hotkey( {
key: 'x',
modifierKeys: [ 'b' ],
fire: () => console.log( 'fire: b+x' ),
enabledProperty: extraEnabledProperty
} ),
new Hotkey( {
key: 'w',
fire: () => console.log( 'fire: w' )
} ),
new Hotkey( {
key: 'a',
fire: () => console.log( 'fire: a' )
} ),
new Hotkey( {
key: 's',
fire: () => console.log( 'fire: s' )
} ),
new Hotkey( {
key: 'd',
fire: () => console.log( 'fire: d' )
} )
]
} );
}
}

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
"phet-io"
],
"simulation": true,
"supportsOutputJS": true
"supportsOutputJS": true,
"simFeatures": {
"supportsInteractiveDescription": true,
"supportsDynamicLocale": true
}
},
"eslintConfig": {
"extends": "../chipper/eslint/sim_eslintrc.js"
Expand Down
Loading

0 comments on commit 18fe37e

Please sign in to comment.