src/app/models/scenario-calcul-mental.ts
Scénarios pour l’activité Calcul mental
constructor(cabri: CabriDataService, accountService: AccountService, globalService: GlobalService, page: any, cd: ChangeDetectorRef, ttsService: any)
|
| populateScenario |
populateScenario(randomize: boolean)
|
|
Creates feedbacks for calcul mental on top of general feedbacks
Returns:
void
|
| dynamicAnswerFeedback |
dynamicAnswerFeedback(status: AnswerStatus, responseTimeInSeconds: number, needsHelp: AnswerNeedsHelp, award: string, slow: number, fast: number, minAverage: number, minExtreme: number)
|
|
Creates a feedback phrase depending of the answer context
Returns:
void
|
| playSoundWithAward |
playSoundWithAward(award: any)
|
|
Returns:
void
|
| playIntroShort |
playIntroShort()
|
|
LEGACY Introduction - replaced by playIntroShort
Returns:
void
|
| Private pickRandom |
pickRandom(arr: string[])
|
|
Introduction C3
Returns:
string
|
| Public buildIntroShortText |
buildIntroShortText()
|
|
Returns:
string
|
| nextPlayerInit |
nextPlayerInit()
|
|
Lancement de l’activité / 1er joueur
Returns:
void
|
| nextPlayerSwitch |
nextPlayerSwitch()
|
|
Joueur suivant - faster text after 5 answers
Returns:
void
|
| readCurrentOperationNormal |
readCurrentOperationNormal()
|
|
Returns:
void
|
| readCurrentOperationProbleme |
readCurrentOperationProbleme()
|
|
Returns:
void
|
| readCurrentOperationCollection |
readCurrentOperationCollection(firstTime: any)
|
|
message before the user starts a new question for "les nombres autrement"
Returns:
void
|
| badResponseMoonWithResult |
badResponseMoonWithResult(responseTimeInSeconds: number)
|
|
Mauvaise réponse avec affichage solution - utilise dynamic feedback
Returns:
void
|
| badResponseMoonWithResultNextQ |
badResponseMoonWithResultNextQ(responseTimeInSeconds: any)
|
|
Mauvaise réponse avec affichage solution et question suivante - utilise dynamic feedback
Returns:
void
|
| badResponseMoonWithResultZeroModeNextQOptional |
badResponseMoonWithResultZeroModeNextQOptional(nextQ: boolean, responseTimeInSeconds: number)
|
|
Mauvaise réponse avec affichage solution et question suivante pour le mode prononciation du nombre affiché
Returns:
void
|
| restartActivity |
restartActivity()
|
|
Recommencer l’activité
Returns:
void
|
| unitsTutorial |
unitsTutorial()
|
|
UNITS TUTORIAL part 1
Returns:
void
|
| unitsTutorial2 |
unitsTutorial2()
|
|
Returns:
void
|
| unitsTutorialValidated |
unitsTutorialValidated()
|
|
UNITS TUTORIAL part 2 (validated)
Returns:
void
|
| explainWriteOperationOut |
explainWriteOperationOut(nbNumbers: any)
|
|
Returns:
void
|
| getRewardType |
getRewardType()
|
|
Returns:
void
|
| cabri |
cabri: |
| help2NumberSeparation |
help2NumberSeparation: |
| Public journeysService |
journeysService: |
| Public page |
page: |
import { PlayTTSService } from "src/app/services/play-tts.service";
import { ChangeDetectorRef, inject } from "@angular/core";
import { CalculMentalPage } from "../page/cabri/cabri.page";
import { AccountService } from "../services/account.service";
import { CabriDataService } from "../services/cabri-data.service";
import { GlobalService } from "../services/global.service";
import { ScenarioPhrase } from "./scenario-phrase";
import { ScenarioCabri } from "./scenario-cabri";
import { AnswerAverage, AnswerSpeed, AnswerStatus, AnswerNeedsHelp, AnswerExtreme } from "./activity-answer";
import { AppUtils, Fraction } from "../app-utils";
import { AwardsType } from "./enums/awards";
import { JourneysService } from "../services/journeys.service";
import { getRewardLabel, getRewardNameInPhrase, RewardType } from "../models/domains";
declare var MathJax: {
startup: any;
svg: any;
tex: any;
tex2svg: any;
tex2svgPromise: any;
loader: any;
Hub: any;
config: any;
tex2mml: any;
defsGlobalCaching: any;
};
/**
* Scénarios pour l’activité Calcul mental
*/
export class ScenarioCalculMental extends ScenarioCabri {
public page: CalculMentalPage;
public get journeysService(): JourneysService {
return this.cabri.journeysService;
}
help2NumberSeparation: string;
constructor(
public cabri: CabriDataService,
accountService: AccountService,
globalService: GlobalService,
page: any,
cd: ChangeDetectorRef,
ttsService: PlayTTSService
) {
super(cabri, accountService, globalService, page, cd, ttsService);
}
/**
* Creates feedbacks for calcul mental on top of general feedbacks
*/
populateScenario(randomize?: boolean) {
// randomize to rise diversity
randomize = true;
super.populateScenario(randomize);
// SUCCESS 1ST TRY
// SLOW
this.addFeedbacks(
{ status: AnswerStatus.VALID1ST, speed: AnswerSpeed.SLOW, calculNamingMode: false },
2,
[
$localize`Elle n’était pas facile celle-là ! Bravo !`,
$localize`Oui ! Très bon calcul #playerName !`,
$localize`Un petit pas pour toi, un grand pas pour ton apprentissage ! Bravo !`,
$localize`Youpi, tu as trouvé la solution !`
],
2
);
// NORMAL
this.addFeedbacks(
{ success: true, calculNamingMode: false },
1,
[
$localize`Bien joué #playerName ! Quel calcul intergalactique !`,
$localize`Quelle réponse super-numérique ! Bien joué #playerName !`,
$localize`Par Toutatis ! Quelle maîtrise des cosmopérations !`,
$localize`Quelle cosmo-réponse ! Bien joué !`,
//$localize`Bravo #playerName ! Tu as gagné une #award !`,
//$localize`Et encore une #award ! Youpi !`,
$localize`Quelle giga-réponse ! Bravo`,
//$localize`Hop ! Une #award ! Super !`,
$localize`Oui #playerName, bien joué !`,
//$localize`Youpi ! Une #award !`,
//$localize`Une #award de plus au tableau ! Super !`,
$localize`Oui ! Bravo #playerName !`,
//$localize`Et hop ! Une #award en plus !`,
$localize`Méga-boulonique cette réponse !`,
//$localize`Youpi ! Une #award de gagnée !`,
//$localize`Et une #award en plus pour ta collection !`,
$localize`Oui ! Une nouvelle constellation en vue !`
//$localize`Tiens ! Voila une #award pour compléter ta collection !`
],
2
);
// FAST
this.addFeedbacks(
{ status: AnswerStatus.VALID1ST, speed: AnswerSpeed.FAST, calculNamingMode: false },
2,
[
$localize`Tu n'as fait qu’une bouchée de cette opération ! Bravo !`,
$localize`Toi tu manges des opérations au petit déjeuner, non ?`,
$localize`Wahou ! Aussi rapide qu’une étoile filante !`,
$localize`Tu réfléchis plus vite que la lumière !`,
$localize`Lumino-fantastique !`,
$localize`Supra-luminique !`,
$localize`Vitesse lumière !`,
$localize`Tu réfléchis plus vite que la lumière !`,
$localize`Quelle cosmo-réponse ! Tu es supra-luminique !`,
$localize`Par Toutatis ! Quelle maîtrise !`
],
2
);
// PROGRESSION ABOVE AVERAGE
this.addFeedbacks(
{ status: AnswerStatus.VALID1ST, progressionAverage: AnswerAverage.ABOVE, calculNamingMode: false },
3,
[$localize`Oui, bien joué ! La victoire se rapproche !`],
2
);
// PROGRESSION BELOW AVERAGE
this.addFeedbacks(
{ status: AnswerStatus.VALID1ST, progressionAverage: AnswerAverage.BELOW },
3,
[$localize`Bien joué #playerName ! Continue ! Tu peux y arriver !`],
2
);
// PROGRESSION NO ERRORS TILL THEN
this.addFeedbacks(
{ status: AnswerStatus.VALID1ST, progressionExtreme: AnswerExtreme.ALLGOOD },
3,
[
$localize`Sans faute jusqu’ici ! Joli !`,
$localize`Wahou ! Rien ne t’arrête #playerName !`,
$localize`Quelle série ! Et une #award en plus !`,
$localize`Incroyable ! Jusqu’où iras-tu comme ça ?`,
$localize`Epoustouflant #playerName !`
],
2
);
// PROGRESSION ONLY ERRORS TILL THEN
this.addFeedbacks(
{ status: AnswerStatus.VALID1ST, progressionExtreme: AnswerExtreme.ALLBAD },
4,
[$localize`Bravo #playerName ! Tu vois, avec persévérance on y arrive toujours ! Continue comme ça !`],
2
);
// PROGRESSION NO ERRORS TILL THEN - FAST ANSWER
// this.addFeedbacks({ status: AnswerStatus.VALID1ST, speed: AnswerSpeed.FAST, progressionExtreme: AnswerExtreme.ALLGOOD }, 3, [
// $localize`TODO?`
// ], 2);
// SUCCESS 2ND TRY
this.addFeedbacks(
{ status: AnswerStatus.VALID2ND, calculNamingMode: false },
2,
[
$localize`Quelle cosmo-réponse ! Bien rattrapé !`,
$localize`Bien rattrapé #playerName ! Quel calcul intergalactique !`,
$localize`Quelle réponse super-numérique ! Bien joué #playerName !`,
$localize`Wahou ! Tu m’impressionnes #playerName ! Continue comme ça !`
],
2
);
// this.addFeedbacks({ status: AnswerStatus.VALID2ND, progressionExtreme: AnswerExtreme.ALLBAD }, 3, [
// $localize`TODO?`
// ], 2);
// this.addFeedbacks({ status: AnswerStatus.VALID2ND, progressionExtreme: AnswerExtreme.ALLGOOD }, 3, [
// $localize`TODO?`
// ], 2);
// ERRORS
// FIRST ERROR - retry with help
this.addFeedbacks(
{ status: AnswerStatus.ERROR1ST, needsHelp: AnswerNeedsHelp.YES, calculNamingMode: false },
2,
[$localize`Mince ! On dirait qu’il y a un boulon dans l'opération ! Je vais t’aider.`],
2
);
// FIRST ERROR - retry without help
this.addFeedbacks(
{ status: AnswerStatus.ERROR1ST, needsHelp: AnswerNeedsHelp.NO, calculNamingMode: false },
2,
[$localize`Mince ! On dirait qu’il y a un boulon dans l’opération ! Reprenons.`],
2
);
// SECOND ERROR - failed
this.addFeedbacks({ status: AnswerStatus.ERROR2ND, calculNamingMode: false }, 2, [
$localize`Ce n'est pas ça... Il faut dire qu’elle est difficile celle-là !`,
$localize`Tu y étais presque ! Pas facile cette opération !`,
$localize`Mince ! On dirait qu’il y a un boulon dans l’opération !`
]);
// +ZERO MODE - NOMMER UN NOMBRE
// this.addFeedbacks({ status: AnswerStatus.VALID1ST, calculNamingMode: true }, 3, [
// $localize`TODO`,
// ], 2);
// this.addFeedbacks({ status: AnswerStatus.ERROR2ND, calculNamingMode: true }, 2, [
// $localize`TODO`,
// ], 2);
// PROBLEM MODE
// SUCCESS 1ST TRY
// SLOW
this.addFeedbacks(
{ status: AnswerStatus.VALID1ST, speed: AnswerSpeed.SLOW, calculNamingMode: false, calculProblemMode: true },
2,
[$localize`Il était pas facile celui-là ! Bravo !`],
2
);
// NORMAL
this.addFeedbacks(
{ success: true, calculNamingMode: false, calculProblemMode: true },
1,
[
$localize`Bien joué #playerName ! Belle analyse !`,
$localize`Quelle déduction super-numérique ! Bien joué #playerName !`,
$localize`Bravo ! Tu as su trouver la solution comme un vrai enquêteur de l’espace !`,
$localize`Quelle cosmo-résolution ! Bien joué !`
],
2
);
// FAST
this.addFeedbacks(
{ status: AnswerStatus.VALID1ST, speed: AnswerSpeed.FAST, calculNamingMode: false, calculProblemMode: true },
2,
[$localize`Tu n'as fait qu’une bouchée de ce problème ! Bravo !`],
2
);
// PROGRESSION ABOVE AVERAGE
this.addFeedbacks(
{ status: AnswerStatus.VALID1ST, progressionAverage: AnswerAverage.ABOVE, calculNamingMode: false, calculProblemMode: true },
1,
[$localize`Je suis impressionnée ! Tu maîtrises l’analyse des problèmes à la perfection !`],
2
);
this.addFeedbacks(
{ status: AnswerStatus.ERROR2ND, calculNamingMode: false, calculProblemMode: true },
2,
[$localize`Oups ! Ce n’est pas ça ! Pas facile ce problème...`],
2
);
// ERRORS
// FIRST ERROR - retry with help
this.addFeedbacks(
{ status: AnswerStatus.ERROR1ST, needsHelp: AnswerNeedsHelp.YES, calculNamingMode: false, calculProblemMode: true },
3,
[$localize`Mince ! Pas facile ce problème ! Voyons le sous forme d’opération !`],
2
);
// FIRST ERROR - retry without help
this.addFeedbacks(
{ status: AnswerStatus.ERROR1ST, needsHelp: AnswerNeedsHelp.NO, calculNamingMode: false, calculProblemMode: true },
3,
[$localize`Non... Essaye encore en transformant bien le problème en opération !`],
2
);
// SECOND ERROR - failed
this.addFeedbacks(
{ status: AnswerStatus.ERROR2ND, calculNamingMode: false, calculProblemMode: true },
3,
[
$localize`Ce n'est pas ça... Il faut dire qu’il est difficile celui-ci !`,
$localize`Tu y étais presque ! Pas facile celui-ci !`,
$localize`Mince ! Dur à percer ce problème !`
],
2
);
// DONT'T KNOW THE ANWSER
this.addFeedbacks({ status: AnswerStatus.ERROR2ND, needsHelp: AnswerNeedsHelp.IGNORE }, 1, [
$localize`Tu ne connais pas la réponse, mais ce n’est pas grave.Essayons la prochaine fois `
]);
if (randomize) {
AppUtils.shuffleArray(this.feedbacks);
// console.error("feedbacks shuffled = ", this.feedbacks);
}
}
/**
* Creates a feedback phrase depending of the answer context
*/
async dynamicAnswerFeedback(
status: AnswerStatus,
responseTimeInSeconds: number,
needsHelp = AnswerNeedsHelp.NO,
award?: string,
slow = 20,
fast = 5,
minAverage = 5,
minExtreme = 3
) {
const phrase = this.getContextualFeedbackPhrase(
status,
responseTimeInSeconds,
award,
slow,
fast,
minAverage,
minExtreme,
needsHelp
);
if (award) {
this.page.updatePlayerAndTeamStarboards(award);
this.page.showHideAward();
}
let speechSequence = [new ScenarioPhrase(phrase).showAward(award)];
if (this.page.endOfActivity() && this.answer.success) {
speechSequence = [
new ScenarioPhrase([
$localize`Wahou ! Quelle expédition !`,
$localize`Oui ! Quelle expédition !`,
$localize`Bravo ! Quel voyage !`,
$localize`${this.page.currentUser.name}:playerName: ! Tu as gagné la dernière étoile !`,
$localize`Bien joué ! Quel cosmo-voyage !`
])
.setRandomMode()
.showAward(award)
];
}
await this.runMathiaSpeech(speechSequence);
}
async playSoundWithAward(award) {
let speechSequence;
if (this.page.endOfActivity()) {
this.page.hideBubbleText = false;
speechSequence = [
new ScenarioPhrase([
$localize`Wahou ! Quelle expédition !`,
$localize`Oui ! Quelle expédition !`,
$localize`Bravo ! Quel voyage !`,
$localize`${this.page.currentUser.name}:playerName: ! Tu as gagné la dernière étoile !`,
$localize`Bien joué ! Quel cosmo-voyage !`
])
.setRandomMode()
.showAward(award)
];
await this.runMathiaSpeech(speechSequence);
} else {
this.page.hideBubbleText = true;
if (award && award !== AwardsType.moon) {
this.page.audioService.playStarSound();
} else {
this.page.audioService.playAwardMoonSound();
}
if (award) {
this.page.updatePlayerAndTeamStarboards(award);
this.page.showHideAward();
const s = new ScenarioPhrase(" ", async () => {
await this.timeOut(500);
});
if (!this.accountService.user.isC3) {
s.showAward(award);
}
speechSequence = [s];
await this.runMathiaSpeech(speechSequence);
}
this.page.hideBubbleText = false;
}
}
/**
* LEGACY Introduction - replaced by playIntroShort
*/
// async playIntro() {
// const players: any = this.page.currentTeam.map(student => student.name).join(" ! ") + " ! ";
// // Verbs:
// let commencerContinuer;
// let reDécoller;
// let rePartons;
// commencerContinuer = $localize`commencer`;
// reDécoller = $localize`décoller`;
// rePartons = $localize`partons`;
// // SEQUENCE:
// if (this.page.currentTeam.length > 1 && !this.fromInputMethodsTutorial) {
// // MULTI:
// const introTeam: Array<any> = [
// new ScenarioPhrase([
// players + $localize` Bienvenue à bord ! `
// ]).setRandomMode(),
// new ScenarioPhrase([
// $localize`Etes-vous prêts à explorer l’univers des mathématiques ?`,
// $localize`Attention au décollage vers la galaxie des mathématiques ! Prêts ?`,
// $localize`Vous êtes prêts à ${commencerContinuer} notre voyage mathémati-cosmique ?`,
// $localize`Prêts pour ${reDécoller} vers la galaxie des mathématiques ?`,
// $localize`Attachez votre ceinture, nous ${rePartons} à la découverte des mathématiques !`,
// $localize`Notre fusée est prête à ${reDécoller} vers l’univers des nombres ! On y va ?`,
// $localize`Tout le monde est prêt ? Bien, ${rePartons} à la découverte des astér-opérations !`,
// $localize`J’espère que vous êtes prêts car nous ${rePartons} explorer les cosmopérations !`
// ]).setRandomMode()
// ];
// await this.runMathiaSpeech(introTeam);
// } else if (this.page.currentTeam.length === 1) {
// // SOLO:
// const introSolo: Array<any> = [
// new ScenarioPhrase([
// this.fromInputMethodsTutorial ?
// " "
// :
// this.page.currentUser.name + $localize` ! Bienvenue à bord !`
// ]).setRandomMode(),
// new ScenarioPhrase([
// // "Es-tu prêt à explorer l’univers des mathématiques ?",
// // "Prêt pour décoller vers la galaxie des mathématiques ?",
// // "Prêt pour un nouveau voyage mathémati-cosmique ?",
// $localize`Attache ta ceinture, nous partons à la découverte des mathématiques !`,
// // $localize`Notre fusée est prête à décoller vers l’univers des nombres ! On y va ?`
// ]).setRandomMode(),
// new ScenarioPhrase(["3... 2... 1..."]),
// new ScenarioPhrase(
// [
// $localize`Allons-y !`,
// $localize`C’est parti !`,
// // $localize`Paré au décollage !`,
// // $localize`Allumage des réacteurs !`,
// $localize`Vers l’infini et au-delà !`,
// $localize`Que la force soit avec toi !`
// ]
// ).setRandomMode()
// ];
// this.fromInputMethodsTutorial = false;
// await this.runMathiaSpeech(introSolo);
// }
// }
/**
* Introduction shorter version + adapts to end of InputMethodsTutorial (solo + multi)
*/
async playIntroShort() {
const players: any = this.page.currentTeam.map(student => student.name).join(" ! ") + " ! ";
// SEQUENCE:
if (this.page.currentTeam.length > 1 && !this.fromInputMethodsTutorial) {
// MULTI:
const introTeam: Array<any> = [
new ScenarioPhrase([
// players + $localize` Bienvenue dans la galaxie des mathématiques !`,
players + $localize` Bienvenue dans l’univers des nombres !`
]).setRandomMode()
];
await this.runMathiaSpeech(introTeam);
// scenario multi continues in this.nextPlayerInit()
} else if (this.page.currentTeam.length === 1) {
// SOLO:
const introSolo = [
new ScenarioPhrase([
this.fromInputMethodsTutorial
? $localize`Maintenant attache ta ceinture ${this.page.currentUser.name}, nous partons à la découverte des mathématiques !`
: this.page.currentUser.name + $localize` ! Attache ta ceinture, nous partons à la découverte des mathématiques !`
]).setRandomMode()
];
introSolo.push(
new ScenarioPhrase(["3... 2... 1..."]),
new ScenarioPhrase([
// $localize`Allons-y !`,
$localize`C’est parti !`,
// $localize`Paré au décollage !`,
// $localize`Allumage des réacteurs !`,
$localize`Vers l’infini et au-delà !`,
$localize`Que la force soit avec toi !`
]).setRandomMode()
);
await this.runMathiaSpeech(introSolo);
}
}
/**
* Introduction C3
*/
private pickRandom(arr: string[]): string {
return arr[Math.floor(Math.random() * arr.length)];
}
public buildIntroShortText(): string {
const players = this.page.currentTeam.map(s => s.name).join(" ! ") + " ! ";
if (this.page.currentTeam.length > 1 && !this.fromInputMethodsTutorial) {
const line1 = this.pickRandom([players + $localize` Bienvenue dans l’univers des nombres !`]);
return line1;
}
if (this.page.currentTeam.length === 1) {
const line1 = this.pickRandom([
this.fromInputMethodsTutorial
? $localize`Maintenant attache ta ceinture ${this.page.currentUser.name}, nous partons à la découverte des mathématiques !`
: this.page.currentUser.name + $localize` ! Attache ta ceinture, nous partons à la découverte des mathématiques !`
]);
const line2 = "3... 2... 1...";
const line3 = this.pickRandom([
$localize`C’est parti !`,
$localize`Vers l’infini et au-delà !`,
$localize`Que la force soit avec toi !`
]);
return `${line1}\n${line2}\n${line3}`;
}
return "";
}
/**
* Lancement de l’activité / 1er joueur
*/
async nextPlayerInit() {
const nextPlayerInit: Array<any> = [
new ScenarioPhrase([
$localize`Comme vous êtes ${this.page.currentTeam.length} dans l’équipe, vous allez vous passer les commandes chacun votre tour pour piloter !`,
$localize`Vous êtes ${this.page.currentTeam.length} dans l’équipe donc vous allez répondre chacun votre tour !`
]).setRandomMode(),
new ScenarioPhrase([
$localize`C’est toi qui commences ${this.page.currentUser.name}:playerName: !`,
$localize`${this.page.currentUser.name}:playerName:, c’est toi qui vas essayer de résoudre la première opération !`,
$localize`À toi de commencer ${this.page.currentUser.name}:playerName: !`,
$localize`${this.page.currentUser.name}:playerName:, à toi l’honneur de répondre en premier !`
// this.page.currentUser.name + ", tu es prêt ? C’est à toi de commencer !"
]).setRandomMode(),
new ScenarioPhrase(["3... 2... 1..."]),
new ScenarioPhrase([
$localize`Allons-y !`,
$localize`C’est parti !`,
$localize`Décollage !`,
$localize`Allumage des réacteurs !`,
$localize`Que la force soit avec toi !`,
$localize`Vers l’infini et au-delà !`
])
];
await this.runMathiaSpeech(nextPlayerInit);
}
/**
* Joueur suivant - faster text after 5 answers
*/
async nextPlayerSwitch() {
const nextPlayerContent: Array<any> = [
new ScenarioPhrase(
this.cabriService.teamTotalAwards < 5
? [
$localize`Maintenant c’est à ${this.page.currentUser.name}:playerName: de piloter ! Vas-y ${this.page.currentUser.name} !`,
$localize`Maintenant à toi ${this.page.currentUser.name}:playerName: ! Vas-y !`,
$localize`Maintenant à ton tour ${this.page.currentUser.name}:playerName: ! Vas-y !`,
$localize`${this.page.currentUser.name}:playerName: ? Tu es toujours là ? Ok, à toi de jouer !`,
$localize`Et maintenant c’est à... ${this.page.currentUser.name}:playerName: !`,
$localize`À ${this.page.currentUser.name}:playerName: maintenant !`,
$localize`${this.page.currentUser.name}:playerName:, à toi !`
]
: [
$localize`À ton tour ${this.page.currentUser.name}:playerName: !`,
$localize`À toi ${this.page.currentUser.name}:playerName: !`,
$localize`Et maintenant c’est à... ${this.page.currentUser.name}:playerName: !`,
$localize`À ${this.page.currentUser.name}:playerName: maintenant !`,
$localize`${this.page.currentUser.name}:playerName:, à toi !`,
$localize`Quel voyage ! À toi ${this.page.currentUser.name}:playerName: !`
]
)
];
await this.runMathiaSpeech(nextPlayerContent);
}
/**
* @ignore
* message before the user starts a new question for "calcul mental"
*/
async readCurrentOperationNormal() {
const content: Array<any> = [new ScenarioPhrase([this.page.readCurrentOperation(this.page.setOperationMode)]).hideBubble()];
await this.runMathiaSpeech(content);
}
/**
* @ignore
* message before the user starts a new question for "résolution de problème"
*/
async readCurrentOperationProbleme() {
const phrases = this.page.cabriService.currentExercice.probleme.consigneTTS.split(".");
const content: Array<any> = [];
if (!this.page.failure) {
phrases.forEach(element => {
content.push(new ScenarioPhrase([element]).hideBubble());
});
} else {
content.push(new ScenarioPhrase([phrases[phrases.length - 1]]).hideBubble());
}
await this.runMathiaSpeech(content);
}
/**
* message before the user starts a new question for "les nombres autrement"
*/
async readCurrentOperationCollection(firstTime = null) {
let speechSequence: any;
let genericInstructions;
if (firstTime) {
genericInstructions = [new ScenarioPhrase([$localize`Quel est le résultat de l’opération ?`]).setRandomMode().hideBubble()];
} else {
if (this.page.currentTeam?.length === 1) {
genericInstructions = [
new ScenarioPhrase([
$localize`Peux-tu me dire le résultat ?`,
$localize`Quel est le résultat de l’opération ?`,
$localize`Et maintenant, quel est le résultat ?`,
$localize`Et maintenant ?`,
$localize`Et cette opération ? Peux-tu la résoudre ?`,
$localize`Et celle-ci ? Peux-tu la résoudre ?`,
$localize`Et celle-ci ?`,
$localize`Quel est le résultat ?`,
$localize`Peux-tu me dire le résultat de l’opération ?`,
$localize`Et celle-là ?`
]).hideBubble()
];
} else {
genericInstructions = [
new ScenarioPhrase([
$localize`Quel est le résultat de l’opération ?`,
$localize`Peux-tu me dire le résultat de l’opération ?`,
$localize`Quel est le résultat ?`,
$localize`Peux-tu me dire le résultat ?`,
$localize`Quel est le résultat de l’opération ?`,
$localize`Peux-tu me dire le résultat de l’opération ?`,
$localize`Quel est le résultat ?`,
$localize`Peux-tu me dire le résultat ?`,
$localize` ${this.page.currentUser.name}:playerName:, quel est le résultat de l’opération ?`,
$localize`Peux-tu me dire le résultat de l’opération ${this.page.currentUser.name}:playerName: ?`,
$localize` ${this.page.currentUser.name}:playerName:, quel est le résultat ?`,
$localize`Peux-tu me dire le résultat ${this.page.currentUser.name}:playerName: ?`
])
.setRandomMode()
.hideBubble()
];
}
}
if (this.cabriService.currentExercice.resultMode === "+zero" && !this.cabriService.collectionModeInCM) {
if (firstTime) {
genericInstructions = [
new ScenarioPhrase([$localize`Quel est le nombre affiché à l’écran ?`]).setRandomMode().hideBubble()
];
} else if (!this.cabriService.collectionModeInCM) {
if (
this.cabriService.currentExercice?.responseMode &&
this.cabriService.currentExercice?.responseMode === "not-voice" &&
this.cabriService.holoMode === "0"
) {
genericInstructions = [
new ScenarioPhrase([
$localize`Quel est le nombre affiché à l’écran ?`,
$localize`Quel est le nombre affiché ?`,
$localize`Quel est le nombre affiché à l’écran ?`,
$localize`Quel est le nombre affiché ?`,
$localize`${this.page.currentUser.name}:playerName:, quel est le nombre affiché à l’écran ?`,
$localize`${this.page.currentUser.name}:playerName:, quel est le nombre affiché ?`
])
.setRandomMode()
.hideBubble()
];
} else {
genericInstructions = [
new ScenarioPhrase([
$localize`Quel est le nombre affiché à l’écran ?`,
$localize`Peux-tu me dire le nombre affiché à l’écran ?`,
$localize`Quel est le nombre affiché ?`,
$localize`Peux-tu me dire le nombre affiché ?`,
$localize`Quel est le nombre affiché à l’écran ?`,
$localize`Peux-tu me dire le nombre affiché à l’écran ?`,
$localize`Quel est le nombre affiché ?`,
$localize`Peux-tu me dire le nombre affiché ?`,
$localize`${this.page.currentUser.name}:playerName:, quel est le nombre affiché à l’écran ?`,
$localize`Peux-tu me dire le nombre affiché à l’écran ${this.page.currentUser.name}:playerName: ?`,
$localize`${this.page.currentUser.name}:playerName: , quel est le nombre affiché ?`,
$localize`Peux-tu me dire le nombre affiché ${this.page.currentUser.name}:playerName: ?`
])
.setRandomMode()
.hideBubble()
];
}
}
}
if (this.cabriService.collectionModeInCM) {
if (firstTime) {
if (this.cabriService.currentExercice && this.cabriService.currentExercice.operation === "1") {
speechSequence = [
new ScenarioPhrase([$localize`Combien y a t-il de planètes affichées ?`]).setRandomMode().hideBubble()
];
} else {
speechSequence = genericInstructions;
}
} else {
if (this.cabriService.currentExercice && this.cabriService.currentExercice.operation === "1") {
speechSequence = [
new ScenarioPhrase([
$localize`Combien y a t-il de planètes affichées ?`,
$localize`Combien y a t-il de planètes ?`,
$localize`Combien vois-tu de planètes ?`,
$localize`Quel est le résultat de l’opération ?`,
$localize`Peux-tu me dire le résultat de l’opération ?`,
$localize`Quel est le résultat ?`,
$localize`Peux-tu me dire le résultat ?`,
$localize`Combien y a t-il de planètes affichées ?`,
$localize`Combien y a t-il de planètes ?`,
$localize`Combien vois-tu de planètes ?`,
$localize`Quel est le résultat de l’opération ?`,
$localize`Peux-tu me dire le résultat de l’opération ?`,
$localize`Quel est le résultat ?`,
$localize`Peux-tu me dire le résultat ?`,
$localize`${this.page.currentUser.name}:playerName:, combien y a t-il de planètes affichées ?`,
$localize`${this.page.currentUser.name}:playerName:, combien y a t-il de planètes ?`,
$localize`${this.page.currentUser.name}:playerName:, quel est le résultat de l’opération ?`,
$localize`${this.page.currentUser.name}:playerName:, quel est le résultat ?`,
$localize`Peux-tu me dire le résultat de l’opération${this.page.currentUser.name}:playerName: ?`
])
.setRandomMode()
.hideBubble()
];
} else if (this.cabriService.currentExercice.resultMode === "+zero") {
speechSequence = [
new ScenarioPhrase([
$localize`Combien y a t-il de planètes affichées ?`,
$localize`Combien y a t-il de planètes ?`,
$localize`Combien vois-tu de planètes ?`,
$localize`Combien y a t-il de planètes affichées ?`,
$localize`Combien y a t-il de planètes ?`,
$localize`Combien vois-tu de planètes ?`,
$localize`Peux-tu me dire combien de planètes sont affichées ?`,
$localize`Combien vois-tu de planètes à l’écran ?`,
$localize`${this.page.currentUser.name}:playerName:, combien y a t-il de planètes affichées ?`,
$localize`${this.page.currentUser.name}:playerName:, combien y a t-il de planètes ?`,
$localize`${this.page.currentUser.name}:playerName:,combien vois-tu de planètes ?`,
$localize`Combien y a t-il de planètes affichées ${this.page.currentUser.name}:playerName: ?`,
$localize`Combien y a t-il de planètes ${this.page.currentUser.name}:playerName: ?`,
$localize`Combien vois-tu de planètes ${this.page.currentUser.name}:playerName: ?`
])
.setRandomMode()
.hideBubble()
];
} else {
speechSequence = genericInstructions;
}
}
} else if (
this.cabriService.diceModeInCM ||
this.cabriService.fingersModeInCM ||
this.cabriService.lettersModeInCM ||
this.cabriService.coinsModeInCM
) {
speechSequence = genericInstructions;
}
// if needed in the future ->
// else if (this.cabriService.fingersModeInCM) {
// speechSequence = [
// new ScenarioPhrase(
// [
// "Quel est le résultat de l'opération ?",
// this.page.currentUser.name + ", quel est le résultat de l'opération ?"
// ]
// ).setRandomMode()
// ];
// } else if (this.cabriService.lettersModeInCM) {
// speechSequence = [
// new ScenarioPhrase(
// [
// "Quel est le résultat de l'opération ?",
// this.page.currentUser.name + ", quel est le résultat de l'opération ?"
// ]
// ).setRandomMode()
// ];
// } else if (this.cabriService.coinsModeInCM) {
// speechSequence = [
// new ScenarioPhrase(
// [
// "Quel est le résultat de l'opération ?",
// this.page.currentUser.name + ", quel est le résultat de l'opération ?"
// ]
// ).setRandomMode()
// ];
// }
await this.runMathiaSpeech(speechSequence);
}
/**
* Mauvaise réponse avec affichage solution - utilise dynamic feedback
*/
async badResponseMoonWithResult(responseTimeInSeconds: number) {
// TTS need text not symbols
let opSign = "";
switch (Number(this.cabriService.currentActivity.variables["v-cursor-op"])) {
case 1:
opSign = "+";
break;
case 2:
opSign = "×";
break;
case 3:
opSign = "-";
break;
case 4:
opSign = ":";
break;
default:
this.globalService.analyticService.sendAnalytics("no_cursor_op??badResponseMoonWithResult", {
activity_id: this.cabriService.currentActivity.id,
activityVariables: JSON.stringify(this.cabriService.currentActivity.variables)
});
}
let opSignTTS = opSign.replace("−", $localize`moins`);
opSignTTS = opSignTTS.replace("-", $localize`moins`);
opSignTTS = opSignTTS.replace("×", $localize`fois`);
opSignTTS = opSignTTS.replace("*", $localize`fois`);
opSignTTS = opSignTTS.replace("+", $localize`plus`);
opSignTTS = opSignTTS.replace(":", $localize`diviser par`);
const endResult = (
this.page.setOperationMode === "nb1" || this.page.setOperationMode === "nb2" ? this.page.operationResult : this.page.goodResult
).toString();
// TTS "une" -> "un":
let nb1TTS = this.cabriService.nb1.toString();
if (nb1TTS === "1") {
nb1TTS = nb1TTS.replace("1", $localize`un`);
}
let nb2TTS = this.cabriService.nb2.toString();
if (nb2TTS === "1") {
nb2TTS = nb2TTS.replace("1", $localize`un`);
}
let nb3TTS = this.cabriService.nb3?.toString();
if (nb3TTS === "1") {
nb3TTS = nb3TTS.replace("1", $localize`un`);
}
let nb4TTS = this.cabriService.nb4?.toString();
if (nb4TTS === "1") {
nb4TTS = nb4TTS.replace("1", $localize`un`);
}
let endResultTTS = endResult;
if (endResultTTS === "1") {
endResultTTS = endResultTTS.replace("1", $localize`un`);
}
const vars = this.cabriService.currentActivity.currentVariables;
// valeurs “visuelles”
const displayedValues = [vars.nb1, vars.nb2, vars.nb3, vars.nb4].filter(v => v !== undefined && v !== null).join(` ${opSign} `);
// valeurs TTS
const ttsValues = [nb1TTS, nb2TTS, nb3TTS, nb4TTS].filter(v => v !== undefined && v !== null).join(` ${opSignTTS} `);
const phrase = this.getContextualFeedbackPhrase(AnswerStatus.ERROR2ND, responseTimeInSeconds);
const moonResult: Array<any> = [
new ScenarioPhrase([phrase], async () => {
await this.page.cabri.setOperation("full", this.page.operationResult.toString());
if (this.cabriService.collectionModeInCM) {
this.page.cabriService.moonResultCollection = true;
this.page.detectChanges();
}
if (!this.cabriService.mirrorMode) {
this.page.cabri.toggleOperationWrapperPosition("down");
} else {
this.page.cabri.toggleOperationWrapperPosition("up");
}
if(!this.accountService.user.isC3){
this.page.cabri.showOperationAndWrapper(); //Ne pas réafficher le calcul lors du résultat
}
}).setRandomMode(),
new ScenarioPhrase(
[$localize`Regarde, la bonne réponse était : ${displayedValues} égale ${endResult} !`],
async () => {
await this.timeOut(3000);
this.page.cabri.hideOperationAndWrapper();
if (this.cabriService.collectionModeInCM) {
this.page.cabriService.moonResultCollection = false;
this.page.detectChanges();
}
this.page.showHideAward();
},
[$localize`:tts:Regarde, la bonne réponse était : ${ttsValues} égale ${endResultTTS} !`]
),
// ✅ placeholder, remplacé juste après
null as any
];
// ✅ remplacement ciblé, aucune autre modif structurelle
if (this.accountService.user.isC3) {
const rewardType = await this.getRewardType(); // RewardType
const rewardInPhrase = getRewardNameInPhrase(rewardType);
moonResult[2] = new ScenarioPhrase(
[$localize`Tu as quand même gagné ${rewardInPhrase} !`, $localize`Nous avons quand même gagné ${rewardInPhrase} !`],
async () => {
await this.timeOut(1000);
}
).setRandomMode();
} else {
moonResult[2] = new ScenarioPhrase(
[$localize`Tu as quand même gagné une lune !`, $localize`Nous avons quand même gagné une lune !`],
async () => {
await this.timeOut(1000);
}
)
.setRandomMode()
.showAward("moon");
}
await this.runMathiaSpeech(moonResult);
}
/**
* Mauvaise réponse avec affichage solution et question suivante - utilise dynamic feedback
*/
async badResponseMoonWithResultNextQ(responseTimeInSeconds) {
// TTS need text not symbols
let opSign = "";
let opType = Number(this.cabriService.currentActivity.variables["v-cursor-op"]);
switch (opType) {
case 1:
opSign = "+";
break;
case 2:
opSign = "×";
break;
case 3:
opSign = "-";
break;
case 4:
opSign = ":";
break;
case 5:
opSign = this.cabriService.currentActivity.currentVariables._customOperation;
break;
default:
this.globalService.analyticService.sendAnalytics("no_cursor_op??badResponseMoonWithResultNextQ", {
activity_id: this.cabriService.currentActivity.id,
activityVariables: JSON.stringify(this.cabriService.currentActivity.variables)
});
}
const replacements: Record<string, string> = {
"−": $localize`moins`,
"-": $localize`moins`,
"×": $localize`fois`,
"*": $localize`fois`,
"+": $localize`plusse`,
":": $localize`divisé par`,
"/": $localize`divisé par`,
};
let opSignTTS = opSign.replace(/[−\-×*+:\/]/g, (match) => replacements[match]);
const prononciationsFractions = {
2: "demi",
3: "tiers",
4: "quart",
5: "cinquième",
6: "sixième",
7: "septième",
8: "huitième",
9: "neuvième",
10: "dixième",
11: "onzième",
12: "douzième"
};
const endResult =
this.page.setOperationMode === "nb1" || this.page.setOperationMode === "nb2"
? this.cabriService.currentActivity.currentVariables.operationResult
: this.cabriService.currentActivity.currentVariables.result;
// TTS "une" -> "un":
let nb1TTS = this.cabriService.nb1.toString();
nb1TTS = Number(Number(nb1TTS).toFixed(8)).toString().replace(".", ",");
if (nb1TTS === "1") {
nb1TTS = nb1TTS.replace("1", $localize`un`);
}
if (this.cabriService.currentActivity.currentVariables.nb1 instanceof Fraction) {
nb1TTS =
this.cabriService.currentActivity.currentVariables.nb1.numerateur +
prononciationsFractions[this.cabriService.currentActivity.currentVariables.nb1.denominateur];
}
let nb2TTS = this.cabriService.nb2.toString();
nb2TTS = Number(Number(nb2TTS).toFixed(8)).toString().replace(".", ",");
if (nb2TTS === "1") {
nb2TTS = nb2TTS.replace("1", $localize`un`);
}
if (this.cabriService.currentActivity.currentVariables.nb2 instanceof Fraction) {
nb2TTS =
this.cabriService.currentActivity.currentVariables.nb2.numerateur +
prononciationsFractions[this.cabriService.currentActivity.currentVariables.nb2.denominateur];
}
let nb3TTS = this.cabriService.currentActivity.currentVariables.nb3?.toString();
if (nb3TTS) {
nb3TTS = Number(Number(nb3TTS).toFixed(8)).toString().replace(".", ",");
}
if (nb3TTS === "1") {
nb3TTS = nb3TTS.replace("1", $localize`un`);
}
let nb4TTS = this.cabriService.currentActivity.currentVariables.nb4?.toString();
if (nb4TTS) {
nb4TTS = Number(Number(nb4TTS).toFixed(8)).toString().replace(".", ",");
}
if (nb4TTS === "1") {
nb4TTS = nb4TTS.replace("1", $localize`un`);
}
let endResultTTS = Number(Number(endResult).toFixed(8)).toString().replace(".", ",");
if (endResultTTS === "1") {
endResultTTS = endResultTTS.replace("1", $localize`un`);
}
if (endResult instanceof Fraction) {
endResultTTS = endResult.numerateur + prononciationsFractions[endResult.denominateur];
}
const vars = this.cabriService.currentActivity.currentVariables;
const values = [vars.nb1, vars.nb2, vars.nb3, vars.nb4].filter(v => v !== undefined && v !== null);
let latexOperation;
if (opType < 5) {
latexOperation = values
.map(v =>
v instanceof Fraction
? v.toLatex()
: v
.toFixed(8)
.replace(/\.?0+$/, "")
.replace(".", ",")
)
.join(` ${opSign} `);
} else {
latexOperation = this.cabriService.currentActivity.variables._customOperation;
for (let i = 1; i <= 4; i++) {
const key = `nb${i}`;
const value = this.cabriService.currentActivity.currentVariables[key];
if (value) {
latexOperation = latexOperation.replace(
new RegExp(`\\$${key}\\$`, "g"),
value
.toFixed(8)
.replace(/\.?0+$/, "")
.replace(".", ",")
);
}
}
latexOperation = latexOperation.replace(/\//g, ":");
if (opType < 5 && latexOperation.indexOf(":") > -1) {
latexOperation = latexOperation.replace(/\)/g, "");
latexOperation = latexOperation.replace(/\(/g, "");
let frac = latexOperation.split(":");
latexOperation = "\\frac{" + frac[0] + "}{" + frac[1] + "}";
}
}
const latexResult =
endResult instanceof Fraction
? endResult.toLatex()
: Number(endResult.toString())
.toFixed(8)
.replace(/\.?0+$/, "")
.replace(".", ",");
const resultSvg = await MathJax.tex2svgPromise(latexResult);
// valeurs TTS
let ttsValues;
if (opType < 5) {
ttsValues = [nb1TTS, nb2TTS, nb3TTS, nb4TTS].filter(v => v !== undefined && v !== null).join(` ${opSignTTS} `);
} else {
ttsValues = opSignTTS;
for (let i = 1; i <= 4; i++) {
const key = `nb${i}`;
const value = this.cabriService.currentActivity.currentVariables[key];
if (value) {
ttsValues = ttsValues.replace(
new RegExp(`\\$${key}\\$`, "g"),
value
.toFixed(8)
.replace(/\.?0+$/, "")
.replace(".", ",")
);
}
}
}
let phrase;
if (this.page.needsHelp) {
phrase = this.getContextualFeedbackPhrase(AnswerStatus.ERROR2ND, responseTimeInSeconds, "", 0, 0, 0, 0, AnswerNeedsHelp.IGNORE);
} else {
phrase = this.getContextualFeedbackPhrase(AnswerStatus.ERROR2ND, responseTimeInSeconds);
}
// TODO => adapt next opération phrases to problem mode via scenario tags
const moonResult = new Array();
const firstCallback = async () => {
await this.page.waitEndOfAnimation;
await this.page.cabri.setOperation("full", this.page.operationResult.toString());
if (this.cabriService.collectionModeInCM) {
this.page.cabriService.moonResultCollection = true;
this.page.detectChanges();
}
if (!this.cabriService.mirrorMode) {
this.page.cabri.toggleOperationWrapperPosition("down");
} else {
this.page.cabri.toggleOperationWrapperPosition("up");
}
if(!this.accountService.user.isC3){
this.page.cabri.showOperationAndWrapper(); //Ne pas réafficher le calcul lors du résultat
}
};
if (this.page.sonicAward) {
moonResult.push(new ScenarioPhrase([" "], firstCallback).hideBubble());
} else {
moonResult.push(new ScenarioPhrase([phrase], firstCallback).setRandomMode());
}
const textScenario =
$localize`Regarde, la bonne réponse était : ` + `$$` + latexOperation + `$$` + $localize ` égale ` + `$$` + latexResult + `$$` + " !";
const textTTS = $localize`:tts:Regarde, la bonne réponse était : ${ttsValues} égale ${endResultTTS} !`;
moonResult.push(
new ScenarioPhrase(
[
textScenario
],
async () => {
await this.timeOut(3000);
if (this.cabriService.collectionModeInCM) {
this.page.cabriService.moonResultCollection = false;
this.page.detectChanges();
}
this.page.cabri.hideOperationAndWrapper();
this.page.showHideAward();
},
//[$localize`:tts:Regarde, la bonne réponse était : ${nb1TTS} ${opSignTTS} ${nb2TTS} égale ${endResultTTS} !`]
[$localize`:tts:Regarde, la bonne réponse était : ${ttsValues} égale ${endResultTTS} !`]
)
);
if (this.accountService.user.isC3) {
const rewardType = await this.getRewardType(); // doit être RewardType
const rewardInPhrase = getRewardNameInPhrase(rewardType); // "un diamant", "une étoile", etc.
moonResult.push(
new ScenarioPhrase(
[$localize`Tu as quand même gagné ${rewardInPhrase} !`, $localize`Nous avons quand même gagné ${rewardInPhrase} !`],
async () => {
await this.timeOut(1000);
}
).setRandomMode()
);
} else {
moonResult.push(
new ScenarioPhrase(
[$localize`Tu as quand même gagné une lune !`, $localize`Nous avons quand même gagné une lune !`],
async () => {
await this.timeOut(1000);
}
)
.setRandomMode()
.showAward("moon")
);
}
moonResult.push(
new ScenarioPhrase(
[
$localize`Passons à la prochaine opération !`,
$localize`Voyons si nous avons plus de chance avec la prochaine opération !`,
$localize`Essayons une autre cosmopération !`,
$localize`Allez, cap sur la prochaine opération !`,
// doit être compatible avec plusieurs joueurs / le nextPlayer sur la nextQuestion:
// "La prochaine opération va te donner la chance de te rattraper !",
$localize`Reprenons la bonne trajectoire avec le calcul suivant`,
$localize`Retournons à la barre, ce n’est pas fini !`,
$localize`C’est parti pour une nouvelle cosmopération !`,
$localize`Rectifions le cap avec la prochaine opération !`,
$localize`Allons chercher une étoile sur le prochain calcul !`,
$localize`Voyons si nous pouvons trouver le résultat de la prochaine cosmopération !`
],
async () => {
await this.timeOut(1000);
}
).setRandomMode()
);
await this.runMathiaSpeech(moonResult);
}
/**
* Mauvaise réponse avec affichage solution et question suivante pour le mode prononciation du nombre affiché
*/
async badResponseMoonWithResultZeroModeNextQOptional(nextQ = false, responseTimeInSeconds: number) {
const endResult = (
this.page.setOperationMode === "nb1" || this.page.setOperationMode === "nb2" ? this.page.operationResult : this.page.goodResult
).toString();
let endResultTTS = endResult;
if (endResultTTS === "1") {
endResultTTS = endResultTTS.replace("1", "un");
}
// TTS need text not symbols
let opSign = "";
switch (Number(this.cabriService.currentActivity.variables["v-cursor-op"])) {
case 1:
opSign = "+";
break;
case 2:
opSign = "*";
break;
case 3:
opSign = "-";
break;
case 4:
opSign = ":";
break;
default:
this.globalService.analyticService.sendAnalytics("no_cursor_op??", {
activity_id: this.cabriService.currentActivity.id,
activityVariables: JSON.stringify(this.cabriService.currentActivity.variables)
});
}
let opSignTTS = opSign.replace("−", $localize`moins`);
opSignTTS = opSignTTS.replace("-", $localize`moins`);
opSignTTS = opSignTTS.replace("×", $localize`fois`);
opSignTTS = opSignTTS.replace("*", $localize`fois`);
opSignTTS = opSignTTS.replace("+", $localize`plus`);
const phrase = this.getContextualFeedbackPhrase(AnswerStatus.ERROR2ND, responseTimeInSeconds);
const moonResult = new Array();
const firstCallback = async () => {
await this.page.waitEndOfAnimation;
if (!this.cabriService.mirrorMode) {
this.page.cabri.toggleOperationWrapperPosition("down");
} else {
this.page.cabri.toggleOperationWrapperPosition("up");
}
this.page.cabri.showOperationAndWrapper();
};
if (this.page.sonicAward) {
moonResult.push(new ScenarioPhrase([" "], firstCallback).hideBubble());
} else {
moonResult.push(new ScenarioPhrase([phrase], firstCallback).setRandomMode());
}
moonResult.push(
new ScenarioPhrase(
[$localize`Regarde, le nombre affiché était : ${endResult} !`],
async () => {
await this.timeOut(3000);
this.page.cabri.hideOperationAndWrapper();
this.page.showHideAward();
},
[$localize`:tts:Regarde, le nombre affiché était : ${endResultTTS} !`]
)
);
moonResult.push(
new ScenarioPhrase(
[$localize`Tu as quand même gagné une lune !`, $localize`Nous avons quand même gagné une lune !`],
async () => {
await this.timeOut(1000);
}
)
.setRandomMode()
.showAward("moon")
);
if (nextQ) {
const nextQuestion = new ScenarioPhrase(
[
$localize`Passons au prochain nombre !`,
$localize`Voyons si nous avons plus de chance avec le prochain nombre !`,
$localize`Essayons avec un autre nombre !`,
$localize`Allez, cap sur le prochain nombre !`,
$localize`Reprenons la bonne trajectoire avec le nombre suivant`,
$localize`Retournons à la barre, ce n’est pas fini !`,
$localize`C’est parti pour une nouvelle question !`,
$localize`Rectifions le cap avec le prochain nombre !`,
$localize`Allons chercher une étoile sur le prochain nombre !`,
$localize`Voyons si nous pouvons trouver le prochain nombre !`
],
async () => {
await this.timeOut(1000);
}
).setRandomMode();
moonResult.push(nextQuestion);
}
await this.runMathiaSpeech(moonResult);
}
/**
* Recommencer l’activité
*/
async restartActivity() {
const playRestart: Array<any> = [
new ScenarioPhrase([$localize`Une nouvelle expédition est parée au lancement ? Youpi !`]),
new ScenarioPhrase([$localize`C’est reparti pour un nouveau voyage dans l’espace des nombres !`])
];
await this.runMathiaSpeech(playRestart);
}
/**
* UNITS TUTORIAL part 1
*/
async unitsTutorial() {
// let this.help2NumberSeparation;
let unitsHelpMessageBubble;
let unitsHelpMessage1;
let unitsHelpMessage2;
let unitsHelpMessage3;
let unitsHelpMessage4;
let unitsHelpMessage5;
// Formatage:
let nb1 = "";
let nb1ThousandsString: string;
let nb1HundredsString: string;
let nb1TensString: string;
let nb1OnesString: string;
let separatorCount = 0;
if (this.cabriService.nb1.length === 4 && this.cabriService.nb1M !== 0) {
nb1ThousandsString = this.cabriService.nb1M + " " + this.cabriService.nb1Thousands;
}
if (this.cabriService.nb1.length >= 3 && this.cabriService.nb1C !== 0) {
nb1HundredsString = this.cabriService.nb1C + " " + this.cabriService.nb1Hundreds;
}
if (this.cabriService.nb1.length >= 2 && this.cabriService.nb1D !== 0) {
nb1TensString = this.cabriService.nb1D + " " + this.cabriService.nb1Tens;
}
if (this.cabriService.nb1.length >= 1 && this.cabriService.nb1U !== 0) {
nb1OnesString = this.cabriService.nb1U + " " + this.cabriService.nb1Units;
}
if (nb1ThousandsString) {
// should never happen // help disabled when thousands
nb1 = nb1ThousandsString;
}
if (nb1HundredsString) {
nb1 = nb1 + nb1HundredsString;
if (nb1TensString && nb1OnesString) {
separatorCount = 2;
nb1 = nb1 + ", ";
} else if (nb1TensString || nb1OnesString) {
nb1 = nb1 + " " + $localize`et` + " ";
separatorCount = 1;
}
}
if (nb1TensString) {
nb1 = nb1 + nb1TensString;
if (separatorCount === 2 || (separatorCount === 0 && nb1OnesString)) {
nb1 = nb1 + " " + $localize`et` + " ";
}
}
if (nb1OnesString) {
nb1 = nb1 + nb1OnesString;
}
// concat nb2 number + units:
let nb2 = "";
let nb2ThousandsString: string;
let nb2HundredsString: string;
let nb2TensString: string;
let nb2OnesString: string;
let separatorCount2 = 0;
if (this.cabriService.nb2.length === 4 && this.cabriService.nb2M !== 0) {
nb2ThousandsString = this.cabriService.nb2M + " " + this.cabriService.nb2Thousands;
}
if (this.cabriService.nb2.length >= 3 && this.cabriService.nb2C !== 0) {
nb2HundredsString = this.cabriService.nb2C + " " + this.cabriService.nb2Hundreds;
}
if (this.cabriService.nb2.length >= 2 && this.cabriService.nb2D !== 0) {
nb2TensString = this.cabriService.nb2D + " " + this.cabriService.nb2Tens;
}
if (this.cabriService.nb2.length >= 1 && this.cabriService.nb2U !== 0) {
nb2OnesString = this.cabriService.nb2U + " " + this.cabriService.nb2Units;
}
if (nb2ThousandsString) {
// should never happen // help disabled when thousands
nb2 = nb2ThousandsString;
}
if (nb2HundredsString) {
nb2 = nb2 + nb2HundredsString;
if (nb2TensString && nb2OnesString) {
separatorCount2 = 2;
nb2 = nb2 + ", ";
} else if (nb2TensString || nb2OnesString) {
nb2 = nb2 + " " + $localize`et` + " ";
separatorCount2 = 1;
}
}
if (nb2TensString) {
nb2 = nb2 + nb2TensString;
if (separatorCount2 === 2 || (separatorCount2 === 0 && nb2OnesString)) {
nb2 = nb2 + " " + $localize`et` + " ";
}
}
if (nb2OnesString) {
nb2 = nb2 + nb2OnesString;
}
// concat result number + units:
let res = "";
let resThousandsString: string;
let resHundredsString: string;
let resTensString: string;
let resOnesString: string;
let separatorCount3 = 0;
if (this.cabriService.result.length === 4 && this.cabriService.resM !== 0) {
resThousandsString = this.cabriService.resM + " " + this.cabriService.resThousands;
}
if (this.cabriService.result.length >= 3 && this.cabriService.resC !== 0) {
resHundredsString = this.cabriService.resC + " " + this.cabriService.resHundreds;
}
if (this.cabriService.result.length >= 2 && this.cabriService.resD !== 0) {
resTensString = this.cabriService.resD + " " + this.cabriService.resTens;
}
if (this.cabriService.result.length >= 1 && this.cabriService.resU !== 0) {
resOnesString = this.cabriService.resU + " " + this.cabriService.resUnits;
}
if (resThousandsString) {
// should never happen // help disabled when thousands
res = resThousandsString + ", ";
}
if (resHundredsString) {
res = res + resHundredsString;
if (resTensString && resOnesString) {
separatorCount3 = 2;
res = res + ", ";
} else if (resTensString || resOnesString) {
res = res + " " + $localize`et` + " ";
separatorCount3 = 1;
}
}
if (resTensString) {
res = res + resTensString;
if (separatorCount3 === 2 || (separatorCount3 === 0 && resOnesString)) {
res = res + " " + $localize`et` + " ";
}
}
if (resOnesString) {
res = res + resOnesString;
}
if (this.cabriService.result.length === 4) {
this.help2NumberSeparation = $localize`les milliers, les centaines, les dizaines et les unités `;
} else if (this.cabriService.result.length === 3) {
this.help2NumberSeparation = $localize` les centaines, les dizaines et les unités `;
} else if (this.cabriService.result.length === 2) {
this.help2NumberSeparation = $localize` les dizaines et les unités `;
} else if (this.cabriService.result.length === 1) {
this.help2NumberSeparation = $localize` les unités `;
}
// PASSAGE A LA DIZAINE SUP:
if (String(Number(this.cabriService.nb1U) + Number(this.cabriService.nb2U)).length === 2) {
const nb1nb2UResult = (Number(this.cabriService.nb1U) + Number(this.cabriService.nb2U)).toString();
unitsHelpMessageBubble = $localize`Regarde. ${this.cabriService.nb1}:operateur1: + ${this.cabriService.nb2}:operateur2:, c’est ${nb1}:operateur1Unite: + ${nb2}:operateur2Unite:. Avec ${nb1nb2UResult} unités, on peut faire une nouvelle dizaine. En tout, on obtient donc ${res}:resultatOpearation:.`;
unitsHelpMessage1 = $localize`Regarde. ${this.cabriService.nb1}:operateur1: plus ${this.cabriService.nb2}:operateur2:`;
unitsHelpMessage2 = $localize`c’est ${nb1}:operateur1Unite:`;
unitsHelpMessage3 = $localize`plus ${nb2}:operateur2Unite: .`;
unitsHelpMessage4 = $localize`Avec ${nb1nb2UResult} unités, on peut faire une nouvelle dizaine.`;
unitsHelpMessage5 = $localize`En tout, on obtient donc ${res}:resultatOpearation: .`;
unitsHelpMessage2 = unitsHelpMessage2
.replace($localize` 1 unité`, $localize` une unité`)
.replace($localize` 1 dizaine`, $localize` une dizaine`)
.replace($localize` 1 centaine`, $localize` une centaine`);
unitsHelpMessage3 = unitsHelpMessage3
.replace($localize` 1 unité`, $localize` une unité`)
.replace($localize` 1 dizaine`, $localize` une dizaine`)
.replace($localize` 1 centaine`, $localize` une centaine`);
unitsHelpMessage4 = unitsHelpMessage4
.replace($localize` 1 unité`, $localize` une unité`)
.replace($localize` 1 dizaine`, $localize` une dizaine`)
.replace($localize` 1 centaine`, $localize` une centaine`);
unitsHelpMessage5 = unitsHelpMessage5
.replace($localize` 1 unité`, $localize` une unité`)
.replace($localize` 1 dizaine`, $localize` une dizaine`)
.replace($localize` 1 centaine`, $localize` une centaine`);
const unitsTutorialDizaineSup: Array<any> = [
new ScenarioPhrase(
unitsHelpMessageBubble,
async () => {
this.page.activateButton("btn-toggle-help-nb1");
await this.timeOutNoSkip(500);
this.page.cabri.hackHelpImageRendering();
},
unitsHelpMessage1
),
new ScenarioPhrase(
unitsHelpMessageBubble,
async () => {
this.page.activateButton("btn-toggle-help-nb2");
await this.timeOutNoSkip(500);
this.page.cabri.hackHelpImageRendering();
},
unitsHelpMessage2
),
new ScenarioPhrase(
unitsHelpMessageBubble,
async () => {
this.page.activateButton("btn-show-help");
await this.timeOutNoSkip(500);
this.page.cabri.hackHelpImageRendering();
},
unitsHelpMessage3
),
new ScenarioPhrase(unitsHelpMessageBubble, async () => {}, unitsHelpMessage4),
new ScenarioPhrase(unitsHelpMessageBubble, async () => {}, unitsHelpMessage5)
];
await this.runMathiaSpeech(unitsTutorialDizaineSup);
} else {
// PAS DE PASSAGE DIZAINE SUP:
unitsHelpMessageBubble = $localize`Regarde. ${this.cabriService.nb1}:operateur1: + ${this.cabriService.nb2}:operateur2:, c’est ${nb1}:operateur1Unite: + ${nb2}:operateur2Unite:. En tout, on obtient donc ${res}:resultatOpearation:.`;
unitsHelpMessage1 = $localize`Regarde. ${this.cabriService.nb1}:operateur1: plus ${this.cabriService.nb2}:operateur2:`;
unitsHelpMessage2 = $localize`c’est ${nb1}`;
unitsHelpMessage3 = $localize`plus ${nb2} .`;
unitsHelpMessage4 = $localize`En tout, on obtient donc ${res}:resultatOpearation: .`;
unitsHelpMessage2 = unitsHelpMessage2
.replace($localize` 1 unité`, $localize` une unité`)
.replace($localize` 1 dizaine`, $localize` une dizaine`)
.replace($localize` 1 centaine`, $localize` une centaine`);
unitsHelpMessage3 = unitsHelpMessage3
.replace($localize` 1 unité`, $localize` une unité`)
.replace($localize` 1 dizaine`, $localize` une dizaine`)
.replace($localize` 1 centaine`, $localize` une centaine`);
unitsHelpMessage4 = unitsHelpMessage4
.replace($localize` 1 unité`, $localize` une unité`)
.replace($localize` 1 dizaine`, $localize` une dizaine`)
.replace($localize` 1 centaine`, $localize` une centaine`);
const unitsTutorial: Array<any> = [
new ScenarioPhrase(
unitsHelpMessageBubble,
async () => {
this.page.activateButton("btn-toggle-help-nb1");
await this.timeOutNoSkip(500);
this.page.cabri.hackHelpImageRendering();
},
unitsHelpMessage1
),
new ScenarioPhrase(
unitsHelpMessageBubble,
async () => {
this.page.activateButton("btn-toggle-help-nb2");
await this.timeOutNoSkip(500);
this.page.cabri.hackHelpImageRendering();
},
unitsHelpMessage2
),
new ScenarioPhrase(
unitsHelpMessageBubble,
async () => {
this.page.activateButton("btn-show-help");
await this.timeOutNoSkip(500);
this.page.cabri.hackHelpImageRendering();
},
unitsHelpMessage3
),
new ScenarioPhrase(unitsHelpMessageBubble, async () => {}, unitsHelpMessage4)
];
await this.runMathiaSpeech(unitsTutorial);
}
}
async unitsTutorial2() {
await this.page.cabri.toggleOperationSmallHelp(true);
this.cabriService.cabriInputNumpadStatus = false;
const wrapperPosition = !this.cabriService.mirrorMode ? "down" : "up";
this.page.cabri.toggleOperationWrapperPosition(wrapperPosition);
if (!this.page.cabri.paramDisplayMode || this.page.cabri.paramDisplayMode?.value !== "collection") {
this.page.cabri.showOperationAndWrapper();
}
this.page.cabri.hilightCDU();
const saveNB1 = Number(this.cabriService.nb1);
const saveNB2 = Number(this.cabriService.nb2);
let nb1 = saveNB1 % 10;
let nb2 = saveNB2 % 10;
this.page.setNumber1(nb1);
this.page.setNumber2(nb2);
await this.page.changeVariables(true);
await this.timeOutNoSkip(500);
this.page.cabri.hackHelpImageRendering();
this.detectChanges();
// unités
await this.runMathiaSpeech([
new ScenarioPhrase(
$localize`Commençons par les unités. ${nb1}:operateur1Unite: d'un côté et ${nb2}:operateur2Unite: de l’autre.`,
() => {},
$localize`Commençons par les unités.` +
" " +
(nb1 === 1 ? $localize`une` : nb1) +
" " +
$localize`d’un côté et` +
" " +
(nb2 === 1 ? $localize`une` : nb2) +
" " +
$localize`de l'autre.`
)
]);
for (let i = 0; i < nb1 + 1; i++) {
this.page.setNumber1(nb1 - i);
this.page.setNumber2(nb2 + i);
await this.page.changeVariables(true);
this.page.cabri.hackHelpImageRendering();
if (nb2 + i === 10) {
await this.readText($localize`Avec 10 unités, je fais une nouvelle dizaine.`);
}
await this.timeOutNoSkip(500);
}
let nbD = Math.floor((nb1 + nb2) / 10);
const nbU = (nb1 + nb2) % 10;
if (nbD > 0) {
await this.readText(
$localize`On obtient donc une dizaine et` + " " + (nbU === 1 ? $localize`une unité` : $localize`${nbU} unités`)
);
} else {
await this.readText($localize`On obtient donc` + " " + (nbU === 1 ? $localize`une unité` : $localize`${nbU} unités`));
}
if (saveNB1 > 9 || saveNB2 > 9) {
// dizaines
nb1 = Math.floor(saveNB1 / 10) % 10;
nb2 = Math.floor(saveNB2 / 10) % 10;
this.page.setNumber1(nb1 * 10);
this.page.setNumber2(nb2 * 10 + nbU);
await this.page.changeVariables(true);
await this.timeOutNoSkip(500);
this.page.cabri.hackHelpImageRendering();
await this.runMathiaSpeech([
new ScenarioPhrase(
$localize`Continuons avec les dizaines. ${nb1}:operateur1Unite: d'un côté et ${nb2}:operateur2Unite: de l’autre.`,
() => {},
$localize`Continuons avec les dizaines.` +
" " +
(nb1 === 1 ? $localize`une` : nb1) +
" " +
$localize`d’un côté et` +
" " +
(nb2 === 1 ? $localize`une` : nb2) +
" " +
$localize`de l'autre.`
)
]);
if (nbD > 0) {
await this.readText($localize`Sans oublier la retenue de l’addition des unités. On rajoute donc une dizaine.`);
nb1 = (Math.floor(saveNB1 / 10) % 10) + 1;
this.page.setNumber1(nb1 * 10);
await this.page.changeVariables(true);
await this.timeOutNoSkip(500);
this.page.cabri.hackHelpImageRendering();
}
for (let i = 0; i < nb1 + 1; i++) {
this.page.setNumber1((nb1 - i) * 10);
this.page.setNumber2((nb2 + i) * 10 + nbU);
await this.page.changeVariables(true);
this.page.cabri.hackHelpImageRendering();
if (nb2 + i === 10) {
await this.readText($localize`Avec 10 dizaines, je fais une nouvelle centaine.`);
}
await this.timeOutNoSkip(500);
}
let nbC = Math.floor((nb1 + nb2) / 10);
nbD = (nb1 + nb2) % 10;
if (nbC > 0) {
await this.readText(
$localize`On obtient donc une centaine et` + " " + (nbD === 1 ? $localize`une dizaine` : $localize`${nbD} dizaines`)
);
} else {
await this.readText($localize`On obtient donc` + " " + (nbD === 1 ? $localize`une dizaine` : $localize`${nbD} dizaines`));
}
if (saveNB1 > 99 || saveNB2 > 99) {
// centaines
nb1 = Math.floor(saveNB1 / 100) % 10;
nb2 = Math.floor(saveNB2 / 100) % 10;
this.page.setNumber1(nb1 * 100);
this.page.setNumber2(nb2 * 100 + nbD * 10 + nbU);
await this.page.changeVariables(true);
await this.timeOutNoSkip(500);
this.page.cabri.hackHelpImageRendering();
await this.runMathiaSpeech([
new ScenarioPhrase(
$localize`Continuons avec les centaines. ${nb1} d'un côté et ${nb2} de l’autre.`,
() => {},
$localize`Continuons avec les centaines.` +
" " +
(nb1 === 1 ? $localize`une` : nb1) +
" " +
$localize`d’un côté et` +
" " +
(nb2 === 1 ? $localize`une` : nb2) +
" " +
$localize`de l'autre.`
)
]);
if (nbC > 0) {
await this.readText($localize`Sans oublier la retenue de l’addition des dizaines. On rajoute donc une centaine.`);
nb1 = (Math.floor(saveNB1 / 100) % 10) + 1;
this.page.setNumber1(nb1 * 100);
await this.page.changeVariables(true);
this.page.cabri.hackHelpImageRendering();
await this.timeOutNoSkip(500);
}
for (let i = 0; i < Math.min(nb1 + 1, 11 - nb2); i++) {
this.page.setNumber1((nb1 - i) * 100);
this.page.setNumber2((nb2 + i) * 100 + nbD * 10 + nbU);
await this.page.changeVariables(true);
this.page.cabri.hackHelpImageRendering();
if (nb2 + i === 10) {
await this.readText($localize`Avec 10 centaines, je fais un nouveau millier.`);
}
await this.timeOutNoSkip(500);
}
let nbM = Math.floor((nb1 + nb2) / 10);
nbC = (nb1 + nb2) % 10;
if (nbM > 0) {
await this.readText(
$localize`On obtient donc un millier et` + " " + (nbC === 1 ? $localize`une centaine` : $localize`${nbC} centaines`)
);
} else {
await this.readText(
$localize`On obtient donc` + " " + (nbC === 1 ? $localize`une centaine` : $localize`${nbC} centaines`)
);
}
}
}
await AppUtils.timeOut(3000);
this.page.setNumber1(saveNB1);
this.page.setNumber2(saveNB2);
await this.page.changeVariables(true);
await this.timeOutNoSkip(500);
this.page.cabri.hackHelpImageRendering();
this.cabriService.cabriInputNumpadStatus = true;
this.page.cabri.toggleOperationWrapperPosition("up");
this.page.cabri.hideOperationAndWrapper();
}
/**
* UNITS TUTORIAL part 2 (validated)
*/
async unitsTutorialValidated() {
const speechSequence = [
new ScenarioPhrase(
$localize`Maintenant, essaye à nouveau de trouver le résultat en séparant ${this.help2NumberSeparation} comme nous l’avons vu.`,
async () => {}
),
new ScenarioPhrase($localize`Reprenons !`, async () => {})
];
await this.runMathiaSpeech(speechSequence);
}
async explainWriteOperationOut(nbNumbers) {
let phrase = $localize`Commence par saisir le chiffre des unités, puis celui des dizaines`;
if (nbNumbers > 2) {
phrase += $localize`, des centaines`;
}
if (nbNumbers > 3) {
phrase += " " + $localize` et des milliers`;
}
phrase += ".";
const speechSequence = [
new ScenarioPhrase($localize`Dans ce mode, les chiffres s’écrivent de droite à gauche.`),
new ScenarioPhrase(phrase)
];
await this.runMathiaSpeech(speechSequence);
}
async getRewardType() {
console.log("selectedSubDomain reward:", this.journeysService.selectedSubDomain?.reward);
return this.journeysService.selectedSubDomain?.reward;
}
}