@gamelearn/arcade-components 1.4.11 → 1.4.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.
@@ -48,6 +48,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
48
48
 
49
49
  var emitEvent = _ref.emitEvent,
50
50
  lines = _ref.lines,
51
+ edges = _ref.edges,
51
52
  characters = _ref.characters,
52
53
  actors = _ref.actors,
53
54
  background = _ref.background,
@@ -73,6 +74,9 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
73
74
  var voiceOverSlots = [];
74
75
  var voiceOver = currentLineData.voiceOver,
75
76
  decision = currentLineData.decision;
77
+ var isBranched = !!edges;
78
+ var isVoiceOver = voiceOver || currentLineData.type === 'conversationalNarration';
79
+ var isDecision = decision || currentLineData.type === 'conversationalDecision';
76
80
  var isFlex = currentLineData.flex;
77
81
  var translate = (0, _react.useCallback)(function (id) {
78
82
  return emitEvent({
@@ -81,7 +85,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
81
85
  });
82
86
  }, [emitEvent]);
83
87
  var getCurrentMessage = (0, _react.useCallback)(function () {
84
- if (voiceOver) {
88
+ if (isVoiceOver) {
85
89
  return currentLineData;
86
90
  }
87
91
 
@@ -97,7 +101,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
97
101
  return currentLineData.slots.find(function (slot) {
98
102
  return slot.uid && slot.text;
99
103
  });
100
- }, [currentLineData, voiceOver]);
104
+ }, [currentLineData, isVoiceOver]);
101
105
  var getVoice = (0, _react.useCallback)(function (_ref2) {
102
106
  var id = _ref2.id,
103
107
  _ref2$type = _ref2.type,
@@ -118,8 +122,8 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
118
122
  return null;
119
123
  }, [translate]);
120
124
  var currentMessage = (0, _react.useMemo)(function () {
121
- return !decision ? getCurrentMessage() : {};
122
- }, [getCurrentMessage, decision]);
125
+ return !isDecision ? getCurrentMessage() : {};
126
+ }, [getCurrentMessage, isDecision]);
123
127
  var playSpeech = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
124
128
  var payload, url;
125
129
  return regeneratorRuntime.wrap(function _callee$(_context) {
@@ -163,7 +167,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
163
167
  return line.slots;
164
168
  });
165
169
  var lastLine = lines[currentLine - 1] ? lines[currentLine - 1] : {};
166
- var hasCharacters = !currentLineData.decision && ((_currentLineData$slot = currentLineData.slots) === null || _currentLineData$slot === void 0 ? void 0 : _currentLineData$slot.filter(function (slot) {
170
+ var hasCharacters = !isDecision && ((_currentLineData$slot = currentLineData.slots) === null || _currentLineData$slot === void 0 ? void 0 : _currentLineData$slot.filter(function (slot) {
167
171
  return slot.uid;
168
172
  }).length);
169
173
  var currentSlots = [];
@@ -190,7 +194,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
190
194
  return slot;
191
195
  });
192
196
 
193
- if (voiceOver) {
197
+ if (isVoiceOver) {
194
198
  var rightWithSlots = lines.slice(currentLine).find(function (line) {
195
199
  return line.slots;
196
200
  });
@@ -200,7 +204,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
200
204
  voiceOverSlots = lineWithSlots.slots;
201
205
  isFlex = lineWithSlots.flex;
202
206
  }
203
- } else if (!decision && hasCharacters) {
207
+ } else if (!isDecision && hasCharacters) {
204
208
  currentLineData.slots.forEach(function (slot) {
205
209
  var indx = currentCharacters.findIndex(function (char) {
206
210
  return char.uid === slot.uid;
@@ -230,29 +234,85 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
230
234
  lodSettings: lodSettings,
231
235
  actors: actors,
232
236
  currentMessage: currentMessage || {},
233
- slots: !voiceOver ? currentLineData.slots : voiceOverSlots,
237
+ slots: !isVoiceOver ? currentLineData.slots : voiceOverSlots,
234
238
  flex: isFlex
235
239
  };
240
+ var finishConversation = (0, _react.useCallback)(function () {
241
+ setFinished(true);
242
+ emitEvent({
243
+ type: 'success'
244
+ });
245
+ }, [emitEvent]);
246
+ var handleDecisionBranch = (0, _react.useCallback)(function (choice, reset) {
247
+ var currentId = [3, 2, 1][choice.id];
248
+ var optionsEdges = edges.filter(function (edge) {
249
+ return edge.fromId === currentLineData.id;
250
+ });
251
+ var currentEdge = optionsEdges.find(function (edge) {
252
+ return parseInt(edge.fromPointIndex) === currentId;
253
+ });
254
+ var destinationEdge = lines.findIndex(function (l) {
255
+ return l.id === currentEdge.toId;
256
+ });
236
257
 
237
- var handleClickNext = function handleClickNext() {
238
- playSound('click-ui');
239
- var line = currentLine;
240
- var maxLine = lines.length - 1;
258
+ if (currentEdge.fromId === currentEdge.toId) {
259
+ reset();
260
+ } else if (destinationEdge >= 0) {
261
+ setCurrentLine(destinationEdge);
262
+ } else {
263
+ finishConversation();
264
+ }
265
+ }, [currentLineData.id, edges, finishConversation, lines]);
241
266
 
242
- if (line + 1 <= maxLine) {
243
- setCurrentLine(line + 1);
267
+ var handleBranchDirection = function handleBranchDirection() {
268
+ var forward = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
269
+ var keys = forward ? ['fromId', 'toId'] : ['toId', 'fromId'];
270
+ var foundEdge = edges.find(function (edge) {
271
+ return edge[keys[0]] === currentLineData.id;
272
+ });
273
+
274
+ if (!(foundEdge !== null && foundEdge !== void 0 && foundEdge[keys[0]])) {
275
+ finishConversation();
244
276
  } else {
245
- setFinished(true);
246
- emitEvent({
247
- type: 'success'
277
+ var destination = lines.findIndex(function (line) {
278
+ return line.id === foundEdge[keys[1]];
248
279
  });
280
+
281
+ if (destination >= 0) {
282
+ setCurrentLine(destination);
283
+ } else {
284
+ finishConversation();
285
+ }
286
+ }
287
+ };
288
+
289
+ var handleClickNext = function handleClickNext(choice, reset) {
290
+ playSound('click-ui');
291
+
292
+ if (isBranched) {
293
+ if (choice) {
294
+ handleDecisionBranch(choice, reset);
295
+ } else {
296
+ handleBranchDirection();
297
+ }
298
+ } else {
299
+ var line = currentLine;
300
+ var maxLine = lines.length - 1;
301
+
302
+ if (line + 1 <= maxLine) {
303
+ setCurrentLine(line + 1);
304
+ } else {
305
+ finishConversation();
306
+ }
249
307
  }
250
308
  };
251
309
 
252
310
  var handleClickBack = function handleClickBack() {
253
311
  playSound('click-ui');
254
312
 
255
- if (currentLine > 0) {
313
+ if (isBranched) {
314
+ handleBranchDirection(false);
315
+ } else if (currentLine > 0) {
256
316
  setCurrentLine(currentLine - 1);
257
317
  }
258
318
  };
@@ -279,6 +339,8 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
279
339
  }, [stop]);
280
340
 
281
341
  var decisionPayload = _objectSpread(_objectSpread({}, currentLineData.payload), {}, {
342
+ required: !isBranched,
343
+ branched: isBranched,
282
344
  onFinish: handleClickNext,
283
345
  emitEvent: emitEvent,
284
346
  soundActions: soundActions,
@@ -290,8 +352,8 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
290
352
  }
291
353
  });
292
354
 
293
- if (decision) {
294
- return /*#__PURE__*/_react.default.createElement(_decisionComponent.default, decisionPayload);
355
+ if (isDecision) {
356
+ return /*#__PURE__*/_react.default.createElement(_decisionComponent.default, decisionPayload); // todo cambiar el decision para indicar la decisión escogida
295
357
  }
296
358
 
297
359
  return /*#__PURE__*/_react.default.createElement("div", {
@@ -309,8 +371,8 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
309
371
  }) : null, /*#__PURE__*/_react.default.createElement("div", {
310
372
  className: "conversation--controls"
311
373
  }, /*#__PURE__*/_react.default.createElement("button", {
312
- className: "gat--btn__round ".concat(currentLine > 0 && !lastLine.decision ? '' : 'disabled'),
313
- disabled: currentLine > 0 && !lastLine.decision ? '' : true,
374
+ className: "gat--btn__round ".concat(currentLine > 0 && (!lastLine.decision || isBranched) ? '' : 'disabled'),
375
+ disabled: currentLine > 0 && (!lastLine.decision || isBranched) ? '' : true,
314
376
  type: "button",
315
377
  onClick: handleClickBack
316
378
  }, /*#__PURE__*/_react.default.createElement("span", {
@@ -318,7 +380,9 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
318
380
  })), /*#__PURE__*/_react.default.createElement("button", {
319
381
  className: "gat--btn__round",
320
382
  type: "button",
321
- onClick: handleClickNext
383
+ onClick: function onClick() {
384
+ return handleClickNext();
385
+ }
322
386
  }, /*#__PURE__*/_react.default.createElement("span", {
323
387
  className: "icon-next"
324
388
  }))))));
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.withoutBackground = exports.voiceOverProps = exports.textToSpeechProps = exports.conversationPropsNoFeedbackNoRewards = exports.conversationPropsLodSettings = exports.conversationProps = exports.converOld = void 0;
6
+ exports.withoutBackground = exports.voiceOverProps = exports.textToSpeechProps = exports.conversationPropsNoFeedbackNoRewards = exports.conversationPropsLodSettings = exports.conversationProps = exports.converOld = exports.branchedConver = void 0;
7
7
 
8
8
  var _mocker = require("helpers/mocker");
9
9
 
@@ -19,6 +19,300 @@ var animations = {
19
19
  url: 'https://min.int.gamelearn.io/cooked.gl-lms-storage/clients/5981fca94d82290bcbe957fe/animation/5f06e116f9efdd00112fcc6f/male_missunderstand_1.glb'
20
20
  }
21
21
  };
22
+ var branchedConver = {
23
+ emitEvent: _mocker.emitEvent,
24
+ soundActions: _mocker.soundActions,
25
+ lines: [{
26
+ id: 'line1',
27
+ type: 'conversationalPhrase',
28
+ flex: true,
29
+ slots: [{
30
+ emotion: '',
31
+ text: '',
32
+ uid: 'DbKslR',
33
+ talking: false,
34
+ alias: 'paco',
35
+ text_labelId: 'text_0_0_nlrZh8Np',
36
+ alias_labelId: 'alias_0_0_nlrZh2Iq'
37
+ }, {
38
+ emotion: 'neutral',
39
+ text: '',
40
+ uid: null,
41
+ talking: false,
42
+ text_labelId: 'text_0_1_nlrZiNfB',
43
+ alias_labelId: 'alias_0_1_nlrZijhw'
44
+ }, {
45
+ emotion: 'neutral',
46
+ text: '',
47
+ uid: null,
48
+ talking: false,
49
+ text_labelId: 'text_0_2_nlrZiBF3',
50
+ alias_labelId: 'alias_0_2_nlrZiR6G'
51
+ }, {
52
+ emotion: 'neutral',
53
+ text: '',
54
+ uid: null,
55
+ talking: false,
56
+ text_labelId: 'text_0_3_nlrZinJN',
57
+ alias_labelId: 'alias_0_3_nlrZjLWB'
58
+ }, {
59
+ emotion: 'neutral',
60
+ text: 'Hola!',
61
+ uid: 'kjTHqt',
62
+ talking: true,
63
+ alias: 'manolo',
64
+ text_labelId: 'text_0_4_nlrZjUV9',
65
+ alias_labelId: 'alias_0_4_nlrZj81d'
66
+ }],
67
+ audioId: '5f1078861d84860011e179d0',
68
+ hasAlias: true,
69
+ text_labelId: 'text_0_nlrZj4Nr',
70
+ audioId_labelId: 'audioId_0_nlrZkkdo'
71
+ }, {
72
+ id: 'line2',
73
+ flex: true,
74
+ type: 'conversationalPhrase',
75
+ slots: [{
76
+ emotion: '',
77
+ text: '',
78
+ uid: 'DbKslR',
79
+ talking: false,
80
+ alias: 'paco',
81
+ text_labelId: 'text_0_0_nlrZh8Np',
82
+ alias_labelId: 'alias_0_0_nlrZh2Iq'
83
+ }, {
84
+ emotion: 'neutral',
85
+ text: '',
86
+ uid: null,
87
+ talking: false,
88
+ text_labelId: 'text_0_1_nlrZiNfB',
89
+ alias_labelId: 'alias_0_1_nlrZijhw'
90
+ }, {
91
+ emotion: 'neutral',
92
+ text: '',
93
+ uid: null,
94
+ talking: false,
95
+ text_labelId: 'text_0_2_nlrZiBF3',
96
+ alias_labelId: 'alias_0_2_nlrZiR6G'
97
+ }, {
98
+ emotion: 'neutral',
99
+ text: '',
100
+ uid: null,
101
+ talking: false,
102
+ text_labelId: 'text_0_3_nlrZinJN',
103
+ alias_labelId: 'alias_0_3_nlrZjLWB'
104
+ }, {
105
+ emotion: 'neutral',
106
+ text: 'Hola!',
107
+ uid: 'kjTHqi',
108
+ talking: true,
109
+ alias: 'manolo',
110
+ text_labelId: 'text_0_4_nlrZjUV9',
111
+ alias_labelId: 'alias_0_4_nlrZj81d'
112
+ }],
113
+ audioId: '5f1078861d84860011e179d0',
114
+ hasAlias: true,
115
+ text_labelId: 'text_0_nlrZj4Nr',
116
+ audioId_labelId: 'audioId_0_nlrZkkdo'
117
+ }, {
118
+ id: 'line3',
119
+ flex: true,
120
+ type: 'conversationalPhrase',
121
+ slots: [{
122
+ emotion: '',
123
+ text: '',
124
+ uid: 'DbKslR',
125
+ talking: false,
126
+ alias: 'paco',
127
+ text_labelId: 'text_0_0_nlrZh8Np',
128
+ alias_labelId: 'alias_0_0_nlrZh2Iq'
129
+ }, {
130
+ emotion: 'neutral',
131
+ text: '',
132
+ uid: null,
133
+ talking: false,
134
+ text_labelId: 'text_0_1_nlrZiNfB',
135
+ alias_labelId: 'alias_0_1_nlrZijhw'
136
+ }, {
137
+ emotion: 'neutral',
138
+ text: '',
139
+ uid: null,
140
+ talking: false,
141
+ text_labelId: 'text_0_2_nlrZiBF3',
142
+ alias_labelId: 'alias_0_2_nlrZiR6G'
143
+ }, {
144
+ emotion: 'neutral',
145
+ text: '',
146
+ uid: null,
147
+ talking: false,
148
+ text_labelId: 'text_0_3_nlrZinJN',
149
+ alias_labelId: 'alias_0_3_nlrZjLWB'
150
+ }, {
151
+ emotion: 'neutral',
152
+ text: 'Hola!',
153
+ uid: 'kjTHqx',
154
+ talking: true,
155
+ alias: 'manolo',
156
+ text_labelId: 'text_0_4_nlrZjUV9',
157
+ alias_labelId: 'alias_0_4_nlrZj81d'
158
+ }],
159
+ audioId: '5f1078861d84860011e179d0',
160
+ hasAlias: true,
161
+ text_labelId: 'text_0_nlrZj4Nr',
162
+ audioId_labelId: 'audioId_0_nlrZkkdo'
163
+ }, {
164
+ id: 'line3',
165
+ type: 'conversationalDecision',
166
+ payload: {
167
+ options: [{
168
+ id: 0,
169
+ right: false,
170
+ feedback: 'dfgsdfgsdfgsdfghdfgh',
171
+ text: 'Si',
172
+ rewards: [],
173
+ audioId: '',
174
+ text_labelId: 'text_3_0_u4s8j5fa',
175
+ feedback_labelId: 'feedback_3_0_u4s8jVTv',
176
+ audioId_labelId: 'audioId_3_0_u4s8jyiK'
177
+ }, {
178
+ id: 1,
179
+ right: false,
180
+ feedback: 'fasdfasdfg',
181
+ text: 'No',
182
+ rewards: [],
183
+ audioId: '',
184
+ text_labelId: 'text_3_1_u4s8jzBF',
185
+ feedback_labelId: 'feedback_3_1_u4s8jWNa',
186
+ audioId_labelId: 'audioId_3_1_u4s8jaJY'
187
+ }, {
188
+ id: 2,
189
+ right: true,
190
+ feedback: 'asdfasd',
191
+ text: 'Patata',
192
+ rewards: [],
193
+ audioId: '',
194
+ text_labelId: 'text_3_2_u4s8jA2Z',
195
+ feedback_labelId: 'feedback_3_2_u4s8jBIJ',
196
+ audioId_labelId: 'audioId_3_2_u4s8j23g'
197
+ }],
198
+ required: true,
199
+ question: 'Funciona la decisión',
200
+ question_labelId: 'question_3_u4s8i10a'
201
+ },
202
+ decision: true
203
+ }, {
204
+ id: 'line4',
205
+ flex: true,
206
+ type: 'conversationalPhrase',
207
+ slots: [{
208
+ emotion: 'angry',
209
+ text: '',
210
+ uid: 'DbKslR',
211
+ talking: false,
212
+ alias: 'paco',
213
+ text_labelId: 'text_0_0_nlrZh8Np',
214
+ alias_labelId: 'alias_0_0_nlrZh2Iq'
215
+ }, {
216
+ emotion: 'neutral',
217
+ text: '',
218
+ uid: null,
219
+ talking: false,
220
+ text_labelId: 'text_0_1_nlrZiNfB',
221
+ alias_labelId: 'alias_0_1_nlrZijhw'
222
+ }, {
223
+ emotion: 'neutral',
224
+ text: '',
225
+ uid: null,
226
+ talking: false,
227
+ text_labelId: 'text_0_2_nlrZiBF3',
228
+ alias_labelId: 'alias_0_2_nlrZiR6G'
229
+ }, {
230
+ emotion: 'neutral',
231
+ text: '',
232
+ uid: null,
233
+ talking: false,
234
+ text_labelId: 'text_0_3_nlrZinJN',
235
+ alias_labelId: 'alias_0_3_nlrZjLWB'
236
+ }, {
237
+ emotion: 'neutral',
238
+ text: 'Hola!',
239
+ uid: 'kjTHqi',
240
+ talking: true,
241
+ alias: 'manolo',
242
+ text_labelId: 'text_0_4_nlrZjUV9',
243
+ alias_labelId: 'alias_0_4_nlrZj81d'
244
+ }],
245
+ audioId: '5f1078861d84860011e179d0',
246
+ hasAlias: true,
247
+ text_labelId: 'text_0_nlrZj4Nr',
248
+ audioId_labelId: 'audioId_0_nlrZkkdo'
249
+ }, {
250
+ id: 'line5',
251
+ type: 'conversationalNarration',
252
+ name: 'Narrador',
253
+ text: 'Probando el voice over',
254
+ audioId: '',
255
+ voiceOver: true,
256
+ text_labelId: 'text_2_nylZEurm',
257
+ audioId_labelId: 'audioId_2_nylZECnV'
258
+ }],
259
+ background: {
260
+ imgId: '605369a5901f3e00123b81ca',
261
+ imgName: 'b27bb40dcb1189d14012131a35b48a36.jpeg',
262
+ img: {
263
+ url: 'https://min.int.gamelearn.io/cooked.gl-lms-storage/clients/58dccfba26561500117caf53/image/605369a5901f3e00123b81ca/b27bb40dcb1189d14012131a35b48a36.jpeg'
264
+ }
265
+ },
266
+ characters: [{
267
+ name: 'Testing',
268
+ resourceId: '5f68d7b6a373890011a78a11',
269
+ resource: {
270
+ url: 'https://min.int.gamelearn.io/cooked.gl-lms-storage/clients/5981fca94d82290bcbe957fe/object/5eff09c2085be00011aae087/pr0238_yacht_001.glb'
271
+ },
272
+ type: 'object',
273
+ uid: 'DbKslR'
274
+ }, {
275
+ name: 'Male senior dark-skinned 01',
276
+ resourceId: '5f5214cec39e26001123797f',
277
+ resource: {
278
+ url: 'https://min.int.gamelearn.io/cooked.gl-lms-storage/clients/5981fca94d82290bcbe957fe/character/5f5214cec39e26001123797f/ch0112_philip_001.glb',
279
+ animations: animations
280
+ },
281
+ type: 'character',
282
+ uid: 'kjTHqi'
283
+ }, {
284
+ name: 'Female senior light-skinned 01',
285
+ resourceId: '5f5214cec39e26001123797f',
286
+ resource: {
287
+ url: 'https://min.int.gamelearn.io/cooked.gl-lms-storage/clients/5981fca94d82290bcbe957fe/character/5f60759328beb100113b694c/ch0116_bima_001_rig_v01_llaveronuevo.glb',
288
+ animations: {
289
+ neutral: {
290
+ resource: {}
291
+ }
292
+ }
293
+ },
294
+ type: 'character',
295
+ uid: 'kjTHqt'
296
+ }, {
297
+ name: 'Taxi',
298
+ resourceId: '5f5214cec39e26001123797f',
299
+ resource: {
300
+ url: 'https://min.int.gamelearn.io/cooked.gl-lms-storage/clients/5981fca94d82290bcbe957fe/object/5e53b649ef1f60000fb9cc1c/draco_pr0065_car_004.glb'
301
+ },
302
+ type: 'object',
303
+ uid: 'kjTHqx'
304
+ }],
305
+ edges: [{
306
+ id: '1',
307
+ fromId: 'line1',
308
+ toId: 'line3'
309
+ }, {
310
+ id: '2',
311
+ fromId: 'line3',
312
+ toId: 'line2'
313
+ }]
314
+ };
315
+ exports.branchedConver = branchedConver;
22
316
  var converOld = {
23
317
  emitEvent: _mocker.emitEvent,
24
318
  soundActions: _mocker.soundActions,
@@ -55,7 +55,9 @@ var DecisionComponent = function DecisionComponent(_ref) {
55
55
  inheritProps = _props$inheritProps === void 0 ? {} : _props$inheritProps,
56
56
  required = props.required,
57
57
  question = props.question,
58
- _onFinish = props.onFinish;
58
+ _onFinish = props.onFinish,
59
+ branched = props.branched,
60
+ simplifiedOptions = props.simplifiedOptions;
59
61
  var inherited = Object.keys(inheritProps).length > 0;
60
62
 
61
63
  var _useState = (0, _react.useState)('options'),
@@ -104,6 +106,7 @@ var DecisionComponent = function DecisionComponent(_ref) {
104
106
  selectedView: selectedView,
105
107
  emitEvent: emitEvent,
106
108
  inherited: inherited,
109
+ branched: branched,
107
110
  soundActions: soundActions,
108
111
  showingResults: selectedView === 'results',
109
112
  currentSelectedChoice: resultChoice,
@@ -136,24 +139,36 @@ var DecisionComponent = function DecisionComponent(_ref) {
136
139
 
137
140
  if (!failed && selectedView === 'results') {
138
141
  if (inherited) {
139
- emitEvent({
140
- type: 'addPoints',
141
- payload: choice.rewards,
142
- finish: true,
143
- complex: true,
144
- onFinish: function onFinish() {
145
- if (_onFinish) {
146
- _onFinish();
147
- } else {
148
- emitEvent({
149
- type: 'success'
150
- });
151
- }
152
-
153
- setResultChoice({});
154
- selectView('options');
142
+ if (simplifiedOptions) {
143
+ if (_onFinish) {
144
+ _onFinish(choice, function () {
145
+ setResultChoice({});
146
+ selectView('options');
147
+ });
155
148
  }
156
- });
149
+ } else {
150
+ emitEvent({
151
+ type: 'addPoints',
152
+ payload: choice.rewards,
153
+ finish: true,
154
+ complex: true,
155
+ onFinish: function onFinish() {
156
+ if (_onFinish) {
157
+ _onFinish(choice, function () {
158
+ setResultChoice({});
159
+ selectView('options');
160
+ });
161
+ } else {
162
+ emitEvent({
163
+ type: 'success'
164
+ });
165
+ }
166
+
167
+ setResultChoice({});
168
+ selectView('options');
169
+ }
170
+ });
171
+ }
157
172
  } else {
158
173
  emitEvent({
159
174
  type: 'addPoints',
@@ -163,32 +178,46 @@ var DecisionComponent = function DecisionComponent(_ref) {
163
178
  });
164
179
  }
165
180
  } else if (Object.keys(choice).length > 0) {
166
- if (choice.right) {
167
- playSound('score');
168
- } else {
169
- playSound('fail');
170
-
171
- if (inherited) {
172
- emitEvent({
173
- type: 'addPoints',
174
- payload: choice.rewards,
175
- finish: false,
176
- complex: true
177
- });
178
- } else if (!required) {
179
- emitEvent({
180
- type: 'addPoints',
181
- payload: choice.rewards,
182
- finish: true,
183
- complex: true,
184
- onFinish: _onFinish
185
- });
181
+ if (!simplifiedOptions) {
182
+ if (choice.right) {
183
+ playSound('score');
184
+ } else {
185
+ playSound('fail');
186
+
187
+ if (!branched) {
188
+ if (inherited) {
189
+ emitEvent({
190
+ type: 'addPoints',
191
+ payload: choice.rewards,
192
+ finish: false,
193
+ complex: true
194
+ });
195
+ } else if (!required) {
196
+ emitEvent({
197
+ type: 'addPoints',
198
+ payload: choice.rewards,
199
+ finish: true,
200
+ complex: true,
201
+ onFinish: _onFinish ? function () {
202
+ return _onFinish(choice, function () {
203
+ setResultChoice({});
204
+ selectView('options');
205
+ });
206
+ } : null
207
+ });
208
+ }
209
+ }
186
210
  }
187
- }
188
211
 
189
- setResultChoice(choice);
190
- playCurrentAudio(choice);
191
- selectView('results');
212
+ setResultChoice(choice);
213
+ playCurrentAudio(choice);
214
+ selectView('results');
215
+ } else {
216
+ _onFinish(choice, function () {
217
+ setResultChoice({});
218
+ selectView('options');
219
+ });
220
+ }
192
221
  }
193
222
  },
194
223
  // onExit: () => {
@@ -67,6 +67,7 @@ var DialogComponent = function DialogComponent(_ref) {
67
67
  var emitEvent = _ref.emitEvent,
68
68
  lines = _ref.lines,
69
69
  actors = _ref.actors,
70
+ edges = _ref.edges,
70
71
  soundActions = _ref.soundActions,
71
72
  zoomInActor = _ref.zoomInActor,
72
73
  autoPlay = _ref.autoPlay;
@@ -123,12 +124,17 @@ var DialogComponent = function DialogComponent(_ref) {
123
124
  var currentLine = lines[line];
124
125
  var lastLine = lines[line - 1];
125
126
  var lastSet = (0, _react.useRef)(false);
127
+ var isBranched = !!edges;
128
+ var voiceOver = currentLine.voiceOver,
129
+ decision = currentLine.decision;
126
130
  var translate = (0, _react.useCallback)(function (id) {
127
131
  return emitEvent({
128
132
  type: 'translate',
129
133
  payload: id
130
134
  });
131
135
  }, [emitEvent]);
136
+ var isVoiceOver = voiceOver || currentLine.type === 'conversationalNarration';
137
+ var isDecision = decision || currentLine.type === 'conversationalDecision';
132
138
  var getVoice = (0, _react.useCallback)(function (_ref2) {
133
139
  var id = _ref2.id,
134
140
  _ref2$type = _ref2.type,
@@ -268,34 +274,88 @@ var DialogComponent = function DialogComponent(_ref) {
268
274
  messagePosition.current.parent = null;
269
275
  if (zoomInActor) animationStart.current = true;
270
276
  }, [zoomInActor]);
277
+ var finishConversation = (0, _react.useCallback)(function () {
278
+ resetAnims();
279
+ lastSet.current = true;
280
+ setCurrentMessage({});
281
+ resetCameraView();
282
+ setTimeout(function () {
283
+ emitEvent({
284
+ type: 'success'
285
+ });
286
+ camera.copy(defaultCamera.current);
287
+ });
288
+ }, [camera, emitEvent, resetAnims, resetCameraView]);
289
+ var handleBranchDirection = (0, _react.useCallback)(function () {
290
+ var forward = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
291
+ var keys = forward ? ['fromId', 'toId'] : ['toId', 'fromId'];
292
+ var foundEdge = edges.find(function (edge) {
293
+ return edge[keys[0]] === currentLine.id;
294
+ });
295
+
296
+ if (!(foundEdge !== null && foundEdge !== void 0 && foundEdge[keys[0]])) {
297
+ finishConversation();
298
+ } else {
299
+ var destination = lines.findIndex(function (l) {
300
+ return l.id === foundEdge[keys[1]];
301
+ });
302
+
303
+ if (destination >= 0) {
304
+ setCurrentMessage({});
305
+ changeLine(destination);
306
+ } else {
307
+ finishConversation();
308
+ }
309
+ }
310
+ }, [currentLine.id, edges, finishConversation, lines]);
271
311
  var backLine = (0, _react.useCallback)(function () {
272
- if (lastLine && !lastLine.decision) {
312
+ if (isBranched) {
313
+ handleBranchDirection(false);
314
+ } else if (lastLine && !(lastLine !== null && lastLine !== void 0 && lastLine.decision) || lastLine.type && !lastLine.type !== 'conversationalDecision') {
273
315
  setCurrentMessage({});
274
316
  changeLine(line - 1);
275
317
  }
276
- }, [lastLine, line]);
277
- var nextLine = (0, _react.useCallback)(function () {
278
- if (line < lines.length - 1) {
318
+ }, [handleBranchDirection, isBranched, lastLine, line]);
319
+ var handleDecisionBranch = (0, _react.useCallback)(function (choice, reset) {
320
+ var currentId = [3, 2, 1][choice.id];
321
+ var optionsEdges = edges.filter(function (edge) {
322
+ return edge.fromId === currentLine.id;
323
+ });
324
+ var currentEdge = optionsEdges.find(function (edge) {
325
+ return parseInt(edge.fromPointIndex) === currentId;
326
+ });
327
+ var destinationEdge = lines.findIndex(function (l) {
328
+ return l.id === currentEdge.toId;
329
+ });
330
+
331
+ if (currentEdge.fromId === currentEdge.toId) {
332
+ reset();
333
+ } else if (destinationEdge >= 0) {
279
334
  setCurrentMessage({});
280
- changeLine(line + 1);
335
+ changeLine(destinationEdge);
281
336
  } else {
282
- resetAnims();
283
- lastSet.current = true;
337
+ finishConversation();
338
+ }
339
+ }, [currentLine.id, edges, finishConversation, lines]);
340
+ var nextLine = (0, _react.useCallback)(function (choice, reset) {
341
+ if (isBranched) {
342
+ if (choice) {
343
+ handleDecisionBranch(choice, reset);
344
+ } else {
345
+ handleBranchDirection();
346
+ }
347
+ } else if (line < lines.length - 1) {
284
348
  setCurrentMessage({});
285
- resetCameraView();
286
- setTimeout(function () {
287
- emitEvent({
288
- type: 'success'
289
- });
290
- camera.copy(defaultCamera.current);
291
- }, currentLine.decision ? 0 : 1200);
349
+ changeLine(line + 1);
350
+ } else {
351
+ finishConversation();
292
352
  }
293
- }, [camera, currentLine === null || currentLine === void 0 ? void 0 : currentLine.decision, emitEvent, line, lines.length, resetAnims, resetCameraView]); // Position bubble over talking character/and switch emotions
353
+ }, [isBranched, line, lines.length, handleDecisionBranch, handleBranchDirection, finishConversation]); // Position bubble over talking character/and switch emotions
294
354
 
295
355
  (0, _react.useEffect)(function () {
296
- if (currentLine.decision) {
356
+ if (isDecision) {
297
357
  resetCameraView();
298
- } else if (currentLine.voiceOver) {
358
+ } else if (isVoiceOver) {
299
359
  resetCameraView();
300
360
  setCurrentMessage({
301
361
  text: currentLine.text,
@@ -402,7 +462,7 @@ var DialogComponent = function DialogComponent(_ref) {
402
462
  });
403
463
  }
404
464
  }
405
- }, [actors, camera, currentLine, zoomInActor, getCurrentVisible, translate, getAvatarURL, loadEmotion, resetCameraView]); // Sound logic
465
+ }, [actors, camera, currentLine, zoomInActor, getCurrentVisible, translate, getAvatarURL, loadEmotion, resetCameraView, isDecision, isVoiceOver]); // Sound logic
406
466
 
407
467
  (0, _react.useEffect)(function () {
408
468
  var _currentLine$audio;
@@ -546,24 +606,25 @@ var DialogComponent = function DialogComponent(_ref) {
546
606
  }
547
607
  }
548
608
  });
549
-
550
- var decisionPayload = _objectSpread(_objectSpread({}, currentLine.payload), {}, {
551
- inheritProps: {
552
- slots: [],
553
- disableBackground: true
554
- },
555
- onFinish: nextLine,
556
- emitEvent: emitEvent,
557
- soundActions: soundActions
558
- });
559
-
560
609
  var cleanStyle = {
561
610
  width: '100vw',
562
611
  height: '100vh',
563
612
  position: 'static'
564
613
  };
565
614
 
566
- if (currentLine.decision) {
615
+ if (isDecision) {
616
+ var decisionPayload = _objectSpread(_objectSpread({}, currentLine.payload), {}, {
617
+ inheritProps: {
618
+ slots: [],
619
+ disableBackground: true
620
+ },
621
+ required: !isBranched,
622
+ branched: isBranched,
623
+ onFinish: nextLine,
624
+ emitEvent: emitEvent,
625
+ soundActions: soundActions
626
+ });
627
+
567
628
  return /*#__PURE__*/_react.default.createElement(_arcadeThreeCore.HtmlPro, {
568
629
  zIndexRange: [3, 3],
569
630
  style: cleanStyle,
@@ -602,16 +663,18 @@ var DialogComponent = function DialogComponent(_ref) {
602
663
  }, /*#__PURE__*/_react.default.createElement("div", {
603
664
  className: "dialog-component-controls"
604
665
  }, /*#__PURE__*/_react.default.createElement("button", {
605
- disabled: line <= 0 || (lastLine === null || lastLine === void 0 ? void 0 : lastLine.decision),
666
+ disabled: line <= 0 || (lastLine === null || lastLine === void 0 ? void 0 : lastLine.decision) || isBranched,
606
667
  type: "button",
607
668
  onClick: backLine,
608
- className: "gat--btn__round ".concat(line <= 0 || lastLine !== null && lastLine !== void 0 && lastLine.decision ? 'disabled' : '')
669
+ className: "gat--btn__round ".concat(line <= 0 || lastLine !== null && lastLine !== void 0 && lastLine.decision || isBranched ? 'disabled' : '')
609
670
  }, /*#__PURE__*/_react.default.createElement("span", {
610
671
  className: "icon-back"
611
672
  })), /*#__PURE__*/_react.default.createElement("button", {
612
673
  className: "gat--btn__round",
613
674
  type: "button",
614
- onClick: nextLine
675
+ onClick: function onClick() {
676
+ return nextLine();
677
+ }
615
678
  }, /*#__PURE__*/_react.default.createElement("span", {
616
679
  className: "icon-next"
617
680
  })))) : null);
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.mockScene = exports.mockProps = void 0;
6
+ exports.mockScene = exports.mockProps = exports.branchedMockProps = void 0;
7
7
 
8
8
  var _bg001_street = _interopRequireDefault(require("test/mocks/bg001_street.json"));
9
9
 
@@ -275,6 +275,270 @@ var mockProps = {
275
275
  actors: []
276
276
  };
277
277
  exports.mockProps = mockProps;
278
+ var branchedMockProps = {
279
+ emitEvent: _mocker.emitEvent,
280
+ soundActions: _mocker.soundActions,
281
+ autoPlay: false,
282
+ lines: [{
283
+ id: 'line1',
284
+ flex: true,
285
+ slots: [{
286
+ emotion: '',
287
+ text: '',
288
+ uid: null,
289
+ talking: false,
290
+ alias: 'paco',
291
+ text_labelId: 'text_0_0_nlrZh8Np',
292
+ alias_labelId: 'alias_0_0_nlrZh2Iq'
293
+ }, {
294
+ emotion: 'neutral',
295
+ text: '',
296
+ uid: null,
297
+ talking: false,
298
+ text_labelId: 'text_0_1_nlrZiNfB',
299
+ alias_labelId: 'alias_0_1_nlrZijhw'
300
+ }, {
301
+ emotion: 'neutral',
302
+ text: '',
303
+ uid: null,
304
+ talking: false,
305
+ text_labelId: 'text_0_2_nlrZiBF3',
306
+ alias_labelId: 'alias_0_2_nlrZiR6G'
307
+ }, {
308
+ emotion: 'neutral',
309
+ text: '',
310
+ uid: null,
311
+ talking: false,
312
+ text_labelId: 'text_0_3_nlrZinJN',
313
+ alias_labelId: 'alias_0_3_nlrZjLWB'
314
+ }, {
315
+ emotion: 'neutral',
316
+ text: 'En un lugar de la Mancha, de cuyo nombre no quiero acordarme, no ha mucho tiempo que vivía un hidalgo de los de lanza en astillero, adarga antigua, rocín flaco. En un lugar de la Mancha, de cuyo nombre no quiero acordarme, no ha mucho tiempo que vivía un hidalgo de los de lanza en astillero, adarga an',
317
+ uid: 'snHJhg',
318
+ talking: true,
319
+ character: {
320
+ resource: {
321
+ animations: animations
322
+ }
323
+ },
324
+ alias: 'Manolo',
325
+ text_labelId: 'text_0_4_nlrZjUV9',
326
+ alias_labelId: 'alias_0_4_nlrZj81d'
327
+ }],
328
+ audioId: '5f1078861d84860011e179d0',
329
+ hasAlias: true,
330
+ text_labelId: 'text_0_nlrZj4Nr',
331
+ audioId_labelId: 'audioId_0_nlrZkkdo'
332
+ }, {
333
+ id: 'line2',
334
+ flex: true,
335
+ slots: [{
336
+ emotion: '',
337
+ text: '',
338
+ uid: null,
339
+ talking: false,
340
+ alias: 'paco',
341
+ text_labelId: 'text_0_0_nlrZh8Np',
342
+ alias_labelId: 'alias_0_0_nlrZh2Iq'
343
+ }, {
344
+ emotion: 'neutral',
345
+ text: '',
346
+ uid: null,
347
+ talking: false,
348
+ text_labelId: 'text_0_1_nlrZiNfB',
349
+ alias_labelId: 'alias_0_1_nlrZijhw'
350
+ }, {
351
+ emotion: 'neutral',
352
+ text: '',
353
+ uid: null,
354
+ talking: false,
355
+ text_labelId: 'text_0_2_nlrZiBF3',
356
+ alias_labelId: 'alias_0_2_nlrZiR6G'
357
+ }, {
358
+ emotion: 'neutral',
359
+ text: '',
360
+ uid: null,
361
+ talking: false,
362
+ text_labelId: 'text_0_3_nlrZinJN',
363
+ alias_labelId: 'alias_0_3_nlrZjLWB'
364
+ }, {
365
+ emotion: 'neutral',
366
+ text: 'Hola!',
367
+ character: {
368
+ resource: {
369
+ animations: animations
370
+ }
371
+ },
372
+ uid: 'jLKRKJ',
373
+ talking: true,
374
+ alias: 'Manolo',
375
+ text_labelId: 'text_0_4_nlrZjUV9',
376
+ alias_labelId: 'alias_0_4_nlrZj81d'
377
+ }],
378
+ audioId: '5f1078861d84860011e179d0',
379
+ hasAlias: true,
380
+ text_labelId: 'text_0_nlrZj4Nr',
381
+ audioId_labelId: 'audioId_0_nlrZkkdo'
382
+ }, {
383
+ id: 'line3',
384
+ flex: true,
385
+ slots: [{
386
+ emotion: '',
387
+ text: '',
388
+ uid: null,
389
+ talking: false,
390
+ alias: 'paco',
391
+ text_labelId: 'text_0_0_nlrZh8Np',
392
+ alias_labelId: 'alias_0_0_nlrZh2Iq'
393
+ }, {
394
+ emotion: 'neutral',
395
+ text: '',
396
+ uid: null,
397
+ talking: false,
398
+ text_labelId: 'text_0_1_nlrZiNfB',
399
+ alias_labelId: 'alias_0_1_nlrZijhw'
400
+ }, {
401
+ emotion: 'neutral',
402
+ text: '',
403
+ uid: null,
404
+ talking: false,
405
+ text_labelId: 'text_0_2_nlrZiBF3',
406
+ alias_labelId: 'alias_0_2_nlrZiR6G'
407
+ }, {
408
+ emotion: 'neutral',
409
+ text: '',
410
+ uid: null,
411
+ talking: false,
412
+ text_labelId: 'text_0_3_nlrZinJN',
413
+ alias_labelId: 'alias_0_3_nlrZjLWB'
414
+ }, {
415
+ emotion: 'neutral',
416
+ text: 'Hola!',
417
+ uid: 'snHJhg',
418
+ character: {
419
+ resource: {
420
+ animations: animations
421
+ }
422
+ },
423
+ talking: true,
424
+ alias: 'Manolo',
425
+ text_labelId: 'text_0_4_nlrZjUV9',
426
+ alias_labelId: 'alias_0_4_nlrZj81d'
427
+ }],
428
+ audioId: '5f1078861d84860011e179d0',
429
+ hasAlias: true,
430
+ text_labelId: 'text_0_nlrZj4Nr',
431
+ audioId_labelId: 'audioId_0_nlrZkkdo'
432
+ }, {
433
+ id: 'line4',
434
+ payload: {
435
+ options: [{
436
+ id: 0,
437
+ right: false,
438
+ feedback: 'dfgsdfgsdfgsdfghdfgh',
439
+ text: 'Si',
440
+ rewards: [],
441
+ audioId: '',
442
+ text_labelId: 'text_3_0_u4s8j5fa',
443
+ feedback_labelId: 'feedback_3_0_u4s8jVTv',
444
+ audioId_labelId: 'audioId_3_0_u4s8jyiK'
445
+ }, {
446
+ id: 1,
447
+ right: false,
448
+ feedback: 'fasdfasdfg',
449
+ text: 'No',
450
+ rewards: [],
451
+ audioId: '',
452
+ text_labelId: 'text_3_1_u4s8jzBF',
453
+ feedback_labelId: 'feedback_3_1_u4s8jWNa',
454
+ audioId_labelId: 'audioId_3_1_u4s8jaJY'
455
+ }, {
456
+ id: 2,
457
+ right: true,
458
+ feedback: 'asdfasd',
459
+ text: 'Patata',
460
+ rewards: [],
461
+ audioId: '',
462
+ text_labelId: 'text_3_2_u4s8jA2Z',
463
+ feedback_labelId: 'feedback_3_2_u4s8jBIJ',
464
+ audioId_labelId: 'audioId_3_2_u4s8j23g'
465
+ }],
466
+ required: true,
467
+ question: 'Funciona la decisión',
468
+ question_labelId: 'question_3_u4s8i10a'
469
+ },
470
+ decision: true
471
+ }, {
472
+ id: 'line5',
473
+ flex: true,
474
+ slots: [{
475
+ emotion: 'angry',
476
+ text: '',
477
+ uid: null,
478
+ talking: false,
479
+ alias: 'paco',
480
+ text_labelId: 'text_0_0_nlrZh8Np',
481
+ alias_labelId: 'alias_0_0_nlrZh2Iq'
482
+ }, {
483
+ emotion: 'neutral',
484
+ text: '',
485
+ uid: null,
486
+ talking: false,
487
+ text_labelId: 'text_0_1_nlrZiNfB',
488
+ alias_labelId: 'alias_0_1_nlrZijhw'
489
+ }, {
490
+ emotion: 'neutral',
491
+ text: '',
492
+ uid: null,
493
+ talking: false,
494
+ text_labelId: 'text_0_2_nlrZiBF3',
495
+ alias_labelId: 'alias_0_2_nlrZiR6G'
496
+ }, {
497
+ emotion: 'neutral',
498
+ text: '',
499
+ uid: null,
500
+ talking: false,
501
+ text_labelId: 'text_0_3_nlrZinJN',
502
+ alias_labelId: 'alias_0_3_nlrZjLWB'
503
+ }, {
504
+ emotion: 'neutral',
505
+ text: 'Hola!',
506
+ uid: 'snHJhg',
507
+ talking: true,
508
+ character: {
509
+ resource: {
510
+ animations: animations
511
+ }
512
+ },
513
+ alias: 'Manolo',
514
+ text_labelId: 'text_0_4_nlrZjUV9',
515
+ alias_labelId: 'alias_0_4_nlrZj81d'
516
+ }],
517
+ audioId: '5f1078861d84860011e179d0',
518
+ hasAlias: true,
519
+ text_labelId: 'text_0_nlrZj4Nr',
520
+ audioId_labelId: 'audioId_0_nlrZkkdo'
521
+ }],
522
+ background: {
523
+ imgId: '605369a5901f3e00123b81ca',
524
+ imgName: 'b27bb40dcb1189d14012131a35b48a36.jpeg',
525
+ img: {
526
+ url: 'https://min.int.gamelearn.io/cooked.gl-lms-storage/clients/58dccfba26561500117caf53/image/605369a5901f3e00123b81ca/b27bb40dcb1189d14012131a35b48a36.jpeg'
527
+ }
528
+ },
529
+ characters: [],
530
+ actors: [],
531
+ edges: [{
532
+ id: '1',
533
+ fromId: 'line1',
534
+ toId: 'line3'
535
+ }, {
536
+ id: '2',
537
+ fromId: 'line3',
538
+ toId: 'line2'
539
+ }]
540
+ };
541
+ exports.branchedMockProps = branchedMockProps;
278
542
  var mockScene = {
279
543
  background: _bg001_street.default,
280
544
  elements: _characters.elements,
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.4.11",
5
+ "version": "1.4.12",
6
6
  "main": "dist/index.js",
7
7
  "files": [
8
8
  "dist",