@gamelearn/arcade-components 1.22.11 → 1.22.12
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.
|
@@ -31,6 +31,8 @@ var _useEkho = _interopRequireDefault(require("../../../helpers/useEkho"));
|
|
|
31
31
|
|
|
32
32
|
var _LangIsRtl = _interopRequireDefault(require("../../../helpers/LangIsRtl"));
|
|
33
33
|
|
|
34
|
+
var _gsap = _interopRequireDefault(require("gsap"));
|
|
35
|
+
|
|
34
36
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
35
37
|
|
|
36
38
|
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); }
|
|
@@ -65,6 +67,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
65
67
|
|
|
66
68
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
67
69
|
|
|
70
|
+
// Global
|
|
68
71
|
var isMobile = (0, _deviceDetection.DeviceDetection)();
|
|
69
72
|
var crossFadeDuration = 0.5;
|
|
70
73
|
var characterMs = 75;
|
|
@@ -134,17 +137,23 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
134
137
|
var loader = (0, _react.useMemo)(function () {
|
|
135
138
|
return new _GLTFLoader.GLTFLoader();
|
|
136
139
|
}, []);
|
|
137
|
-
var defaultCamera = (0, _react.
|
|
140
|
+
var defaultCamera = (0, _react.useMemo)(function () {
|
|
141
|
+
return camera.clone();
|
|
142
|
+
}, []);
|
|
138
143
|
var messagePosition = (0, _react.useRef)({
|
|
139
144
|
pos: [0, 0, 0],
|
|
140
145
|
child: null
|
|
141
146
|
});
|
|
142
|
-
|
|
147
|
+
|
|
148
|
+
var _useState11 = (0, _react.useState)(false),
|
|
149
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
150
|
+
animationRunning = _useState12[0],
|
|
151
|
+
setAnimationRunning = _useState12[1];
|
|
152
|
+
|
|
143
153
|
var bubbleRef = (0, _react.useRef)();
|
|
144
154
|
var groupRef = (0, _react.useRef)();
|
|
145
155
|
var animationTarget = (0, _react.useRef)(new _three.Object3D());
|
|
146
156
|
var currentLine = lines[line];
|
|
147
|
-
var currentLineData = lines[line];
|
|
148
157
|
var lastLine = lines[line - 1];
|
|
149
158
|
var lastSet = (0, _react.useRef)(false);
|
|
150
159
|
var isBranched = !!edges;
|
|
@@ -174,10 +183,10 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
174
183
|
});
|
|
175
184
|
}, [emitEvent]);
|
|
176
185
|
|
|
177
|
-
var
|
|
178
|
-
|
|
179
|
-
previousLineWasDecision =
|
|
180
|
-
setPreviousLineWasDecision =
|
|
186
|
+
var _useState13 = (0, _react.useState)(false),
|
|
187
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
|
188
|
+
previousLineWasDecision = _useState14[0],
|
|
189
|
+
setPreviousLineWasDecision = _useState14[1];
|
|
181
190
|
|
|
182
191
|
var isVoiceOver = voiceOver || (currentLine === null || currentLine === void 0 ? void 0 : currentLine.type) === 'conversationalNarration';
|
|
183
192
|
var isDecision = decision || (currentLine === null || currentLine === void 0 ? void 0 : currentLine.type) === 'conversationalDecision';
|
|
@@ -201,7 +210,8 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
201
210
|
return '';
|
|
202
211
|
});
|
|
203
212
|
return ((_slot$character = slot.character) === null || _slot$character === void 0 ? void 0 : (_slot$character$resou = _slot$character.resource) === null || _slot$character$resou === void 0 ? void 0 : _slot$character$resou.url) || (object === null || object === void 0 ? void 0 : object.completeUrl) || '';
|
|
204
|
-
}, [actors]);
|
|
213
|
+
}, [actors]); // Move to three core?
|
|
214
|
+
|
|
205
215
|
var loadEmotion = (0, _react.useCallback)(function (slot, element) {
|
|
206
216
|
var _slot$character2;
|
|
207
217
|
|
|
@@ -258,7 +268,7 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
258
268
|
var resetCameraView = (0, _react.useCallback)(function () {
|
|
259
269
|
messagePosition.current.child = null;
|
|
260
270
|
messagePosition.current.parent = null;
|
|
261
|
-
if (zoomInActor)
|
|
271
|
+
if (zoomInActor) setAnimationRunning(true);
|
|
262
272
|
}, [zoomInActor]);
|
|
263
273
|
var finishConversation = (0, _react.useCallback)(function () {
|
|
264
274
|
resetAnims();
|
|
@@ -272,7 +282,7 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
272
282
|
emitEvent({
|
|
273
283
|
type: 'success'
|
|
274
284
|
});
|
|
275
|
-
camera.copy(defaultCamera
|
|
285
|
+
camera.copy(defaultCamera);
|
|
276
286
|
});
|
|
277
287
|
}, [camera, emitEvent, resetAnims, resetCameraView]);
|
|
278
288
|
var handleBranchDirection = (0, _react.useCallback)(function () {
|
|
@@ -299,18 +309,6 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
299
309
|
}
|
|
300
310
|
}
|
|
301
311
|
}, [currentLine === null || currentLine === void 0 ? void 0 : currentLine.id, edges, finishConversation, lines]);
|
|
302
|
-
var backLine = (0, _react.useCallback)(function () {
|
|
303
|
-
setAudioFailed(false);
|
|
304
|
-
|
|
305
|
-
if (isBranched) {
|
|
306
|
-
handleBranchDirection(false);
|
|
307
|
-
} else if (lastLine && !(lastLine !== null && lastLine !== void 0 && lastLine.decision) || lastLine.type && !lastLine.type !== 'conversationalDecision') {
|
|
308
|
-
setCurrentMessage({
|
|
309
|
-
show: false
|
|
310
|
-
});
|
|
311
|
-
changeLine(line - 1);
|
|
312
|
-
}
|
|
313
|
-
}, [handleBranchDirection, isBranched, lastLine, line]);
|
|
314
312
|
var handleDecisionBranch = (0, _react.useCallback)(function (choice, reset) {
|
|
315
313
|
var currentId = [3, 2, 1][choice.id];
|
|
316
314
|
var optionsEdges = edges.filter(function (edge) {
|
|
@@ -336,8 +334,20 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
336
334
|
finishConversation();
|
|
337
335
|
}
|
|
338
336
|
}, [currentLine === null || currentLine === void 0 ? void 0 : currentLine.id, edges, finishConversation, lines]);
|
|
337
|
+
var backLine = (0, _react.useCallback)(function () {
|
|
338
|
+
setAudioFailed(false);
|
|
339
|
+
|
|
340
|
+
if (isBranched) {
|
|
341
|
+
handleBranchDirection(false);
|
|
342
|
+
} else if (lastLine && !(lastLine !== null && lastLine !== void 0 && lastLine.decision) || lastLine.type && !lastLine.type !== 'conversationalDecision') {
|
|
343
|
+
setCurrentMessage({
|
|
344
|
+
show: false
|
|
345
|
+
});
|
|
346
|
+
changeLine(line - 1);
|
|
347
|
+
}
|
|
348
|
+
}, [handleBranchDirection, isBranched, lastLine, line]);
|
|
339
349
|
var nextLine = (0, _react.useCallback)(function (choice, reset) {
|
|
340
|
-
setPreviousLineWasDecision(
|
|
350
|
+
setPreviousLineWasDecision(currentLine.decision);
|
|
341
351
|
setAudioFailed(false);
|
|
342
352
|
|
|
343
353
|
if (isBranched) {
|
|
@@ -354,7 +364,7 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
354
364
|
} else {
|
|
355
365
|
finishConversation();
|
|
356
366
|
}
|
|
357
|
-
}, [
|
|
367
|
+
}, [currentLine === null || currentLine === void 0 ? void 0 : currentLine.decision, isBranched, line, lines.length, handleDecisionBranch, handleBranchDirection, finishConversation]);
|
|
358
368
|
|
|
359
369
|
var manualBackLine = function manualBackLine() {
|
|
360
370
|
setAutomatic(false);
|
|
@@ -412,7 +422,7 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
412
422
|
});
|
|
413
423
|
var currentParticipants = [].concat(_toConsumableArray(slottedCharacters.map(function (slot) {
|
|
414
424
|
return slot.uid;
|
|
415
|
-
}) || []), [talkingCharacter.uid]);
|
|
425
|
+
}) || []), [talkingCharacter === null || talkingCharacter === void 0 ? void 0 : talkingCharacter.uid]);
|
|
416
426
|
var notInvolvedParticipants = charactersInvolved.filter(function (charUid) {
|
|
417
427
|
return !currentParticipants.includes(charUid);
|
|
418
428
|
});
|
|
@@ -462,18 +472,23 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
462
472
|
var target = new _three.Object3D();
|
|
463
473
|
head.getWorldPosition(target.position);
|
|
464
474
|
target.applyQuaternion(camera.quaternion);
|
|
465
|
-
target.translateX(1.25);
|
|
466
475
|
var distance = camera.position.distanceTo(target.position);
|
|
467
476
|
var staticDisplay = distance > 70 && !zoomInActor && !showArrowTop;
|
|
468
|
-
target.translateY(staticDisplay || showArrowTop ? 0 : 3);
|
|
477
|
+
target.translateY(staticDisplay || showArrowTop ? 0 : 3); // Detectar posicion de personaje a izq o derecha de pantalla
|
|
478
|
+
|
|
479
|
+
var vector = new _three.Vector3();
|
|
480
|
+
vector.setFromMatrixPosition(head.matrixWorld);
|
|
481
|
+
var p = vector.project(defaultCamera);
|
|
482
|
+
var isLeft = p.x < 0;
|
|
469
483
|
messagePosition.current = {
|
|
470
484
|
pos: target.position.toArray(),
|
|
471
485
|
child: head,
|
|
472
|
-
parent: element
|
|
486
|
+
parent: element,
|
|
487
|
+
isLeft: isLeft
|
|
473
488
|
};
|
|
474
489
|
|
|
475
490
|
if (zoomInActor) {
|
|
476
|
-
|
|
491
|
+
setAnimationRunning(true);
|
|
477
492
|
} // Ugly timeout to wait for zoom in ( maybe use tween (?))
|
|
478
493
|
|
|
479
494
|
|
|
@@ -491,7 +506,7 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
491
506
|
avatar: '',
|
|
492
507
|
show: true
|
|
493
508
|
});
|
|
494
|
-
}, zoomInActor ?
|
|
509
|
+
}, zoomInActor ? 1000 : 0);
|
|
495
510
|
}
|
|
496
511
|
});
|
|
497
512
|
} else {
|
|
@@ -553,7 +568,7 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
553
568
|
return function () {
|
|
554
569
|
stop();
|
|
555
570
|
};
|
|
556
|
-
}, [currentMessage, nextLine, start, stop, currentLine === null || currentLine === void 0 ? void 0 : currentLine.audioType, autoPlayCond, audio, voice, audioFailed]); // Positioning logic
|
|
571
|
+
}, [currentMessage, nextLine, start, stop, currentLine === null || currentLine === void 0 ? void 0 : currentLine.audioType, autoPlayCond, audio, voice, audioFailed]); // Positioning Bubble Message logic
|
|
557
572
|
|
|
558
573
|
var checkBubblePosition = (0, _react.useCallback)(function () {
|
|
559
574
|
if (bubbleRef.current && currentLine !== null && currentLine !== void 0 && currentLine.slots) {
|
|
@@ -564,7 +579,7 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
564
579
|
var x = bubbleRect.x + bubbleRect.width;
|
|
565
580
|
var y = bubbleRect.y - bubbleRect.height;
|
|
566
581
|
|
|
567
|
-
if ((x < 0 || x > window.innerWidth) && currentMessage.inScene) {
|
|
582
|
+
if (!messagePosition.current.isLeft || (x < 0 || x > window.innerWidth) && currentMessage.inScene) {
|
|
568
583
|
var child = messagePosition.current.child;
|
|
569
584
|
|
|
570
585
|
if (child) {
|
|
@@ -602,13 +617,11 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
602
617
|
}, [camera.quaternion, currentLine === null || currentLine === void 0 ? void 0 : currentLine.slots, currentMessage.inScene, getAvatarURL]);
|
|
603
618
|
(0, _react.useEffect)(function () {
|
|
604
619
|
checkBubblePosition();
|
|
605
|
-
}, [checkBubblePosition]);
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
if (animationStart.current) {
|
|
611
|
-
var targetPosition = messagePosition.current.child ? messagePosition.current.pos : defaultCamera.current.position.toArray();
|
|
620
|
+
}, [checkBubblePosition]);
|
|
621
|
+
(0, _react.useEffect)(function () {
|
|
622
|
+
if (animationRunning) {
|
|
623
|
+
var cam = camera;
|
|
624
|
+
var targetPosition = messagePosition.current.child ? messagePosition.current.pos : defaultCamera.position.toArray();
|
|
612
625
|
animationTarget.current.position.fromArray(targetPosition);
|
|
613
626
|
|
|
614
627
|
if (messagePosition.current.parent) {
|
|
@@ -616,41 +629,55 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
616
629
|
animationTarget.current.applyQuaternion(cam.quaternion);
|
|
617
630
|
}
|
|
618
631
|
|
|
619
|
-
|
|
632
|
+
var mult = messagePosition.current.isLeft ? -1 : 1;
|
|
633
|
+
var headSpace = 2.25 * mult; // move bubble
|
|
634
|
+
|
|
635
|
+
messagePosition.current.pos[0] = messagePosition.current.pos[0] - 1.25;
|
|
636
|
+
animationTarget.current.translateX(-10 * mult - headSpace);
|
|
620
637
|
animationTarget.current.translateY(-5);
|
|
621
638
|
animationTarget.current.translateZ(30);
|
|
622
639
|
}
|
|
623
640
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
checkBubblePosition();
|
|
644
|
-
} else {
|
|
645
|
-
if (changedMats.current.length) {
|
|
646
|
-
changedMats.current.forEach(function (o) {
|
|
647
|
-
var object = o.object;
|
|
648
|
-
object.material.visible = true;
|
|
649
|
-
});
|
|
650
|
-
}
|
|
641
|
+
_gsap.default.to(cam.position, {
|
|
642
|
+
duration: 1,
|
|
643
|
+
ease: 'power3.easeInOut',
|
|
644
|
+
onComplete: function onComplete() {
|
|
645
|
+
setAnimationRunning(false);
|
|
646
|
+
raycast.set(cam.getWorldPosition(new _three.Vector3(0, 0, 0)), cam.getWorldDirection(new _three.Vector3()));
|
|
647
|
+
var objects = raycast.intersectObjects(scene.children, true);
|
|
648
|
+
changedMats.current = objects.filter(function (o) {
|
|
649
|
+
return o.distance < 10;
|
|
650
|
+
}); // TODO: CHECK IF OBJECT BETWEEN CAMERA AND TARGET
|
|
651
|
+
|
|
652
|
+
if (changedMats.current.length) {
|
|
653
|
+
changedMats.current.forEach(function (o) {
|
|
654
|
+
var object = o.object;
|
|
655
|
+
object.material.visible = false;
|
|
656
|
+
});
|
|
657
|
+
}
|
|
651
658
|
|
|
652
|
-
|
|
659
|
+
if (lastSet.current || !messagePosition.current.child) {
|
|
660
|
+
cam.copy(defaultCamera);
|
|
661
|
+
}
|
|
662
|
+
},
|
|
663
|
+
x: animationTarget.current.position.x,
|
|
664
|
+
y: animationTarget.current.position.y,
|
|
665
|
+
z: animationTarget.current.position.z
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
}, [animationRunning]); // Animate Camera
|
|
669
|
+
// 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
|
|
670
|
+
|
|
671
|
+
(0, _fiber.useFrame)(function () {
|
|
672
|
+
if (animationRunning) {
|
|
673
|
+
if (changedMats.current.length) {
|
|
674
|
+
changedMats.current.forEach(function (o) {
|
|
675
|
+
var object = o.object;
|
|
676
|
+
object.material.visible = true;
|
|
677
|
+
});
|
|
653
678
|
}
|
|
679
|
+
|
|
680
|
+
checkBubblePosition();
|
|
654
681
|
}
|
|
655
682
|
});
|
|
656
683
|
var cleanStyle = {
|
|
@@ -682,7 +709,8 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
682
709
|
}, /*#__PURE__*/_react.default.createElement(_decisionComponent.default, _extends({
|
|
683
710
|
inScene: true
|
|
684
711
|
}, decisionPayload)));
|
|
685
|
-
}
|
|
712
|
+
} // 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
|
|
713
|
+
|
|
686
714
|
|
|
687
715
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, currentMessage.text ? /*#__PURE__*/_react.default.createElement("group", {
|
|
688
716
|
ref: groupRef,
|
|
@@ -712,16 +740,17 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
712
740
|
dir: (0, _LangIsRtl.default)() ? 'rtl' : 'ltr',
|
|
713
741
|
className: "dialog-component-controls"
|
|
714
742
|
}, /*#__PURE__*/_react.default.createElement("button", {
|
|
715
|
-
disabled: disableBackButton,
|
|
716
743
|
type: "button",
|
|
717
744
|
onClick: manualBackLine,
|
|
718
|
-
|
|
745
|
+
disabled: disableBackButton || animationRunning,
|
|
746
|
+
className: "gat--btn__round ".concat(disableBackButton || animationRunning ? 'disabled' : '')
|
|
719
747
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
720
748
|
className: (0, _LangIsRtl.default)() ? 'icon-next' : 'icon-back'
|
|
721
749
|
})), /*#__PURE__*/_react.default.createElement("button", {
|
|
722
|
-
className: "gat--btn__round",
|
|
723
750
|
type: "button",
|
|
724
|
-
onClick: manualNextLine
|
|
751
|
+
onClick: manualNextLine,
|
|
752
|
+
disabled: animationRunning,
|
|
753
|
+
className: "gat--btn__round ".concat(animationRunning ? 'disabled' : '')
|
|
725
754
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
726
755
|
className: (0, _LangIsRtl.default)() ? 'icon-back' : 'icon-next'
|
|
727
756
|
})))));
|
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.22.
|
|
5
|
+
"version": "1.22.12",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"@testing-library/react": "11.1.0",
|
|
22
22
|
"@testing-library/user-event": "13.5.0",
|
|
23
23
|
"global": "^4.4.0",
|
|
24
|
+
"gsap": "^3.10.1",
|
|
24
25
|
"hls.js": "0.12.4",
|
|
25
26
|
"html-react-parser": "^1.4.0",
|
|
26
27
|
"interactjs": "^1.10.11",
|
|
@@ -109,4 +110,4 @@
|
|
|
109
110
|
"post-merge": "bash node_modules/@gamelearn/version/scripts/after_version_update.sh -p hooks.config"
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
|
-
}
|
|
113
|
+
}
|