@gamelearn/arcade-components 0.21.11 → 0.22.1

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.
@@ -37,15 +37,19 @@ var AnimateElement = function AnimateElement(_ref) {
37
37
 
38
38
  var _useAnimations = (0, _drei.useAnimations)(animations),
39
39
  ref = _useAnimations.ref,
40
- mixer = _useAnimations.mixer,
41
- actions = _useAnimations.actions;
40
+ mixer = _useAnimations.mixer;
42
41
 
43
42
  (0, _react.useEffect)(function () {
44
- var _Object$values;
45
-
46
- mixer.stopAllAction();
47
- (_Object$values = Object.values(actions)) === null || _Object$values === void 0 ? void 0 : _Object$values[0].play();
48
- }, [actions, model, mixer]);
43
+ if (ref.current) {
44
+ mixer.stopAllAction();
45
+ var clip = animations[0];
46
+
47
+ if (clip) {
48
+ var action = mixer.clipAction(clip, ref.current);
49
+ action.play();
50
+ }
51
+ }
52
+ }, [mixer, ref, animations]);
49
53
  return /*#__PURE__*/_react.default.createElement("primitive", _extends({
50
54
  ref: ref,
51
55
  object: model,
@@ -21,8 +21,6 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
21
21
 
22
22
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
23
 
24
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
25
-
26
24
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
27
25
 
28
26
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@@ -47,6 +45,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
47
45
  var emitEvent = _ref.emitEvent,
48
46
  lines = _ref.lines,
49
47
  characters = _ref.characters,
48
+ actors = _ref.actors,
50
49
  background = _ref.background,
51
50
  soundActions = _ref.soundActions,
52
51
  lodSettings = _ref.lodSettings;
@@ -92,6 +91,32 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
92
91
  return line.slots;
93
92
  });
94
93
  var lastLine = lines[currentLine - 1] ? lines[currentLine - 1] : {};
94
+ var hasCharacters = !currentLineData.decision && currentLineData.slots.filter(function (slot) {
95
+ return slot.uid;
96
+ }).length;
97
+ var currentSlots = [];
98
+
99
+ if (currentLineData.slots) {
100
+ currentSlots = currentLineData.slots;
101
+ } else if (leftWithSlots) {
102
+ currentSlots = leftWithSlots.slots;
103
+ }
104
+
105
+ var currentCharacters = currentSlots.filter(function (slot) {
106
+ return slot.uid;
107
+ }).map(function (slot) {
108
+ var character = (characters || actors || []).find(function (c) {
109
+ return c.uid === slot.uid;
110
+ });
111
+
112
+ if (character) {
113
+ slot.resource = character.resource;
114
+ slot.type = character.type;
115
+ }
116
+
117
+ if (!slot.resource) slot.resource = {};
118
+ return slot;
119
+ });
95
120
 
96
121
  if (voiceOver) {
97
122
  var rightWithSlots = lines.slice(currentLine).find(function (line) {
@@ -103,14 +128,14 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
103
128
  voiceOverSlots = lineWithSlots.slots;
104
129
  isFlex = lineWithSlots.flex;
105
130
  }
106
- } else if (!decision) {
131
+ } else if (!decision && hasCharacters) {
107
132
  currentLineData.slots.forEach(function (slot) {
108
- var indx = characters.findIndex(function (char) {
133
+ var indx = currentCharacters.findIndex(function (char) {
109
134
  return char.uid === slot.uid;
110
135
  });
111
136
 
112
137
  if (indx >= 0) {
113
- characters[indx].emotion = slot.emotion;
138
+ currentCharacters[indx].emotion = slot.emotion;
114
139
  }
115
140
  });
116
141
 
@@ -118,10 +143,10 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
118
143
  var notFlexedPosition = currentLineData.slots.findIndex(function (char) {
119
144
  return char.uid === currentMessage.uid;
120
145
  });
121
- var flexedPosition = characters.findIndex(function (char) {
146
+ var flexedPosition = currentCharacters.findIndex(function (char) {
122
147
  return char.uid === currentMessage.uid;
123
148
  });
124
- characters.forEach(function (c) {
149
+ currentCharacters.forEach(function (c) {
125
150
  if (c.uid === currentMessage.uid) c.name = currentMessage.alias;
126
151
  });
127
152
  currentMessage.position = isFlex ? flexedPosition : notFlexedPosition;
@@ -129,7 +154,9 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
129
154
  }
130
155
 
131
156
  var listProps = {
132
- characters: characters,
157
+ characters: currentCharacters,
158
+ lodSettings: lodSettings,
159
+ actors: actors,
133
160
  currentMessage: currentMessage || {},
134
161
  slots: !voiceOver ? currentLineData.slots : voiceOverSlots,
135
162
  flex: isFlex
@@ -171,7 +198,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
171
198
  emitEvent: emitEvent,
172
199
  soundActions: soundActions,
173
200
  inheritProps: {
174
- characters: characters,
201
+ characters: currentCharacters,
175
202
  background: background,
176
203
  flex: leftWithSlots ? leftWithSlots.flex : true,
177
204
  slots: !leftWithSlots ? [] : leftWithSlots.slots
@@ -189,10 +216,7 @@ var ConversationProViewer = function ConversationProViewer(_ref) {
189
216
  style: backgroundImage ? {
190
217
  backgroundImage: "url(\"".concat(backgroundImage, "\")")
191
218
  } : {}
192
- }, /*#__PURE__*/_react.default.createElement(_SlotList.default, _extends({}, listProps, {
193
- characters: characters,
194
- lodSettings: lodSettings
195
- })), /*#__PURE__*/_react.default.createElement("div", {
219
+ }, /*#__PURE__*/_react.default.createElement(_SlotList.default, listProps), /*#__PURE__*/_react.default.createElement("div", {
196
220
  className: "conversation--body"
197
221
  }, currentMessage ? /*#__PURE__*/_react.default.createElement(_Message.default, {
198
222
  current: currentMessage,
@@ -7,8 +7,6 @@ exports.default = void 0;
7
7
 
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
 
10
- var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
10
  var _Slot = _interopRequireDefault(require("./Slot"));
13
11
 
14
12
  var _scene = _interopRequireDefault(require("./scene"));
@@ -19,6 +17,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
19
17
 
20
18
  var SlotList = function SlotList(_ref) {
21
19
  var characters = _ref.characters,
20
+ actors = _ref.actors,
22
21
  lodSettings = _ref.lodSettings,
23
22
  currentMessage = _ref.currentMessage,
24
23
  flex = _ref.flex,
@@ -37,6 +36,33 @@ var SlotList = function SlotList(_ref) {
37
36
  };
38
37
  };
39
38
 
39
+ var gameChars = slots.reduce(function (acc, current) {
40
+ var actor = actors === null || actors === void 0 ? void 0 : actors.find(function (a) {
41
+ return a.uid === current.uid;
42
+ });
43
+ var char = Object.assign({}, current);
44
+
45
+ if (current.character) {
46
+ char.name = current.alias || current.character.name;
47
+ char.resource = char.character.resource;
48
+ delete char.character;
49
+ char.type = 'character';
50
+ acc.push(char);
51
+ } else if (actor) {
52
+ var resource = actor.resource;
53
+ char.name = current.alias || current.name;
54
+ char.resource = resource;
55
+ char.type = actor.type;
56
+ acc.push(char);
57
+ } else if (!flex) {
58
+ acc.push(null);
59
+ }
60
+
61
+ return acc;
62
+ }, []);
63
+ var hasGameChars = gameChars.length && gameChars.some(function (c) {
64
+ return c;
65
+ });
40
66
  var currentChars = characters.filter(function (c) {
41
67
  return slots.find(function (s) {
42
68
  return c.uid === s.uid;
@@ -44,6 +70,25 @@ var SlotList = function SlotList(_ref) {
44
70
  });
45
71
 
46
72
  var Slots = function Slots() {
73
+ if (hasGameChars) {
74
+ return gameChars.map(function (character, index) {
75
+ if (!character) {
76
+ return /*#__PURE__*/_react.default.createElement("div", {
77
+ key: "void_".concat(index),
78
+ className: "conversation--character__item void ".concat(index)
79
+ });
80
+ }
81
+
82
+ return /*#__PURE__*/_react.default.createElement(_Slot.default, _extends({
83
+ key: character.uid + index
84
+ }, characterProps({
85
+ character: character,
86
+ active: character.talking,
87
+ slot: index
88
+ })));
89
+ });
90
+ }
91
+
47
92
  if (flex) {
48
93
  return currentChars.map(function (character, index) {
49
94
  var active = currentMessage.position === index;
@@ -57,7 +102,7 @@ var SlotList = function SlotList(_ref) {
57
102
  });
58
103
  }
59
104
 
60
- return slots.length > 0 && characters.length > 0 ? slots.map(function (el, index) {
105
+ return slots.length > 0 ? slots.map(function (el, index) {
61
106
  var character = characters.find(function (char) {
62
107
  return char.uid === el.uid;
63
108
  });
@@ -84,7 +129,7 @@ var SlotList = function SlotList(_ref) {
84
129
  return /*#__PURE__*/_react.default.createElement("div", {
85
130
  className: "conversation--characters"
86
131
  }, /*#__PURE__*/_react.default.createElement(_scene.default, {
87
- characters: currentChars,
132
+ characters: hasGameChars ? gameChars : currentChars,
88
133
  slots: slots,
89
134
  flex: flex,
90
135
  currentMessage: currentMessage,
@@ -92,18 +137,6 @@ var SlotList = function SlotList(_ref) {
92
137
  }), children ? children : /*#__PURE__*/_react.default.createElement(Slots, null));
93
138
  };
94
139
 
95
- SlotList.propTypes = {
96
- characters: _propTypes.default.arrayOf(_propTypes.default.shape({
97
- name: _propTypes.default.string,
98
- url: _propTypes.default.string
99
- })),
100
- currentMessage: _propTypes.default.shape({
101
- emotion: _propTypes.default.string,
102
- position: _propTypes.default.number
103
- }),
104
- flex: _propTypes.default.bool,
105
- slots: _propTypes.default.arrayOf(_propTypes.default.shape({}))
106
- };
107
140
  SlotList.defaultProps = {
108
141
  characters: [],
109
142
  currentMessage: {},
@@ -18,15 +18,15 @@ var Panels = function Panels(_ref) {
18
18
  flex = _ref.flex,
19
19
  lodSettings = _ref.lodSettings;
20
20
  return slots.map(function (slot, slotPosition) {
21
+ var currentCharacter = null;
21
22
  var characterPos = characters.findIndex(function (c) {
22
- return c.uid === slot.uid;
23
+ return c && c.uid === slot.uid;
23
24
  });
24
25
 
25
26
  if (characterPos >= 0) {
26
27
  var currentPosition = !flex ? slotPosition : characterPos;
27
- var currentCharacter = Object.assign({}, characters[characterPos]);
28
- currentCharacter.index = characterPos;
29
- currentCharacter.slot = slotPosition;
28
+ currentCharacter = Object.assign({}, characters[characterPos]);
29
+ currentCharacter.slot = currentPosition;
30
30
  return /*#__PURE__*/_react.default.createElement(_Panel.default, {
31
31
  key: "".concat(currentCharacter.uid, "_").concat(slotPosition, "_").concat(characterPos),
32
32
  character: currentCharacter,
@@ -60,6 +60,7 @@ var WriterPuzzleComponent = function WriterPuzzleComponent(_ref) {
60
60
  skip = _ref.skip,
61
61
  type = _ref.type,
62
62
  documentTitle = _ref.documentTitle,
63
+ documentTitle_labelId = _ref.documentTitle_labelId,
63
64
  texts = _ref.texts,
64
65
  soundActions = _ref.soundActions;
65
66
 
@@ -163,20 +164,20 @@ var WriterPuzzleComponent = function WriterPuzzleComponent(_ref) {
163
164
  var currentDecision = decisionsList.filter(function (obj) {
164
165
  return obj.currenTextParagraph === indexOfText;
165
166
  });
166
- return currentDecision[0].fullText;
167
+ return currentDecision[0].fullText_labelId;
167
168
  };
168
169
 
169
170
  var createLecture = function createLecture() {
170
171
  return texts.map(function (element, indexOfText) {
171
172
  if (element.type === 'fixed') {
172
- if (element.fullText) {
173
- return element.fullText;
174
- }
173
+ var _element$fullText_lab;
174
+
175
+ return (_element$fullText_lab = element.fullText_labelId) !== null && _element$fullText_lab !== void 0 ? _element$fullText_lab : element.fullText;
175
176
  } else if (element.type === 'election') {
176
- var correctElection = getCorrectElection(element);
177
+ var correctElection = getCorrectElection(element); // 0,1,2 or undefined
177
178
 
178
- if (correctElection) {
179
- return element.electionTexts[correctElection].fullText;
179
+ if (correctElection >= 0) {
180
+ return element.electionTexts[correctElection].fullText_labelId;
180
181
  } // If there is no correct Election then it should pick the election of student
181
182
 
182
183
 
@@ -237,11 +238,12 @@ var WriterPuzzleComponent = function WriterPuzzleComponent(_ref) {
237
238
  var handleLectures = function handleLectures() {
238
239
  var text = createLecture();
239
240
  emitEvent({
240
- type: 'finishLecture',
241
+ type: 'finishMedia',
241
242
  payload: {
242
- name: documentTitle,
243
+ name: documentTitle_labelId,
243
244
  text: text,
244
- documentType: type
245
+ documentType: type,
246
+ type: 'text'
245
247
  }
246
248
  });
247
249
  };
@@ -291,18 +293,16 @@ var WriterPuzzleComponent = function WriterPuzzleComponent(_ref) {
291
293
  };
292
294
 
293
295
  var handleFinish = function handleFinish() {
294
- if (checkAllDecisionsRightWrong()) {
295
- // if all Decisions are right or wrong we just skip to end
296
- setReviewDone(true);
297
- setFeedbackScreenDone(true);
298
- endGame();
299
- }
300
-
301
296
  if (!checkIfFeedbackNeeded()) {
302
297
  // THis case is for when we do not have any Decision
303
298
  setReviewDone(true);
304
299
  setFeedbackScreen(true);
305
300
  endGame();
301
+ } else if (checkAllDecisionsRightWrong()) {
302
+ // if all Decisions are right or wrong we just skip to end
303
+ setReviewDone(true);
304
+ setFeedbackScreenDone(true);
305
+ endGame();
306
306
  }
307
307
 
308
308
  if (!reviewDone) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gamelearn/arcade-components",
3
3
  "license": "Gamelearn",
4
- "version": "0.21.11",
4
+ "version": "0.22.1",
5
5
  "main": "dist/index.js",
6
6
  "files": [
7
7
  "dist",