@gamelearn/arcade-components 1.18.5 → 1.19.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.
@@ -134,16 +134,19 @@ var DialogComponent = function DialogComponent(_ref) {
134
134
  var lastLine = lines[line - 1];
135
135
  var lastSet = (0, _react.useRef)(false);
136
136
  var isBranched = !!edges;
137
- var voiceOver = currentLine.voiceOver,
138
- decision = currentLine.decision;
137
+
138
+ var _ref2 = currentLine || {},
139
+ voiceOver = _ref2.voiceOver,
140
+ decision = _ref2.decision;
141
+
139
142
  var translate = (0, _react.useCallback)(function (id) {
140
143
  return emitEvent({
141
144
  type: 'translate',
142
145
  payload: id
143
146
  });
144
147
  }, [emitEvent]);
145
- var isVoiceOver = voiceOver || currentLine.type === 'conversationalNarration';
146
- var isDecision = decision || currentLine.type === 'conversationalDecision';
148
+ var isVoiceOver = voiceOver || (currentLine === null || currentLine === void 0 ? void 0 : currentLine.type) === 'conversationalNarration';
149
+ var isDecision = decision || (currentLine === null || currentLine === void 0 ? void 0 : currentLine.type) === 'conversationalDecision';
147
150
  var getCurrentVisible = (0, _react.useCallback)(function (uid) {
148
151
  var object;
149
152
  scene.traverseVisible(function (node) {
@@ -240,7 +243,7 @@ var DialogComponent = function DialogComponent(_ref) {
240
243
  var forward = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
241
244
  var keys = forward ? ['fromId', 'toId'] : ['toId', 'fromId'];
242
245
  var foundEdge = edges.find(function (edge) {
243
- return edge[keys[0]] === currentLine.id;
246
+ return edge[keys[0]] === (currentLine === null || currentLine === void 0 ? void 0 : currentLine.id);
244
247
  });
245
248
 
246
249
  if (!(foundEdge !== null && foundEdge !== void 0 && foundEdge[keys[0]])) {
@@ -259,7 +262,7 @@ var DialogComponent = function DialogComponent(_ref) {
259
262
  finishConversation();
260
263
  }
261
264
  }
262
- }, [currentLine.id, edges, finishConversation, lines]);
265
+ }, [currentLine === null || currentLine === void 0 ? void 0 : currentLine.id, edges, finishConversation, lines]);
263
266
  var backLine = (0, _react.useCallback)(function () {
264
267
  setAudioFailed(false);
265
268
 
@@ -275,7 +278,7 @@ var DialogComponent = function DialogComponent(_ref) {
275
278
  var handleDecisionBranch = (0, _react.useCallback)(function (choice, reset) {
276
279
  var currentId = [3, 2, 1][choice.id];
277
280
  var optionsEdges = edges.filter(function (edge) {
278
- return edge.fromId === currentLine.id;
281
+ return edge.fromId === (currentLine === null || currentLine === void 0 ? void 0 : currentLine.id);
279
282
  });
280
283
  var currentEdge = optionsEdges.find(function (edge) {
281
284
  return parseInt(edge.fromPointIndex) === currentId;
@@ -296,7 +299,7 @@ var DialogComponent = function DialogComponent(_ref) {
296
299
  } else {
297
300
  finishConversation();
298
301
  }
299
- }, [currentLine.id, edges, finishConversation, lines]);
302
+ }, [currentLine === null || currentLine === void 0 ? void 0 : currentLine.id, edges, finishConversation, lines]);
300
303
  var nextLine = (0, _react.useCallback)(function (choice, reset) {
301
304
  setAudioFailed(false);
302
305
 
@@ -333,8 +336,8 @@ var DialogComponent = function DialogComponent(_ref) {
333
336
  } else if (isVoiceOver) {
334
337
  resetCameraView();
335
338
  setCurrentMessage({
336
- text: currentLine.text,
337
- name: currentLine.alias || currentLine.name || "[ ".concat(translate('storylines.misc.voiceOver'), " ]"),
339
+ text: currentLine === null || currentLine === void 0 ? void 0 : currentLine.text,
340
+ name: (currentLine === null || currentLine === void 0 ? void 0 : currentLine.alias) || (currentLine === null || currentLine === void 0 ? void 0 : currentLine.name) || "[ ".concat(translate('storylines.misc.voiceOver'), " ]"),
338
341
  left: false,
339
342
  inScene: false,
340
343
  voiceOver: true,
@@ -344,10 +347,10 @@ var DialogComponent = function DialogComponent(_ref) {
344
347
  show: true
345
348
  });
346
349
  } else if (!lastSet.current) {
347
- var talkingCharacter = currentLine.slots.find(function (slot) {
350
+ var talkingCharacter = currentLine === null || currentLine === void 0 ? void 0 : currentLine.slots.find(function (slot) {
348
351
  return slot.talking;
349
352
  });
350
- var slottedCharacters = currentLine.slots.filter(function (slot) {
353
+ var slottedCharacters = currentLine === null || currentLine === void 0 ? void 0 : currentLine.slots.filter(function (slot) {
351
354
  return slot.uid && !slot.talking;
352
355
  }); // Check not talking elements emotion
353
356
 
@@ -379,64 +382,46 @@ var DialogComponent = function DialogComponent(_ref) {
379
382
  if (startAction && action && startAction !== action) {
380
383
  mixer.stopAllAction();
381
384
  (0, _helpers.executeCrossFade)(startAction, action, crossFadeDuration);
382
- } // Ugly timeout to wait an animation transition
385
+ }
386
+ });
387
+
388
+ if (talkingCharacter.uid === element.uid) {
389
+ var showArrowTop = talkingCharacter.text.length > maxCharacterToSwitch;
390
+ var head = element.getObjectByName('Head_M');
391
+ var target = new _three.Object3D();
392
+ head.getWorldPosition(target.position);
393
+ target.applyQuaternion(camera.quaternion);
394
+ target.translateX(1.25);
395
+ var distance = camera.position.distanceTo(target.position);
396
+ var staticDisplay = distance > 70 && !zoomInActor && !showArrowTop;
397
+ target.translateY(staticDisplay || showArrowTop ? 0 : 3);
398
+ messagePosition.current = {
399
+ pos: target.position.toArray(),
400
+ child: head,
401
+ parent: element
402
+ };
403
+
404
+ if (zoomInActor) {
405
+ animationStart.current = true;
406
+ } // Ugly timeout to wait for zoom in ( maybe use tween (?))
383
407
 
384
408
 
385
409
  setTimeout(function () {
386
- if (talkingCharacter.uid === element.uid) {
387
- var showArrowTop = talkingCharacter.text.length > maxCharacterToSwitch;
388
- var head = element.getObjectByName('Head_M');
389
- var target = new _three.Object3D();
390
- head.getWorldPosition(target.position);
391
- target.applyQuaternion(camera.quaternion);
392
- target.translateX(1.25);
393
- var distanceToCam = camera.position.distanceTo(element.position);
394
- var bbox = new _three.Box3().setFromObject(element);
395
- var size = bbox.getSize(new _three.Vector3());
396
- var distanceMultiplier = 1;
397
-
398
- if (distanceToCam > 200 && !zoomInActor) {
399
- distanceMultiplier = size.y / 3.5;
400
-
401
- if (distanceToCam > 400) {
402
- distanceMultiplier = size.y / 2;
403
-
404
- if (distanceToCam > 600) {
405
- distanceMultiplier = size.y / 1.5;
406
- }
407
- }
408
- }
409
-
410
- var baseY = 3 * distanceMultiplier;
411
- target.translateY(showArrowTop ? 1.25 : baseY);
412
- messagePosition.current = {
413
- pos: target.position.toArray(),
414
- child: head,
415
- parent: element
416
- };
417
-
418
- if (zoomInActor) {
419
- animationStart.current = true;
420
- } // Ugly timeout to wait for zoom in ( maybe use tween (?))
421
-
422
-
423
- setTimeout(function () {
424
- var _talkingCharacter$cha;
425
-
426
- setCurrentMessage({
427
- text: talkingCharacter.text,
428
- name: talkingCharacter.alias || ((_talkingCharacter$cha = talkingCharacter.character) === null || _talkingCharacter$cha === void 0 ? void 0 : _talkingCharacter$cha.name),
429
- left: true,
430
- top: showArrowTop,
431
- inScene: true,
432
- thinkful: talkingCharacter.emotion === 'thinkful',
433
- avatar: '',
434
- show: true
435
- });
436
- }, zoomInActor ? 1200 : 0);
437
- }
438
- }, 1000 * crossFadeDuration);
439
- });
410
+ var _talkingCharacter$cha;
411
+
412
+ distance = camera.position.distanceTo(target.position);
413
+ setCurrentMessage({
414
+ text: talkingCharacter.text,
415
+ name: talkingCharacter.alias || ((_talkingCharacter$cha = talkingCharacter.character) === null || _talkingCharacter$cha === void 0 ? void 0 : _talkingCharacter$cha.name),
416
+ left: true,
417
+ top: showArrowTop || distance > 70,
418
+ inScene: true,
419
+ thinkful: talkingCharacter.emotion === 'thinkful',
420
+ avatar: '',
421
+ show: true
422
+ });
423
+ }, zoomInActor ? 1200 : 0);
424
+ }
440
425
  } else {
441
426
  var _talkingCharacter$cha2;
442
427
 
@@ -460,9 +445,9 @@ var DialogComponent = function DialogComponent(_ref) {
460
445
  }
461
446
  }
462
447
  }, [actors, camera, currentLine, zoomInActor, getCurrentVisible, translate, getAvatarURL, loadEmotion, resetCameraView, isDecision, isVoiceOver]);
463
- var autoPlayCond = automatic && !currentLine.decision;
464
- var audio = Object.keys(currentLine.audio || {}).length;
465
- var voice = Object.keys(currentLine.voice || {}).length; // Sound logic
448
+ var autoPlayCond = automatic && !(currentLine !== null && currentLine !== void 0 && currentLine.decision);
449
+ var audio = Object.keys((currentLine === null || currentLine === void 0 ? void 0 : currentLine.audio) || {}).length;
450
+ var voice = Object.keys((currentLine === null || currentLine === void 0 ? void 0 : currentLine.voice) || {}).length; // Sound logic
466
451
 
467
452
  var stopEkho = (0, _useEkho.default)({
468
453
  audioType: currentLine === null || currentLine === void 0 ? void 0 : currentLine.audioType,
@@ -499,12 +484,12 @@ var DialogComponent = function DialogComponent(_ref) {
499
484
  }, [currentMessage, nextLine, start, stop, currentLine === null || currentLine === void 0 ? void 0 : currentLine.audioType, autoPlayCond, audio, voice, audioFailed]); // Positioning logic
500
485
 
501
486
  var checkBubblePosition = (0, _react.useCallback)(function () {
502
- if (bubbleRef.current && currentLine.slots) {
503
- var talkingCharacter = currentLine.slots.find(function (slot) {
487
+ if (bubbleRef.current && currentLine !== null && currentLine !== void 0 && currentLine.slots) {
488
+ var talkingCharacter = currentLine === null || currentLine === void 0 ? void 0 : currentLine.slots.find(function (slot) {
504
489
  return slot.talking;
505
490
  });
506
491
  var bubbleRect = bubbleRef.current.getBoundingClientRect();
507
- var x = bubbleRect.x + bubbleRect.width - 75;
492
+ var x = bubbleRect.x + bubbleRect.width;
508
493
  var y = bubbleRect.y - bubbleRect.height;
509
494
 
510
495
  if ((x < 0 || x > window.innerWidth) && currentMessage.inScene) {
@@ -520,7 +505,7 @@ var DialogComponent = function DialogComponent(_ref) {
520
505
  var distanceX = bubbleRect.width + bubbleRect.width / divider;
521
506
  bubbleRef.current.parentNode.style.transform = "translate3d(-".concat(distanceX, "px, -").concat(bubbleRect.height, "px, 0px)");
522
507
  bubbleRect = bubbleRef.current.getBoundingClientRect();
523
- var completeOutside = x > window.innerWidth + bubbleRect.width || y < -bubbleRect.height || y > window.innerHeight || x < -bubbleRect.width;
508
+ var completeOutside = x > window.innerWidth + bubbleRect.width || y < -bubbleRect.height || y > window.innerHeight || x < -bubbleRect.width || bubbleRect.x < 10;
524
509
 
525
510
  if (completeOutside) {
526
511
  bubbleRef.current.parentNode.style.transform = '';
@@ -547,8 +532,8 @@ var DialogComponent = function DialogComponent(_ref) {
547
532
  checkBubblePosition();
548
533
  }, [checkBubblePosition]); // Animate Camera
549
534
 
550
- (0, _fiber.useFrame)(function (_ref2, delta) {
551
- var cam = _ref2.camera;
535
+ (0, _fiber.useFrame)(function (_ref3, delta) {
536
+ var cam = _ref3.camera;
552
537
 
553
538
  if (animationStart.current) {
554
539
  var targetPosition = messagePosition.current.child ? messagePosition.current.pos : defaultCamera.current.position.toArray();
@@ -640,7 +625,7 @@ var DialogComponent = function DialogComponent(_ref) {
640
625
  }, /*#__PURE__*/_react.default.createElement(_SpeechBubbleComponent.default, {
641
626
  ref: bubbleRef,
642
627
  message: currentMessage
643
- }))) : null, currentMessage.show ? /*#__PURE__*/_react.default.createElement(_arcadeThreeCore.HtmlPro, {
628
+ }))) : null, /*#__PURE__*/_react.default.createElement(_arcadeThreeCore.HtmlPro, {
644
629
  style: {
645
630
  width: '100vw',
646
631
  height: '100vh'
@@ -666,7 +651,7 @@ var DialogComponent = function DialogComponent(_ref) {
666
651
  onClick: manualNextLine
667
652
  }, /*#__PURE__*/_react.default.createElement("span", {
668
653
  className: (0, _LangIsRtl.default)() ? 'icon-back' : 'icon-next'
669
- })))) : null);
654
+ })))));
670
655
  };
671
656
 
672
657
  var _default = DialogComponent;
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.18.5",
5
+ "version": "1.19.1",
6
6
  "main": "dist/index.js",
7
7
  "files": [
8
8
  "dist",