@gamelearn/arcade-components 2.15.1 → 2.15.3

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.
@@ -19,8 +19,6 @@ var _arcadeThreeCore = require("@gamelearn/arcade-three-core");
19
19
 
20
20
  var _gsap = _interopRequireDefault(require("gsap"));
21
21
 
22
- var _decisionComponent = _interopRequireDefault(require("../../decision-component"));
23
-
24
22
  var _helpers = require("../../../helpers");
25
23
 
26
24
  var _useTimeout2 = _interopRequireDefault(require("../../../helpers/useTimeout"));
@@ -31,14 +29,14 @@ var _LangIsRtl = _interopRequireDefault(require("../../../helpers/LangIsRtl"));
31
29
 
32
30
  var _BubbleWrapper = _interopRequireDefault(require("./BubbleWrapper"));
33
31
 
32
+ var _DialogDecision = _interopRequireDefault(require("./DialogDecision"));
33
+
34
34
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
35
 
36
36
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
37
37
 
38
38
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
39
39
 
40
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
41
-
42
40
  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; }
43
41
 
44
42
  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; }
@@ -145,6 +143,7 @@ var DialogComponent = function DialogComponent(_ref) {
145
143
  var lastLine = lines[line - 1];
146
144
  var lastSet = (0, _react.useRef)(false);
147
145
  var isBranched = !!edges;
146
+ var onZoomEnd = (0, _react.useRef)(function () {});
148
147
 
149
148
  var _ref2 = currentLineData || {},
150
149
  voiceOver = _ref2.voiceOver,
@@ -302,7 +301,10 @@ var DialogComponent = function DialogComponent(_ref) {
302
301
  var resetCameraView = (0, _react.useCallback)(function () {
303
302
  messagePosition.current.child = null;
304
303
  messagePosition.current.parent = null;
305
- if (zoomInActor) setAnimationRunning(true);
304
+
305
+ if (zoomInActor) {
306
+ setAnimationRunning(true);
307
+ }
306
308
  }, [zoomInActor]);
307
309
 
308
310
  var resetTalkingAnimation = function resetTalkingAnimation() {
@@ -529,9 +531,7 @@ var DialogComponent = function DialogComponent(_ref) {
529
531
 
530
532
 
531
533
  (0, _react.useEffect)(function () {
532
- if (isDecision) {
533
- resetCameraView();
534
- } else if (isVoiceOver) {
534
+ if (isVoiceOver) {
535
535
  resetCameraView();
536
536
  setCurrentMessage({
537
537
  text: currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.text,
@@ -543,36 +543,36 @@ var DialogComponent = function DialogComponent(_ref) {
543
543
  avatar: getAvatarURL(talkingCharacter),
544
544
  show: true
545
545
  });
546
- } else if (!lastSet.current) {
547
- var slottedCharacters = currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.slots.filter(function (slot) {
548
- return slot.uid && !slot.talking;
549
- });
550
- var currentParticipants = [].concat(_toConsumableArray(slottedCharacters.map(function (slot) {
551
- return slot.uid;
552
- }) || []), [talkingCharacter === null || talkingCharacter === void 0 ? void 0 : talkingCharacter.uid]);
553
- var notInvolvedParticipants = charactersInvolved.filter(function (charUid) {
554
- return !currentParticipants.includes(charUid);
555
- });
556
- notInvolvedParticipants.forEach(function (uid) {
557
- var element = getCurrentVisible(uid);
558
-
559
- if (element) {
560
- executeDefaultAnimation(element);
561
- }
562
- }); // Check not talking elements emotion
546
+ } else if (!lastSet.current && !isDecision) {
547
+ // Talking element logic
548
+ if (talkingCharacter) {
549
+ var slottedCharacters = currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.slots.filter(function (slot) {
550
+ return slot.uid && !slot.talking;
551
+ });
552
+ var currentParticipants = [].concat(_toConsumableArray(slottedCharacters.map(function (slot) {
553
+ return slot.uid;
554
+ }) || []), [talkingCharacter === null || talkingCharacter === void 0 ? void 0 : talkingCharacter.uid]);
555
+ var notInvolvedParticipants = charactersInvolved.filter(function (charUid) {
556
+ return !currentParticipants.includes(charUid);
557
+ });
558
+ notInvolvedParticipants.forEach(function (uid) {
559
+ var element = getCurrentVisible(uid);
563
560
 
564
- slottedCharacters.forEach(function (slot) {
565
- var element = getCurrentVisible(slot.uid);
561
+ if (element) {
562
+ executeDefaultAnimation(element);
563
+ }
564
+ }); // Check not talking elements emotion
566
565
 
567
- if (element) {
568
- loadEmotion(slot, element, function (_, action, defaultAction) {
569
- var startAction = element.userData.lastEmotion ? element.userData.lastEmotion : defaultAction;
570
- (0, _helpers.executeCrossFade)(startAction, action, crossFadeDuration);
571
- });
572
- }
573
- }); // Talking element logic
566
+ slottedCharacters.forEach(function (slot) {
567
+ var element = getCurrentVisible(slot.uid);
574
568
 
575
- if (talkingCharacter) {
569
+ if (element) {
570
+ loadEmotion(slot, element, function (_, action, defaultAction) {
571
+ var startAction = element.userData.lastEmotion ? element.userData.lastEmotion : defaultAction;
572
+ (0, _helpers.executeCrossFade)(startAction, action, crossFadeDuration);
573
+ });
574
+ }
575
+ });
576
576
  var element = getCurrentVisible(talkingCharacter.uid);
577
577
  var object = actors.find(function (a) {
578
578
  return a.uid === talkingCharacter.uid;
@@ -592,11 +592,7 @@ var DialogComponent = function DialogComponent(_ref) {
592
592
  var showArrowTop = talkingCharacter.text.length > maxCharacterToSwitch;
593
593
  moveBubble(element, showArrowTop);
594
594
 
595
- if (zoomInActor) {
596
- setAnimationRunning(true);
597
- }
598
-
599
- setTimeout(function () {
595
+ var setMessage = function setMessage() {
600
596
  var _talkingCharacter$cha5;
601
597
 
602
598
  setCurrentMessage({
@@ -607,7 +603,14 @@ var DialogComponent = function DialogComponent(_ref) {
607
603
  avatar: getAvatarURL(talkingCharacter),
608
604
  show: true
609
605
  });
610
- }, zoomInActor ? 1200 : 0);
606
+ };
607
+
608
+ if (zoomInActor) {
609
+ onZoomEnd.current = setMessage;
610
+ setAnimationRunning(true);
611
+ } else {
612
+ setMessage();
613
+ }
611
614
  }
612
615
  });
613
616
  } else {
@@ -697,7 +700,6 @@ var DialogComponent = function DialogComponent(_ref) {
697
700
  }, [currentMessage, nextLine, start, stop, currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType, autoPlayCond, audio, voice, audioFailed]);
698
701
  (0, _react.useEffect)(function () {
699
702
  if (animationRunning && !zoomStarted.current) {
700
- zoomStarted.current = true;
701
703
  var cam = camera;
702
704
  var targetPosition = messagePosition.current.child ? messagePosition.current.pos : defaultCamera.position.toArray();
703
705
  animationTarget.current.position.fromArray(targetPosition);
@@ -717,7 +719,22 @@ var DialogComponent = function DialogComponent(_ref) {
717
719
  _gsap.default.to(cam.position, {
718
720
  duration: 1,
719
721
  ease: 'power3.easeInOut',
722
+ onStart: function onStart() {
723
+ zoomStarted.current = true;
724
+ },
725
+ onUpdate: function onUpdate() {
726
+ if (changedMats.current.length) {
727
+ changedMats.current.forEach(function (o) {
728
+ var object = o.object;
729
+ object.material.visible = true;
730
+ });
731
+ }
732
+ },
720
733
  onComplete: function onComplete() {
734
+ onZoomEnd.current();
735
+
736
+ onZoomEnd.current = function () {};
737
+
721
738
  zoomStarted.current = false;
722
739
  setAnimationRunning(false);
723
740
  raycast.set(cam.getWorldPosition(new _three.Vector3(0, 0, 0)), cam.getWorldDirection(new _three.Vector3()));
@@ -741,33 +758,16 @@ var DialogComponent = function DialogComponent(_ref) {
741
758
  y: animationTarget.current.position.y,
742
759
  z: animationTarget.current.position.z
743
760
  });
744
- } else {
761
+ } else if (zoomStarted.current) {
745
762
  zoomStarted.current = false;
746
763
  }
747
- }, [animationRunning]); // Animate Camera
748
- // 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
749
-
750
- (0, _fiber.useFrame)(function () {
751
- if (animationRunning) {
752
- if (changedMats.current.length) {
753
- changedMats.current.forEach(function (o) {
754
- var object = o.object;
755
- object.material.visible = true;
756
- });
757
- }
758
- }
759
- });
760
- var container = document.querySelector('.screens--container');
761
- var cleanStyle = {
762
- width: '100vw',
763
- height: '100vh',
764
- position: 'static'
765
- };
764
+ }, [animationRunning]);
766
765
  var disableBackButton = (0, _react.useMemo)(function () {
767
766
  var disabled = line === 0 || previousLineWasDecision();
768
767
  return disabled;
769
768
  }, [line, previousLineWasDecision]);
770
769
  keyboardControl(isDecision || disableBackButton || animationRunning ? null : manualBackLine, isDecision || animationRunning ? null : manualNextLine);
770
+ var container = document.querySelector('.screens--container');
771
771
 
772
772
  if (isDecision) {
773
773
  var decisionPayload = _objectSpread(_objectSpread({}, currentLineData.payload), {}, {
@@ -781,22 +781,16 @@ var DialogComponent = function DialogComponent(_ref) {
781
781
  emitEvent: emitEvent,
782
782
  pause: pause,
783
783
  soundActions: soundActions,
784
- keyboardControl: keyboardControl
784
+ keyboardControl: keyboardControl,
785
+ onMount: function onMount() {
786
+ resetCameraView();
787
+ },
788
+ onUnMount: function onUnMount() {
789
+ zoomStarted.current = false;
790
+ }
785
791
  });
786
792
 
787
- return /*#__PURE__*/_react.default.createElement(_arcadeThreeCore.HtmlPro, {
788
- zIndexRange: [6, 6],
789
- style: cleanStyle,
790
- portal: container ? {
791
- current: container
792
- } : undefined,
793
- onOcclude: function onOcclude() {},
794
- calculatePosition: function calculatePosition() {
795
- return [0, 0];
796
- }
797
- }, /*#__PURE__*/_react.default.createElement(_decisionComponent.default, _extends({
798
- inScene: true
799
- }, decisionPayload)));
793
+ return /*#__PURE__*/_react.default.createElement(_DialogDecision.default, decisionPayload);
800
794
  }
801
795
 
802
796
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, currentMessage.text ? /*#__PURE__*/_react.default.createElement(_BubbleWrapper.default, {
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _react = _interopRequireWildcard(require("react"));
11
+
12
+ var _arcadeThreeCore = require("@gamelearn/arcade-three-core");
13
+
14
+ var _decisionComponent = _interopRequireDefault(require("../../decision-component"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
+
20
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
+
22
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
23
+
24
+ var cleanStyle = {
25
+ width: '100vw',
26
+ height: '100vh',
27
+ position: 'static'
28
+ };
29
+
30
+ var DialogDecision = function DialogDecision(props) {
31
+ var container = document.querySelector('.screens--container');
32
+ (0, _react.useEffect)(function () {
33
+ if (props.onMount) props.onMount();
34
+ return function () {
35
+ if (props.onUnMount) props.onUnMount();
36
+ }; // eslint-disable-next-line react-hooks/exhaustive-deps
37
+ }, []);
38
+ return /*#__PURE__*/_react.default.createElement(_arcadeThreeCore.HtmlPro, {
39
+ zIndexRange: [6, 6],
40
+ style: cleanStyle,
41
+ portal: container ? {
42
+ current: container
43
+ } : undefined,
44
+ onOcclude: function onOcclude() {},
45
+ calculatePosition: function calculatePosition() {
46
+ return [0, 0];
47
+ }
48
+ }, /*#__PURE__*/_react.default.createElement(_decisionComponent.default, _extends({
49
+ inScene: true
50
+ }, props)));
51
+ };
52
+
53
+ var _default = DialogDecision;
54
+ exports.default = _default;
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.15.1",
5
+ "version": "2.15.3",
6
6
  "main": "dist/index.js",
7
7
  "files": [
8
8
  "dist",