@gamelearn/arcade-components 0.27.2 → 0.27.4

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.
@@ -95,7 +95,7 @@ var DecisionComponent = function DecisionComponent(_ref) {
95
95
  var listProps = _objectSpread(_objectSpread({}, inheritProps), {}, {
96
96
  slots: inheritProps.slots ? inheritProps.slots : inheritProps.characters,
97
97
  currentMessage: {
98
- position: -1,
98
+ position: null,
99
99
  emotion: ''
100
100
  }
101
101
  });
@@ -58,6 +58,9 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
58
58
  var isMobile = (0, _deviceDetection.DeviceDetection)();
59
59
  var crossFadeDuration = 0.5; // Mobile always zoom in?
60
60
 
61
+ var raycast = new _three.Raycaster();
62
+ raycast.firstHitOnly = true;
63
+
61
64
  var DialogComponent = function DialogComponent(_ref) {
62
65
  var _currentLine$audio3, _currentLine$audio4;
63
66
 
@@ -100,6 +103,7 @@ var DialogComponent = function DialogComponent(_ref) {
100
103
  camera = _useThree2[0],
101
104
  scene = _useThree2[1];
102
105
 
106
+ var changedMats = (0, _react.useRef)([]);
103
107
  var loader = (0, _react.useMemo)(function () {
104
108
  return new _GLTFLoader.GLTFLoader();
105
109
  }, []);
@@ -207,10 +211,10 @@ var DialogComponent = function DialogComponent(_ref) {
207
211
 
208
212
  var onLoadAnim = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {};
209
213
  var animation = (_slot$character2 = slot.character) === null || _slot$character2 === void 0 ? void 0 : _slot$character2.resource.animations[slot.emotion];
214
+ var mixer = element.userData.mixer;
210
215
 
211
- if (animation) {
212
- var mixer = element.userData.mixer;
213
- loader.load(animation === null || animation === void 0 ? void 0 : animation.url, function (anim) {
216
+ if (animation && animation.url) {
217
+ loader.load(animation.url, function (anim) {
214
218
  var emotionClip = anim.animations[0];
215
219
  var defaultClip = element.userData.defaultAnim;
216
220
  var emotionAction = mixer.clipAction(emotionClip, element);
@@ -223,6 +227,8 @@ var DialogComponent = function DialogComponent(_ref) {
223
227
  element.userData.currentEmotion = emotionAction;
224
228
  onLoadAnim(mixer, emotionAction, defaultAction);
225
229
  });
230
+ } else {
231
+ onLoadAnim();
226
232
  }
227
233
  }, [loader]); // Reset currentEmotion to defaultAnim
228
234
 
@@ -325,7 +331,7 @@ var DialogComponent = function DialogComponent(_ref) {
325
331
  loadEmotion(slot, element, function (mixer, action, defaultAction) {
326
332
  var startAction = element.userData.lastEmotion ? element.userData.lastEmotion : defaultAction;
327
333
 
328
- if (startAction !== action) {
334
+ if (startAction && action && startAction !== action) {
329
335
  mixer.stopAllAction();
330
336
  (0, _helpers.executeCrossFade)(startAction, action, crossFadeDuration);
331
337
  }
@@ -343,7 +349,7 @@ var DialogComponent = function DialogComponent(_ref) {
343
349
  loadEmotion(talkingCharacter, element, function (mixer, action, defaultAction) {
344
350
  var startAction = element.userData.lastEmotion ? element.userData.lastEmotion : defaultAction;
345
351
 
346
- if (startAction !== action) {
352
+ if (startAction && action && startAction !== action) {
347
353
  mixer.stopAllAction();
348
354
  (0, _helpers.executeCrossFade)(startAction, action, crossFadeDuration);
349
355
  } // Ugly timeout to wait an animation transition
@@ -423,7 +429,7 @@ var DialogComponent = function DialogComponent(_ref) {
423
429
  if (line >= lines.length - 1 && automatic) {
424
430
  setAutomatic(false);
425
431
  } else if (automatic && currentMessage.text && !currentLine.decision) {
426
- var time = 70 * (currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.text.length);
432
+ var time = 75 * (currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.text.length);
427
433
  timeout = setTimeout(function () {
428
434
  nextLine();
429
435
  }, time < 1400 ? 1400 : time);
@@ -494,13 +500,25 @@ var DialogComponent = function DialogComponent(_ref) {
494
500
  animationTarget.current.applyQuaternion(camera.quaternion);
495
501
  }
496
502
 
497
- animationTarget.current.translateX(13);
503
+ animationTarget.current.translateX(12);
498
504
  animationTarget.current.translateY(-5);
499
505
  animationTarget.current.translateZ(30);
500
506
  }
501
507
 
502
508
  if (animationTarget.current.position.distanceTo(camera.position) < 1) {
503
509
  animationStart.current = false;
510
+ raycast.set(camera.getWorldPosition(new _three.Vector3(0, 0, 0)), camera.getWorldDirection(new _three.Vector3()));
511
+ var objects = raycast.intersectObjects(scene.children, true);
512
+ changedMats.current = objects.filter(function (o) {
513
+ return o.distance < 10;
514
+ });
515
+
516
+ if (changedMats.current.length) {
517
+ changedMats.current.forEach(function (o) {
518
+ var object = o.object;
519
+ object.material.visible = false;
520
+ });
521
+ }
504
522
 
505
523
  if (lastSet.current || !messagePosition.current.child) {
506
524
  camera.copy(defaultCamera.current);
@@ -508,6 +526,13 @@ var DialogComponent = function DialogComponent(_ref) {
508
526
 
509
527
  checkBubblePosition();
510
528
  } else {
529
+ if (changedMats.current.length) {
530
+ changedMats.current.forEach(function (o) {
531
+ var object = o.object;
532
+ object.material.visible = true;
533
+ });
534
+ }
535
+
511
536
  camera.position.lerp(animationTarget.current.position, delta * 2.5);
512
537
  }
513
538
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gamelearn/arcade-components",
3
3
  "license": "Gamelearn",
4
- "version": "0.27.2",
4
+ "version": "0.27.4",
5
5
  "main": "dist/index.js",
6
6
  "files": [
7
7
  "dist",