@gamelearn/arcade-components 2.22.1 → 2.23.1

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.
@@ -46,7 +46,9 @@ var ComicComponent = function ComicComponent(_ref) {
46
46
  soundActions = _ref$soundActions === void 0 ? [function () {}, function () {}] : _ref$soundActions,
47
47
  autoPlay = _ref.autoPlay,
48
48
  pause = _ref.pause,
49
+ progress = _ref.progress,
49
50
  keyboardControl = _ref.keyboardControl;
51
+ var defaultSlide = (progress === null || progress === void 0 ? void 0 : progress.slide) || 0;
50
52
 
51
53
  var translate = function translate(id) {
52
54
  return emitEvent({
@@ -74,7 +76,7 @@ var ComicComponent = function ComicComponent(_ref) {
74
76
  start = _useTimeout.start,
75
77
  stop = _useTimeout.stop;
76
78
 
77
- var _useState7 = (0, _react.useState)(0),
79
+ var _useState7 = (0, _react.useState)(defaultSlide),
78
80
  _useState8 = _slicedToArray(_useState7, 2),
79
81
  slideCount = _useState8[0],
80
82
  setCount = _useState8[1];
@@ -99,22 +101,36 @@ var ComicComponent = function ComicComponent(_ref) {
99
101
  setAudioFailed(false);
100
102
 
101
103
  if (slideCount + 1 < slides.length && !pause) {
104
+ var next = slideCount + 1;
102
105
  setTransition('slide-animation');
103
- setCount(slideCount + 1);
106
+ setCount(next);
104
107
  setStarted(true);
108
+ emitEvent({
109
+ type: 'notifyProgress',
110
+ payload: {
111
+ slide: next
112
+ }
113
+ });
105
114
  }
106
- }, [pause, slideCount, slides.length]);
115
+ }, [pause, slideCount, slides.length, emitEvent]);
107
116
  var goToPreviousSlide = (0, _react.useCallback)(function () {
108
117
  setStarted(false);
109
118
  setAudioFailed(false);
110
119
 
111
120
  if (slideCount - 1 >= 0) {
121
+ var next = slideCount - 1;
112
122
  setTransition('slide-animation');
113
- setCount(slideCount - 1);
123
+ setCount(next);
114
124
  setStarted(true);
115
125
  play('click-ui');
126
+ emitEvent({
127
+ type: 'notifyProgress',
128
+ payload: {
129
+ slide: next
130
+ }
131
+ });
116
132
  }
117
- }, [play, slideCount]);
133
+ }, [play, slideCount, emitEvent]);
118
134
 
119
135
  var handleManualNext = function handleManualNext() {
120
136
  play('click-ui');
@@ -71,7 +71,9 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
71
71
  background = _ref.background,
72
72
  soundActions = _ref.soundActions,
73
73
  lodSettings = _ref.lodSettings,
74
- autoPlay = _ref.autoPlay;
74
+ autoPlay = _ref.autoPlay,
75
+ progress = _ref.progress;
76
+ var defaultLine = (progress === null || progress === void 0 ? void 0 : progress.line) || 0;
75
77
 
76
78
  var _useState = (0, _react.useState)(false),
77
79
  _useState2 = _slicedToArray(_useState, 2),
@@ -93,7 +95,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
93
95
  audioFailed = _useState8[0],
94
96
  setAudioFailed = _useState8[1];
95
97
 
96
- var _useState9 = (0, _react.useState)(0),
98
+ var _useState9 = (0, _react.useState)(defaultLine),
97
99
  _useState10 = _slicedToArray(_useState9, 2),
98
100
  currentLine = _useState10[0],
99
101
  setCurrentLine = _useState10[1];
@@ -137,8 +139,15 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
137
139
  var lastLine = lines.find(function (line) {
138
140
  return line.id === (lastEdge === null || lastEdge === void 0 ? void 0 : lastEdge.fromId);
139
141
  });
142
+
143
+ if (!lastNodeId && (progress === null || progress === void 0 ? void 0 : progress.line) >= 0) {
144
+ return {
145
+ decision: true
146
+ };
147
+ }
148
+
140
149
  return lastLine;
141
- }, [edges, lines, lastNodeId]);
150
+ }, [edges, lines, lastNodeId, progress === null || progress === void 0 ? void 0 : progress.line]);
142
151
  var previousLineWasDecision = (0, _react.useCallback)(function () {
143
152
  if (isBranched) {
144
153
  // if we have edges, we need to check if the previous line was a decision
@@ -280,13 +289,19 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
280
289
  reset();
281
290
  } else if (destinationEdge >= 0) {
282
291
  setCurrentLine(destinationEdge);
292
+ emitEvent({
293
+ type: 'notifyProgress',
294
+ payload: {
295
+ line: destinationEdge
296
+ }
297
+ });
283
298
  } else {
284
299
  finishConversation();
285
300
  }
286
301
  } else {
287
302
  finishConversation();
288
303
  }
289
- }, [currentLineData.id, edges, finishConversation, lines]);
304
+ }, [currentLineData.id, edges, emitEvent, finishConversation, lines]);
290
305
  var handleBranchDirection = (0, _react.useCallback)(function () {
291
306
  var forward = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
292
307
  var keys = forward ? ['fromId', 'toId'] : ['toId', 'fromId'];
@@ -312,10 +327,16 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
312
327
 
313
328
  if (destination >= 0) {
314
329
  setCurrentLine(destination);
330
+ emitEvent({
331
+ type: 'notifyProgress',
332
+ payload: {
333
+ line: destination
334
+ }
335
+ });
315
336
  } else {
316
337
  finishConversation();
317
338
  }
318
- }, [currentLineData.id, edges, edgesHistory, finishConversation, lastNodeId, lines]);
339
+ }, [currentLineData.id, edges, edgesHistory, emitEvent, finishConversation, lastNodeId, lines]);
319
340
  var handleClickNext = (0, _react.useCallback)(function (choice, reset) {
320
341
  var isLast = false;
321
342
  setTTsStart(false);
@@ -334,7 +355,14 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
334
355
  var maxLine = lines.length - 1;
335
356
 
336
357
  if (line + 1 <= maxLine) {
337
- setCurrentLine(line + 1);
358
+ var next = line + 1;
359
+ setCurrentLine(next);
360
+ emitEvent({
361
+ type: 'notifyProgress',
362
+ payload: {
363
+ line: next
364
+ }
365
+ });
338
366
  } else if (currentLineData.decision) {
339
367
  finishConversation();
340
368
  } else {
@@ -345,7 +373,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
345
373
  if (!isLast) {
346
374
  setStarted(true);
347
375
  }
348
- }, [currentLine, currentLineData.decision, currentLineData.id, finishConversation, handleBranchDirection, handleDecisionBranch, isBranched, lines.length, edgesHistory]);
376
+ }, [emitEvent, currentLine, currentLineData.decision, currentLineData.id, finishConversation, handleBranchDirection, handleDecisionBranch, isBranched, lines.length, edgesHistory]);
349
377
 
350
378
  var handleClickBack = function handleClickBack() {
351
379
  setStarted(false);
@@ -355,7 +383,14 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
355
383
  if (isBranched) {
356
384
  handleBranchDirection(false);
357
385
  } else if (!previousLineWasDecision()) {
358
- setCurrentLine(currentLine - 1);
386
+ var next = currentLine - 1;
387
+ setCurrentLine(next);
388
+ emitEvent({
389
+ type: 'notifyProgress',
390
+ payload: {
391
+ line: next
392
+ }
393
+ });
359
394
  }
360
395
 
361
396
  setStarted(true);
@@ -453,6 +488,14 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
453
488
 
454
489
  (0, _react.useEffect)(function () {
455
490
  if (isBranched && !mounted) {
491
+ var defaultBranch = progress === null || progress === void 0 ? void 0 : progress.line;
492
+
493
+ if (defaultBranch >= 0) {
494
+ setMounted(true);
495
+ setCurrentLine(defaultBranch);
496
+ return;
497
+ }
498
+
456
499
  var startNodes = lines.filter(function (node) {
457
500
  return !edges.find(function (edge) {
458
501
  return edge.toId === node.id;
@@ -469,7 +512,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
469
512
  }
470
513
  }
471
514
  }
472
- }, [edges, isBranched, lines, mounted]);
515
+ }, [edges, isBranched, lines, mounted, progress === null || progress === void 0 ? void 0 : progress.line]);
473
516
  keyboardControl(isDecision || disableBackButton ? null : manualClickBack, isDecision ? null : manualClickNext);
474
517
 
475
518
  var decisionPayload = _objectSpread(_objectSpread({}, currentLineData.payload), {}, {
@@ -83,9 +83,11 @@ var DialogComponent = function DialogComponent(_ref) {
83
83
  soundActions = _ref.soundActions,
84
84
  zoomInActor = _ref.zoomInActor,
85
85
  autoPlay = _ref.autoPlay,
86
- pause = _ref.pause;
86
+ pause = _ref.pause,
87
+ progress = _ref.progress;
88
+ var defaultLine = (progress === null || progress === void 0 ? void 0 : progress.line) || 0;
87
89
 
88
- var _useState = (0, _react.useState)(0),
90
+ var _useState = (0, _react.useState)(defaultLine),
89
91
  _useState2 = _slicedToArray(_useState, 2),
90
92
  line = _useState2[0],
91
93
  changeLine = _useState2[1];
@@ -210,6 +212,13 @@ var DialogComponent = function DialogComponent(_ref) {
210
212
  var lastL = lines.find(function (l) {
211
213
  return l.id === (lastEdge === null || lastEdge === void 0 ? void 0 : lastEdge.fromId);
212
214
  });
215
+
216
+ if (!lastNodeId && (progress === null || progress === void 0 ? void 0 : progress.line) >= 0) {
217
+ return {
218
+ decision: true
219
+ };
220
+ }
221
+
213
222
  return lastL;
214
223
  }, [edges, lines, lastNodeId]);
215
224
  var previousLineWasDecision = (0, _react.useCallback)(function () {
@@ -480,10 +489,16 @@ var DialogComponent = function DialogComponent(_ref) {
480
489
  show: false
481
490
  });
482
491
  changeLine(destination);
492
+ emitEvent({
493
+ type: 'notifyProgress',
494
+ payload: {
495
+ line: destination
496
+ }
497
+ });
483
498
  } else {
484
499
  finishConversation();
485
500
  }
486
- }, [currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.id, edges, finishConversation, lines]);
501
+ }, [currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.id, emitEvent, edges, finishConversation, lines]);
487
502
  var handleDecisionBranch = (0, _react.useCallback)(function (choice, reset) {
488
503
  var currentId = [3, 2, 1][choice.id];
489
504
  var optionsEdges = edges.filter(function (edge) {
@@ -504,6 +519,12 @@ var DialogComponent = function DialogComponent(_ref) {
504
519
  show: false
505
520
  });
506
521
  changeLine(destinationEdge);
522
+ emitEvent({
523
+ type: 'notifyProgress',
524
+ payload: {
525
+ line: destinationEdge
526
+ }
527
+ });
507
528
  }
508
529
  } else {
509
530
  finishConversation();
@@ -517,12 +538,19 @@ var DialogComponent = function DialogComponent(_ref) {
517
538
  if (isBranched) {
518
539
  handleBranchDirection(false);
519
540
  } else if (!previousLineWasDecision()) {
541
+ var next = line - 1;
520
542
  setCurrentMessage({
521
543
  show: false
522
544
  });
523
- changeLine(line - 1);
545
+ changeLine(next);
546
+ emitEvent({
547
+ type: 'notifyProgress',
548
+ payload: {
549
+ line: next
550
+ }
551
+ });
524
552
  }
525
- }, [handleBranchDirection, isBranched, lastLine, line, talkingCharacter]);
553
+ }, [handleBranchDirection, emitEvent, isBranched, lastLine, line, talkingCharacter]);
526
554
  var nextLine = (0, _react.useCallback)(function (choice, reset) {
527
555
  lastTalking.current = _objectSpread({}, talkingCharacter);
528
556
  resetTalkingAnimation();
@@ -536,14 +564,21 @@ var DialogComponent = function DialogComponent(_ref) {
536
564
  handleBranchDirection();
537
565
  }
538
566
  } else if (line < lines.length - 1) {
567
+ var next = line + 1;
539
568
  setCurrentMessage({
540
569
  show: false
541
570
  });
542
- changeLine(line + 1);
571
+ changeLine(next);
572
+ emitEvent({
573
+ type: 'notifyProgress',
574
+ payload: {
575
+ line: next
576
+ }
577
+ });
543
578
  } else if (currentLineData.decision) {
544
579
  finishConversation();
545
580
  }
546
- }, [currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.decision, isBranched, line, lines.length, handleDecisionBranch, handleBranchDirection, finishConversation, talkingCharacter]);
581
+ }, [emitEvent, currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.decision, isBranched, line, lines.length, handleDecisionBranch, handleBranchDirection, finishConversation, talkingCharacter]);
547
582
 
548
583
  var manualBackLine = function manualBackLine() {
549
584
  setAutomatic(false);
@@ -573,6 +608,14 @@ var DialogComponent = function DialogComponent(_ref) {
573
608
 
574
609
  (0, _react.useEffect)(function () {
575
610
  if (isBranched && !mounted) {
611
+ var defaultBranch = progress === null || progress === void 0 ? void 0 : progress.line;
612
+
613
+ if (defaultBranch >= 0) {
614
+ setMounted(true);
615
+ changeLine(defaultBranch);
616
+ return;
617
+ }
618
+
576
619
  var startNodes = lines.filter(function (node) {
577
620
  return !edges.find(function (edge) {
578
621
  return edge.toId === node.id;
@@ -65,7 +65,8 @@ var Questions = function Questions(_ref) {
65
65
  return !disabled ? updateForm(answer, question.id, index) : null;
66
66
  },
67
67
  key: answer.text,
68
- className: "unset-button test--response__item ".concat(disabled ? 'review' : '', " ").concat(getClass(answer))
68
+ className: "unset-button test--response__item ".concat(disabled ? 'review' : '', " ").concat(getClass(answer)),
69
+ disabled: disabled && !getClass(answer)
69
70
  }, /*#__PURE__*/_react.default.createElement("div", {
70
71
  className: "test--response__index"
71
72
  }, LABELS_INDEX[index]), /*#__PURE__*/_react.default.createElement("div", {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@gamelearn/arcade-components",
3
3
  "author": "Gamelearn",
4
4
  "license": "unlicense",
5
- "version": "2.22.1",
5
+ "version": "2.23.1",
6
6
  "main": "dist/index.js",
7
7
  "files": [
8
8
  "dist",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@babel/runtime": "^7.18.6",
17
- "@gamelearn/arcade-styles": "2.15.1",
17
+ "@gamelearn/arcade-styles": "2.15.2",
18
18
  "@gamelearn/arcade-three-core": "^1.24.3-beta.2",
19
19
  "@react-three/a11y": "^3.0.0",
20
20
  "@react-three/drei": "9.4.3",