@vived/app 2.14.0 → 2.15.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.
Files changed (41) hide show
  1. package/lib/Entities/MemoizedBoolean.d.ts +1 -0
  2. package/lib/Entities/MemoizedBoolean.js +3 -0
  3. package/lib/Entities/MemoizedNumber.d.ts +1 -0
  4. package/lib/Entities/MemoizedNumber.js +3 -0
  5. package/lib/Entities/MemoizedString.d.ts +1 -0
  6. package/lib/Entities/MemoizedString.js +3 -0
  7. package/lib/Entities/MemoizedVector2.d.ts +1 -0
  8. package/lib/Entities/MemoizedVector2.js +3 -0
  9. package/lib/Entities/MemoizedVector3.d.ts +1 -0
  10. package/lib/Entities/MemoizedVector3.js +3 -0
  11. package/lib/Entities/QuestionChallenge.d.ts +21 -0
  12. package/lib/Entities/QuestionChallenge.js +103 -0
  13. package/lib/Entities/QuestionChallengeAnswer.d.ts +32 -0
  14. package/lib/Entities/QuestionChallengeAnswer.js +51 -0
  15. package/lib/Entities/index.d.ts +2 -0
  16. package/lib/Entities/index.js +2 -0
  17. package/lib/PresentationManagers/QuestionChallenge/AuthorQuestionChallengeAnswerPM.d.ts +24 -0
  18. package/lib/PresentationManagers/QuestionChallenge/AuthorQuestionChallengeAnswerPM.js +65 -0
  19. package/lib/PresentationManagers/QuestionChallenge/AuthorQuestionChallengePM.d.ts +17 -0
  20. package/lib/PresentationManagers/QuestionChallenge/AuthorQuestionChallengePM.js +46 -0
  21. package/lib/PresentationManagers/QuestionChallenge/QuestionChallengeAnswerPM.d.ts +17 -0
  22. package/lib/PresentationManagers/QuestionChallenge/QuestionChallengeAnswerPM.js +51 -0
  23. package/lib/PresentationManagers/QuestionChallenge/QuestionChallengePM.d.ts +15 -0
  24. package/lib/PresentationManagers/QuestionChallenge/QuestionChallengePM.js +34 -0
  25. package/lib/PresentationManagers/QuestionChallenge/index.d.ts +4 -0
  26. package/lib/PresentationManagers/QuestionChallenge/index.js +16 -0
  27. package/lib/PresentationManagers/index.d.ts +1 -0
  28. package/lib/PresentationManagers/index.js +1 -0
  29. package/lib/UseCases/QuestionChallenge/SerializeQuestionChallenge.d.ts +25 -0
  30. package/lib/UseCases/QuestionChallenge/SerializeQuestionChallenge.js +70 -0
  31. package/lib/UseCases/QuestionChallenge/index.d.ts +4 -0
  32. package/lib/UseCases/QuestionChallenge/index.js +16 -0
  33. package/lib/UseCases/QuestionChallenge/setQuesionChallengeAnswerFeedback.d.ts +2 -0
  34. package/lib/UseCases/QuestionChallenge/setQuesionChallengeAnswerFeedback.js +16 -0
  35. package/lib/UseCases/QuestionChallenge/setQuesionChallengeAnswerText.d.ts +2 -0
  36. package/lib/UseCases/QuestionChallenge/setQuesionChallengeAnswerText.js +16 -0
  37. package/lib/UseCases/QuestionChallenge/toggleQuesionChallengeAnswerIsCorrect.d.ts +2 -0
  38. package/lib/UseCases/QuestionChallenge/toggleQuesionChallengeAnswerIsCorrect.js +16 -0
  39. package/lib/UseCases/index.d.ts +1 -0
  40. package/lib/UseCases/index.js +1 -0
  41. package/package.json +1 -1
@@ -2,6 +2,7 @@ export declare class MemoizedBoolean {
2
2
  private _val;
3
3
  get val(): boolean;
4
4
  set val(b: boolean);
5
+ setValQuietly(val: boolean): void;
5
6
  private onChangeCallback;
6
7
  constructor(initialValue: boolean, onChangeCallback: () => void);
7
8
  }
@@ -15,5 +15,8 @@ class MemoizedBoolean {
15
15
  this._val = b;
16
16
  this.onChangeCallback();
17
17
  }
18
+ setValQuietly(val) {
19
+ this._val = val;
20
+ }
18
21
  }
19
22
  exports.MemoizedBoolean = MemoizedBoolean;
@@ -2,6 +2,7 @@ export declare class MemoizedNumber {
2
2
  private _val;
3
3
  get val(): number;
4
4
  set val(b: number);
5
+ setValQuietly(val: number): void;
5
6
  private onChangeCallback;
6
7
  constructor(initialValue: number, onChangeCallback: () => void);
7
8
  }
@@ -15,5 +15,8 @@ class MemoizedNumber {
15
15
  this._val = b;
16
16
  this.onChangeCallback();
17
17
  }
18
+ setValQuietly(val) {
19
+ this._val = val;
20
+ }
18
21
  }
19
22
  exports.MemoizedNumber = MemoizedNumber;
@@ -2,6 +2,7 @@ export declare class MemoizedString {
2
2
  private _val;
3
3
  get val(): string;
4
4
  set val(b: string);
5
+ setValQuietly(val: string): void;
5
6
  private onChangeCallback;
6
7
  constructor(initialValue: string, onChangeCallback: () => void);
7
8
  }
@@ -15,5 +15,8 @@ class MemoizedString {
15
15
  this._val = b;
16
16
  this.onChangeCallback();
17
17
  }
18
+ setValQuietly(val) {
19
+ this._val = val;
20
+ }
18
21
  }
19
22
  exports.MemoizedString = MemoizedString;
@@ -3,6 +3,7 @@ export declare class MemoizedVector2 {
3
3
  private _val;
4
4
  get val(): Vector2;
5
5
  set val(v: Vector2);
6
+ setValQuietly(val: Vector2): void;
6
7
  private onChangeCallback;
7
8
  constructor(initialValue: Vector2, onChangeCallback: () => void);
8
9
  }
@@ -16,5 +16,8 @@ class MemoizedVector2 {
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;
@@ -3,6 +3,7 @@ export declare class MemoizedVector3 {
3
3
  private _val;
4
4
  get val(): Vector3;
5
5
  set val(v: Vector3);
6
+ setValQuietly(val: Vector3): void;
6
7
  private onChangeCallback;
7
8
  constructor(initialValue: Vector3, onChangeCallback: () => void);
8
9
  }
@@ -16,5 +16,8 @@ class MemoizedVector3 {
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;
@@ -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
+ }
@@ -13,3 +13,5 @@ export * from "./StateMachine";
13
13
  export * from "./UndoRedo";
14
14
  export * from "./MouseInput";
15
15
  export * from "./TouchInput";
16
+ export * from "./QuestionChallengeAnswer";
17
+ export * from "./QuestionChallenge";
@@ -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);
@@ -0,0 +1,24 @@
1
+ import { QuestionChallenge } from "../../Entities";
2
+ export declare const defaultAuthorQuestionChallengeAnswerVM: AuthorQuestionChallengeAnswerVM;
3
+ export interface AuthorQuestionChallengeAnswerVM {
4
+ answerText: string;
5
+ feedbackText: string;
6
+ isCorrect: boolean;
7
+ allowDelete: boolean;
8
+ setAnswerText: (text: string) => void;
9
+ setFeedbackText: (text: string) => void;
10
+ toggleIsCorrect: () => void;
11
+ deleteAnswer: () => void;
12
+ }
13
+ export declare class AuthorQuestionChallengeAnswerPM {
14
+ private answerID;
15
+ private questionChallengeEntity;
16
+ private updateView;
17
+ private answer?;
18
+ setTextUC: (text: string) => void;
19
+ setFeedbackUC: (text: string) => void;
20
+ toggleIsCorrectUC: () => void;
21
+ dispose: () => void;
22
+ private doUpdateView;
23
+ constructor(answerID: string, questionChallengeEntity: QuestionChallenge, updateView: (vm: AuthorQuestionChallengeAnswerVM) => void);
24
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthorQuestionChallengeAnswerPM = exports.defaultAuthorQuestionChallengeAnswerVM = void 0;
4
+ const setQuesionChallengeAnswerFeedback_1 = require("../../UseCases/QuestionChallenge/setQuesionChallengeAnswerFeedback");
5
+ const setQuesionChallengeAnswerText_1 = require("../../UseCases/QuestionChallenge/setQuesionChallengeAnswerText");
6
+ const toggleQuesionChallengeAnswerIsCorrect_1 = require("../../UseCases/QuestionChallenge/toggleQuesionChallengeAnswerIsCorrect");
7
+ exports.defaultAuthorQuestionChallengeAnswerVM = {
8
+ answerText: "",
9
+ feedbackText: "",
10
+ isCorrect: false,
11
+ allowDelete: false,
12
+ setAnswerText: (text) => {
13
+ console.log("Default setAnswerText: " + text);
14
+ },
15
+ setFeedbackText: (text) => {
16
+ console.log("Default setFeedbackText: " + text);
17
+ },
18
+ toggleIsCorrect: () => {
19
+ console.log("Default toggleIsCorrect");
20
+ },
21
+ deleteAnswer: () => {
22
+ console.log("Default deleteAnswer");
23
+ },
24
+ };
25
+ class AuthorQuestionChallengeAnswerPM {
26
+ constructor(answerID, questionChallengeEntity, updateView) {
27
+ this.answerID = answerID;
28
+ this.questionChallengeEntity = questionChallengeEntity;
29
+ this.updateView = updateView;
30
+ this.dispose = () => {
31
+ var _a;
32
+ (_a = this.answer) === null || _a === void 0 ? void 0 : _a.removeObserver(this.doUpdateView);
33
+ this.questionChallengeEntity.removeObserver(this.doUpdateView);
34
+ };
35
+ this.doUpdateView = () => {
36
+ if (this.answer === undefined)
37
+ return;
38
+ const { feedbackText, text, isCorrect } = this.answer;
39
+ const allowDelete = this.questionChallengeEntity.getAllAnswers().length > 2 ? true : false;
40
+ const vm = {
41
+ answerText: text,
42
+ isCorrect,
43
+ feedbackText,
44
+ allowDelete,
45
+ setAnswerText: this.setTextUC,
46
+ setFeedbackText: this.setFeedbackUC,
47
+ toggleIsCorrect: this.toggleIsCorrectUC,
48
+ deleteAnswer: () => {
49
+ this.questionChallengeEntity.removeAnswer(this.answerID);
50
+ },
51
+ };
52
+ this.updateView(vm);
53
+ };
54
+ this.answer = questionChallengeEntity.getAnswer(answerID);
55
+ this.setTextUC = setQuesionChallengeAnswerText_1.makeSetQuestionChallengeAnswerText(answerID, questionChallengeEntity);
56
+ this.setFeedbackUC = setQuesionChallengeAnswerFeedback_1.makeSetQuestionChallengeAnswerFeedback(answerID, questionChallengeEntity);
57
+ this.toggleIsCorrectUC = toggleQuesionChallengeAnswerIsCorrect_1.makeToggleQuesionChallengeAnswerIsCorrect(answerID, questionChallengeEntity);
58
+ if (this.answer) {
59
+ this.doUpdateView();
60
+ this.answer.addObserver(this.doUpdateView);
61
+ this.questionChallengeEntity.addObserver(this.doUpdateView);
62
+ }
63
+ }
64
+ }
65
+ exports.AuthorQuestionChallengeAnswerPM = AuthorQuestionChallengeAnswerPM;
@@ -0,0 +1,17 @@
1
+ import { QuestionChallenge } from "../../Entities";
2
+ export declare const defaultAuthorQuestionChallengeVM: AuthorQuestionChallengeVM;
3
+ export interface AuthorQuestionChallengeVM {
4
+ text: string;
5
+ answers: string[];
6
+ enableResetButton: boolean;
7
+ setQuestionText: (text: string) => void;
8
+ reset: () => void;
9
+ createAnswer: () => void;
10
+ }
11
+ export declare class AuthorQuestionChallengePM {
12
+ private questionChallengeEntity;
13
+ private updateView;
14
+ dispose: () => void;
15
+ private doUpdateView;
16
+ constructor(questionChallengeEntity: QuestionChallenge, updateView: (vm: AuthorQuestionChallengeVM) => void);
17
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthorQuestionChallengePM = exports.defaultAuthorQuestionChallengeVM = void 0;
4
+ exports.defaultAuthorQuestionChallengeVM = {
5
+ text: "",
6
+ answers: [],
7
+ enableResetButton: false,
8
+ setQuestionText: (text) => {
9
+ console.log("Default setQuestionText: " + text);
10
+ },
11
+ reset: () => {
12
+ console.log("Default reset");
13
+ },
14
+ createAnswer: () => {
15
+ console.log("Default reset");
16
+ },
17
+ };
18
+ class AuthorQuestionChallengePM {
19
+ constructor(questionChallengeEntity, updateView) {
20
+ this.questionChallengeEntity = questionChallengeEntity;
21
+ this.updateView = updateView;
22
+ this.dispose = () => {
23
+ this.questionChallengeEntity.removeObserver(this.doUpdateView);
24
+ };
25
+ this.doUpdateView = () => {
26
+ const { text, tries } = this.questionChallengeEntity;
27
+ const answers = this.questionChallengeEntity
28
+ .getAllAnswers()
29
+ .map((ans) => ans.id);
30
+ const vm = {
31
+ text,
32
+ answers,
33
+ enableResetButton: tries > 0,
34
+ setQuestionText: (txt) => {
35
+ this.questionChallengeEntity.text = txt;
36
+ },
37
+ reset: () => this.questionChallengeEntity.reset(),
38
+ createAnswer: () => this.questionChallengeEntity.createAnswer(""),
39
+ };
40
+ this.updateView(vm);
41
+ };
42
+ this.doUpdateView();
43
+ this.questionChallengeEntity.addObserver(this.doUpdateView);
44
+ }
45
+ }
46
+ exports.AuthorQuestionChallengePM = AuthorQuestionChallengePM;
@@ -0,0 +1,17 @@
1
+ import { QuestionChallenge } from "../../Entities";
2
+ export declare const defaultQestionChallengeAnswerVM: QuestionChallengeAnswerVM;
3
+ export interface QuestionChallengeAnswerVM {
4
+ displayText: string;
5
+ isShowingFeedback: boolean;
6
+ isCorrect: boolean;
7
+ submitAnswer: () => void;
8
+ }
9
+ export declare class QuestionChallengeAnswerPM {
10
+ private answerID;
11
+ private questionChallengeEntity;
12
+ private updateView;
13
+ private answer?;
14
+ dispose: () => void;
15
+ private doUpdateView;
16
+ constructor(answerID: string, questionChallengeEntity: QuestionChallenge, updateView: (vm: QuestionChallengeAnswerVM) => void);
17
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QuestionChallengeAnswerPM = exports.defaultQestionChallengeAnswerVM = void 0;
4
+ exports.defaultQestionChallengeAnswerVM = {
5
+ displayText: "",
6
+ isShowingFeedback: false,
7
+ isCorrect: false,
8
+ submitAnswer: () => {
9
+ console.log("Default submitAnswer");
10
+ },
11
+ };
12
+ class QuestionChallengeAnswerPM {
13
+ constructor(answerID, questionChallengeEntity, updateView) {
14
+ this.answerID = answerID;
15
+ this.questionChallengeEntity = questionChallengeEntity;
16
+ this.updateView = updateView;
17
+ this.dispose = () => {
18
+ var _a;
19
+ (_a = this.answer) === null || _a === void 0 ? void 0 : _a.removeObserver(this.doUpdateView);
20
+ };
21
+ this.doUpdateView = () => {
22
+ if (!this.answer)
23
+ return;
24
+ const { feedbackText, showFeedback, text, isCorrect } = this.answer;
25
+ let displayText = text ? text : `Answer`;
26
+ if (showFeedback) {
27
+ if (feedbackText) {
28
+ displayText = feedbackText;
29
+ }
30
+ else {
31
+ displayText = isCorrect ? "Correct" : "Incorrect";
32
+ }
33
+ }
34
+ const vm = {
35
+ displayText,
36
+ isCorrect,
37
+ isShowingFeedback: showFeedback,
38
+ submitAnswer: () => {
39
+ this.questionChallengeEntity.submitAnswer(this.answerID);
40
+ },
41
+ };
42
+ this.updateView(vm);
43
+ };
44
+ this.answer = questionChallengeEntity.getAnswer(answerID);
45
+ if (this.answer) {
46
+ this.doUpdateView();
47
+ this.answer.addObserver(this.doUpdateView);
48
+ }
49
+ }
50
+ }
51
+ exports.QuestionChallengeAnswerPM = QuestionChallengeAnswerPM;
@@ -0,0 +1,15 @@
1
+ import { QuestionChallenge } from "../../Entities";
2
+ export declare const defaultQuestionChallengeVM: QuestionChallengeVM;
3
+ export interface QuestionChallengeVM {
4
+ text: string;
5
+ tries: number;
6
+ gotItRight: boolean;
7
+ answers: string[];
8
+ }
9
+ export declare class QuestionChallengePM {
10
+ private questionChallengeEntity;
11
+ private updateView;
12
+ dispose: () => void;
13
+ private doUpdateView;
14
+ constructor(questionChallengeEntity: QuestionChallenge, updateView: (vm: QuestionChallengeVM) => void);
15
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QuestionChallengePM = exports.defaultQuestionChallengeVM = void 0;
4
+ exports.defaultQuestionChallengeVM = {
5
+ text: "",
6
+ answers: [],
7
+ gotItRight: false,
8
+ tries: 0,
9
+ };
10
+ class QuestionChallengePM {
11
+ constructor(questionChallengeEntity, updateView) {
12
+ this.questionChallengeEntity = questionChallengeEntity;
13
+ this.updateView = updateView;
14
+ this.dispose = () => {
15
+ this.questionChallengeEntity.removeObserver(this.doUpdateView);
16
+ };
17
+ this.doUpdateView = () => {
18
+ const { tries, text } = this.questionChallengeEntity;
19
+ const answers = this.questionChallengeEntity
20
+ .getAllAnswers()
21
+ .map((ans) => ans.id);
22
+ const vm = {
23
+ text,
24
+ tries,
25
+ gotItRight: this.questionChallengeEntity.gotItRight,
26
+ answers,
27
+ };
28
+ this.updateView(vm);
29
+ };
30
+ this.doUpdateView();
31
+ this.questionChallengeEntity.addObserver(this.doUpdateView);
32
+ }
33
+ }
34
+ exports.QuestionChallengePM = QuestionChallengePM;
@@ -0,0 +1,4 @@
1
+ export * from "./QuestionChallengePM";
2
+ export * from "./QuestionChallengeAnswerPM";
3
+ export * from "./AuthorQuestionChallengeAnswerPM";
4
+ export * from "./AuthorQuestionChallengePM";
@@ -0,0 +1,16 @@
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("./QuestionChallengePM"), exports);
14
+ __exportStar(require("./QuestionChallengeAnswerPM"), exports);
15
+ __exportStar(require("./AuthorQuestionChallengeAnswerPM"), exports);
16
+ __exportStar(require("./AuthorQuestionChallengePM"), exports);
@@ -4,3 +4,4 @@ export * from "./ShowBabylonInspectorPM";
4
4
  export * from "./HasRedoPM";
5
5
  export * from "./HasUndoPM";
6
6
  export * from "./FocusCameraPM";
7
+ export * from "./QuestionChallenge";
@@ -16,3 +16,4 @@ __exportStar(require("./ShowBabylonInspectorPM"), exports);
16
16
  __exportStar(require("./HasRedoPM"), exports);
17
17
  __exportStar(require("./HasUndoPM"), exports);
18
18
  __exportStar(require("./FocusCameraPM"), exports);
19
+ __exportStar(require("./QuestionChallenge"), exports);
@@ -0,0 +1,25 @@
1
+ import { QuestionChallenge, SerializedSystem, StateMachine } from "../../Entities";
2
+ export declare class SerializeQuestionChallenge implements SerializedSystem {
3
+ private questionChallenge;
4
+ name: string;
5
+ seriliziationVersion: number;
6
+ getSystemState(): object;
7
+ applySystemState(state: object, version: number): void;
8
+ applyDefaultState(): void;
9
+ private applyDataV1;
10
+ private applyDataV2;
11
+ constructor(questionChallenge: QuestionChallenge, stateMachine: StateMachine);
12
+ }
13
+ export interface ChallengeDataV2 {
14
+ questionText: string;
15
+ answers: AnswerDataV1[];
16
+ }
17
+ export interface ChallengeDataV1 {
18
+ answers: AnswerDataV1[];
19
+ }
20
+ export interface AnswerDataV1 {
21
+ id: string;
22
+ text: string;
23
+ feedback: string;
24
+ isCorrect: boolean;
25
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SerializeQuestionChallenge = void 0;
4
+ const Entities_1 = require("../../Entities");
5
+ class SerializeQuestionChallenge {
6
+ constructor(questionChallenge, stateMachine) {
7
+ this.questionChallenge = questionChallenge;
8
+ this.name = "question";
9
+ this.seriliziationVersion = 2;
10
+ stateMachine.registerSerializedSystem(this);
11
+ }
12
+ getSystemState() {
13
+ const answers = this.questionChallenge
14
+ .getAllAnswers()
15
+ .map((answer) => {
16
+ return {
17
+ id: answer.id,
18
+ feedback: answer.feedbackText,
19
+ isCorrect: answer.isCorrect,
20
+ text: answer.text,
21
+ };
22
+ });
23
+ const state = {
24
+ questionText: this.questionChallenge.text,
25
+ answers,
26
+ };
27
+ return state;
28
+ }
29
+ applySystemState(state, version) {
30
+ if (state && version === 1) {
31
+ const castState = state;
32
+ this.applyDataV1(castState);
33
+ }
34
+ else if (state && version === 2) {
35
+ const castState = state;
36
+ this.applyDataV2(castState);
37
+ }
38
+ else {
39
+ // Unsupported version
40
+ console.warn(`Unsupported data version ${version} for serialized system ${this.name}. Reverting to default state`);
41
+ this.applyDefaultState();
42
+ }
43
+ }
44
+ applyDefaultState() {
45
+ this.questionChallenge.setDefaultState();
46
+ }
47
+ applyDataV1(data) {
48
+ this.questionChallenge.removeAllAnswers();
49
+ this.questionChallenge.text = "";
50
+ data.answers.forEach((answerData) => {
51
+ const answer = Entities_1.makeQuestionChallengeAnswer(answerData.id);
52
+ answer.text = answerData.text;
53
+ answer.isCorrect = answerData.isCorrect;
54
+ answer.feedbackText = answerData.feedback;
55
+ this.questionChallenge.addAnswer(answer);
56
+ });
57
+ }
58
+ applyDataV2(data) {
59
+ this.questionChallenge.removeAllAnswers();
60
+ this.questionChallenge.text = data.questionText;
61
+ data.answers.forEach((answerData) => {
62
+ const answer = Entities_1.makeQuestionChallengeAnswer(answerData.id);
63
+ answer.text = answerData.text;
64
+ answer.isCorrect = answerData.isCorrect;
65
+ answer.feedbackText = answerData.feedback;
66
+ this.questionChallenge.addAnswer(answer);
67
+ });
68
+ }
69
+ }
70
+ exports.SerializeQuestionChallenge = SerializeQuestionChallenge;
@@ -0,0 +1,4 @@
1
+ export * from "./SerializeQuestionChallenge";
2
+ export * from "./setQuesionChallengeAnswerFeedback";
3
+ export * from "./setQuesionChallengeAnswerText";
4
+ export * from "./toggleQuesionChallengeAnswerIsCorrect";
@@ -0,0 +1,16 @@
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("./SerializeQuestionChallenge"), exports);
14
+ __exportStar(require("./setQuesionChallengeAnswerFeedback"), exports);
15
+ __exportStar(require("./setQuesionChallengeAnswerText"), exports);
16
+ __exportStar(require("./toggleQuesionChallengeAnswerIsCorrect"), exports);
@@ -0,0 +1,2 @@
1
+ import { QuestionChallenge } from "../../Entities";
2
+ export declare function makeSetQuestionChallengeAnswerFeedback(answerID: string, questionChallenge: QuestionChallenge): (feedback: string) => void;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeSetQuestionChallengeAnswerFeedback = void 0;
4
+ function makeSetQuestionChallengeAnswerFeedback(answerID, questionChallenge) {
5
+ return function setQuestionChallengeAnswerFeedback(feedback) {
6
+ const answer = questionChallenge.getAnswer(answerID);
7
+ if (answer) {
8
+ answer.feedbackText = feedback;
9
+ }
10
+ else {
11
+ console.warn("[setQuestionChallengeAnswerFeedback] Unable to find question by id " +
12
+ answerID);
13
+ }
14
+ };
15
+ }
16
+ exports.makeSetQuestionChallengeAnswerFeedback = makeSetQuestionChallengeAnswerFeedback;
@@ -0,0 +1,2 @@
1
+ import { QuestionChallenge } from "../../Entities";
2
+ export declare function makeSetQuestionChallengeAnswerText(answerID: string, questionChallenge: QuestionChallenge): (text: string) => void;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeSetQuestionChallengeAnswerText = void 0;
4
+ function makeSetQuestionChallengeAnswerText(answerID, questionChallenge) {
5
+ return function setQuestionChallengeAnswerText(text) {
6
+ const answer = questionChallenge.getAnswer(answerID);
7
+ if (answer) {
8
+ answer.text = text;
9
+ }
10
+ else {
11
+ console.warn("[setQuestionChallengeAnswerText] Unable to find question by id " +
12
+ answerID);
13
+ }
14
+ };
15
+ }
16
+ exports.makeSetQuestionChallengeAnswerText = makeSetQuestionChallengeAnswerText;
@@ -0,0 +1,2 @@
1
+ import { QuestionChallenge } from "../../Entities";
2
+ export declare function makeToggleQuesionChallengeAnswerIsCorrect(answerID: string, questionChallenge: QuestionChallenge): () => void;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeToggleQuesionChallengeAnswerIsCorrect = void 0;
4
+ function makeToggleQuesionChallengeAnswerIsCorrect(answerID, questionChallenge) {
5
+ return function toggleQuesionChallengeAnswerIsCorrect() {
6
+ const answer = questionChallenge.getAnswer(answerID);
7
+ if (answer) {
8
+ answer.isCorrect = !answer.isCorrect;
9
+ }
10
+ else {
11
+ console.warn("[toggleQuesionChallengeAnswerIsCorrect] Unable to find question by id " +
12
+ answerID);
13
+ }
14
+ };
15
+ }
16
+ exports.makeToggleQuesionChallengeAnswerIsCorrect = makeToggleQuesionChallengeAnswerIsCorrect;
@@ -1,2 +1,3 @@
1
1
  export * from "./setDevicePreview";
2
2
  export * from "./FocusCamera";
3
+ export * from "./QuestionChallenge";
@@ -12,3 +12,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./setDevicePreview"), exports);
14
14
  __exportStar(require("./FocusCamera"), exports);
15
+ __exportStar(require("./QuestionChallenge"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vived/app",
3
- "version": "2.14.0",
3
+ "version": "2.15.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",