File

src/app/models/cabri-integration-galaxiedescalculs.ts

Constructor

constructor(cabriService: CabriDataService, globalService: GlobalService, _ngZone: any, page: any, renderer: Renderer2)

Methods

updateCabriPosition
updateCabriPosition(holoMode: string)

Update DOM Cabri elements

Parameters :
  • holoMode

    Holo mode

  • platform

    Platform

Returns: any
onBabylonReady
onBabylonReady()
Returns: any
updateCabriBackground
updateCabriBackground(renderCanvas: any, condition: any)
Returns: void
checkActivityChange
checkActivityChange()
Returns: boolean
saveDom
saveDom()
Returns: void
restoreDom
restoreDom(activityChange: boolean)
Returns: void
getCurrentOperation
getCurrentOperation()
Returns: void
clearResponse
clearResponse()
Returns: any
setResponse
setResponse(value: any)
Returns: void

Properties

_ngZone
_ngZone: any
cabriService
cabriService: CabriDataService
Public castelGrid
castelGrid: CastelGrid
globalService
globalService: GlobalService
page
page: any
renderer
renderer: Renderer2
Public selectedCellNumber
selectedCellNumber: number
import { CabriIntegration } from "./cabri-integration";
import { CabriDataService } from "../services/cabri-data.service";
import { GlobalService } from "../services/global.service";
import { Platform } from "@ionic/angular";
import { ElementRef, Renderer2 } from "@angular/core";
import { CastelGrid } from "./castel-grid";

declare var window: {
	store: any;
	document: any;
	innerWidth: any;
	innerHeight: any;
	outerWidth: any;
	outerHeight: any;
};

export class CabriIntegrationGalaxieDesCalculs extends CabriIntegration {
	public castelGrid: CastelGrid;
	public selectedCellNumber: number;

	constructor(
		public cabriService: CabriDataService,
		public globalService: GlobalService,
		public _ngZone,
		public page,
		public renderer: Renderer2
	) {
		super(cabriService, globalService, _ngZone, page, renderer);
		this.cabriRenderStarted = true;
		this.page = page;
	}

	// RESIZE REDONE
	/**
	 * Update DOM Cabri elements
	 * @param holoMode Holo mode
	 * @param platform Platform
	 */
	updateCabriPosition(holoMode: string = null): Promise<void> {
		return super.updateCabriPosition(holoMode, "galaxie");
	}

	onBabylonReady(): Promise<void> {
		return new Promise(async (resolve, reject) => {
			await super.onBabylonReady();
			await this.importMascotteMeshes(1.14, 1.2);
			this.scene.onAfterRenderObservable.addOnce(() => {
				this.unlockRotation();
				this.camera.alpha = -Math.PI / 2;
				window.store.getters.cps.setPageOrientation(this.camera.alpha, this.camera.beta);
				this.replaceCabriLights();
				resolve();
			});
		});
	}

	async updateCabriBackground(renderCanvas, condition) {
		window.store.getters.cabri.Scene.meshes.forEach(async m => {
			// m.doNotSyncBoundingInfo = true;
			// m.freezeWorldMatrix();
			// m.convertToUnIndexedMesh();
			if (m.id === "background") {
				this.checkFlatHoloMode(m);
				await this.switchBackgroundLauncher(m, renderCanvas.clientHeight, renderCanvas.clientWidth);
				// background width proportion = 4096/3072 = 1.333333:
				if (condition === 2) {
					m.scaling.x = 1.1;
					m.scaling.z = 1.1;
				}
				console.log("cabri background resized");
			}
		});
	}

	checkActivityChange(): boolean {
		return true;
		const activityChange =
			this.cabriService.currentSavedDom !== "galaxiedescalculs" ||
			this.cabriService.savedDomHoloMode !== this.cabriService.holoMode ||
			this.cabriService.savedDomMirrorMode !== this.cabriService.mirrorMode;
		// console.log("checkActivityChange = " + activityChange);
		return activityChange;
	}

	saveDom() {
		super.saveDom();
		this.cabriService.currentSavedDom = "galaxiedescalculs";
	}

	restoreDom(activityChange: boolean = false) {
		super.restoreDom();
		window.document.querySelector("#page-div section").style.opacity = "1";
		window.document.querySelector("#page-div").style.height = window.innerHeight;

		if (activityChange) {
			// clean all custom elements in #page-div
			if (
				window.document.querySelector("#page-div #operationWrapper") &&
				window.document.querySelector("#page-div #operationWrapper").length > 0
			) {
				window.document.querySelector("#page-div").removeChild(window.document.querySelector("#page-div #operationWrapper"));
			}
			if (
				window.document.querySelector("#page-div #operationWrapperCordova") &&
				window.document.querySelector("#page-div #operationWrapperCordova").length > 0
			) {
				window.document.querySelector("#page-div").removeChild(window.document.querySelector("#page-div #operationWrapperCordova"));
			}
		}

		this.startRender();
	}
	// getCurrentOperation(): string {
	// 	let str = "";

	// 	const nbGR = window.store.getters.cps.getValueByName("v-good-responses").value;
	// 	const a = window.store.getters.cps.getValueByName("v-first-number").value;
	// 	const c = window.store.getters.cps.getValueByName("v-operation").value;
	// 	const pas = window.store.getters.cps.getValueByName("v-pas").value;

	// 	str = a + nbGR * c * pas + (c > 0 ? " + " : " - ") + pas;
	// 	return str;
	// }

	getCurrentOperation() {
		let operation = "";
		const currentCell = this.castelGrid.getCellById(this.selectedCellNumber);
		if (!currentCell) {
			return;
		}
		operation += this.castelGrid.cells[0][currentCell.col].value;

		if (this.castelGrid.mode === "addition" || this.castelGrid.mode === "addition-classic") {
			operation += " + ";
		} else if (this.castelGrid.mode === "multiplication") {
			operation += " × ";
		} else if (this.castelGrid.mode === "soustraction") {
			operation += " - ";
		}

		operation += this.castelGrid.cells[currentCell.row][0].value;

		return operation;
	}

	clearResponse(): Promise<any> {
		// selector
		// #cabriText-34531 > div > div.editor-container > div.editor-content > div > p
		// if(window.document.querySelector('.ZDR .svg-container')){
		//   window.document.querySelector('.ZDR .svg-container').innerHTML = '';
		// }
		// if(window.document.querySelector('.theZDR p')){
		//   window.document.querySelector('.theZDR p').innerHTML = '';
		//   window.document.querySelector('.theZDR').style.opacity = '0';
		// }
		return;
	}

	setResponse(value: any) {
		// display response
		// window.document.querySelector('.theZDR p').innerHTML = value;
		// window.document.querySelector('.theZDR').style.opacity = '1';
	}
}

results matching ""

    No results matching ""