@gamelearn/arcade-components 1.20.1 → 1.21.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.
@@ -31,6 +31,8 @@ var AnimationComponent = function AnimationComponent(_ref) {
31
31
  var animation = _ref.animation,
32
32
  loopTimes = _ref.loopTimes,
33
33
  resource = _ref.resource,
34
+ enableInteraction = _ref.enableInteraction,
35
+ makeDefault = _ref.makeDefault,
34
36
  emitEvent = _ref.emitEvent;
35
37
 
36
38
  var _useState = (0, _react.useState)(false),
@@ -46,7 +48,7 @@ var AnimationComponent = function AnimationComponent(_ref) {
46
48
  }, []);
47
49
  (0, _react.useEffect)(function () {
48
50
  setMounted(false);
49
- }, [resource.elementUid, animation.url]);
51
+ }, [resource.uid, animation.url]);
50
52
  (0, _react.useEffect)(function () {
51
53
  if (!mounted) {
52
54
  var object;
@@ -57,6 +59,10 @@ var AnimationComponent = function AnimationComponent(_ref) {
57
59
  });
58
60
 
59
61
  if (object) {
62
+ var canInteract = enableInteraction;
63
+ if (canInteract) emitEvent({
64
+ type: 'success'
65
+ });
60
66
  loader.load(animation.url, function (gltf) {
61
67
  var mixer = object.userData.mixer;
62
68
  var defaultAnim = object.userData.defaultAnim;
@@ -68,7 +74,18 @@ var AnimationComponent = function AnimationComponent(_ref) {
68
74
 
69
75
  var finishCallback = function finishCallback() {
70
76
  (0, _helpers.executeCrossFade)(currentAction, oldAction, 0.5);
71
- emitEvent({
77
+
78
+ if (makeDefault) {
79
+ emitEvent({
80
+ type: 'saveAnimation',
81
+ payload: {
82
+ uid: resource.uid,
83
+ animation: animation.id
84
+ }
85
+ });
86
+ }
87
+
88
+ if (!canInteract) emitEvent({
72
89
  type: 'success'
73
90
  });
74
91
  mixer.removeEventListener('finished', finishCallback);
@@ -83,7 +100,7 @@ var AnimationComponent = function AnimationComponent(_ref) {
83
100
  });
84
101
  }
85
102
  }
86
- }, [scene, animation.url, loopTimes, emitEvent, mounted, loader, resource.uid]);
103
+ }, [scene, animation.url, loopTimes, emitEvent, mounted, loader, resource.uid, makeDefault, animation, resource, enableInteraction]);
87
104
  return null;
88
105
  };
89
106
 
@@ -300,6 +300,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
300
300
  };
301
301
 
302
302
  var autoplayCond = automatic && !isDecision;
303
+ var disableBackButton = currentLine === 0 || currentLine > 0 && (lastLine === null || lastLine === void 0 ? void 0 : lastLine.decision);
303
304
  var stopEkho = (0, _useEkho.default)({
304
305
  audioType: currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType,
305
306
  voice: currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.voice,
@@ -332,7 +333,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
332
333
  return function () {
333
334
  stop();
334
335
  };
335
- }, [currentMessage, start, stop, handleClickNext, currentLineData.audioType, autoplayCond, audioFailed]);
336
+ }, [currentMessage, start, stop, handleClickNext, currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType, autoplayCond, audioFailed]);
336
337
 
337
338
  var decisionPayload = _objectSpread(_objectSpread({}, currentLineData.payload), {}, {
338
339
  required: !isBranched,
@@ -368,8 +369,8 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
368
369
  }) : null, /*#__PURE__*/_react.default.createElement("div", {
369
370
  className: "conversation--controls"
370
371
  }, /*#__PURE__*/_react.default.createElement("button", {
371
- className: "gat--btn__round ".concat(currentLine > 0 && (!lastLine.decision || isBranched) ? '' : 'disabled'),
372
- disabled: currentLine > 0 && (!lastLine.decision || isBranched) ? '' : true,
372
+ className: "gat--btn__round ".concat(disableBackButton ? 'disabled' : ''),
373
+ disabled: disableBackButton ? true : '',
373
374
  type: "button",
374
375
  onClick: manualClickBack
375
376
  }, /*#__PURE__*/_react.default.createElement("span", {
@@ -200,14 +200,16 @@ var DialogComponent = function DialogComponent(_ref) {
200
200
  var defaultAction = mixer.clipAction(element.userData.defaultAnim, element);
201
201
 
202
202
  if (element.userData.currentEmotion !== defaultAction) {
203
- mixer.stopAllAction();
204
- (0, _helpers.executeCrossFade)(startAction, defaultAction, crossFadeDuration);
203
+ setTimeout(function () {
204
+ mixer.stopAllAction();
205
+ (0, _helpers.executeCrossFade)(startAction, defaultAction, crossFadeDuration / Math.floor(Math.random() * 3));
205
206
 
206
- if (element.userData.currentEmotion) {
207
- element.userData.lastEmotion = element.userData.currentEmotion;
208
- }
207
+ if (element.userData.currentEmotion) {
208
+ element.userData.lastEmotion = element.userData.currentEmotion;
209
+ }
209
210
 
210
- element.userData.currentEmotion = defaultAction;
211
+ element.userData.currentEmotion = defaultAction;
212
+ }, Math.floor(Math.random() * 3) * 500);
211
213
  }
212
214
  }; // Reset currentEmotion to defaultAnim
213
215
 
@@ -359,12 +361,14 @@ var DialogComponent = function DialogComponent(_ref) {
359
361
 
360
362
  if (element) {
361
363
  loadEmotion(slot, element, function (mixer, action, defaultAction) {
362
- var startAction = element.userData.lastEmotion ? element.userData.lastEmotion : defaultAction;
364
+ setTimeout(function () {
365
+ var startAction = element.userData.lastEmotion ? element.userData.lastEmotion : defaultAction;
363
366
 
364
- if (startAction && action && startAction !== action) {
365
- mixer.stopAllAction();
366
- (0, _helpers.executeCrossFade)(startAction, action, crossFadeDuration);
367
- }
367
+ if (startAction && action && startAction !== action) {
368
+ mixer.stopAllAction();
369
+ (0, _helpers.executeCrossFade)(startAction, action, crossFadeDuration / Math.floor(Math.random() * 3));
370
+ }
371
+ }, Math.floor(Math.random() * 3) * 500);
368
372
  });
369
373
  }
370
374
  }); // Talking element logic
@@ -586,6 +590,7 @@ var DialogComponent = function DialogComponent(_ref) {
586
590
  height: '100vh',
587
591
  position: 'static'
588
592
  };
593
+ var disableBackButton = line === 0 || line > 0 && (lastLine === null || lastLine === void 0 ? void 0 : lastLine.decision);
589
594
 
590
595
  if (isDecision) {
591
596
  var decisionPayload = _objectSpread(_objectSpread({}, currentLine.payload), {}, {
@@ -601,7 +606,7 @@ var DialogComponent = function DialogComponent(_ref) {
601
606
  });
602
607
 
603
608
  return /*#__PURE__*/_react.default.createElement(_arcadeThreeCore.HtmlPro, {
604
- zIndexRange: [3, 3],
609
+ zIndexRange: [6, 6],
605
610
  style: cleanStyle,
606
611
  calculatePosition: function calculatePosition() {
607
612
  return [0, 0];
@@ -630,7 +635,7 @@ var DialogComponent = function DialogComponent(_ref) {
630
635
  width: '100vw',
631
636
  height: '100vh'
632
637
  },
633
- zIndexRange: [3, 3],
638
+ zIndexRange: [6, 6],
634
639
  onOcclude: function onOcclude() {},
635
640
  calculatePosition: function calculatePosition() {
636
641
  return [0, 0];
@@ -639,10 +644,10 @@ var DialogComponent = function DialogComponent(_ref) {
639
644
  dir: (0, _LangIsRtl.default)() ? 'rtl' : 'ltr',
640
645
  className: "dialog-component-controls"
641
646
  }, /*#__PURE__*/_react.default.createElement("button", {
642
- disabled: line <= 0 || (lastLine === null || lastLine === void 0 ? void 0 : lastLine.decision) || isBranched,
647
+ disabled: disableBackButton,
643
648
  type: "button",
644
649
  onClick: manualBackLine,
645
- className: "gat--btn__round ".concat(line <= 0 || lastLine !== null && lastLine !== void 0 && lastLine.decision || isBranched ? 'disabled' : '')
650
+ className: "gat--btn__round ".concat(disableBackButton ? 'disabled' : '')
646
651
  }, /*#__PURE__*/_react.default.createElement("span", {
647
652
  className: (0, _LangIsRtl.default)() ? 'icon-next' : 'icon-back'
648
653
  })), /*#__PURE__*/_react.default.createElement("button", {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@gamelearn/arcade-components",
3
3
  "author": "Gamelearn",
4
4
  "license": "unlicense",
5
- "version": "1.20.1",
5
+ "version": "1.21.1",
6
6
  "main": "dist/index.js",
7
7
  "files": [
8
8
  "dist",