@gamelearn/arcade-components 2.0.2 → 2.1.0
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.
package/dist/components/conversational-pro-component/components/ConversationalProComponent.js
CHANGED
|
@@ -59,7 +59,7 @@ var characterMs = 75;
|
|
|
59
59
|
var minMs = 1400;
|
|
60
60
|
|
|
61
61
|
var ConversationProViewer = function ConversationProViewer(_ref) {
|
|
62
|
-
var _background$img, _currentLineData$
|
|
62
|
+
var _background$img, _currentLineData$slot3, _currentMessage$text;
|
|
63
63
|
|
|
64
64
|
var emitEvent = _ref.emitEvent,
|
|
65
65
|
lines = _ref.lines,
|
|
@@ -110,12 +110,12 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
|
|
|
110
110
|
|
|
111
111
|
var backgroundImage = (background === null || background === void 0 ? void 0 : (_background$img = background.img) === null || _background$img === void 0 ? void 0 : _background$img.url) || null;
|
|
112
112
|
var currentLineData = lines[currentLine];
|
|
113
|
+
var voiceOver = currentLineData.voiceOver,
|
|
114
|
+
decision = currentLineData.decision;
|
|
113
115
|
var voiceOverSlots = [];
|
|
114
116
|
var isBranched = !!edges;
|
|
115
117
|
var isVoiceOver = voiceOver || currentLineData.type === 'conversationalNarration';
|
|
116
118
|
var isDecision = decision || currentLineData.type === 'conversationalDecision';
|
|
117
|
-
var voiceOver = currentLineData.voiceOver,
|
|
118
|
-
decision = currentLineData.decision;
|
|
119
119
|
var isFlex = currentLineData.flex;
|
|
120
120
|
|
|
121
121
|
var _useState13 = (0, _react.useState)([]),
|
|
@@ -154,11 +154,13 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
|
|
|
154
154
|
});
|
|
155
155
|
}, [emitEvent]);
|
|
156
156
|
var getCurrentMessage = (0, _react.useCallback)(function () {
|
|
157
|
+
var _currentLineData$slot, _currentLineData$slot2;
|
|
158
|
+
|
|
157
159
|
if (isVoiceOver) {
|
|
158
160
|
return currentLineData;
|
|
159
161
|
}
|
|
160
162
|
|
|
161
|
-
var currentMessage = currentLineData.slots.find(function (slot) {
|
|
163
|
+
var currentMessage = currentLineData === null || currentLineData === void 0 ? void 0 : (_currentLineData$slot = currentLineData.slots) === null || _currentLineData$slot === void 0 ? void 0 : _currentLineData$slot.find(function (slot) {
|
|
162
164
|
return slot.uid && slot.talking;
|
|
163
165
|
});
|
|
164
166
|
|
|
@@ -167,7 +169,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
|
|
|
167
169
|
} // Old conversational schema
|
|
168
170
|
|
|
169
171
|
|
|
170
|
-
return currentLineData.slots.find(function (slot) {
|
|
172
|
+
return currentLineData === null || currentLineData === void 0 ? void 0 : (_currentLineData$slot2 = currentLineData.slots) === null || _currentLineData$slot2 === void 0 ? void 0 : _currentLineData$slot2.find(function (slot) {
|
|
171
173
|
return slot.uid && slot.text;
|
|
172
174
|
});
|
|
173
175
|
}, [currentLineData, isVoiceOver]);
|
|
@@ -186,9 +188,10 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
|
|
|
186
188
|
var leftWithSlots = lines.slice(0, currentLine + 1).reverse().find(function (line) {
|
|
187
189
|
return line.slots;
|
|
188
190
|
});
|
|
189
|
-
var hasCharacters = !isDecision && ((_currentLineData$
|
|
191
|
+
var hasCharacters = !isDecision && ((_currentLineData$slot3 = currentLineData.slots) === null || _currentLineData$slot3 === void 0 ? void 0 : _currentLineData$slot3.filter(function (slot) {
|
|
190
192
|
return slot.uid;
|
|
191
193
|
}).length);
|
|
194
|
+
var autoPlayTime = characterMs * ((currentMessage === null || currentMessage === void 0 ? void 0 : (_currentMessage$text = currentMessage.text) === null || _currentMessage$text === void 0 ? void 0 : _currentMessage$text.length) || 0);
|
|
192
195
|
var currentSlots = [];
|
|
193
196
|
|
|
194
197
|
if (currentLineData.slots) {
|
|
@@ -410,26 +413,32 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
|
|
|
410
413
|
(0, _react.useEffect)(function () {
|
|
411
414
|
var _currentMessage$emoti2;
|
|
412
415
|
|
|
413
|
-
|
|
416
|
+
var timeout;
|
|
417
|
+
|
|
418
|
+
if (((currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType) === 'none' || audioFailed) && !(currentMessage !== null && currentMessage !== void 0 && (_currentMessage$emoti2 = currentMessage.emotion) !== null && _currentMessage$emoti2 !== void 0 && _currentMessage$emoti2.includes('think'))) {
|
|
414
419
|
setTTsStart(true);
|
|
420
|
+
timeout = setTimeout(function () {
|
|
421
|
+
setTTsStart(false);
|
|
422
|
+
}, autoPlayTime < minMs ? minMs : autoPlayTime);
|
|
415
423
|
}
|
|
416
|
-
|
|
424
|
+
|
|
425
|
+
return function () {
|
|
426
|
+
if (timeout) clearTimeout(timeout);
|
|
427
|
+
};
|
|
428
|
+
}, [audioFailed, currentLineData, currentMessage === null || currentMessage === void 0 ? void 0 : currentMessage.emotion, autoPlayTime]); // Autoplay logic
|
|
417
429
|
|
|
418
430
|
(0, _react.useEffect)(function () {
|
|
419
431
|
if (autoplayCond && ((currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType) === 'none' || audioFailed)) {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
var time = characterMs * ((currentMessage === null || currentMessage === void 0 ? void 0 : (_currentMessage$text = currentMessage.text) === null || _currentMessage$text === void 0 ? void 0 : _currentMessage$text.length) || 0); // if it's not last node
|
|
423
|
-
|
|
432
|
+
// if it's not last node
|
|
424
433
|
if (!isEndNode()) {
|
|
425
|
-
start(handleClickNext,
|
|
434
|
+
start(handleClickNext, autoPlayTime < minMs ? minMs : autoPlayTime);
|
|
426
435
|
}
|
|
427
436
|
}
|
|
428
437
|
|
|
429
438
|
return function () {
|
|
430
439
|
stop();
|
|
431
440
|
};
|
|
432
|
-
}, [currentMessage, start, stop, handleClickNext, currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType, autoplayCond, audioFailed, lines, isEndNode]); // Calculate start node
|
|
441
|
+
}, [currentMessage, start, stop, handleClickNext, currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType, autoplayCond, audioFailed, lines, isEndNode, autoPlayTime]); // Calculate start node
|
|
433
442
|
|
|
434
443
|
(0, _react.useEffect)(function () {
|
|
435
444
|
if (isBranched && !mounted) {
|
|
@@ -212,23 +212,22 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
212
212
|
var lastEdge = edges.find(function (edge) {
|
|
213
213
|
return edge.fromId === lastNodeId;
|
|
214
214
|
});
|
|
215
|
-
var
|
|
216
|
-
return
|
|
215
|
+
var lastL = lines.find(function (l) {
|
|
216
|
+
return l.id === lastEdge.fromId;
|
|
217
217
|
});
|
|
218
|
-
return
|
|
218
|
+
return lastL;
|
|
219
219
|
}, [edges, lines, lastNodeId]);
|
|
220
220
|
var previousLineWasDecision = (0, _react.useCallback)(function () {
|
|
221
221
|
if (isBranched) {
|
|
222
222
|
// if we have edges, we need to check if the previous line was a decision
|
|
223
|
-
var
|
|
223
|
+
var _lastL = findLastLineBranched();
|
|
224
224
|
|
|
225
|
-
return
|
|
226
|
-
}
|
|
227
|
-
// if there is no branching, the previous line is the previous one
|
|
228
|
-
var _lastLine2 = lines[currentLineData - 1] ? lines[currentLineData - 1] : {};
|
|
225
|
+
return _lastL === null || _lastL === void 0 ? void 0 : _lastL.decision;
|
|
226
|
+
} // if there is no branching, the previous line is the previous one
|
|
229
227
|
|
|
230
|
-
|
|
231
|
-
}
|
|
228
|
+
|
|
229
|
+
var lastL = lines[currentLineData - 1] ? lines[currentLineData - 1] : {};
|
|
230
|
+
return currentLineData > 0 && (lastL === null || lastL === void 0 ? void 0 : lastL.decision);
|
|
232
231
|
}, [currentLineData, isBranched, lines, lastNodeId, edges]);
|
|
233
232
|
var getCurrentVisible = (0, _react.useCallback)(function (uid) {
|
|
234
233
|
if (!uid) return null;
|
|
@@ -304,7 +303,12 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
304
303
|
|
|
305
304
|
var restTalkingAnimation = function restTalkingAnimation() {
|
|
306
305
|
var element = getCurrentVisible(talkingCharacter === null || talkingCharacter === void 0 ? void 0 : talkingCharacter.uid);
|
|
307
|
-
|
|
306
|
+
|
|
307
|
+
if (!element) {
|
|
308
|
+
startTalking(false);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
|
|
308
312
|
var _element$userData = element.userData,
|
|
309
313
|
mixer = _element$userData.mixer,
|
|
310
314
|
defaultAnim = _element$userData.defaultAnim,
|
|
@@ -575,10 +579,6 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
575
579
|
element.userData.defaultAnim = action.getClip();
|
|
576
580
|
}
|
|
577
581
|
|
|
578
|
-
if ((currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType) === 'none' && talkingCharacter.emotion !== 'thinkful') {
|
|
579
|
-
startTalking(true);
|
|
580
|
-
}
|
|
581
|
-
|
|
582
582
|
if (talkingCharacter.uid === element.uid) {
|
|
583
583
|
var showArrowTop = talkingCharacter.text.length > maxCharacterToSwitch;
|
|
584
584
|
moveBubble(element, showArrowTop);
|
|
@@ -661,13 +661,24 @@ var DialogComponent = function DialogComponent(_ref) {
|
|
|
661
661
|
return function () {
|
|
662
662
|
stopEkho();
|
|
663
663
|
};
|
|
664
|
-
}, [line, stopEkho]);
|
|
664
|
+
}, [line, stopEkho]);
|
|
665
|
+
(0, _react.useEffect)(function () {
|
|
666
|
+
if (((currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType) === 'none' || audioFailed) && currentMessage !== null && currentMessage !== void 0 && currentMessage.show && (talkingCharacter === null || talkingCharacter === void 0 ? void 0 : talkingCharacter.emotion) !== 'thinkful') {
|
|
667
|
+
var _currentMessage$text;
|
|
668
|
+
|
|
669
|
+
startTalking(true);
|
|
670
|
+
var time = characterMs * ((currentMessage === null || currentMessage === void 0 ? void 0 : (_currentMessage$text = currentMessage.text) === null || _currentMessage$text === void 0 ? void 0 : _currentMessage$text.length) || 0);
|
|
671
|
+
setTimeout(function () {
|
|
672
|
+
startTalking(false);
|
|
673
|
+
}, time < minMs ? minMs : time);
|
|
674
|
+
}
|
|
675
|
+
}, [audioFailed, currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType, talkingCharacter === null || talkingCharacter === void 0 ? void 0 : talkingCharacter.emotion, currentMessage]); // Autoplay logic
|
|
665
676
|
|
|
666
677
|
(0, _react.useEffect)(function () {
|
|
667
678
|
if (autoPlayCond && currentMessage.show && ((currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType) === 'none' || audioFailed)) {
|
|
668
|
-
var _currentMessage$
|
|
679
|
+
var _currentMessage$text2;
|
|
669
680
|
|
|
670
|
-
var time = characterMs * ((currentMessage === null || currentMessage === void 0 ? void 0 : (_currentMessage$
|
|
681
|
+
var time = characterMs * ((currentMessage === null || currentMessage === void 0 ? void 0 : (_currentMessage$text2 = currentMessage.text) === null || _currentMessage$text2 === void 0 ? void 0 : _currentMessage$text2.length) || 0); // if it's not last node
|
|
671
682
|
|
|
672
683
|
if (!isEndNode()) {
|
|
673
684
|
start(nextLine, time < minMs ? minMs : time);
|
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.0
|
|
5
|
+
"version": "2.1.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/runtime": "^7.18.6",
|
|
17
|
-
"@gamelearn/arcade-styles": "2.0
|
|
17
|
+
"@gamelearn/arcade-styles": "2.1.0",
|
|
18
18
|
"@gamelearn/arcade-three-core": "1.17.1",
|
|
19
19
|
"@react-three/drei": "9.4.3",
|
|
20
20
|
"@react-three/fiber": "8.0.17",
|