@gamelearn/arcade-components 0.24.8 → 0.24.10

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.
@@ -50,6 +50,7 @@ var ConfigController = function ConfigController(_ref) {
50
50
 
51
51
  (0, _react.useEffect)(function () {
52
52
  gl.shadowMap.enabled = current.shadows;
53
+ gl.shadowMap.needsUpdate = true;
53
54
 
54
55
  if (!current.animate) {
55
56
  invalidate();
@@ -27,6 +27,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
27
27
 
28
28
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
29
29
 
30
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
31
+
32
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
33
+
30
34
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
31
35
 
32
36
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -59,21 +63,24 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
59
63
  playSound = _soundActions[0],
60
64
  stop = _soundActions[1];
61
65
 
66
+ var _useState3 = (0, _react.useState)(false),
67
+ _useState4 = _slicedToArray(_useState3, 2),
68
+ finished = _useState4[0],
69
+ setFinished = _useState4[1];
70
+
62
71
  var backgroundImage = (background === null || background === void 0 ? void 0 : (_background$img = background.img) === null || _background$img === void 0 ? void 0 : _background$img.url) || null;
63
72
  var currentLineData = lines[currentLine];
64
73
  var voiceOverSlots = [];
65
74
  var voiceOver = currentLineData.voiceOver,
66
75
  decision = currentLineData.decision;
67
76
  var isFlex = currentLineData.flex;
68
-
69
- var translate = function translate(id) {
77
+ var translate = (0, _react.useCallback)(function (id) {
70
78
  return emitEvent({
71
79
  type: 'translate',
72
80
  payload: id
73
81
  });
74
- };
75
-
76
- var getCurrentMessage = function getCurrentMessage() {
82
+ }, [emitEvent]);
83
+ var getCurrentMessage = (0, _react.useCallback)(function () {
77
84
  if (voiceOver) {
78
85
  return currentLineData;
79
86
  }
@@ -90,9 +97,65 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
90
97
  return currentLineData.slots.find(function (slot) {
91
98
  return slot.uid && slot.text;
92
99
  });
93
- };
100
+ }, [currentLineData, voiceOver]);
101
+ var getVoice = (0, _react.useCallback)(function (_ref2) {
102
+ var id = _ref2.id,
103
+ _ref2$type = _ref2.type,
104
+ type = _ref2$type === void 0 ? 'base' : _ref2$type;
105
+ var usedVoices = translate('usedVoices');
106
+ var gameChars = translate('gameCharacters');
107
+
108
+ if (type === 'base') {
109
+ return usedVoices === null || usedVoices === void 0 ? void 0 : usedVoices[id];
110
+ } else if (type === 'character') {
111
+ var _gameChars$id;
112
+
113
+ return gameChars === null || gameChars === void 0 ? void 0 : (_gameChars$id = gameChars[id]) === null || _gameChars$id === void 0 ? void 0 : _gameChars$id.voiceId;
114
+ }
94
115
 
95
- var currentMessage = !decision ? getCurrentMessage() : {}; // Recupera la antigua linea de la conversacion para conservar los personajes en voice-over
116
+ return null;
117
+ }, [translate]);
118
+ var currentMessage = (0, _react.useMemo)(function () {
119
+ return !decision ? getCurrentMessage() : {};
120
+ }, [getCurrentMessage, decision]);
121
+ var playSpeech = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
122
+ var payload, speechUrl;
123
+ return regeneratorRuntime.wrap(function _callee$(_context) {
124
+ while (1) {
125
+ switch (_context.prev = _context.next) {
126
+ case 0:
127
+ if (!currentLineData.voice.id) {
128
+ _context.next = 7;
129
+ break;
130
+ }
131
+
132
+ payload = {
133
+ voiceId: getVoice(currentLineData.voice),
134
+ text: currentMessage.text
135
+ };
136
+
137
+ if (!(payload.voiceId && payload.text)) {
138
+ _context.next = 7;
139
+ break;
140
+ }
141
+
142
+ _context.next = 5;
143
+ return emitEvent({
144
+ type: 'playSpeech',
145
+ payload: payload
146
+ });
147
+
148
+ case 5:
149
+ speechUrl = _context.sent;
150
+ playSound(speechUrl);
151
+
152
+ case 7:
153
+ case "end":
154
+ return _context.stop();
155
+ }
156
+ }
157
+ }, _callee);
158
+ })), [currentLineData.voice, getVoice, currentMessage, emitEvent, playSound]); // Recupera la antigua linea de la conversacion para conservar los personajes en voice-over
96
159
 
97
160
  var leftWithSlots = lines.slice(0, currentLine + 1).reverse().find(function (line) {
98
161
  return line.slots;
@@ -177,6 +240,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
177
240
  if (line + 1 <= maxLine) {
178
241
  setCurrentLine(line + 1);
179
242
  } else {
243
+ setFinished(true);
180
244
  emitEvent({
181
245
  type: 'success'
182
246
  });
@@ -192,13 +256,20 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
192
256
  };
193
257
 
194
258
  (0, _react.useEffect)(function () {
195
- var _lines$currentLine, _lines$currentLine$au;
259
+ var _currentLineData$audi;
260
+
261
+ if ((currentLineData === null || currentLineData === void 0 ? void 0 : currentLineData.audioType) === 'voice' && !finished) {
262
+ playSpeech();
263
+ } else if (currentLineData !== null && currentLineData !== void 0 && (_currentLineData$audi = currentLineData.audio) !== null && _currentLineData$audi !== void 0 && _currentLineData$audi.url) {
264
+ var _currentLineData$audi2;
265
+
266
+ playSound(currentLineData === null || currentLineData === void 0 ? void 0 : (_currentLineData$audi2 = currentLineData.audio) === null || _currentLineData$audi2 === void 0 ? void 0 : _currentLineData$audi2.url);
267
+ }
196
268
 
197
- playSound((_lines$currentLine = lines[currentLine]) === null || _lines$currentLine === void 0 ? void 0 : (_lines$currentLine$au = _lines$currentLine.audio) === null || _lines$currentLine$au === void 0 ? void 0 : _lines$currentLine$au.url);
198
269
  return function () {
199
270
  stop();
200
271
  };
201
- }, [currentLine, lines, playSound, stop]);
272
+ }, [currentLineData, currentMessage, finished, lines, playSound, playSpeech, stop]);
202
273
 
203
274
  var decisionPayload = _objectSpread(_objectSpread({}, currentLineData.payload), {}, {
204
275
  onFinish: handleClickNext,
@@ -45,12 +45,14 @@ var SlotList = function SlotList(_ref) {
45
45
  if (current.character) {
46
46
  char.name = current.alias || current.character.name;
47
47
  char.resource = char.character.resource;
48
+ char.position = char.position >= 0 ? char.position : -1;
48
49
  delete char.character;
49
50
  char.type = 'character';
50
51
  acc.push(char);
51
52
  } else if (actor) {
52
53
  var resource = actor.resource;
53
54
  char.name = current.alias || current.name;
55
+ char.position = char.position >= 0 ? char.position : -1;
54
56
  char.resource = resource;
55
57
  char.type = actor.type;
56
58
  acc.push(char);
@@ -83,7 +85,7 @@ var SlotList = function SlotList(_ref) {
83
85
  key: character.uid + index
84
86
  }, characterProps({
85
87
  character: character,
86
- active: character.talking,
88
+ active: currentMessage.position === character.position,
87
89
  slot: index
88
90
  })));
89
91
  });
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.conversationPropsLodSettings = exports.conversationPropsNoFeedbackNoRewards = exports.withoutBackground = exports.voiceOverProps = exports.conversationProps = exports.converOld = void 0;
6
+ exports.textToSpeechProps = exports.conversationPropsLodSettings = exports.conversationPropsNoFeedbackNoRewards = exports.withoutBackground = exports.voiceOverProps = exports.conversationProps = exports.converOld = void 0;
7
7
 
8
8
  var _mocker = require("helpers/mocker");
9
9
 
@@ -1131,4 +1131,104 @@ var conversationPropsLodSettings = {
1131
1131
  uid: 'kjTHqx'
1132
1132
  }]
1133
1133
  };
1134
- exports.conversationPropsLodSettings = conversationPropsLodSettings;
1134
+ exports.conversationPropsLodSettings = conversationPropsLodSettings;
1135
+ var textToSpeechProps = {
1136
+ "actors": [],
1137
+ "background": {},
1138
+ "lines": [{
1139
+ "audioId_labelId": "audioId_0_u8GqjXR4",
1140
+ "audioType": "voice",
1141
+ "flex": false,
1142
+ "hasAlias": true,
1143
+ "slots": [{
1144
+ "alias": "alias_0_0_u8GqgZXt",
1145
+ "alias_labelId": "alias_0_0_u8GqgZXt",
1146
+ "emotion": "neutral",
1147
+ "talking": true,
1148
+ "text": "text_0_0_u8Gqfb0d",
1149
+ "text_labelId": "text_0_0_u8Gqfb0d",
1150
+ "uid": "OxVPqm"
1151
+ }, {
1152
+ "alias_labelId": "alias_0_1_u8GqgVBv",
1153
+ "emotion": "neutral",
1154
+ "talking": false,
1155
+ "text": "",
1156
+ "text_labelId": "text_0_1_u8GqgH0e",
1157
+ "uid": null
1158
+ }, {
1159
+ "alias_labelId": "alias_0_2_u8GqgGOU",
1160
+ "emotion": "neutral",
1161
+ "talking": false,
1162
+ "text": "",
1163
+ "text_labelId": "text_0_2_u8GqgCxs",
1164
+ "uid": null
1165
+ }, {
1166
+ "alias_labelId": "alias_0_3_u8Gqhwkb",
1167
+ "emotion": "neutral",
1168
+ "talking": false,
1169
+ "text": "",
1170
+ "text_labelId": "text_0_3_u8GqhLmZ",
1171
+ "uid": null
1172
+ }, {
1173
+ "alias_labelId": "alias_0_4_u8GqhHJG",
1174
+ "emotion": "neutral",
1175
+ "talking": false,
1176
+ "text": "",
1177
+ "text_labelId": "text_0_4_u8Gqh68W",
1178
+ "uid": null
1179
+ }],
1180
+ "text_labelId": "text_0_u8Gqjbqa",
1181
+ "voice": {
1182
+ type: "character",
1183
+ id: "OxVPqm"
1184
+ }
1185
+ }, {
1186
+ "audioId_labelId": "audioId_0_u8GqjXR4",
1187
+ "audioType": "voice",
1188
+ "flex": false,
1189
+ "hasAlias": true,
1190
+ "slots": [{
1191
+ "alias": "alias_0_0_u8GqgZXt",
1192
+ "alias_labelId": "alias_0_0_u8GqgZXt",
1193
+ "emotion": "neutral",
1194
+ "talking": true,
1195
+ "text": "text_0_0_u8Gqfb0d",
1196
+ "text_labelId": "text_0_0_u8Gqfb0d",
1197
+ "uid": "OxVPqm"
1198
+ }, {
1199
+ "alias_labelId": "alias_0_1_u8GqgVBv",
1200
+ "emotion": "neutral",
1201
+ "talking": false,
1202
+ "text": "",
1203
+ "text_labelId": "text_0_1_u8GqgH0e",
1204
+ "uid": null
1205
+ }, {
1206
+ "alias_labelId": "alias_0_2_u8GqgGOU",
1207
+ "emotion": "neutral",
1208
+ "talking": false,
1209
+ "text": "",
1210
+ "text_labelId": "text_0_2_u8GqgCxs",
1211
+ "uid": null
1212
+ }, {
1213
+ "alias_labelId": "alias_0_3_u8Gqhwkb",
1214
+ "emotion": "neutral",
1215
+ "talking": false,
1216
+ "text": "",
1217
+ "text_labelId": "text_0_3_u8GqhLmZ",
1218
+ "uid": null
1219
+ }, {
1220
+ "alias_labelId": "alias_0_4_u8GqhHJG",
1221
+ "emotion": "neutral",
1222
+ "talking": false,
1223
+ "text": "",
1224
+ "text_labelId": "text_0_4_u8Gqh68W",
1225
+ "uid": null
1226
+ }],
1227
+ "text_labelId": "text_0_u8Gqjbqa",
1228
+ voice: {
1229
+ type: "base",
1230
+ id: "female_01"
1231
+ }
1232
+ }]
1233
+ };
1234
+ exports.textToSpeechProps = textToSpeechProps;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gamelearn/arcade-components",
3
3
  "license": "Gamelearn",
4
- "version": "0.24.8",
4
+ "version": "0.24.10",
5
5
  "main": "dist/index.js",
6
6
  "files": [
7
7
  "dist",