From 5926f3b613a30001e708701976670c7344b0e917 Mon Sep 17 00:00:00 2001 From: Mountler Date: Mon, 24 Feb 2025 11:24:04 +0100 Subject: [PATCH] refactored proximity check --- .../ILearningElementController.ts | 9 +++-- .../LearningElementController.ts | 25 +++++++++----- .../LearningElements/LearningElementView.ts | 33 ++++++++++--------- .../Babylon/SceneManagement/ScenePresenter.ts | 2 -- 4 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/Components/Core/Presentation/Babylon/LearningElements/ILearningElementController.ts b/src/Components/Core/Presentation/Babylon/LearningElements/ILearningElementController.ts index 8bf527d6a..d1209b624 100644 --- a/src/Components/Core/Presentation/Babylon/LearningElements/ILearningElementController.ts +++ b/src/Components/Core/Presentation/Babylon/LearningElements/ILearningElementController.ts @@ -1,7 +1,12 @@ import { ActionEvent } from "@babylonjs/core"; -export default interface ILearningElementController { - picked( overrideIsInteractable?: boolean): void; +interface IAccessibilityControls { + accessibilityPicked(): void; +} + +export default interface ILearningElementController + extends IAccessibilityControls { + picked(event?: ActionEvent): void; pointerOver(event?: ActionEvent): void; pointerOut(event?: ActionEvent): void; } diff --git a/src/Components/Core/Presentation/Babylon/LearningElements/LearningElementController.ts b/src/Components/Core/Presentation/Babylon/LearningElements/LearningElementController.ts index 40aeb5c3d..b2bad90c6 100644 --- a/src/Components/Core/Presentation/Babylon/LearningElements/LearningElementController.ts +++ b/src/Components/Core/Presentation/Babylon/LearningElements/LearningElementController.ts @@ -42,16 +42,25 @@ export default class LearningElementController } } + @bind + picked(): void { + if (this.viewModel.isInteractable.Value) { + this.onPicked(); + } + } + + @bind + accessibilityPicked(): void { + this.onPicked(); + } @bind - picked(overrideIsInteractable?: boolean): void { - if (this.viewModel.isInteractable.Value || overrideIsInteractable) { - this.bottomTooltipPresenter.hideAll(); - if (this.viewModel.type === LearningElementTypes.adaptivity) { - this.startLoadAdaptivityElementUseCase(); - } else { - this.startLoadElementUseCase(); - } + private onPicked() { + this.bottomTooltipPresenter.hideAll(); + if (this.viewModel.type === LearningElementTypes.adaptivity) { + this.startLoadAdaptivityElementUseCase(); + } else { + this.startLoadElementUseCase(); } } diff --git a/src/Components/Core/Presentation/Babylon/LearningElements/LearningElementView.ts b/src/Components/Core/Presentation/Babylon/LearningElements/LearningElementView.ts index 7b9af5976..15a0fc101 100644 --- a/src/Components/Core/Presentation/Babylon/LearningElements/LearningElementView.ts +++ b/src/Components/Core/Presentation/Babylon/LearningElements/LearningElementView.ts @@ -89,32 +89,34 @@ export default class LearningElementView { true, )) as Mesh[]; - this.viewModel.modelMeshes[0].accessibilityTag = { description: this.viewModel.name + " " + this.viewModel.id, // @ts-ignore - eventHandler:{ + eventHandler: { click: () => { // this.viewModel.isInteractable.Value = true; - this.controller.picked(true); - + this.controller.accessibilityPicked(); + // get position on screen - const canvas = this.scenePresenter.Scene.getEngine().getRenderingCanvas(); - const position = this.viewModel.modelMeshes[0].getPositionInCameraSpace(this.scenePresenter.Scene.activeCamera!); - + const canvas = + this.scenePresenter.Scene.getEngine().getRenderingCanvas(); + const position = + this.viewModel.modelMeshes[0].getPositionInCameraSpace( + this.scenePresenter.Scene.activeCamera!, + ); + // simulate click on that position - const event = new MouseEvent('click', { + const event = new MouseEvent("click", { view: window, bubbles: true, cancelable: true, clientX: position.x, - clientY: position.y + clientY: position.y, }); canvas!.dispatchEvent(event); - - } - } - } + }, + }, + }; // position and rotate model this.viewModel.modelMeshes[0].position = this.viewModel.position; @@ -177,9 +179,8 @@ export default class LearningElementView { // register interaction callbacks actionManager.registerAction( - new ExecuteCodeAction( - ActionManager.OnPickTrigger, - (e) => this.controller.picked(false), + new ExecuteCodeAction(ActionManager.OnPickTrigger, (e) => + this.controller.picked(), ), ); actionManager.registerAction( diff --git a/src/Components/Core/Presentation/Babylon/SceneManagement/ScenePresenter.ts b/src/Components/Core/Presentation/Babylon/SceneManagement/ScenePresenter.ts index c46742dc7..739242bb0 100644 --- a/src/Components/Core/Presentation/Babylon/SceneManagement/ScenePresenter.ts +++ b/src/Components/Core/Presentation/Babylon/SceneManagement/ScenePresenter.ts @@ -20,7 +20,6 @@ import ILoggerPort from "src/Components/Core/Application/Ports/Interfaces/ILogge import CORE_TYPES from "~DependencyInjection/CoreTypes"; import { LogLevelTypes } from "src/Components/Core/Domain/Types/LogLevelTypes"; import { Inspector } from "@babylonjs/inspector"; -import {HTMLTwinRenderer} from "@babylonjs/accessibility"; /** * @description This class is responsible for creating the Scene and managing the NavMesh navigation. @@ -111,7 +110,6 @@ export default class ScenePresenter implements IScenePresenter { sceneOptions?: SceneOptions, ): Promise { await this.sceneDefinition.createScene(engine, sceneOptions); - } disposeScene(): void {