@gamelearn/arcade-components 1.22.9 → 1.22.10-hotfix-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.
@@ -80,6 +80,7 @@ var ComicComponent = function ComicComponent(_ref) {
80
80
 
81
81
  var slide = slides === null || slides === void 0 ? void 0 : slides[slideCount];
82
82
  var close = (0, _react.useCallback)(function () {
83
+ setStarted(false);
83
84
  emitEvent({
84
85
  type: 'success'
85
86
  });
@@ -120,7 +121,7 @@ var ComicComponent = function ComicComponent(_ref) {
120
121
  goToPreviousSlide();
121
122
  };
122
123
 
123
- var stopEkho = (0, _useEkho.default)({
124
+ (0, _useEkho.default)({
124
125
  audioType: slides === null || slides === void 0 ? void 0 : (_slides$slideCount = slides[slideCount]) === null || _slides$slideCount === void 0 ? void 0 : _slides$slideCount.audioType,
125
126
  voice: slides === null || slides === void 0 ? void 0 : (_slides$slideCount2 = slides[slideCount]) === null || _slides$slideCount2 === void 0 ? void 0 : _slides$slideCount2.voice,
126
127
  text: slides === null || slides === void 0 ? void 0 : (_slides$slideCount3 = slides[slideCount]) === null || _slides$slideCount3 === void 0 ? void 0 : (_slides$slideCount3$v = _slides$slideCount3.vignettes[0].textData) === null || _slides$slideCount3$v === void 0 ? void 0 : _slides$slideCount3$v.text,
@@ -137,9 +138,6 @@ var ComicComponent = function ComicComponent(_ref) {
137
138
  }
138
139
  }
139
140
  });
140
- (0, _react.useEffect)(function () {
141
- stopEkho();
142
- }, [slideCount, stopEkho]);
143
141
  (0, _react.useEffect)(function () {
144
142
  if (automatic && ((slide === null || slide === void 0 ? void 0 : slide.audioType) === 'none' || audioFailed)) {
145
143
  var _slide$vignettes$, _slide$vignettes$$tex;
@@ -262,6 +262,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
262
262
  }
263
263
  }, [currentLineData.id, edges, finishConversation, lines]);
264
264
  var handleClickNext = (0, _react.useCallback)(function (choice, reset) {
265
+ var isLast = false;
265
266
  setPreviousLineWasDecision(currentLineData.decision);
266
267
  setStarted(false);
267
268
  setAudioFailed(false);
@@ -279,11 +280,14 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
279
280
  if (line + 1 <= maxLine) {
280
281
  setCurrentLine(line + 1);
281
282
  } else {
283
+ isLast = true;
282
284
  finishConversation();
283
285
  }
284
286
  }
285
287
 
286
- setStarted(true);
288
+ if (!isLast) {
289
+ setStarted(true);
290
+ }
287
291
  }, [currentLine, currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.decision, finishConversation, handleBranchDirection, handleDecisionBranch, isBranched, lines.length]);
288
292
 
289
293
  var handleClickBack = function handleClickBack() {
@@ -313,7 +317,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
313
317
 
314
318
  var autoplayCond = automatic && !isDecision;
315
319
  var disableBackButton = currentLine === 0 || previousLineWasDecision || currentLine > 0 && (lastLine === null || lastLine === void 0 ? void 0 : lastLine.decision);
316
- var stopEkho = (0, _useEkho.default)({
320
+ (0, _useEkho.default)({
317
321
  audioType: currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType,
318
322
  voice: currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.voice,
319
323
  started: started,
@@ -329,10 +333,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
329
333
  handleClickNext();
330
334
  }
331
335
  }
332
- });
333
- (0, _react.useEffect)(function () {
334
- stopEkho();
335
- }, [currentLine, stopEkho]); // Autoplay logic
336
+ }); // Autoplay logic
336
337
 
337
338
  (0, _react.useEffect)(function () {
338
339
  if (autoplayCond && ((currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType) === 'none' || audioFailed)) {
@@ -45,6 +45,14 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
45
45
 
46
46
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
47
47
 
48
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
49
+
50
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
51
+
52
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
53
+
54
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
55
+
48
56
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
49
57
 
50
58
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -145,6 +153,20 @@ var DialogComponent = function DialogComponent(_ref) {
145
153
  voiceOver = _ref2.voiceOver,
146
154
  decision = _ref2.decision;
147
155
 
156
+ var charactersInvolved = (0, _react.useMemo)(function () {
157
+ return lines.reduce(function (acc, current) {
158
+ if (current.slots) {
159
+ var participants = current.slots.filter(function (slot) {
160
+ return slot.uid;
161
+ });
162
+ participants.forEach(function (currentParticipant) {
163
+ if (!acc.includes(currentParticipant.uid)) acc.push(currentParticipant.uid);
164
+ });
165
+ }
166
+
167
+ return acc;
168
+ }, []);
169
+ }, [lines]);
148
170
  var translate = (0, _react.useCallback)(function (id) {
149
171
  return emitEvent({
150
172
  type: 'translate',
@@ -184,10 +206,10 @@ var DialogComponent = function DialogComponent(_ref) {
184
206
  var _slot$character2;
185
207
 
186
208
  var onLoadAnim = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {};
187
- var animation = (_slot$character2 = slot.character) === null || _slot$character2 === void 0 ? void 0 : _slot$character2.resource.animations[slot.emotion];
209
+ var animation = (_slot$character2 = slot.character) === null || _slot$character2 === void 0 ? void 0 : _slot$character2.resource.animations[element.isSeated ? "".concat(slot.emotion, "-seated") : slot.emotion];
188
210
  var mixer = element.userData.mixer;
189
211
 
190
- if (animation && animation.url && !element.isSeated) {
212
+ if (animation && animation.url) {
191
213
  loader.load(animation.url, function (anim) {
192
214
  var emotionClip = anim.animations[0];
193
215
  var defaultClip = element.userData.defaultAnim;
@@ -206,31 +228,31 @@ var DialogComponent = function DialogComponent(_ref) {
206
228
  }
207
229
  }, [loader]);
208
230
 
209
- var executeAnimation = function executeAnimation(element) {
210
- var mixer = element.userData.mixer;
211
- var startAction = mixer.clipAction(element.userData.currentEmotion.getClip(), element);
212
- var defaultAction = mixer.clipAction(element.userData.defaultAnim, element);
231
+ var executeDefaultAnimation = function executeDefaultAnimation(element) {
232
+ if (element.userData.mixer && element.userData.currentEmotion) {
233
+ var mixer = element.userData.mixer;
234
+ var startAction = mixer.clipAction(element.userData.currentEmotion.getClip(), element);
235
+ var defaultAction = mixer.clipAction(element.userData.defaultAnim, element);
213
236
 
214
- if (element.userData.currentEmotion !== defaultAction) {
215
- setTimeout(function () {
216
- mixer.stopAllAction();
217
- (0, _helpers.executeCrossFade)(startAction, defaultAction, crossFadeDuration / Math.floor(Math.random() * 3));
237
+ if (element.userData.currentEmotion !== defaultAction) {
238
+ setTimeout(function () {
239
+ mixer.stopAllAction();
240
+ (0, _helpers.executeCrossFade)(startAction, defaultAction, crossFadeDuration / Math.floor(Math.random() * 3));
218
241
 
219
- if (element.userData.currentEmotion) {
220
- element.userData.lastEmotion = element.userData.currentEmotion;
221
- }
242
+ if (element.userData.currentEmotion) {
243
+ element.userData.lastEmotion = element.userData.currentEmotion;
244
+ }
222
245
 
223
- element.userData.currentEmotion = defaultAction;
224
- }, Math.floor(Math.random() * 3) * 500);
246
+ element.userData.currentEmotion = defaultAction;
247
+ }, Math.floor(Math.random() * 3) * 500);
248
+ }
225
249
  }
226
250
  }; // Reset currentEmotion to defaultAnim
227
251
 
228
252
 
229
253
  var resetAnims = (0, _react.useCallback)(function () {
230
254
  scene.traverseVisible(function (node) {
231
- if (node.userData.mixer && node.userData.currentEmotion) {
232
- executeAnimation(node);
233
- }
255
+ return executeDefaultAnimation(node);
234
256
  });
235
257
  }, [scene]);
236
258
  var resetCameraView = (0, _react.useCallback)(function () {
@@ -387,6 +409,19 @@ var DialogComponent = function DialogComponent(_ref) {
387
409
  });
388
410
  var slottedCharacters = currentLine === null || currentLine === void 0 ? void 0 : currentLine.slots.filter(function (slot) {
389
411
  return slot.uid && !slot.talking;
412
+ });
413
+ var currentParticipants = [].concat(_toConsumableArray(slottedCharacters.map(function (slot) {
414
+ return slot.uid;
415
+ }) || []), [talkingCharacter.uid]);
416
+ var notInvolvedParticipants = charactersInvolved.filter(function (charUid) {
417
+ return !currentParticipants.includes(charUid);
418
+ });
419
+ notInvolvedParticipants.forEach(function (uid) {
420
+ var element = getCurrentVisible(uid);
421
+
422
+ if (element) {
423
+ executeDefaultAnimation(element);
424
+ }
390
425
  }); // Check not talking elements emotion
391
426
 
392
427
  slottedCharacters.forEach(function (slot) {
@@ -420,45 +455,45 @@ var DialogComponent = function DialogComponent(_ref) {
420
455
  mixer.stopAllAction();
421
456
  (0, _helpers.executeCrossFade)(startAction, action, crossFadeDuration);
422
457
  }
423
- });
424
-
425
- if (talkingCharacter.uid === element.uid) {
426
- var showArrowTop = talkingCharacter.text.length > maxCharacterToSwitch;
427
- var head = element.getObjectByName('Head_M');
428
- var target = new _three.Object3D();
429
- head.getWorldPosition(target.position);
430
- target.applyQuaternion(camera.quaternion);
431
- target.translateX(1.25);
432
- var distance = camera.position.distanceTo(target.position);
433
- var staticDisplay = distance > 70 && !zoomInActor && !showArrowTop;
434
- target.translateY(staticDisplay || showArrowTop ? 0 : 3);
435
- messagePosition.current = {
436
- pos: target.position.toArray(),
437
- child: head,
438
- parent: element
439
- };
440
-
441
- if (zoomInActor) {
442
- animationStart.current = true;
443
- } // Ugly timeout to wait for zoom in ( maybe use tween (?))
444
458
 
445
-
446
- setTimeout(function () {
447
- var _talkingCharacter$cha;
448
-
449
- distance = camera.position.distanceTo(target.position);
450
- setCurrentMessage({
451
- text: talkingCharacter.text,
452
- name: talkingCharacter.alias || ((_talkingCharacter$cha = talkingCharacter.character) === null || _talkingCharacter$cha === void 0 ? void 0 : _talkingCharacter$cha.name),
453
- left: true,
454
- top: showArrowTop || distance > 70,
455
- inScene: true,
456
- thinkful: talkingCharacter.emotion === 'thinkful',
457
- avatar: '',
458
- show: true
459
- });
460
- }, zoomInActor ? 1200 : 0);
461
- }
459
+ if (talkingCharacter.uid === element.uid) {
460
+ var showArrowTop = talkingCharacter.text.length > maxCharacterToSwitch;
461
+ var head = element.getObjectByName('Head_M');
462
+ var target = new _three.Object3D();
463
+ head.getWorldPosition(target.position);
464
+ target.applyQuaternion(camera.quaternion);
465
+ target.translateX(1.25);
466
+ var distance = camera.position.distanceTo(target.position);
467
+ var staticDisplay = distance > 70 && !zoomInActor && !showArrowTop;
468
+ target.translateY(staticDisplay || showArrowTop ? 0 : 3);
469
+ messagePosition.current = {
470
+ pos: target.position.toArray(),
471
+ child: head,
472
+ parent: element
473
+ };
474
+
475
+ if (zoomInActor) {
476
+ animationStart.current = true;
477
+ } // Ugly timeout to wait for zoom in ( maybe use tween (?))
478
+
479
+
480
+ setTimeout(function () {
481
+ var _talkingCharacter$cha;
482
+
483
+ distance = camera.position.distanceTo(target.position);
484
+ setCurrentMessage({
485
+ text: talkingCharacter.text,
486
+ name: talkingCharacter.alias || ((_talkingCharacter$cha = talkingCharacter.character) === null || _talkingCharacter$cha === void 0 ? void 0 : _talkingCharacter$cha.name),
487
+ left: true,
488
+ top: showArrowTop || distance > 70,
489
+ inScene: true,
490
+ thinkful: talkingCharacter.emotion === 'thinkful',
491
+ avatar: '',
492
+ show: true
493
+ });
494
+ }, zoomInActor ? 1200 : 0);
495
+ }
496
+ });
462
497
  } else {
463
498
  var _talkingCharacter$cha2;
464
499
 
@@ -481,7 +516,7 @@ var DialogComponent = function DialogComponent(_ref) {
481
516
  });
482
517
  }
483
518
  }
484
- }, [actors, camera, currentLine, zoomInActor, getCurrentVisible, translate, getAvatarURL, loadEmotion, resetCameraView, isDecision, isVoiceOver]);
519
+ }, [actors, camera, currentLine, zoomInActor, getCurrentVisible, translate, getAvatarURL, loadEmotion, resetCameraView, isDecision, isVoiceOver, charactersInvolved]);
485
520
  var autoPlayCond = automatic && !(currentLine !== null && currentLine !== void 0 && currentLine.decision);
486
521
  var audio = Object.keys((currentLine === null || currentLine === void 0 ? void 0 : currentLine.audio) || {}).length;
487
522
  var voice = Object.keys((currentLine === null || currentLine === void 0 ? void 0 : currentLine.voice) || {}).length; // Sound logic
@@ -505,6 +540,9 @@ var DialogComponent = function DialogComponent(_ref) {
505
540
  });
506
541
  (0, _react.useEffect)(function () {
507
542
  stopEkho();
543
+ return function () {
544
+ stopEkho();
545
+ };
508
546
  }, [line, stopEkho]); // Autoplay logic
509
547
 
510
548
  (0, _react.useEffect)(function () {
@@ -7,12 +7,6 @@ exports.default = void 0;
7
7
 
8
8
  var _react = require("react");
9
9
 
10
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
11
-
12
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
13
-
14
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
-
16
10
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
17
11
 
18
12
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
@@ -71,14 +65,7 @@ var useEkho = function useEkho(_ref) {
71
65
  type: 'translate',
72
66
  payload: id
73
67
  });
74
- }, [emitEvent]); // Setted when is mounted
75
-
76
- (0, _react.useEffect)(function () {
77
- setIsMounted(true);
78
- return function () {
79
- setIsMounted(false);
80
- };
81
- }, []); // Get translated voices, todo: translate this in arcade translateProps i18n.helper.js
68
+ }, [emitEvent]); // Get translated voices, todo: translate this in arcade translateProps i18n.helper.js
82
69
 
83
70
  var getVoice = (0, _react.useCallback)(function (_ref2) {
84
71
  var id = _ref2.id,
@@ -123,7 +110,7 @@ var useEkho = function useEkho(_ref) {
123
110
  while (1) {
124
111
  switch (_context.prev = _context.next) {
125
112
  case 0:
126
- if (!(payload.voiceId && payload.text)) {
113
+ if (!(isMounted && payload.voiceId && payload.text)) {
127
114
  _context.next = 7;
128
115
  break;
129
116
  }
@@ -160,21 +147,32 @@ var useEkho = function useEkho(_ref) {
160
147
  return function (_x) {
161
148
  return _ref3.apply(this, arguments);
162
149
  };
163
- }(), [emitEvent, onError, setCurrentPlaying]);
150
+ }(), [emitEvent, isMounted, onError, setCurrentPlaying]);
164
151
  var stopCurrentAudio = (0, _react.useCallback)(function () {
165
152
  if (currentPlaying.current.url) {
166
- currentPlaying.current = _objectSpread(_objectSpread({}, currentPlaying.current), {}, {
167
- url: ''
168
- });
153
+ currentPlaying.current = {
154
+ url: '',
155
+ cc: 'tts'
156
+ };
169
157
  stop(currentPlaying.current.cc);
170
158
  }
171
- }, [stop]);
159
+ }, [stop]); // Setted when is mounted
160
+
161
+ (0, _react.useEffect)(function () {
162
+ setIsMounted(true);
163
+ return function () {
164
+ setIsMounted(false);
165
+ stopCurrentAudio();
166
+ };
167
+ }, [stopCurrentAudio]);
172
168
  (0, _react.useEffect)(function () {
173
169
  if (noAudio) {
174
170
  stopCurrentAudio();
175
171
  }
176
172
  }, [noAudio, stopCurrentAudio]);
177
173
  (0, _react.useEffect)(function () {
174
+ stopCurrentAudio();
175
+
178
176
  if (isMounted && started) {
179
177
  if (audioType === 'voice' && voice !== null && voice !== void 0 && voice.id) {
180
178
  var voiceId = getVoice(voice);
@@ -188,7 +186,7 @@ var useEkho = function useEkho(_ref) {
188
186
  onError();
189
187
  }
190
188
  }
191
- }, [getVoice, playSpeech, isMounted, voice, text, audioType, audio === null || audio === void 0 ? void 0 : audio.url, audio, setCurrentPlaying, onError, started]);
189
+ }, [getVoice, playSpeech, isMounted, voice, text, audioType, audio === null || audio === void 0 ? void 0 : audio.url, audio, setCurrentPlaying, onError, started, stopCurrentAudio]);
192
190
  return stopCurrentAudio;
193
191
  };
194
192
 
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.22.9",
5
+ "version": "1.22.10-hotfix-2",
6
6
  "main": "dist/index.js",
7
7
  "files": [
8
8
  "dist",