@vived/app 2.12.0 → 2.15.2
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.
- package/lib/Entities/Babylon.js +1 -1
- package/lib/Entities/FocusCamera.js +9 -9
- package/lib/Entities/MemoizedBoolean.d.ts +1 -0
- package/lib/Entities/MemoizedBoolean.js +3 -0
- package/lib/Entities/MemoizedNumber.d.ts +1 -0
- package/lib/Entities/MemoizedNumber.js +3 -0
- package/lib/Entities/MemoizedString.d.ts +1 -0
- package/lib/Entities/MemoizedString.js +3 -0
- package/lib/Entities/MemoizedVector2.d.ts +1 -0
- package/lib/Entities/MemoizedVector2.js +4 -1
- package/lib/Entities/MemoizedVector3.d.ts +1 -0
- package/lib/Entities/MemoizedVector3.js +4 -1
- package/lib/Entities/MouseInput.d.ts +11 -5
- package/lib/Entities/MouseInput.js +21 -6
- package/lib/Entities/QuestionChallenge.d.ts +21 -0
- package/lib/Entities/QuestionChallenge.js +103 -0
- package/lib/Entities/QuestionChallengeAnswer.d.ts +32 -0
- package/lib/Entities/QuestionChallengeAnswer.js +51 -0
- package/lib/Entities/TouchInput.d.ts +15 -7
- package/lib/Entities/TouchInput.js +53 -24
- package/lib/Entities/index.d.ts +2 -0
- package/lib/Entities/index.js +2 -0
- package/lib/PresentationManagers/QuestionChallenge/AuthorQuestionChallengeAnswerPM.d.ts +24 -0
- package/lib/PresentationManagers/QuestionChallenge/AuthorQuestionChallengeAnswerPM.js +65 -0
- package/lib/PresentationManagers/QuestionChallenge/AuthorQuestionChallengePM.d.ts +17 -0
- package/lib/PresentationManagers/QuestionChallenge/AuthorQuestionChallengePM.js +46 -0
- package/lib/PresentationManagers/QuestionChallenge/QuestionChallengeAnswerPM.d.ts +17 -0
- package/lib/PresentationManagers/QuestionChallenge/QuestionChallengeAnswerPM.js +51 -0
- package/lib/PresentationManagers/QuestionChallenge/QuestionChallengePM.d.ts +15 -0
- package/lib/PresentationManagers/QuestionChallenge/QuestionChallengePM.js +34 -0
- package/lib/PresentationManagers/QuestionChallenge/index.d.ts +4 -0
- package/lib/PresentationManagers/QuestionChallenge/index.js +16 -0
- package/lib/PresentationManagers/index.d.ts +1 -0
- package/lib/PresentationManagers/index.js +1 -0
- package/lib/UseCases/FocusCamera/BumpDollyFocusCamera.js +3 -3
- package/lib/UseCases/FocusCamera/PinchDollyFocusCamera.js +3 -3
- package/lib/UseCases/FocusCamera/PixelDollyFocusCamera.js +3 -3
- package/lib/UseCases/FocusCamera/PixelOrbitFocusCamera.js +1 -1
- package/lib/UseCases/FocusCamera/PixelPlanePanFocusCamera.js +1 -1
- package/lib/UseCases/QuestionChallenge/SerializeQuestionChallenge.d.ts +25 -0
- package/lib/UseCases/QuestionChallenge/SerializeQuestionChallenge.js +70 -0
- package/lib/UseCases/QuestionChallenge/index.d.ts +4 -0
- package/lib/UseCases/QuestionChallenge/index.js +16 -0
- package/lib/UseCases/QuestionChallenge/setQuesionChallengeAnswerFeedback.d.ts +2 -0
- package/lib/UseCases/QuestionChallenge/setQuesionChallengeAnswerFeedback.js +16 -0
- package/lib/UseCases/QuestionChallenge/setQuesionChallengeAnswerText.d.ts +2 -0
- package/lib/UseCases/QuestionChallenge/setQuesionChallengeAnswerText.js +16 -0
- package/lib/UseCases/QuestionChallenge/toggleQuesionChallengeAnswerIsCorrect.d.ts +2 -0
- package/lib/UseCases/QuestionChallenge/toggleQuesionChallengeAnswerIsCorrect.js +16 -0
- package/lib/UseCases/index.d.ts +1 -0
- package/lib/UseCases/index.js +1 -0
- package/lib/ValueObjects/Angle.d.ts +2 -2
- package/lib/ValueObjects/Angle.js +2 -2
- package/lib/ValueObjects/Color.d.ts +4 -8
- package/lib/ValueObjects/Color.js +9 -21
- package/lib/ValueObjects/LineSegment2D.d.ts +4 -6
- package/lib/ValueObjects/LineSegment2D.js +27 -30
- package/lib/ValueObjects/ParametricLine.d.ts +1 -1
- package/lib/ValueObjects/ParametricLine.js +8 -8
- package/lib/ValueObjects/ParametricPlane.d.ts +1 -1
- package/lib/ValueObjects/ParametricPlane.js +10 -10
- package/lib/ValueObjects/Vector2.d.ts +11 -11
- package/lib/ValueObjects/Vector2.js +14 -14
- package/lib/ValueObjects/Vector3.d.ts +16 -16
- package/lib/ValueObjects/Vector3.js +18 -18
- package/package.json +1 -1
package/lib/Entities/Babylon.js
CHANGED
|
@@ -78,7 +78,7 @@ class BabylonImp {
|
|
|
78
78
|
this.sceneRay = rayer;
|
|
79
79
|
};
|
|
80
80
|
this.memoizedShowInspector = new MemoizedBoolean_1.MemoizedBoolean(false, this.observers.notify);
|
|
81
|
-
this.memoizedCanvasSize = new MemoizedVector2_1.MemoizedVector2(ValueObjects_1.Vector2.
|
|
81
|
+
this.memoizedCanvasSize = new MemoizedVector2_1.MemoizedVector2(ValueObjects_1.Vector2.One(), this.observers.notify);
|
|
82
82
|
}
|
|
83
83
|
get showInspector() {
|
|
84
84
|
return this.memoizedShowInspector.val;
|
|
@@ -14,7 +14,7 @@ class FocusCameraImp {
|
|
|
14
14
|
this.defaultAlpha = 0;
|
|
15
15
|
this.defaultBeta = 30;
|
|
16
16
|
this.defaultRadius = 8;
|
|
17
|
-
this.defaultTarget = ValueObjects_1.Vector3.
|
|
17
|
+
this.defaultTarget = ValueObjects_1.Vector3.Zero();
|
|
18
18
|
this.limitRadius = false;
|
|
19
19
|
this.minRadius = 0;
|
|
20
20
|
this.maxRadius = 0;
|
|
@@ -25,13 +25,13 @@ class FocusCameraImp {
|
|
|
25
25
|
this.minBeta = 0;
|
|
26
26
|
this.maxBeta = 0;
|
|
27
27
|
this.limitTarget = false;
|
|
28
|
-
this.maxTargetPosition = ValueObjects_1.Vector3.
|
|
29
|
-
this.minTargetPosition = ValueObjects_1.Vector3.
|
|
28
|
+
this.maxTargetPosition = ValueObjects_1.Vector3.Zero();
|
|
29
|
+
this.minTargetPosition = ValueObjects_1.Vector3.Zero();
|
|
30
30
|
this.observers = new _1.ObserverList();
|
|
31
31
|
this.memoizedAlpha = new _1.MemoizedNumber(0, this.observers.notify);
|
|
32
32
|
this.memoizedBeta = new _1.MemoizedNumber(0, this.observers.notify);
|
|
33
33
|
this.memoizedRadius = new _1.MemoizedNumber(1, this.observers.notify);
|
|
34
|
-
this.memoizedTarget = new _1.MemoizedVector3(ValueObjects_1.Vector3.
|
|
34
|
+
this.memoizedTarget = new _1.MemoizedVector3(ValueObjects_1.Vector3.Zero(), this.observers.notify);
|
|
35
35
|
this.setRadiusLimits = (min, max) => {
|
|
36
36
|
if (min < 0) {
|
|
37
37
|
throw new Error("[Orbit Camera] Mininum Radius must be greater >= 0");
|
|
@@ -103,8 +103,8 @@ class FocusCameraImp {
|
|
|
103
103
|
this.target = this.target;
|
|
104
104
|
};
|
|
105
105
|
this.clearTargetLimits = () => {
|
|
106
|
-
this.maxTargetPosition = ValueObjects_1.Vector3.
|
|
107
|
-
this.minTargetPosition = ValueObjects_1.Vector3.
|
|
106
|
+
this.maxTargetPosition = ValueObjects_1.Vector3.Zero();
|
|
107
|
+
this.minTargetPosition = ValueObjects_1.Vector3.Zero();
|
|
108
108
|
this.limitTarget = false;
|
|
109
109
|
};
|
|
110
110
|
this.registerLerp = (lerper) => {
|
|
@@ -210,7 +210,7 @@ class FocusCameraImp {
|
|
|
210
210
|
targetVals[i] = v;
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
|
-
this.memoizedTarget.val = ValueObjects_1.Vector3.
|
|
213
|
+
this.memoizedTarget.val = ValueObjects_1.Vector3.FromArray(targetVals);
|
|
214
214
|
}
|
|
215
215
|
get direction() {
|
|
216
216
|
const yLength = -Math.sin(this.degToRad(this.beta));
|
|
@@ -221,8 +221,8 @@ class FocusCameraImp {
|
|
|
221
221
|
return new ValueObjects_1.Vector3(xLength, yLength, zLength);
|
|
222
222
|
}
|
|
223
223
|
get cameraPosition() {
|
|
224
|
-
const localOffset = ValueObjects_1.Vector3.
|
|
225
|
-
return ValueObjects_1.Vector3.
|
|
224
|
+
const localOffset = ValueObjects_1.Vector3.NewVectorOfLength(this.direction, -this.radius);
|
|
225
|
+
return ValueObjects_1.Vector3.Add(this.target, localOffset);
|
|
226
226
|
}
|
|
227
227
|
degToRad(degrees) {
|
|
228
228
|
return (degrees * Math.PI) / 180;
|
|
@@ -11,10 +11,13 @@ class MemoizedVector2 {
|
|
|
11
11
|
return this._val;
|
|
12
12
|
}
|
|
13
13
|
set val(v) {
|
|
14
|
-
if (ValueObjects_1.Vector2.
|
|
14
|
+
if (ValueObjects_1.Vector2.Equal(v, this._val))
|
|
15
15
|
return;
|
|
16
16
|
this._val = v;
|
|
17
17
|
this.onChangeCallback();
|
|
18
18
|
}
|
|
19
|
+
setValQuietly(val) {
|
|
20
|
+
this._val = val;
|
|
21
|
+
}
|
|
19
22
|
}
|
|
20
23
|
exports.MemoizedVector2 = MemoizedVector2;
|
|
@@ -11,10 +11,13 @@ class MemoizedVector3 {
|
|
|
11
11
|
return this._val;
|
|
12
12
|
}
|
|
13
13
|
set val(v) {
|
|
14
|
-
if (Vector3_1.Vector3.
|
|
14
|
+
if (Vector3_1.Vector3.Equal(v, this._val))
|
|
15
15
|
return;
|
|
16
16
|
this._val = v;
|
|
17
17
|
this.onChangeCallback();
|
|
18
18
|
}
|
|
19
|
+
setValQuietly(val) {
|
|
20
|
+
this._val = val;
|
|
21
|
+
}
|
|
19
22
|
}
|
|
20
23
|
exports.MemoizedVector3 = MemoizedVector3;
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { Vector2 } from "../ValueObjects";
|
|
2
|
+
export interface MouseInputEvent {
|
|
3
|
+
position: Vector2;
|
|
4
|
+
button: number;
|
|
5
|
+
event: MouseEvent;
|
|
6
|
+
}
|
|
1
7
|
export interface MouseController {
|
|
2
|
-
onClick?: (e:
|
|
3
|
-
onDown?: (e:
|
|
4
|
-
onUp?: (e:
|
|
5
|
-
onMove?: (e:
|
|
6
|
-
onWheel?: (e:
|
|
8
|
+
onClick?: (e: MouseInputEvent) => void;
|
|
9
|
+
onDown?: (e: MouseInputEvent) => void;
|
|
10
|
+
onUp?: (e: MouseInputEvent) => void;
|
|
11
|
+
onMove?: (e: MouseInputEvent) => void;
|
|
12
|
+
onWheel?: (e: MouseInputEvent) => void;
|
|
7
13
|
}
|
|
8
14
|
export interface MouseInput {
|
|
9
15
|
eventElement: HTMLElement | undefined;
|
|
@@ -43,9 +43,10 @@ class MouseInputImp {
|
|
|
43
43
|
};
|
|
44
44
|
this.onMouseDown = (e) => {
|
|
45
45
|
e.preventDefault();
|
|
46
|
+
const inputEvt = this.makeMouseInputEvent(e);
|
|
46
47
|
this.controllers.forEach((c) => {
|
|
47
48
|
if (c.onDown) {
|
|
48
|
-
c.onDown(
|
|
49
|
+
c.onDown(inputEvt);
|
|
49
50
|
}
|
|
50
51
|
});
|
|
51
52
|
this.isPressed = true;
|
|
@@ -53,9 +54,10 @@ class MouseInputImp {
|
|
|
53
54
|
};
|
|
54
55
|
this.onMouseUp = (e) => {
|
|
55
56
|
e.preventDefault();
|
|
57
|
+
const inputEvt = this.makeMouseInputEvent(e);
|
|
56
58
|
this.controllers.forEach((c) => {
|
|
57
59
|
if (c.onUp) {
|
|
58
|
-
c.onUp(
|
|
60
|
+
c.onUp(inputEvt);
|
|
59
61
|
}
|
|
60
62
|
});
|
|
61
63
|
this.isPressed = false;
|
|
@@ -67,7 +69,7 @@ class MouseInputImp {
|
|
|
67
69
|
if (delta.magnitued < this.maxClickMovement) {
|
|
68
70
|
this.controllers.forEach((c) => {
|
|
69
71
|
if (c.onClick) {
|
|
70
|
-
c.onClick(
|
|
72
|
+
c.onClick(inputEvt);
|
|
71
73
|
}
|
|
72
74
|
});
|
|
73
75
|
}
|
|
@@ -75,9 +77,10 @@ class MouseInputImp {
|
|
|
75
77
|
};
|
|
76
78
|
this.onMouseMove = (e) => {
|
|
77
79
|
e.preventDefault();
|
|
80
|
+
const inputEvt = this.makeMouseInputEvent(e);
|
|
78
81
|
this.controllers.forEach((c) => {
|
|
79
82
|
if (c.onMove) {
|
|
80
|
-
c.onMove(
|
|
83
|
+
c.onMove(inputEvt);
|
|
81
84
|
}
|
|
82
85
|
});
|
|
83
86
|
if (!this.pressEvent)
|
|
@@ -93,9 +96,10 @@ class MouseInputImp {
|
|
|
93
96
|
e.preventDefault();
|
|
94
97
|
if (!this.isPressed)
|
|
95
98
|
return;
|
|
99
|
+
const inputEvt = this.makeMouseInputEvent(e);
|
|
96
100
|
this.controllers.forEach((c) => {
|
|
97
101
|
if (c.onUp) {
|
|
98
|
-
c.onUp(
|
|
102
|
+
c.onUp(inputEvt);
|
|
99
103
|
}
|
|
100
104
|
});
|
|
101
105
|
this.pressEvent = undefined;
|
|
@@ -103,9 +107,10 @@ class MouseInputImp {
|
|
|
103
107
|
};
|
|
104
108
|
this.onWheel = (e) => {
|
|
105
109
|
e.preventDefault();
|
|
110
|
+
const inputEvt = this.makeMouseInputEvent(e);
|
|
106
111
|
this.controllers.forEach((c) => {
|
|
107
112
|
if (c.onWheel) {
|
|
108
|
-
c.onWheel(
|
|
113
|
+
c.onWheel(inputEvt);
|
|
109
114
|
}
|
|
110
115
|
});
|
|
111
116
|
};
|
|
@@ -113,4 +118,14 @@ class MouseInputImp {
|
|
|
113
118
|
get eventElement() {
|
|
114
119
|
return this._eventElement;
|
|
115
120
|
}
|
|
121
|
+
makeMouseInputEvent(event) {
|
|
122
|
+
const px = event.offsetX;
|
|
123
|
+
const py = event.offsetY;
|
|
124
|
+
const button = event.button;
|
|
125
|
+
return {
|
|
126
|
+
position: new ValueObjects_1.Vector2(px, py),
|
|
127
|
+
button,
|
|
128
|
+
event,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
116
131
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { QuestionChallengeAnswer } from "./QuestionChallengeAnswer";
|
|
2
|
+
export declare type OnQuestionChallengeChange = () => void;
|
|
3
|
+
export interface QuestionChallenge {
|
|
4
|
+
gotItRight: boolean;
|
|
5
|
+
tries: number;
|
|
6
|
+
text: string;
|
|
7
|
+
addAnswer: (answer: QuestionChallengeAnswer) => void;
|
|
8
|
+
removeAnswer: (id: string) => void;
|
|
9
|
+
getAnswer: (id: string) => QuestionChallengeAnswer | undefined;
|
|
10
|
+
getAllAnswers: () => QuestionChallengeAnswer[];
|
|
11
|
+
hasAnswer: (id: string) => boolean;
|
|
12
|
+
createAnswer: (text: string) => QuestionChallengeAnswer;
|
|
13
|
+
removeAllAnswers: () => void;
|
|
14
|
+
setDefaultState: () => void;
|
|
15
|
+
reset: () => void;
|
|
16
|
+
submitAnswer: (id: string) => void;
|
|
17
|
+
setIDGenerator: (generator: () => string) => void;
|
|
18
|
+
addObserver: (observer: OnQuestionChallengeChange) => void;
|
|
19
|
+
removeObserver: (observer: OnQuestionChallengeChange) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare function makeQuestionChallenge(): QuestionChallenge;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeQuestionChallenge = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const QuestionChallengeAnswer_1 = require("./QuestionChallengeAnswer");
|
|
6
|
+
function makeQuestionChallenge() {
|
|
7
|
+
return new QuestionChallengeImp();
|
|
8
|
+
}
|
|
9
|
+
exports.makeQuestionChallenge = makeQuestionChallenge;
|
|
10
|
+
class QuestionChallengeImp {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.answerLookup = new Map();
|
|
13
|
+
this.observers = new _1.ObserverList();
|
|
14
|
+
this._tries = 0;
|
|
15
|
+
this._gotItRight = false;
|
|
16
|
+
this.memoizedText = new _1.MemoizedString("", this.observers.notify);
|
|
17
|
+
this.generateID = () => {
|
|
18
|
+
const randomNumber = Math.random() * Date.now();
|
|
19
|
+
return `${randomNumber}`;
|
|
20
|
+
};
|
|
21
|
+
this.setIDGenerator = (generator) => {
|
|
22
|
+
this.generateID = generator;
|
|
23
|
+
};
|
|
24
|
+
this.getAllAnswers = () => {
|
|
25
|
+
return Array.from(this.answerLookup.values());
|
|
26
|
+
};
|
|
27
|
+
this.addAnswer = (answer) => {
|
|
28
|
+
if (this.answerLookup.has(answer.id)) {
|
|
29
|
+
throw new Error(`Answer with ID ${answer.id} already exists`);
|
|
30
|
+
}
|
|
31
|
+
this.answerLookup.set(answer.id, answer);
|
|
32
|
+
this.reset();
|
|
33
|
+
};
|
|
34
|
+
this.removeAnswer = (id) => {
|
|
35
|
+
const answer = this.answerLookup.get(id);
|
|
36
|
+
if (!answer)
|
|
37
|
+
return;
|
|
38
|
+
this.answerLookup.delete(id);
|
|
39
|
+
this.reset();
|
|
40
|
+
};
|
|
41
|
+
this.getAnswer = (id) => {
|
|
42
|
+
return this.answerLookup.get(id);
|
|
43
|
+
};
|
|
44
|
+
this.hasAnswer = (id) => {
|
|
45
|
+
return this.answerLookup.has(id);
|
|
46
|
+
};
|
|
47
|
+
this.reset = () => {
|
|
48
|
+
this._gotItRight = false;
|
|
49
|
+
this._tries = 0;
|
|
50
|
+
this.answerLookup.forEach((ans) => (ans.showFeedback = false));
|
|
51
|
+
this.observers.notify();
|
|
52
|
+
};
|
|
53
|
+
this.submitAnswer = (id) => {
|
|
54
|
+
const ans = this.getAnswer(id);
|
|
55
|
+
if (!ans) {
|
|
56
|
+
console.warn(`[Question Challenge] Unable to find answer by ID: ${id}`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this._tries++;
|
|
60
|
+
ans.showFeedback = true;
|
|
61
|
+
this._gotItRight = ans.isCorrect;
|
|
62
|
+
this.observers.notify();
|
|
63
|
+
};
|
|
64
|
+
this.createAnswer = (text) => {
|
|
65
|
+
const id = this.generateID();
|
|
66
|
+
const answer = QuestionChallengeAnswer_1.makeQuestionChallengeAnswer(id);
|
|
67
|
+
answer.text = text;
|
|
68
|
+
this.addAnswer(answer);
|
|
69
|
+
return answer;
|
|
70
|
+
};
|
|
71
|
+
this.removeAllAnswers = () => {
|
|
72
|
+
const allAnswers = Array.from(this.answerLookup.keys());
|
|
73
|
+
allAnswers.forEach((id) => this.removeAnswer(id));
|
|
74
|
+
this.reset();
|
|
75
|
+
};
|
|
76
|
+
this.setDefaultState = () => {
|
|
77
|
+
this.removeAllAnswers();
|
|
78
|
+
const trueAnswer = this.createAnswer("True");
|
|
79
|
+
trueAnswer.isCorrect = true;
|
|
80
|
+
this.createAnswer("False");
|
|
81
|
+
this.memoizedText.setValQuietly("True / False question text");
|
|
82
|
+
this.reset();
|
|
83
|
+
};
|
|
84
|
+
this.addObserver = (observer) => {
|
|
85
|
+
this.observers.add(observer);
|
|
86
|
+
};
|
|
87
|
+
this.removeObserver = (observer) => {
|
|
88
|
+
this.observers.remove(observer);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
get tries() {
|
|
92
|
+
return this._tries;
|
|
93
|
+
}
|
|
94
|
+
get gotItRight() {
|
|
95
|
+
return this._gotItRight;
|
|
96
|
+
}
|
|
97
|
+
get text() {
|
|
98
|
+
return this.memoizedText.val;
|
|
99
|
+
}
|
|
100
|
+
set text(val) {
|
|
101
|
+
this.memoizedText.val = val;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare type OnQuestionAnswerChange = () => void;
|
|
2
|
+
export interface QuestionChallengeAnswer {
|
|
3
|
+
id: string;
|
|
4
|
+
text: string;
|
|
5
|
+
isCorrect: boolean;
|
|
6
|
+
feedbackText: string;
|
|
7
|
+
showFeedback: boolean;
|
|
8
|
+
addObserver(observer: OnQuestionAnswerChange): void;
|
|
9
|
+
removeObserver(observer: OnQuestionAnswerChange): void;
|
|
10
|
+
}
|
|
11
|
+
export declare function makeQuestionChallengeAnswer(id: string): QuestionChallengeAnswerImp;
|
|
12
|
+
declare class QuestionChallengeAnswerImp implements QuestionChallengeAnswer {
|
|
13
|
+
private observers;
|
|
14
|
+
private _id;
|
|
15
|
+
get id(): string;
|
|
16
|
+
private memoizedText;
|
|
17
|
+
get text(): string;
|
|
18
|
+
set text(val: string);
|
|
19
|
+
private memoizedFeedback;
|
|
20
|
+
get feedbackText(): string;
|
|
21
|
+
set feedbackText(val: string);
|
|
22
|
+
private memoizedIsCorrect;
|
|
23
|
+
get isCorrect(): boolean;
|
|
24
|
+
set isCorrect(val: boolean);
|
|
25
|
+
private memoizedShowFeedback;
|
|
26
|
+
get showFeedback(): boolean;
|
|
27
|
+
set showFeedback(val: boolean);
|
|
28
|
+
addObserver(observer: OnQuestionAnswerChange): void;
|
|
29
|
+
removeObserver(observer: OnQuestionAnswerChange): void;
|
|
30
|
+
constructor(id: string);
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeQuestionChallengeAnswer = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
function makeQuestionChallengeAnswer(id) {
|
|
6
|
+
return new QuestionChallengeAnswerImp(id);
|
|
7
|
+
}
|
|
8
|
+
exports.makeQuestionChallengeAnswer = makeQuestionChallengeAnswer;
|
|
9
|
+
class QuestionChallengeAnswerImp {
|
|
10
|
+
constructor(id) {
|
|
11
|
+
this.observers = new _1.ObserverList();
|
|
12
|
+
this.memoizedText = new _1.MemoizedString("Answer", this.observers.notify);
|
|
13
|
+
this.memoizedFeedback = new _1.MemoizedString("", this.observers.notify);
|
|
14
|
+
this.memoizedIsCorrect = new _1.MemoizedBoolean(false, this.observers.notify);
|
|
15
|
+
this.memoizedShowFeedback = new _1.MemoizedBoolean(false, this.observers.notify);
|
|
16
|
+
this._id = id;
|
|
17
|
+
}
|
|
18
|
+
get id() {
|
|
19
|
+
return this._id;
|
|
20
|
+
}
|
|
21
|
+
get text() {
|
|
22
|
+
return this.memoizedText.val;
|
|
23
|
+
}
|
|
24
|
+
set text(val) {
|
|
25
|
+
this.memoizedText.val = val;
|
|
26
|
+
}
|
|
27
|
+
get feedbackText() {
|
|
28
|
+
return this.memoizedFeedback.val;
|
|
29
|
+
}
|
|
30
|
+
set feedbackText(val) {
|
|
31
|
+
this.memoizedFeedback.val = val;
|
|
32
|
+
}
|
|
33
|
+
get isCorrect() {
|
|
34
|
+
return this.memoizedIsCorrect.val;
|
|
35
|
+
}
|
|
36
|
+
set isCorrect(val) {
|
|
37
|
+
this.memoizedIsCorrect.val = val;
|
|
38
|
+
}
|
|
39
|
+
get showFeedback() {
|
|
40
|
+
return this.memoizedShowFeedback.val;
|
|
41
|
+
}
|
|
42
|
+
set showFeedback(val) {
|
|
43
|
+
this.memoizedShowFeedback.val = val;
|
|
44
|
+
}
|
|
45
|
+
addObserver(observer) {
|
|
46
|
+
this.observers.add(observer);
|
|
47
|
+
}
|
|
48
|
+
removeObserver(observer) {
|
|
49
|
+
this.observers.remove(observer);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { Vector2 } from "../ValueObjects";
|
|
2
|
+
export interface TouchInputEvent {
|
|
3
|
+
touchCount: number;
|
|
4
|
+
touchCenter: Vector2;
|
|
5
|
+
touches: TouchData[];
|
|
6
|
+
event: TouchEvent;
|
|
7
|
+
}
|
|
8
|
+
export interface TouchData {
|
|
9
|
+
id: number;
|
|
10
|
+
position: Vector2;
|
|
11
|
+
touch?: Touch;
|
|
12
|
+
}
|
|
2
13
|
export interface TouchController {
|
|
3
|
-
onTouchStart?: (e:
|
|
4
|
-
onTouchMove?: (e:
|
|
5
|
-
onTouchEnd?: (e:
|
|
6
|
-
onTouchCancel?: (e:
|
|
14
|
+
onTouchStart?: (e: TouchInputEvent) => void;
|
|
15
|
+
onTouchMove?: (e: TouchInputEvent) => void;
|
|
16
|
+
onTouchEnd?: (e: TouchInputEvent) => void;
|
|
17
|
+
onTouchCancel?: (e: TouchInputEvent) => void;
|
|
7
18
|
}
|
|
8
19
|
export interface TouchInput {
|
|
9
20
|
eventElement: HTMLElement | undefined;
|
|
@@ -11,9 +22,6 @@ export interface TouchInput {
|
|
|
11
22
|
setEventElement: (eventElement: HTMLElement) => void;
|
|
12
23
|
clearInputElement: () => void;
|
|
13
24
|
updateInputElementBounds: () => void;
|
|
14
|
-
getTouchOffsetPosition: (touch: Touch) => Vector2;
|
|
15
|
-
getDistatnceBetweenTouches: (touch1: Touch, touch2: Touch) => number;
|
|
16
|
-
getTouchsCenter: (touches: TouchList) => Vector2;
|
|
17
25
|
registerController: (controller: TouchController) => void;
|
|
18
26
|
removeController: (controller: TouchController) => void;
|
|
19
27
|
}
|
|
@@ -24,26 +24,6 @@ class TouchInputImp {
|
|
|
24
24
|
const y = touch.clientY - this.eventElementBounds.y;
|
|
25
25
|
return new ValueObjects_1.Vector2(x, y);
|
|
26
26
|
};
|
|
27
|
-
this.getDistatnceBetweenTouches = (touch1, touch2) => {
|
|
28
|
-
const t1 = this.getTouchOffsetPosition(touch1);
|
|
29
|
-
const t2 = this.getTouchOffsetPosition(touch2);
|
|
30
|
-
const delta = ValueObjects_1.Vector2.subtract(t2, t2);
|
|
31
|
-
return delta.magnitued;
|
|
32
|
-
};
|
|
33
|
-
this.getTouchsCenter = (touches) => {
|
|
34
|
-
const touchCount = touches.length;
|
|
35
|
-
if (touchCount === 0)
|
|
36
|
-
return ValueObjects_1.Vector2.zero();
|
|
37
|
-
let sumX = 0;
|
|
38
|
-
let sumY = 0;
|
|
39
|
-
for (let i = 0; i < touchCount; i++) {
|
|
40
|
-
const touch = touches[i];
|
|
41
|
-
const touchPos = this.getTouchOffsetPosition(touch);
|
|
42
|
-
sumX += touchPos.x;
|
|
43
|
-
sumY += touchPos.y;
|
|
44
|
-
}
|
|
45
|
-
return new ValueObjects_1.Vector2(sumX / touches.length, sumY / touches.length);
|
|
46
|
-
};
|
|
47
27
|
this.setEventElement = (eventElement) => {
|
|
48
28
|
if (this._eventElement)
|
|
49
29
|
this.clearInputElement();
|
|
@@ -56,33 +36,37 @@ class TouchInputImp {
|
|
|
56
36
|
};
|
|
57
37
|
this.onTouchStart = (e) => {
|
|
58
38
|
e.preventDefault();
|
|
39
|
+
const touchInput = this.createTouchInputEvent(e);
|
|
59
40
|
this.controllers.forEach((c) => {
|
|
60
41
|
if (c.onTouchStart) {
|
|
61
|
-
c.onTouchStart(
|
|
42
|
+
c.onTouchStart(touchInput);
|
|
62
43
|
}
|
|
63
44
|
});
|
|
64
45
|
};
|
|
65
46
|
this.onTouchMove = (e) => {
|
|
66
47
|
e.preventDefault();
|
|
48
|
+
const touchInput = this.createTouchInputEvent(e);
|
|
67
49
|
this.controllers.forEach((c) => {
|
|
68
50
|
if (c.onTouchMove) {
|
|
69
|
-
c.onTouchMove(
|
|
51
|
+
c.onTouchMove(touchInput);
|
|
70
52
|
}
|
|
71
53
|
});
|
|
72
54
|
};
|
|
73
55
|
this.onTouchEnd = (e) => {
|
|
74
56
|
e.preventDefault();
|
|
57
|
+
const touchInput = this.createTouchInputEvent(e);
|
|
75
58
|
this.controllers.forEach((c) => {
|
|
76
59
|
if (c.onTouchEnd) {
|
|
77
|
-
c.onTouchEnd(
|
|
60
|
+
c.onTouchEnd(touchInput);
|
|
78
61
|
}
|
|
79
62
|
});
|
|
80
63
|
};
|
|
81
64
|
this.onTouchCancel = (e) => {
|
|
82
65
|
e.preventDefault();
|
|
66
|
+
const touchInput = this.createTouchInputEvent(e);
|
|
83
67
|
this.controllers.forEach((c) => {
|
|
84
68
|
if (c.onTouchCancel) {
|
|
85
|
-
c.onTouchCancel(
|
|
69
|
+
c.onTouchCancel(touchInput);
|
|
86
70
|
}
|
|
87
71
|
});
|
|
88
72
|
};
|
|
@@ -108,4 +92,49 @@ class TouchInputImp {
|
|
|
108
92
|
get eventElement() {
|
|
109
93
|
return this._eventElement;
|
|
110
94
|
}
|
|
95
|
+
createTouchInputEvent(event) {
|
|
96
|
+
const touches = [];
|
|
97
|
+
const touchCount = event.touches.length;
|
|
98
|
+
let minX = 0;
|
|
99
|
+
let maxX = 0;
|
|
100
|
+
let minY = 0;
|
|
101
|
+
let maxY = 0;
|
|
102
|
+
for (let i = 0; i < touchCount; i++) {
|
|
103
|
+
const touch = event.touches[i];
|
|
104
|
+
const position = this.getTouchOffsetPosition(touch);
|
|
105
|
+
touches.push({
|
|
106
|
+
id: touch.identifier,
|
|
107
|
+
touch,
|
|
108
|
+
position,
|
|
109
|
+
});
|
|
110
|
+
if (i === 0) {
|
|
111
|
+
minX = position.x;
|
|
112
|
+
maxX = position.x;
|
|
113
|
+
minY = position.y;
|
|
114
|
+
maxY = position.y;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
minX = Math.min(minX, position.x);
|
|
118
|
+
maxX = Math.max(maxX, position.x);
|
|
119
|
+
minY = Math.min(minY, position.y);
|
|
120
|
+
maxY = Math.max(maxY, position.y);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
let cntX = 0;
|
|
124
|
+
let cntY = 0;
|
|
125
|
+
if (touchCount === 1) {
|
|
126
|
+
cntX = maxX;
|
|
127
|
+
cntY = maxY;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
cntX = minX + (maxX - minX) / 2;
|
|
131
|
+
cntY = minY + (maxY - minY) / 2;
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
touchCenter: new ValueObjects_1.Vector2(cntX, cntY),
|
|
135
|
+
touchCount,
|
|
136
|
+
touches,
|
|
137
|
+
event,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
111
140
|
}
|
package/lib/Entities/index.d.ts
CHANGED
package/lib/Entities/index.js
CHANGED
|
@@ -25,3 +25,5 @@ __exportStar(require("./StateMachine"), exports);
|
|
|
25
25
|
__exportStar(require("./UndoRedo"), exports);
|
|
26
26
|
__exportStar(require("./MouseInput"), exports);
|
|
27
27
|
__exportStar(require("./TouchInput"), exports);
|
|
28
|
+
__exportStar(require("./QuestionChallengeAnswer"), exports);
|
|
29
|
+
__exportStar(require("./QuestionChallenge"), exports);
|