@gamelearn/arcade-components 2.18.0 → 2.18.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.
@@ -63,11 +63,12 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
63
63
 
64
64
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
65
65
 
66
- var crossFadeDuration = 0.2;
66
+ var crossFadeDuration = 0.1;
67
67
  var characterMs = 75;
68
68
  var minMs = 1400;
69
69
  var headSize = 2;
70
70
  var raycast = new _three.Raycaster();
71
+ var animationTarget = new _three.Object3D();
71
72
  var maxCharacterToSwitch = 70;
72
73
  raycast.firstHitOnly = true;
73
74
 
@@ -109,12 +110,12 @@ var DialogComponent = function DialogComponent(_ref) {
109
110
  audioFailed = _useState10[0],
110
111
  setAudioFailed = _useState10[1];
111
112
 
112
- var _useThree = (0, _fiber.useThree)(function (state) {
113
- return [state.camera, state.scene];
114
- }),
115
- _useThree2 = _slicedToArray(_useThree, 2),
116
- camera = _useThree2[0],
117
- scene = _useThree2[1];
113
+ var scene = (0, _fiber.useThree)(function (state) {
114
+ return state.scene;
115
+ });
116
+ var camera = (0, _fiber.useThree)(function (state) {
117
+ return state.camera;
118
+ });
118
119
 
119
120
  var _useTimeout = (0, _useTimeout2.default)(),
120
121
  start = _useTimeout.start,
@@ -127,17 +128,11 @@ var DialogComponent = function DialogComponent(_ref) {
127
128
  var defaultCamera = (0, _react.useMemo)(function () {
128
129
  return camera.clone();
129
130
  }, []);
131
+ var actualCamera = (0, _react.useRef)(camera);
130
132
  var messagePosition = (0, _react.useRef)({
131
133
  pos: [0, 0, 0],
132
134
  child: null
133
135
  });
134
-
135
- var _useState11 = (0, _react.useState)(false),
136
- _useState12 = _slicedToArray(_useState11, 2),
137
- animationRunning = _useState12[0],
138
- setAnimationRunning = _useState12[1];
139
-
140
- var animationTarget = (0, _react.useRef)(new _three.Object3D());
141
136
  var currentLineData = lines[line];
142
137
  var lastLine = lines[line - 1];
143
138
  var lastSet = (0, _react.useRef)(false);
@@ -157,9 +152,14 @@ var DialogComponent = function DialogComponent(_ref) {
157
152
  var audio = Object.keys((currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audio) || {}).length;
158
153
  var voice = Object.keys((currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.voice) || {}).length;
159
154
  var isVoiceOver = voiceOver || (currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.type) === 'conversationalNarration';
160
- var isDecision = decision || (currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.type) === 'conversationalDecision';
155
+ var isDecision = decision || (currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.type) === 'conversationalDecision'; // Force camera update (r3f selector not updating)
156
+
157
+ (0, _fiber.useFrame)(function (_ref3) {
158
+ var sceneCam = _ref3.camera;
159
+ actualCamera.current = sceneCam;
160
+ });
161
161
 
162
- var _useState13 = (0, _react.useState)({
162
+ var _useState11 = (0, _react.useState)({
163
163
  text: '',
164
164
  name: '',
165
165
  inScene: false,
@@ -168,9 +168,9 @@ var DialogComponent = function DialogComponent(_ref) {
168
168
  avatar: '',
169
169
  show: false
170
170
  }),
171
- _useState14 = _slicedToArray(_useState13, 2),
172
- currentMessage = _useState14[0],
173
- setCurrentMessage = _useState14[1];
171
+ _useState12 = _slicedToArray(_useState11, 2),
172
+ currentMessage = _useState12[0],
173
+ setCurrentMessage = _useState12[1];
174
174
 
175
175
  var charactersInvolved = (0, _react.useMemo)(function () {
176
176
  return lines.reduce(function (acc, current) {
@@ -193,10 +193,10 @@ var DialogComponent = function DialogComponent(_ref) {
193
193
  });
194
194
  }, [emitEvent]);
195
195
 
196
- var _useState15 = (0, _react.useState)([]),
197
- _useState16 = _slicedToArray(_useState15, 2),
198
- edgesHistory = _useState16[0],
199
- setEdgesHistory = _useState16[1];
196
+ var _useState13 = (0, _react.useState)([]),
197
+ _useState14 = _slicedToArray(_useState13, 2),
198
+ edgesHistory = _useState14[0],
199
+ setEdgesHistory = _useState14[1];
200
200
 
201
201
  var lastNodeId = (0, _react.useMemo)(function () {
202
202
  return edgesHistory[edgesHistory.length - 1];
@@ -251,13 +251,22 @@ var DialogComponent = function DialogComponent(_ref) {
251
251
 
252
252
  var onLoadAnim = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {};
253
253
  var animation;
254
+ var emotion = element.isSeated && !slot.emotion.includes('seated') ? "".concat(slot.emotion, "-seated") : slot.emotion;
254
255
 
255
256
  if (slot !== null && slot !== void 0 && slot.animationId && slot !== null && slot !== void 0 && (_slot$animation = slot.animation) !== null && _slot$animation !== void 0 && _slot$animation.url) {
257
+ // force camera transition seated -> not seated
258
+ if (lastTalking.current && lastTalking.current.uid === element.uid) {
259
+ var currentIsSeated = slot.emotion.includes('seated');
260
+ var lastIsSeated = lastTalking.current.emotion.includes('seated');
261
+ if (currentIsSeated && !lastIsSeated) lastTalking.current = {};
262
+ if (!currentIsSeated && lastIsSeated) lastTalking.current = {};
263
+ }
264
+
256
265
  animation = slot.animation;
257
266
  } else {
258
267
  var _slot$character2;
259
268
 
260
- animation = (_slot$character2 = slot.character) === null || _slot$character2 === void 0 ? void 0 : _slot$character2.resource.animations[element.isSeated ? "".concat(slot.emotion, "-seated") : slot.emotion];
269
+ animation = (_slot$character2 = slot.character) === null || _slot$character2 === void 0 ? void 0 : _slot$character2.resource.animations[emotion];
261
270
  }
262
271
 
263
272
  var mixer = element.userData.mixer;
@@ -290,6 +299,70 @@ var DialogComponent = function DialogComponent(_ref) {
290
299
  mixer.stopAllAction();
291
300
  defaultAction.play();
292
301
  }
302
+ }; // Starts camera transition
303
+
304
+
305
+ var animateCameraTransition = function animateCameraTransition() {
306
+ if (!zoomStarted.current) {
307
+ var cam = actualCamera.current;
308
+ var targetPosition = messagePosition.current.child ? messagePosition.current.pos : defaultCamera.position.toArray();
309
+ animationTarget.position.fromArray(targetPosition);
310
+
311
+ if (messagePosition.current.parent) {
312
+ if (!animationTarget.quaternion.equals(cam.quaternion)) {
313
+ animationTarget.applyQuaternion(cam.quaternion);
314
+ }
315
+
316
+ var mult = messagePosition.current.isLeft ? -1 : 1;
317
+ var headSpace = headSize * mult;
318
+ animationTarget.translateX(-10 * mult + headSpace);
319
+ animationTarget.translateY(-2);
320
+ animationTarget.translateZ(30);
321
+ }
322
+
323
+ _gsap.default.to(cam.position, _objectSpread({
324
+ duration: 0.9,
325
+ ease: 'power3.easeInOut',
326
+ onStart: function onStart() {
327
+ zoomStarted.current = true;
328
+ },
329
+ onUpdate: function onUpdate() {
330
+ if (changedMats.current.length) {
331
+ changedMats.current.forEach(function (o) {
332
+ var object = o.object;
333
+ object.material.visible = true;
334
+ });
335
+ }
336
+ },
337
+ onComplete: function onComplete() {
338
+ if (onZoomEnd.current) {
339
+ onZoomEnd.current();
340
+ onZoomEnd.current = null;
341
+ }
342
+
343
+ raycast.set(cam.getWorldPosition(new _three.Vector3(0, 0, 0)), cam.getWorldDirection(new _three.Vector3()));
344
+ var objects = raycast.intersectObjects(scene.children, true);
345
+ changedMats.current = objects.filter(function (o) {
346
+ return o.distance < 10;
347
+ }); // Make objects invisible in front of the camera
348
+
349
+ if (changedMats.current.length) {
350
+ changedMats.current.forEach(function (o) {
351
+ var object = o.object;
352
+ object.material.side = 0;
353
+ });
354
+ }
355
+
356
+ if (lastSet.current || !messagePosition.current.child) {
357
+ cam.copy(defaultCamera);
358
+ }
359
+
360
+ zoomStarted.current = false;
361
+ }
362
+ }, animationTarget.position));
363
+ } else if (zoomStarted.current) {
364
+ zoomStarted.current = false;
365
+ }
293
366
  }; // Reset currentEmotion to defaultAnim
294
367
 
295
368
 
@@ -305,7 +378,7 @@ var DialogComponent = function DialogComponent(_ref) {
305
378
  messagePosition.current.parent = null;
306
379
 
307
380
  if (zoomInActor) {
308
- setAnimationRunning(true);
381
+ animateCameraTransition();
309
382
  }
310
383
  }, [zoomInActor]);
311
384
 
@@ -367,6 +440,7 @@ var DialogComponent = function DialogComponent(_ref) {
367
440
 
368
441
  (0, _react.useEffect)(function () {
369
442
  return function () {
443
+ lastTalking.current = {};
370
444
  resetAnims();
371
445
  };
372
446
  }, []);
@@ -584,37 +658,38 @@ var DialogComponent = function DialogComponent(_ref) {
584
658
 
585
659
  if (element && !lastSet.current) {
586
660
  loadEmotion(talkingCharacter, element, function (mixer, action, defaultAction) {
587
- if (talkingCharacter.uid === element.uid) {
588
- moveBubble(element);
589
-
590
- var setMessage = function setMessage() {
591
- var _talkingCharacter$cha5;
592
-
593
- setCurrentMessage({
594
- text: talkingCharacter.text,
595
- name: talkingCharacter.alias || ((_talkingCharacter$cha5 = talkingCharacter.character) === null || _talkingCharacter$cha5 === void 0 ? void 0 : _talkingCharacter$cha5.name),
596
- inScene: true,
597
- thinkful: talkingCharacter.emotion === 'thinkful',
598
- avatar: getAvatarURL(talkingCharacter),
599
- show: true
600
- });
601
- };
602
-
603
- if (zoomInActor) {
604
- onZoomEnd.current = setMessage;
605
- setAnimationRunning(true);
606
- } else {
607
- setMessage();
608
- }
609
- }
610
-
611
661
  var startAction = element.userData.lastEmotion ? element.userData.lastEmotion : defaultAction;
612
662
 
613
663
  if (startAction && action && startAction !== action) {
614
- mixer.stopAllAction();
615
664
  (0, _helpers.executeCrossFade)(startAction, action, crossFadeDuration);
616
665
  element.userData.defaultAnim = action.getClip();
617
666
  }
667
+
668
+ setTimeout(function () {
669
+ if (talkingCharacter.uid === element.uid) {
670
+ moveBubble(element);
671
+
672
+ var setMessage = function setMessage() {
673
+ var _talkingCharacter$cha5;
674
+
675
+ setCurrentMessage({
676
+ text: talkingCharacter.text,
677
+ name: talkingCharacter.alias || ((_talkingCharacter$cha5 = talkingCharacter.character) === null || _talkingCharacter$cha5 === void 0 ? void 0 : _talkingCharacter$cha5.name),
678
+ inScene: true,
679
+ thinkful: talkingCharacter.emotion === 'thinkful',
680
+ avatar: getAvatarURL(talkingCharacter),
681
+ show: true
682
+ });
683
+ };
684
+
685
+ if (zoomInActor) {
686
+ onZoomEnd.current = setMessage;
687
+ animateCameraTransition();
688
+ } else {
689
+ setMessage();
690
+ }
691
+ }
692
+ }, 150);
618
693
  });
619
694
  } else {
620
695
  var _talkingCharacter$cha6;
@@ -638,7 +713,7 @@ var DialogComponent = function DialogComponent(_ref) {
638
713
  });
639
714
  }
640
715
  }
641
- }, [actors, camera, currentLineData, zoomInActor, getCurrentVisible, translate, getAvatarURL, loadEmotion, resetCameraView, isDecision, isVoiceOver, charactersInvolved]); // Sound logic
716
+ }, [actors, currentLineData, zoomInActor, getCurrentVisible, translate, getAvatarURL, loadEmotion, resetCameraView, isDecision, isVoiceOver, charactersInvolved]); // Sound logic
642
717
 
643
718
  var stopEkho = (0, _useEkho.default)({
644
719
  audioType: currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType,
@@ -701,75 +776,11 @@ var DialogComponent = function DialogComponent(_ref) {
701
776
  stop();
702
777
  };
703
778
  }, [currentMessage, nextLine, start, stop, currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType, autoPlayCond, audio, voice, audioFailed]);
704
- (0, _react.useEffect)(function () {
705
- if (animationRunning && !zoomStarted.current) {
706
- var cam = camera;
707
- var targetPosition = messagePosition.current.child ? messagePosition.current.pos : defaultCamera.position.toArray();
708
- animationTarget.current.position.fromArray(targetPosition);
709
-
710
- if (messagePosition.current.parent) {
711
- if (!animationTarget.current.quaternion.equals(cam.quaternion)) {
712
- animationTarget.current.applyQuaternion(cam.quaternion);
713
- }
714
-
715
- var mult = messagePosition.current.isLeft ? -1 : 1;
716
- var headSpace = headSize * mult;
717
- animationTarget.current.translateX(-10 * mult + headSpace);
718
- animationTarget.current.translateY(-2);
719
- animationTarget.current.translateZ(30);
720
- }
721
-
722
- _gsap.default.to(cam.position, {
723
- duration: 1,
724
- ease: 'power3.easeInOut',
725
- onStart: function onStart() {
726
- zoomStarted.current = true;
727
- },
728
- onUpdate: function onUpdate() {
729
- if (changedMats.current.length) {
730
- changedMats.current.forEach(function (o) {
731
- var object = o.object;
732
- object.material.visible = true;
733
- });
734
- }
735
- },
736
- onComplete: function onComplete() {
737
- onZoomEnd.current();
738
-
739
- onZoomEnd.current = function () {};
740
-
741
- zoomStarted.current = false;
742
- setAnimationRunning(false);
743
- raycast.set(cam.getWorldPosition(new _three.Vector3(0, 0, 0)), cam.getWorldDirection(new _three.Vector3()));
744
- var objects = raycast.intersectObjects(scene.children, true);
745
- changedMats.current = objects.filter(function (o) {
746
- return o.distance < 10;
747
- }); // Make objects invisible in front of the camera
748
-
749
- if (changedMats.current.length) {
750
- changedMats.current.forEach(function (o) {
751
- var object = o.object;
752
- object.material.side = 0;
753
- });
754
- }
755
-
756
- if (lastSet.current || !messagePosition.current.child) {
757
- cam.copy(defaultCamera);
758
- }
759
- },
760
- x: animationTarget.current.position.x,
761
- y: animationTarget.current.position.y,
762
- z: animationTarget.current.position.z
763
- });
764
- } else if (zoomStarted.current) {
765
- zoomStarted.current = false;
766
- }
767
- }, [animationRunning, camera]);
768
779
  var disableBackButton = (0, _react.useMemo)(function () {
769
780
  var disabled = line === 0 || previousLineWasDecision();
770
781
  return disabled;
771
782
  }, [line, previousLineWasDecision]);
772
- keyboardControl(isDecision || disableBackButton || animationRunning ? null : manualBackLine, isDecision || animationRunning ? null : manualNextLine);
783
+ keyboardControl(isDecision || disableBackButton || !currentMessage.show ? null : manualBackLine, isDecision || !currentMessage.show ? null : manualNextLine);
773
784
  var container = document.querySelector('.screens--container');
774
785
 
775
786
  if (isDecision) {
@@ -819,15 +830,15 @@ var DialogComponent = function DialogComponent(_ref) {
819
830
  }, /*#__PURE__*/_react.default.createElement("button", {
820
831
  type: "button",
821
832
  onClick: manualBackLine,
822
- disabled: disableBackButton || animationRunning,
823
- className: "gat--btn__round ".concat(disableBackButton || animationRunning ? 'disabled' : '')
833
+ disabled: disableBackButton || !currentMessage.show,
834
+ className: "gat--btn__round ".concat(disableBackButton || !currentMessage.show ? 'disabled' : '')
824
835
  }, /*#__PURE__*/_react.default.createElement("span", {
825
836
  className: (0, _LangIsRtl.default)() ? 'icon-next' : 'icon-back'
826
837
  })), /*#__PURE__*/_react.default.createElement("button", {
827
838
  type: "button",
828
839
  onClick: manualNextLine,
829
- disabled: animationRunning,
830
- className: "gat--btn__round \n ".concat(animationRunning ? 'disabled' : '', "\n ").concat(automatic && isEndNode() ? 'glowing-animation' : '')
840
+ disabled: !currentMessage.show,
841
+ className: "gat--btn__round \n ".concat(!currentMessage.show ? 'disabled' : '', "\n ").concat(automatic && isEndNode() ? 'glowing-animation' : '')
831
842
  }, /*#__PURE__*/_react.default.createElement("span", {
832
843
  className: (0, _LangIsRtl.default)() ? 'icon-back' : 'icon-next'
833
844
  })))));
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.18.0",
5
+ "version": "2.18.1",
6
6
  "main": "dist/index.js",
7
7
  "files": [
8
8
  "dist",