@gamelearn/arcade-components 2.18.0 → 2.18.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.
|
@@ -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.
|
|
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
|
|
113
|
-
return
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
|
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
|
-
|
|
172
|
-
currentMessage =
|
|
173
|
-
setCurrentMessage =
|
|
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
|
|
197
|
-
|
|
198
|
-
edgesHistory =
|
|
199
|
-
setEdgesHistory =
|
|
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[
|
|
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,76 @@ 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
|
+
zoomStarted.current = false;
|
|
357
|
+
|
|
358
|
+
if (lastSet.current) {
|
|
359
|
+
emitEvent({
|
|
360
|
+
type: 'success'
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (!messagePosition.current.child) {
|
|
365
|
+
cam.copy(defaultCamera);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}, animationTarget.position));
|
|
369
|
+
} else if (zoomStarted.current) {
|
|
370
|
+
zoomStarted.current = false;
|
|
371
|
+
}
|
|
293
372
|
}; // Reset currentEmotion to defaultAnim
|
|
294
373
|
|
|
295
374
|
|
|
@@ -305,7 +384,7 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
305
384
|
messagePosition.current.parent = null;
|
|
306
385
|
|
|
307
386
|
if (zoomInActor) {
|
|
308
|
-
|
|
387
|
+
animateCameraTransition();
|
|
309
388
|
}
|
|
310
389
|
}, [zoomInActor]);
|
|
311
390
|
|
|
@@ -358,15 +437,18 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
358
437
|
show: false
|
|
359
438
|
});
|
|
360
439
|
resetCameraView();
|
|
361
|
-
camera.copy(defaultCamera);
|
|
362
440
|
resetAnims();
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
441
|
+
|
|
442
|
+
if (!zoomInActor) {
|
|
443
|
+
emitEvent({
|
|
444
|
+
type: 'success'
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
}, [camera, emitEvent, resetAnims, resetCameraView, zoomInActor]); // Reset anim after unmount
|
|
367
448
|
|
|
368
449
|
(0, _react.useEffect)(function () {
|
|
369
450
|
return function () {
|
|
451
|
+
lastTalking.current = {};
|
|
370
452
|
resetAnims();
|
|
371
453
|
};
|
|
372
454
|
}, []);
|
|
@@ -584,37 +666,38 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
584
666
|
|
|
585
667
|
if (element && !lastSet.current) {
|
|
586
668
|
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
669
|
var startAction = element.userData.lastEmotion ? element.userData.lastEmotion : defaultAction;
|
|
612
670
|
|
|
613
671
|
if (startAction && action && startAction !== action) {
|
|
614
|
-
mixer.stopAllAction();
|
|
615
672
|
(0, _helpers.executeCrossFade)(startAction, action, crossFadeDuration);
|
|
616
673
|
element.userData.defaultAnim = action.getClip();
|
|
617
674
|
}
|
|
675
|
+
|
|
676
|
+
setTimeout(function () {
|
|
677
|
+
if (talkingCharacter.uid === element.uid) {
|
|
678
|
+
moveBubble(element);
|
|
679
|
+
|
|
680
|
+
var setMessage = function setMessage() {
|
|
681
|
+
var _talkingCharacter$cha5;
|
|
682
|
+
|
|
683
|
+
setCurrentMessage({
|
|
684
|
+
text: talkingCharacter.text,
|
|
685
|
+
name: talkingCharacter.alias || ((_talkingCharacter$cha5 = talkingCharacter.character) === null || _talkingCharacter$cha5 === void 0 ? void 0 : _talkingCharacter$cha5.name),
|
|
686
|
+
inScene: true,
|
|
687
|
+
thinkful: talkingCharacter.emotion === 'thinkful',
|
|
688
|
+
avatar: getAvatarURL(talkingCharacter),
|
|
689
|
+
show: true
|
|
690
|
+
});
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
if (zoomInActor) {
|
|
694
|
+
onZoomEnd.current = setMessage;
|
|
695
|
+
animateCameraTransition();
|
|
696
|
+
} else {
|
|
697
|
+
setMessage();
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
}, 150);
|
|
618
701
|
});
|
|
619
702
|
} else {
|
|
620
703
|
var _talkingCharacter$cha6;
|
|
@@ -638,7 +721,7 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
638
721
|
});
|
|
639
722
|
}
|
|
640
723
|
}
|
|
641
|
-
}, [actors,
|
|
724
|
+
}, [actors, currentLineData, zoomInActor, getCurrentVisible, translate, getAvatarURL, loadEmotion, resetCameraView, isDecision, isVoiceOver, charactersInvolved]); // Sound logic
|
|
642
725
|
|
|
643
726
|
var stopEkho = (0, _useEkho.default)({
|
|
644
727
|
audioType: currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType,
|
|
@@ -701,75 +784,11 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
701
784
|
stop();
|
|
702
785
|
};
|
|
703
786
|
}, [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
787
|
var disableBackButton = (0, _react.useMemo)(function () {
|
|
769
788
|
var disabled = line === 0 || previousLineWasDecision();
|
|
770
789
|
return disabled;
|
|
771
790
|
}, [line, previousLineWasDecision]);
|
|
772
|
-
keyboardControl(isDecision || disableBackButton ||
|
|
791
|
+
keyboardControl(isDecision || disableBackButton || !currentMessage.show ? null : manualBackLine, isDecision || !currentMessage.show ? null : manualNextLine);
|
|
773
792
|
var container = document.querySelector('.screens--container');
|
|
774
793
|
|
|
775
794
|
if (isDecision) {
|
|
@@ -819,15 +838,15 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
819
838
|
}, /*#__PURE__*/_react.default.createElement("button", {
|
|
820
839
|
type: "button",
|
|
821
840
|
onClick: manualBackLine,
|
|
822
|
-
disabled: disableBackButton ||
|
|
823
|
-
className: "gat--btn__round ".concat(disableBackButton ||
|
|
841
|
+
disabled: disableBackButton || !currentMessage.show,
|
|
842
|
+
className: "gat--btn__round ".concat(disableBackButton || !currentMessage.show ? 'disabled' : '')
|
|
824
843
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
825
844
|
className: (0, _LangIsRtl.default)() ? 'icon-next' : 'icon-back'
|
|
826
845
|
})), /*#__PURE__*/_react.default.createElement("button", {
|
|
827
846
|
type: "button",
|
|
828
847
|
onClick: manualNextLine,
|
|
829
|
-
disabled:
|
|
830
|
-
className: "gat--btn__round \n ".concat(
|
|
848
|
+
disabled: !currentMessage.show,
|
|
849
|
+
className: "gat--btn__round \n ".concat(!currentMessage.show ? 'disabled' : '', "\n ").concat(automatic && isEndNode() ? 'glowing-animation' : '')
|
|
831
850
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
832
851
|
className: (0, _LangIsRtl.default)() ? 'icon-back' : 'icon-next'
|
|
833
852
|
})))));
|