phetsims / joist

Joist is the main framework for PhET Interactive Simulations. Joist creates and displays the simulation content, home screen, navigation bar, About dialog, enables switching between tabs, and other framework-related features.
MIT License
8 stars 6 forks source link

Instrument PreferencesModel to expose all `supports*` flags #859

Closed zepumph closed 1 year ago

zepumph commented 1 year ago

Something like this:


Index: js/preferences/PreferencesModel.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/preferences/PreferencesModel.ts b/js/preferences/PreferencesModel.ts
--- a/js/preferences/PreferencesModel.ts    (revision 3594a6bd1680b9867075fb7b31044b3205390c05)
+++ b/js/preferences/PreferencesModel.ts    (date 1663282745736)
@@ -23,6 +23,7 @@
 import localeProperty from '../i18n/localeProperty.js';
 import merge from '../../../phet-core/js/merge.js';
 import TReadOnlyProperty from '../../../axon/js/TReadOnlyProperty.js';
+import IOType from '../../../tandem/js/types/IOType.js';

 type ModelPropertyLinkable = {
   property: TReadOnlyProperty<unknown> & PhetioObject;
@@ -189,6 +190,7 @@

         // phet-io
         tandem: Tandem.GENERAL_MODEL.createTandem( 'preferencesModel' ),
+        phetioType: PreferencesModel.PreferencesModelIO,
         phetioState: false,
         phetioReadOnly: true
       }, providedOptions ) ),
@@ -461,6 +463,21 @@
            this.supportsInputPreferences() || this.supportsLocalizationPreferences() ||
            this.supportsAudioPreferences( false );
   }
+
+  public static PreferencesModelIO = new IOType( 'PreferencesModel', {
+    valueType: PreferencesModel,
+    toStateObject: ( preferencesModel: PreferencesModel ) => {
+      return {
+        supportsProjectorMode: preferencesModel.visualModel.supportsProjectorMode,
+        supportsInteractiveHighlights: preferencesModel.visualModel.supportsInteractiveHighlights,
+        supportsVoicing: preferencesModel.audioModel.supportsVoicing,
+        supportsSound: preferencesModel.audioModel.supportsSound,
+        supportsExtraSound: preferencesModel.audioModel.supportsExtraSound,
+        supportsGestureControl: preferencesModel.inputModel.supportsGestureControl,
+        supportsMultipleLocales: preferencesModel.localizationModel.supportsMultipleLocales
+      }
+    }
+  } )
 }

 joist.register( 'PreferencesModel', PreferencesModel );
samreid commented 1 year ago

I got that method working and added in some other computed supported properties. You can remove those if you wish. @zepumph do you have time for spot check/review?

It looks like this now:

image
samreid commented 1 year ago

I added one more commit that marks it as phetioFeatured: true.

zepumph commented 1 year ago

Perfect!

samreid commented 1 year ago

Thanks, I have nothing further for this issue. Closing.