Skip to content

Commit

Permalink
Implement Voicing in 'My Challenge' AccordionBox after changes for ph…
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed May 7, 2021
1 parent f493080 commit d5cf235
Showing 1 changed file with 19 additions and 45 deletions.
64 changes: 19 additions & 45 deletions js/create/view/MyChallengeAccordionBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import merge from '../../../../phet-core/js/merge.js';
import Fraction from '../../../../phetcommon/js/model/Fraction.js';
import NumberPicker from '../../../../scenery-phet/js/NumberPicker.js';
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import voicingManager from '../../../../scenery/js/accessibility/speaker/voicingManager.js';
import HBox from '../../../../scenery/js/nodes/HBox.js';
import Node from '../../../../scenery/js/nodes/Node.js';
import RichText from '../../../../scenery/js/nodes/RichText.js';
Expand Down Expand Up @@ -64,34 +63,8 @@ class MyChallengeAccordionBox extends AccordionBox {
mouseAreaXDilation: 5,
mouseAreaYDilation: 5,

voicingCreateObjectResponse: event => {
if ( event.type === 'focus' ) {
return ratioAndProportionStrings.myChallenge;
}
},
voicingCreateContextResponse: event => {
if ( event.type === 'focus' ) {

if ( voicingManager.objectChangesProperty.value ) {
const fullContextSentence = ratioDescriber.getMyChallengeSentence( targetAntecedentProperty.value, targetConsequentProperty.value );

// TODO: we don't have to do this once there is a better way to provide a call to collapseResponses from options.
assert && assert( fullContextSentence.startsWith( ratioAndProportionStrings.myChallenge ), 'assuming this starts with this string' );

return this.expandedProperty.value ? fullContextSentence.replace( ratioAndProportionStrings.myChallenge, '' ) : null;
}
else {
return null;
}
}
},
voicingCreateHintResponse: event => {
if ( event.type === 'focus' ) {
return this.expandedProperty.value ?
ratioAndProportionStrings.a11y.create.myChallengeExpandedHintText :
ratioAndProportionStrings.a11y.create.myChallengeCollapsedHintText;
}
}
// voicing
voicingObjectResponse: ratioAndProportionStrings.myChallenge
},

// phet-io
Expand Down Expand Up @@ -184,30 +157,31 @@ class MyChallengeAccordionBox extends AccordionBox {
const accordionBoxVoicingUtterance = new ActivationUtterance();
this.expandedProperty.lazyLink( expanded => {

if ( expanded ) {
accordionBoxUtterance.alert = ratioDescriber.getCurrentChallengeSentence( targetAntecedentProperty.value, targetConsequentProperty.value );
// strings containing responses used for Voicing
let contextResponse = '';
let hintResponse = '';

if ( expanded ) {
contextResponse = ratioDescriber.getCurrentChallengeSentence( targetAntecedentProperty.value, targetConsequentProperty.value );
hintResponse = ratioAndProportionStrings.a11y.create.myChallengeExpandedHintText;

accordionBoxVoicingUtterance.alert = voicingManager.collectResponses( {
objectResponse: ratioAndProportionStrings.myChallenge,
contextResponse: ratioDescriber.getMyChallengeSentence( targetAntecedentProperty.value, targetConsequentProperty.value ),
interactionHint: ratioAndProportionStrings.a11y.create.myChallengeExpandedHintText,
contextIncludesObjectResponse: true
} );
accordionBoxUtterance.alert = ratioDescriber.getCurrentChallengeSentence( targetAntecedentProperty.value, targetConsequentProperty.value );
}
else {
contextResponse = ratioAndProportionStrings.a11y.ratio.currentChallengeHidden;
hintResponse = ratioAndProportionStrings.a11y.create.myChallengeCollapsedHintText;

accordionBoxUtterance.alert = ratioAndProportionStrings.a11y.ratio.currentChallengeHidden;
accordionBoxVoicingUtterance.alert =
voicingManager.collectResponses( {
objectResponse: ratioAndProportionStrings.myChallenge,
contextResponse: ratioAndProportionStrings.a11y.ratio.myChallengeHidden,
interactionHint: ratioAndProportionStrings.a11y.create.myChallengeCollapsedHintText,
contextIncludesObjectResponse: true
} );
}

this.setButtonVoicingOptions( {
voicingContextResponse: contextResponse,
voicingHintResponse: hintResponse
} );

this.voicingSpeakButtonResponse( { utterance: accordionBoxVoicingUtterance } );
phet.joist.sim.utteranceQueue.addToBack( accordionBoxUtterance );
phet.joist.sim.voicingUtteranceQueue && phet.joist.sim.voicingUtteranceQueue.addToBack( accordionBoxVoicingUtterance );

} );

Property.multilink( [ targetAntecedentProperty, targetConsequentProperty ], ( targetAntecedent, targetConsequent ) => {
Expand Down

0 comments on commit d5cf235

Please sign in to comment.