File

src/app/models/quizz/scenario-quizz.ts

Constructor

constructor(accountService: AccountService, globalService: GlobalService, page: any, cd: ChangeDetectorRef, ttsService: any, oseJourneyService: any)

Methods

runMathiaSpeech
runMathiaSpeech(speechSequence: any, consigne: any)

runMathiaSpeech launcher to display quizz bubble

Parameters :
  • speechSequence

    Array

  • consigne

    obsolete? to remove after testing

Returns: void
readCustomText
readCustomText(consigne: string)

to read a text through the scenario engine (with bubble & events handling)

Parameters :
  • consigne

    text to process

Returns: void
playIntro
playIntro()
Returns: void
askCurrentQuestionAndReadAnswers
askCurrentQuestionAndReadAnswers(skipQuestion: boolean)

TTS sequence of quizz current question (consigne) + answers enumerated

Returns: any
readGoodAnswers
readGoodAnswers()

Reads the correct answer through TTS for remediation

Returns: void
goodResponseShooting
goodResponseShooting()

Bonne réponse avec récompense (étoile filante)

Returns: void
badAnswerCustomAndShowResults
badAnswerCustomAndShowResults(text: string, readGoodAnswers: boolean, timeout: number)

Triggered if bad answer -> reads custom text & triggers remediation (this.readGoodAnswers())

Parameters :
  • text

    text to read

  • readGoodAnswers

    remediation on/off

  • timeout

    to give a little space after phrase if no remediation - skipable

Returns: void
dontKnowShowResults
dontKnowShowResults(multipleGoodAnswers: boolean, readGoodAnswers: boolean, timeout: number)

TTS sequence triggered if user didn't know (joker) + remediation

Parameters :
  • multipleGoodAnswers

    boolean

  • readGoodAnswers

    remediation on/off

  • timeout

    duration value for remediation timeOut

Returns: void
readFeedbackFiche
readFeedbackFiche(feedback: string)

convert feedback from fiche raw text to a speechSequence & run it in runMathiaSpeech()
splits punctuation / removeLineBreaksFromString

Returns: void
nextPlayerInit
nextPlayerInit()

Scenario sequence for multiplayer mode initialization

Returns: void
nextQuestion
nextQuestion()
Returns: void
nextPlayerSwitch
nextPlayerSwitch()
Returns: void
customText
customText(text: string)
Returns: void
endOfActivity
endOfActivity()
Returns: void
skipMathiaSpeechSequence
skipMathiaSpeechSequence(data: any)

skip the scenario sequence on skip button click or manual call from anywhere - handles feedback fiche skip

Parameters :
  • data
Returns: void

Properties

currentPhrase
currentPhrase: { index: number; type: string; }
oseJourneyService
oseJourneyService: any
randomIndex
randomIndex: number
ttsService
ttsService: any
import { FicheComponent } from "src/app/components/fiche/fiche.component";
import { PlayTTSService } from "src/app/services/play-tts.service";
import { ScenarioOse } from "./../scenario-ose";
import { AppUtils } from "./../../app-utils";
import { ChangeDetectorRef } from "@angular/core";
import { AccountService } from "../../services/account.service";
import { GlobalService } from "../../services/global.service";
import { ScenarioPhrase } from "./../scenario-phrase";
import { Fiche } from "../fiche";
import { QuizzPage } from "src/app/page/quizz/quizz.page";
import { OseJourneyService } from "src/app/services/ose-journeys.service";

export class ScenarioQuizz extends ScenarioOse {
	randomIndex: number;
	currentPhrase: { index: number; type: string };
	constructor(
		accountService: AccountService,
		globalService: GlobalService,
		page: QuizzPage,
		cd: ChangeDetectorRef,
		public ttsService: PlayTTSService,
		public oseJourneyService: OseJourneyService
	) {
		super(accountService, globalService, oseJourneyService, page, cd, ttsService);
		this.currentPhrase = { index: 0, type: undefined };
	}

	/**
	 * runMathiaSpeech launcher to display quizz bubble
	 * @param speechSequence Array<ScenarioPhrase>
	 * @param consigne obsolete? to remove after testing
	 */
	async runMathiaSpeech(speechSequence, consigne?) {
		await this.globalService.speechBubbleComponent?.displayGlobalBubble(false);
		this.page.displayBubble(true);
		await super.runMathiaSpeech(speechSequence);
		this.page.displayBubble(false);
	}

	/**
	 * to read a text through the scenario engine (with bubble & events handling)
	 * @param consigne text to process
	 */
	async readCustomText(consigne: string) {
		const speechSequence: Array<any> = [new ScenarioPhrase([consigne]).keepBubbleOn()];
		await this.runMathiaSpeech(speechSequence);
	}

	async playIntro() {
		const speechSequence = [
			new ScenarioPhrase([$localize`Bonjour ${this.page.currentUser?.preview?"":this.page.currentUser.name} !`]).setRandomMode(),
			
			// new ScenarioPhrase([$localize`C’est parti !`]).setRandomMode()
		];
		if(this.page.quizz.theme !== 'test'){
			speechSequence.push(
				new ScenarioPhrase([
					$localize`Faisons un petit quiz sur ${this.page.quizz.theme} !`,
					$localize`Testons tes connaissances sur ${this.page.quizz.theme} !`
				]).setRandomMode()
			)
		} else {
			speechSequence.push(
				new ScenarioPhrase([
					$localize`Faisons un petit quiz pour tester tes connaissances !`
				]).setRandomMode()
			)
		}
		await this.runMathiaSpeech(speechSequence);
		
	}

	/**
	 * TTS sequence of quizz current question (consigne) + answers enumerated
	 */
	async askCurrentQuestionAndReadAnswers(skipQuestion = false): Promise<void> {
		return new Promise(async (resolve, reject) => {
			if(!skipQuestion){
				const speechSequence = [new ScenarioPhrase(this.page.quizz.currentQuestion.text, async () => {})];

				this.page.quizz.currentQuestion.answers.forEach(answer => {
					if (answer.text.toLowerCase() === "je ne sais pas") {
						speechSequence.push(new ScenarioPhrase("Tu ne sais pas ?"));
					} else {
						speechSequence.push(new ScenarioPhrase(`"${answer.text + " ?"}"`));
					}
				})
			
				await this.runMathiaSpeech(speechSequence);
			}
			resolve();
		});
	}

	/**
	 * Reads the correct answer through TTS for remediation
	 */
	async readGoodAnswers() {
		// this.page.quizzPad.highlightGoodAnswer(this.page.quizz.goodAnswersIds[0]);
		const speechSequence = [
			new ScenarioPhrase(`"${this.page.quizz.goodAnswers[0].text}"`, async () => {
				await this.timeOut(1000);
			})
		];
		if (this.page.quizz.goodAnswers.length > 1) {
			speechSequence.push(
				new ScenarioPhrase([$localize`Mais aussi`, $localize`Et aussi`], () => {
					// this.page.quizzPad.highlightGoodAnswer(this.page.quizz.goodAnswersIds[1]);
				}).setRandomMode()
			);
			speechSequence.push(new ScenarioPhrase(`"${this.page.quizz.goodAnswers[1].text}"`));
		}
		if (this.page.quizz.goodAnswers.length > 2) {
			speechSequence.push(
				new ScenarioPhrase([$localize`Ou encore`, $localize`Et enfin`], () => {
					// this.page.quizzPad.highlightGoodAnswer(this.page.quizz.goodAnswersIds[2]);
				}).setRandomMode()
			);
			speechSequence.push(new ScenarioPhrase(`"${this.page.quizz.goodAnswers[2].text}"`));
		}
		await this.runMathiaSpeech(speechSequence);
	}

	/**
	 * Bonne réponse avec récompense (étoile filante)
	 */
	async goodResponseShooting() {
		const speechSequence = [new ScenarioPhrase([$localize`Oui ! Bravo !`])];
		await this.runMathiaSpeech(speechSequence);
	}

	/**
	 * Triggered if bad answer -> reads custom text & triggers remediation (this.readGoodAnswers())
	 * @param text text to read
	 * @param readGoodAnswers remediation on/off
	 * @param timeout to give a little space after phrase if no remediation - skipable
	 */
	async badAnswerCustomAndShowResults(text: string, readGoodAnswers = false, timeout = 10000) {
		this.page.quizzPad.showPadResults(true);
		const speechSequence: Array<any> = [
			new ScenarioPhrase([text], async () => {
				if (!this.skipSequence) {
					if (readGoodAnswers) {
						await this.readGoodAnswers();
					} else {
						await this.timeOutCancelable(timeout);
					}
				}
			}).keepBubbleOn()
		];
		await this.runMathiaSpeech(speechSequence);
	}

	/**
	 * TTS sequence triggered if user didn't know (joker) + remediation
	 * @param multipleGoodAnswers boolean
	 * @param readGoodAnswers remediation on/off
	 * @param timeout duration value for remediation timeOut
	 */
	async dontKnowShowResults(multipleGoodAnswers: boolean, readGoodAnswers = false, timeout = 10000) {
		let speechSequence: Array<any>;
		const callback = async () => {
			if (!this.skipSequence) {
				this.page.quizzPad.showPadResults(true);
				if (readGoodAnswers) {
					await this.readGoodAnswers();
				} else {
					await this.timeOutCancelable(timeout);
				}
			}
		};
		if (multipleGoodAnswers) {
			speechSequence = [
				new ScenarioPhrase(
					[
						$localize`Tu ne sais pas ? Les bonnes réponses étaient...`,
						$localize`Il y avait plusieurs bonnes réponses, regarde !`
					],
					callback
				)
					.setRandomMode()
					.keepBubbleOn()
			];
		} else {
			speechSequence = [
				new ScenarioPhrase([$localize`Tu ne sais pas ? La bonne réponse était celle-ci`], callback).setRandomMode().keepBubbleOn()
			];
		}
		await this.runMathiaSpeech(speechSequence);
	}

	/**
	 * convert feedback from fiche raw text to a speechSequence & run it in runMathiaSpeech()
	 * splits punctuation / removeLineBreaksFromString
	 */
	async readFeedbackFiche(feedback: string) {
		if (feedback.indexOf('"wp-block-group__inner-container"') > -1) {
			feedback = feedback;
		} else {
			feedback = feedback.replace(
				'<div id="fiche-container">',
				"<div id='fiche-container'><div class='wp-block-group'><div class='wp-block-group__inner-container'>"
			);
			feedback += "</div></div>";
		}
		const fiche = new Fiche(feedback, this.page.renderer);
		this.page.cd.detectChanges();
		(this.page.ficheComponent as FicheComponent).readingFeedback = true;
		const feedbackSequence = fiche.ficheTextContent[0];
		await this.readSpeechSequenceFromFicheContent(feedbackSequence);
		// if users needs help to figure out what to do:
		// const speechSequence = [];
		// speechSequence.push(
		// 	new ScenarioPhrase("Appuie sur le bouton en bas à droite pour passer à la question suivante", async () => {
		// 		debugger;
		// 		(this.page.ficheComponent as FicheComponent).readingFeedback = false;
		// 		await this.waitResolveFromOutside();
		// 		console.error("waitResolveFromOutside resolved ");
		// 	}).keepBubbleOn()
		// );
		// await this.runMathiaSpeech(speechSequence);
		(this.page.ficheComponent as FicheComponent).readingFeedback = false;
		await this.waitResolveFromOutside();
	}

	/**
	 * Scenario sequence for multiplayer mode initialization
	 */
	async nextPlayerInit() {
		const nextPlayerInit: Array<any> = [
			new ScenarioPhrase([
				$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.preview?"":this.page.currentUser.name}:playerName: !`,
				$localize`À toi de commencer ${this.page.currentUser.preview?"":this.page.currentUser.name}:playerName: !`,
				$localize`${this.page.currentUser.preview?"":this.page.currentUser.name}:playerName:, à toi l’honneur de répondre en premier !`
			]).setRandomMode(),
			new ScenarioPhrase([
				$localize`Allons-y !`,
				$localize`C’est parti !`
			])
		];
		await this.runMathiaSpeech(nextPlayerInit);
	}

	async nextQuestion() {
		const nextPlayerContent: Array<any> = [
			new ScenarioPhrase([
				// $localize`Passons à la question suivante !`,
				$localize`Continuons !`
				// $localize`Allez, question suivante !`
			]).setRandomMode()
		];
		await this.runMathiaSpeech(nextPlayerContent);
	}

	async nextPlayerSwitch() {
		const nextPlayerContent: Array<any> = [
			new ScenarioPhrase([
				$localize`Maintenant c’est à ${this.page.currentUser.preview?"":this.page.currentUser.name}:playerName: de piloter ! Vas-y ! ${this.page.currentUser.preview?"":this.page.currentUser.name} !`,
				$localize`Maintenant à toi ${this.page.currentUser.preview?"":this.page.currentUser.name}:playerName: ! Vas-y !`,
				$localize`À ton tour ${this.page.currentUser.preview?"":this.page.currentUser.name}:playerName: !`,
				$localize`À toi ${this.page.currentUser.preview?"":this.page.currentUser.name}:playerName: !`,
				$localize`Maintenant à ton tour ${this.page.currentUser.preview?"":this.page.currentUser.name}:playerName: ! Vas-y !`,
				$localize`${this.page.currentUser.preview?"":this.page.currentUser.name}:playerName: ? Tu es toujours là ? À toi de jouer !`,
				$localize`Et maintenant c’est à... ${this.page.currentUser.preview?"":this.page.currentUser.name}:playerName: !`,
				$localize`À ${this.page.currentUser.preview?"":this.page.currentUser.name}:playerName: maintenant !`,
				$localize`${this.page.currentUser.preview?"":this.page.currentUser.name}:playerName:, à toi !`,
				$localize`Quel voyage ! À toi ${this.page.currentUser.preview?"":this.page.currentUser.name}:playerName: !`
			]).setRandomMode()
		];
		await this.runMathiaSpeech(nextPlayerContent);
	}

	async customText(text: string) {
		const speechSequence: Array<any> = [new ScenarioPhrase([text], async () => {}).keepBubbleOn()];
		await this.runMathiaSpeech(speechSequence);
	}

	async endOfActivity() {
		const speechSequence: Array<any> = [new ScenarioPhrase([$localize`Super ${this.page.currentUser.preview?"":this.page.currentUser.name}:playerName: ! Tu as terminé ce quiz !`], async () => {}).keepBubbleOn()];
		await this.runMathiaSpeech(speechSequence);
	}

	/**
	 * skip the scenario sequence on skip button click or manual call from anywhere - handles feedback fiche skip
	 * @param data
	 */
	async skipMathiaSpeechSequence(data: any) {
		if (this.resolveScenarioCallbackFromOutside) {
			console.error("scenario-quizz.skipMathiaSpeechSequence -> this.resolveScenarioCallbackFromOutside()");
			this.resolveScenarioCallbackFromOutside();
			this.resolveScenarioCallbackFromOutside = null;
		} else {
			super.skipMathiaSpeechSequence(data);
		}
	}
}

results matching ""

    No results matching ""