@vived/app 2.25.0 → 2.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ import { Babylon, HoverLabels, MouseController, MouseInput, MouseInputEvent } from "../Entities";
2
+ import { Vector2 } from "../ValueObjects";
3
+ export declare class HoverLabelMouse implements MouseController {
4
+ private hoverLabels;
5
+ private currentTimeout;
6
+ tryHoverLabelUC: (position: Vector2) => void;
7
+ readonly hoverLabelDelay = 500;
8
+ onMove: (e: MouseInputEvent) => void;
9
+ constructor(hoverLabels: HoverLabels, mouseInput: MouseInput, babylon: Babylon);
10
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HoverLabelMouse = void 0;
4
+ const trySetHoverLabel_1 = require("../UseCases/HoverLabels/trySetHoverLabel");
5
+ class HoverLabelMouse {
6
+ constructor(hoverLabels, mouseInput, babylon) {
7
+ this.hoverLabels = hoverLabels;
8
+ this.hoverLabelDelay = 500;
9
+ this.onMove = (e) => {
10
+ this.hoverLabels.hideHoverLabel();
11
+ if (this.currentTimeout) {
12
+ clearTimeout(this.currentTimeout);
13
+ }
14
+ this.currentTimeout = setTimeout(() => {
15
+ this.tryHoverLabelUC(e.position);
16
+ this.currentTimeout = undefined;
17
+ }, this.hoverLabelDelay);
18
+ };
19
+ mouseInput.registerController(this);
20
+ this.tryHoverLabelUC = trySetHoverLabel_1.makeTrySetHoverLabel(hoverLabels, babylon);
21
+ }
22
+ }
23
+ exports.HoverLabelMouse = HoverLabelMouse;
@@ -0,0 +1,14 @@
1
+ import { Babylon, HoverLabels, TouchController, TouchInput, TouchInputEvent } from "../Entities";
2
+ import { Vector2 } from "../ValueObjects";
3
+ export declare const touchLabelDragThreshold = 15;
4
+ export declare class HoverLabelTouch implements TouchController {
5
+ private hoverLabels;
6
+ private lastPosition;
7
+ private startPosition;
8
+ private touchStarted;
9
+ tryHoverLabelUC: (position: Vector2) => void;
10
+ onTouchStart: (e: TouchInputEvent) => void;
11
+ onTouchMove: (e: TouchInputEvent) => void;
12
+ onTouchEnd: () => void;
13
+ constructor(hoverLabels: HoverLabels, touchInput: TouchInput, babylon: Babylon);
14
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HoverLabelTouch = exports.touchLabelDragThreshold = void 0;
4
+ const UseCases_1 = require("../UseCases");
5
+ const ValueObjects_1 = require("../ValueObjects");
6
+ exports.touchLabelDragThreshold = 15;
7
+ class HoverLabelTouch {
8
+ constructor(hoverLabels, touchInput, babylon) {
9
+ this.hoverLabels = hoverLabels;
10
+ this.lastPosition = ValueObjects_1.Vector2.Zero();
11
+ this.startPosition = ValueObjects_1.Vector2.Zero();
12
+ this.touchStarted = false;
13
+ this.onTouchStart = (e) => {
14
+ this.hoverLabels.hideHoverLabel();
15
+ this.touchStarted = false;
16
+ if (e.touchCount !== 1)
17
+ return;
18
+ this.startPosition = e.touches[0].position;
19
+ this.lastPosition = e.touches[0].position;
20
+ this.touchStarted = true;
21
+ };
22
+ this.onTouchMove = (e) => {
23
+ if (!this.touchStarted)
24
+ return;
25
+ this.lastPosition = e.touches[0].position;
26
+ };
27
+ this.onTouchEnd = () => {
28
+ if (!this.touchStarted)
29
+ return;
30
+ const xDiff = this.lastPosition.x - this.startPosition.x;
31
+ const yDiff = this.lastPosition.y - this.startPosition.y;
32
+ const dist = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
33
+ if (dist < exports.touchLabelDragThreshold) {
34
+ this.tryHoverLabelUC(this.lastPosition);
35
+ }
36
+ };
37
+ touchInput.registerController(this);
38
+ this.tryHoverLabelUC = UseCases_1.makeTrySetHoverLabel(hoverLabels, babylon);
39
+ }
40
+ }
41
+ exports.HoverLabelTouch = HoverLabelTouch;
@@ -1 +1,3 @@
1
1
  export * from "./ToolHotkeys";
2
+ export * from "./HoverLabelTouch";
3
+ export * from "./HoverLabelMouse";
@@ -11,3 +11,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./ToolHotkeys"), exports);
14
+ __exportStar(require("./HoverLabelTouch"), exports);
15
+ __exportStar(require("./HoverLabelMouse"), exports);
@@ -0,0 +1,42 @@
1
+ import { Vector2 } from "../ValueObjects";
2
+ import { ObservableEntity } from "./ObservableEntity";
3
+ export declare abstract class HoverLabels extends ObservableEntity {
4
+ /**
5
+ * Should the label be shown
6
+ */
7
+ abstract get show(): boolean;
8
+ /**
9
+ * Pixel coordinates of the label
10
+ */
11
+ abstract get position(): Vector2;
12
+ /**
13
+ * String to display
14
+ */
15
+ abstract get label(): string;
16
+ /**
17
+ * Gets if hover labels should be allowed
18
+ */
19
+ abstract get allowHoverLabels(): boolean;
20
+ /**
21
+ * Sets if hover labels should be shown. Will notify
22
+ */
23
+ abstract set allowHoverLabels(allow: boolean);
24
+ /**
25
+ * Sets up a label for a scene object by id
26
+ */
27
+ abstract setLabelForSceneObject: (sceneObjectID: string, label: string) => void;
28
+ /**
29
+ * Removes the labels for a scene object by id
30
+ */
31
+ abstract removeLabelForSceneObject: (sceneObjectID: string) => void;
32
+ /**
33
+ * Tries to get a label for a scene object by id. Returns undefined if one does not exist
34
+ */
35
+ abstract getLabelFroSceneObject: (sceneObjectID: string) => string | undefined;
36
+ /**
37
+ * Sets up the system to show a label for a scene object at a given position
38
+ */
39
+ abstract showLabelForSceneObject: (sceneObjectID: string, position: Vector2) => void;
40
+ abstract hideHoverLabel: () => void;
41
+ }
42
+ export declare function makeHoverLabels(): HoverLabels;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeHoverLabels = exports.HoverLabels = void 0;
4
+ const ValueObjects_1 = require("../ValueObjects");
5
+ const MemoizedBoolean_1 = require("./MemoizedBoolean");
6
+ const ObservableEntity_1 = require("./ObservableEntity");
7
+ class HoverLabels extends ObservableEntity_1.ObservableEntity {
8
+ }
9
+ exports.HoverLabels = HoverLabels;
10
+ function makeHoverLabels() {
11
+ return new HoverLabelsImp();
12
+ }
13
+ exports.makeHoverLabels = makeHoverLabels;
14
+ class HoverLabelsImp extends HoverLabels {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.labelLookup = new Map();
18
+ this._show = false;
19
+ this._position = ValueObjects_1.Vector2.Zero();
20
+ this._label = "";
21
+ this.memoizedAllow = new MemoizedBoolean_1.MemoizedBoolean(true, this.notify);
22
+ this.setLabelForSceneObject = (sceneObjectID, label) => {
23
+ this.labelLookup.set(sceneObjectID, label);
24
+ };
25
+ this.removeLabelForSceneObject = (sceneObjectID) => {
26
+ this.labelLookup.delete(sceneObjectID);
27
+ };
28
+ this.getLabelFroSceneObject = (sceneObjectID) => {
29
+ return this.labelLookup.get(sceneObjectID);
30
+ };
31
+ this.showLabelForSceneObject = (sceneObjectID, position) => {
32
+ var _a;
33
+ if (this.labelLookup.has(sceneObjectID)) {
34
+ this.doShow((_a = this.labelLookup.get(sceneObjectID)) !== null && _a !== void 0 ? _a : "", position);
35
+ }
36
+ else {
37
+ this.hideHoverLabel();
38
+ }
39
+ };
40
+ this.hideHoverLabel = () => {
41
+ if (!this._show)
42
+ return;
43
+ this._show = false;
44
+ this._label = "";
45
+ this._position = ValueObjects_1.Vector2.Zero();
46
+ this.notify();
47
+ };
48
+ }
49
+ get show() {
50
+ return this._show;
51
+ }
52
+ get position() {
53
+ return this._position;
54
+ }
55
+ get label() {
56
+ return this._label;
57
+ }
58
+ get allowHoverLabels() {
59
+ return this.memoizedAllow.val;
60
+ }
61
+ set allowHoverLabels(allow) {
62
+ if (allow === this.memoizedAllow.val)
63
+ return;
64
+ this.memoizedAllow.val = allow;
65
+ if (allow === false) {
66
+ this.hideHoverLabel();
67
+ }
68
+ }
69
+ doShow(label, pos) {
70
+ if (!this.allowHoverLabels)
71
+ return;
72
+ if (label === this._label &&
73
+ ValueObjects_1.Vector2.Equal(pos, this._position) &&
74
+ this.show) {
75
+ return;
76
+ }
77
+ this._label = label;
78
+ this._position = pos;
79
+ this._show = true;
80
+ this.notify();
81
+ }
82
+ }
@@ -1,6 +1,7 @@
1
1
  export * from "./Babylon";
2
2
  export * from "./BaseApp";
3
3
  export * from "./DevicePreview";
4
+ export * from "./HoverLabels";
4
5
  export * from "./KeyboardInput";
5
6
  export * from "./MemoizedBoolean";
6
7
  export * from "./MemoizedNumber";
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./Babylon"), exports);
14
14
  __exportStar(require("./BaseApp"), exports);
15
15
  __exportStar(require("./DevicePreview"), exports);
16
+ __exportStar(require("./HoverLabels"), exports);
16
17
  __exportStar(require("./KeyboardInput"), exports);
17
18
  __exportStar(require("./MemoizedBoolean"), exports);
18
19
  __exportStar(require("./MemoizedNumber"), exports);
@@ -0,0 +1,17 @@
1
+ import { HoverLabels } from "../Entities";
2
+ import { PresentionManager } from "./PresentationManager";
3
+ export interface HoverLabelVM {
4
+ show: boolean;
5
+ text: string;
6
+ position: {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ }
11
+ export declare class HoverLabelPM extends PresentionManager {
12
+ private hoverLabel;
13
+ private updateView;
14
+ doUpdateView: () => void;
15
+ constructor(hoverLabel: HoverLabels, updateView: (vm: HoverLabelVM) => void);
16
+ static defaultHoverLabelVM: HoverLabelVM;
17
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HoverLabelPM = void 0;
4
+ const PresentationManager_1 = require("./PresentationManager");
5
+ class HoverLabelPM extends PresentationManager_1.PresentionManager {
6
+ constructor(hoverLabel, updateView) {
7
+ super(hoverLabel);
8
+ this.hoverLabel = hoverLabel;
9
+ this.updateView = updateView;
10
+ this.doUpdateView = () => {
11
+ const vm = {
12
+ show: false,
13
+ text: "",
14
+ position: { x: 0, y: 0 },
15
+ };
16
+ if (this.hoverLabel.show) {
17
+ vm.show = true;
18
+ vm.text = this.hoverLabel.label;
19
+ vm.position.x = this.hoverLabel.position.x;
20
+ vm.position.y = this.hoverLabel.position.y;
21
+ }
22
+ this.updateView(vm);
23
+ };
24
+ this.doUpdateView();
25
+ }
26
+ }
27
+ exports.HoverLabelPM = HoverLabelPM;
28
+ HoverLabelPM.defaultHoverLabelVM = {
29
+ show: false,
30
+ text: "",
31
+ position: { x: 0, y: 0 },
32
+ };
@@ -0,0 +1,9 @@
1
+ import { HoverLabels } from "../../Entities";
2
+ import { PresentionManager } from "../PresentationManager";
3
+ export declare class AllowHoverLabelPM extends PresentionManager {
4
+ private hoverLabel;
5
+ private updateView;
6
+ private lastState?;
7
+ doUpdateView: () => void;
8
+ constructor(hoverLabel: HoverLabels, updateView: (allow: boolean) => void);
9
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AllowHoverLabelPM = void 0;
4
+ const PresentationManager_1 = require("../PresentationManager");
5
+ class AllowHoverLabelPM extends PresentationManager_1.PresentionManager {
6
+ constructor(hoverLabel, updateView) {
7
+ super(hoverLabel);
8
+ this.hoverLabel = hoverLabel;
9
+ this.updateView = updateView;
10
+ this.doUpdateView = () => {
11
+ if (this.lastState === this.hoverLabel.allowHoverLabels)
12
+ return;
13
+ this.updateView(this.hoverLabel.allowHoverLabels);
14
+ this.lastState = this.hoverLabel.allowHoverLabels;
15
+ };
16
+ this.doUpdateView();
17
+ }
18
+ }
19
+ exports.AllowHoverLabelPM = AllowHoverLabelPM;
@@ -0,0 +1,17 @@
1
+ import { HoverLabels } from "../../Entities";
2
+ import { PresentionManager } from "../PresentationManager";
3
+ export interface HoverLabelVM {
4
+ show: boolean;
5
+ text: string;
6
+ position: {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ }
11
+ export declare class HoverLabelPM extends PresentionManager {
12
+ private hoverLabel;
13
+ private updateView;
14
+ doUpdateView: () => void;
15
+ constructor(hoverLabel: HoverLabels, updateView: (vm: HoverLabelVM) => void);
16
+ static defaultHoverLabelVM: HoverLabelVM;
17
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HoverLabelPM = void 0;
4
+ const PresentationManager_1 = require("../PresentationManager");
5
+ class HoverLabelPM extends PresentationManager_1.PresentionManager {
6
+ constructor(hoverLabel, updateView) {
7
+ super(hoverLabel);
8
+ this.hoverLabel = hoverLabel;
9
+ this.updateView = updateView;
10
+ this.doUpdateView = () => {
11
+ const vm = {
12
+ show: false,
13
+ text: "",
14
+ position: { x: 0, y: 0 },
15
+ };
16
+ if (this.hoverLabel.show) {
17
+ vm.show = true;
18
+ vm.text = this.hoverLabel.label;
19
+ vm.position.x = this.hoverLabel.position.x;
20
+ vm.position.y = this.hoverLabel.position.y;
21
+ }
22
+ this.updateView(vm);
23
+ };
24
+ this.doUpdateView();
25
+ }
26
+ }
27
+ exports.HoverLabelPM = HoverLabelPM;
28
+ HoverLabelPM.defaultHoverLabelVM = {
29
+ show: false,
30
+ text: "",
31
+ position: { x: 0, y: 0 },
32
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./HoverLabelPM";
2
+ export * from "./AllowHoverLabelPM";
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./HoverLabelPM"), exports);
14
+ __exportStar(require("./AllowHoverLabelPM"), exports);
@@ -9,3 +9,4 @@ export * from "./QuestionChallenge";
9
9
  export * from "./FocusCameraPosRotPM";
10
10
  export * from "./ToolPM";
11
11
  export * from "./TransformNodePM";
12
+ export * from "./HoverLabels";
@@ -21,3 +21,4 @@ __exportStar(require("./QuestionChallenge"), exports);
21
21
  __exportStar(require("./FocusCameraPosRotPM"), exports);
22
22
  __exportStar(require("./ToolPM"), exports);
23
23
  __exportStar(require("./TransformNodePM"), exports);
24
+ __exportStar(require("./HoverLabels"), exports);
@@ -0,0 +1,14 @@
1
+ import { HoverLabels, SerializedSystem, StateMachine } from "../../Entities";
2
+ export declare class SerializeAllowHoverLabel implements SerializedSystem {
3
+ private hoverLabels;
4
+ name: string;
5
+ seriliziationVersion: number;
6
+ getSystemState(): object;
7
+ applySystemState(state: object, version: number): void;
8
+ applyDefaultState(): void;
9
+ private applyDataV1;
10
+ constructor(hoverLabels: HoverLabels, stateMachine: StateMachine);
11
+ }
12
+ export interface AllowHoverLabelV1 {
13
+ allow: boolean;
14
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SerializeAllowHoverLabel = void 0;
4
+ class SerializeAllowHoverLabel {
5
+ constructor(hoverLabels, stateMachine) {
6
+ this.hoverLabels = hoverLabels;
7
+ this.name = "allowHoverLabel";
8
+ this.seriliziationVersion = 1;
9
+ stateMachine.registerSerializedSystem(this);
10
+ }
11
+ getSystemState() {
12
+ const state = {
13
+ allow: this.hoverLabels.allowHoverLabels
14
+ };
15
+ return state;
16
+ }
17
+ applySystemState(state, version) {
18
+ if (state && version === 1) {
19
+ const castState = state;
20
+ this.applyDataV1(castState);
21
+ }
22
+ else {
23
+ // Unsupported version
24
+ console.warn(`Unsupported data version ${version} for serialized system ${this.name}. Reverting to default state`);
25
+ this.applyDefaultState();
26
+ }
27
+ }
28
+ applyDefaultState() {
29
+ this.hoverLabels.allowHoverLabels = true;
30
+ }
31
+ applyDataV1(data) {
32
+ this.hoverLabels.allowHoverLabels = data.allow;
33
+ }
34
+ }
35
+ exports.SerializeAllowHoverLabel = SerializeAllowHoverLabel;
@@ -0,0 +1,3 @@
1
+ import { Babylon, HoverLabels } from "../../Entities";
2
+ import { Vector2 } from "../../ValueObjects";
3
+ export declare function makeTrySetHoverLabel(hoverLabels: HoverLabels, babylon: Babylon): (position: Vector2) => void;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeTrySetHoverLabel = void 0;
4
+ function makeTrySetHoverLabel(hoverLabels, babylon) {
5
+ return function trySetHoverLabel(position) {
6
+ babylon.sceneObjectPick(position).then(sceneObjectID => {
7
+ hoverLabels.showLabelForSceneObject(sceneObjectID, position);
8
+ });
9
+ };
10
+ }
11
+ exports.makeTrySetHoverLabel = makeTrySetHoverLabel;
@@ -3,3 +3,5 @@ export * from "./FocusCamera";
3
3
  export * from "./QuestionChallenge";
4
4
  export * from "./LerpVector3";
5
5
  export * from "./SceneRoot";
6
+ export * from "./HoverLabels/trySetHoverLabel";
7
+ export * from "./HoverLabels/SerializeAllowHoverLabel";
@@ -15,3 +15,5 @@ __exportStar(require("./FocusCamera"), exports);
15
15
  __exportStar(require("./QuestionChallenge"), exports);
16
16
  __exportStar(require("./LerpVector3"), exports);
17
17
  __exportStar(require("./SceneRoot"), exports);
18
+ __exportStar(require("./HoverLabels/trySetHoverLabel"), exports);
19
+ __exportStar(require("./HoverLabels/SerializeAllowHoverLabel"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vived/app",
3
- "version": "2.25.0",
3
+ "version": "2.26.0",
4
4
  "description": "Public package for the VIVED Learning App system",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",