@gamelearn/arcade-components 1.4.23 → 1.4.26

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.
@@ -17,14 +17,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
17
17
 
18
18
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
19
19
 
20
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
21
-
22
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
23
-
24
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
25
-
26
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
27
-
28
20
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
29
21
 
30
22
  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."); }
@@ -46,19 +38,21 @@ var Board = function Board(_ref) {
46
38
  feedbackIsShown = _ref.feedbackIsShown,
47
39
  resolvePuzzle = _ref.resolvePuzzle,
48
40
  soundActions = _ref.soundActions,
49
- handleSuccess = _ref.handleSuccess;
41
+ handleSuccess = _ref.handleSuccess,
42
+ setForceFlipCard = _ref.setForceFlipCard,
43
+ forceFlipCard = _ref.forceFlipCard;
50
44
 
51
- var _useState = (0, _react.useState)(_toConsumableArray(Array(cards.length)).fill(false)),
45
+ var _useState = (0, _react.useState)(Array(cards.length).fill(false)),
52
46
  _useState2 = _slicedToArray(_useState, 2),
53
47
  flipped = _useState2[0],
54
48
  setFlipped = _useState2[1];
55
49
 
56
- var _useState3 = (0, _react.useState)(_toConsumableArray(Array(cards.length)).fill(false)),
50
+ var _useState3 = (0, _react.useState)(Array(cards.length).fill(false)),
57
51
  _useState4 = _slicedToArray(_useState3, 2),
58
52
  wrongOrder = _useState4[0],
59
53
  setWrongOrder = _useState4[1];
60
54
 
61
- var _useState5 = (0, _react.useState)(1),
55
+ var _useState5 = (0, _react.useState)(0),
62
56
  _useState6 = _slicedToArray(_useState5, 2),
63
57
  correctCards = _useState6[0],
64
58
  setCorrectCards = _useState6[1];
@@ -72,17 +66,24 @@ var Board = function Board(_ref) {
72
66
  var isOrderBased = cards.filter(function (card) {
73
67
  return card.order;
74
68
  }).length > 0;
69
+ var flipTimer;
70
+ (0, _react.useEffect)(function () {
71
+ if (forceFlipCard) {
72
+ setForceFlipCard(false);
73
+ reset();
74
+ clearTimeout(flipTimer);
75
+ }
76
+ }, [flipTimer, forceFlipCard, reset, setForceFlipCard]);
77
+ var reset = (0, _react.useCallback)(function () {
78
+ setFlipped(Array(cards.length).fill(false)); // reset it to the original length
75
79
 
76
- var reset = function reset() {
77
- setFlipped(_toConsumableArray(Array(cards.length)).fill(false)); // reset it to the original length
78
-
79
- setWrongOrder(_toConsumableArray(Array(cards.length)).fill(false));
80
- setCorrectCards(1);
80
+ setWrongOrder(Array(cards.length).fill(false));
81
+ setCorrectCards(0);
81
82
  setCurrentOrder(1);
82
- };
83
+ }, [cards.length, setCurrentOrder]);
83
84
 
84
85
  var timedReset = function timedReset() {
85
- setTimeout(function () {
86
+ flipTimer = setTimeout(function () {
86
87
  reset();
87
88
  }, 3000);
88
89
  };
@@ -113,15 +114,17 @@ var Board = function Board(_ref) {
113
114
  flipAllCorrect();
114
115
  }
115
116
  }, [flipAllCorrect, resolvePuzzle]);
117
+ (0, _react.useEffect)(function () {
118
+ if (correctCards === numberOfCorrectCards) {
119
+ endPuzzle();
120
+ setCorrectCards(0);
121
+ }
122
+ }, [correctCards, endPuzzle, numberOfCorrectCards]);
116
123
 
117
124
  var handleCorrect = function handleCorrect(index) {
118
125
  flipACard(index);
119
126
  handleSuccess(cards[index].id || null);
120
127
  setCorrectCards(correctCards + 1);
121
-
122
- if (correctCards === numberOfCorrectCards) {
123
- endPuzzle();
124
- }
125
128
  };
126
129
 
127
130
  var _handleClick = function handleClick(index) {
@@ -92,6 +92,11 @@ var CardsSelectorPuzzleComponent = function CardsSelectorPuzzleComponent(_ref) {
92
92
  var _soundActions = _slicedToArray(soundActions, 1),
93
93
  playSound = _soundActions[0];
94
94
 
95
+ var _useState17 = (0, _react.useState)(false),
96
+ _useState18 = _slicedToArray(_useState17, 2),
97
+ forceFlipCard = _useState18[0],
98
+ setForceFlipCard = _useState18[1];
99
+
95
100
  var translate = function translate(id) {
96
101
  return emitEvent({
97
102
  type: 'translate',
@@ -115,6 +120,8 @@ var CardsSelectorPuzzleComponent = function CardsSelectorPuzzleComponent(_ref) {
115
120
  }, [emitEvent]);
116
121
 
117
122
  var endPuzzle = function endPuzzle() {
123
+ var _info$solution, _specificFeedbacks$co;
124
+
118
125
  emitEvent({
119
126
  type: 'hidePuzzleButtons',
120
127
  payload: true
@@ -125,33 +132,27 @@ var CardsSelectorPuzzleComponent = function CardsSelectorPuzzleComponent(_ref) {
125
132
  setFeedbackResult(true);
126
133
  setFeedbackIsShown(true);
127
134
  } else {
128
- var _info$solution, _specificFeedbacks$co;
129
-
130
135
  setFeedbackResult(true);
131
136
  setFeedbackIsShown(true);
132
137
  setFinished(true);
138
+ }
133
139
 
134
- var _info$solution$right = info === null || info === void 0 ? void 0 : (_info$solution = info.solution) === null || _info$solution === void 0 ? void 0 : _info$solution.right,
135
- rewards = _info$solution$right.rewards;
140
+ var _info$solution$right = info === null || info === void 0 ? void 0 : (_info$solution = info.solution) === null || _info$solution === void 0 ? void 0 : _info$solution.right,
141
+ rewards = _info$solution$right.rewards;
136
142
 
137
- var specificRewards = (specificFeedbacks === null || specificFeedbacks === void 0 ? void 0 : (_specificFeedbacks$co = specificFeedbacks.correctFeedbacks) === null || _specificFeedbacks$co === void 0 ? void 0 : _specificFeedbacks$co.map(function (spReward) {
138
- return spReward.rewards;
139
- }).flat()) || [];
140
- var rewardsData = [].concat(_toConsumableArray(accRewards), _toConsumableArray(rewards), _toConsumableArray(specificRewards));
141
- setTimeout(function () {
142
- playSound('score');
143
- closeFeedbackAndShowPoints(rewardsData);
144
- }, 3000);
145
- }
143
+ var specificRewards = (specificFeedbacks === null || specificFeedbacks === void 0 ? void 0 : (_specificFeedbacks$co = specificFeedbacks.correctFeedbacks) === null || _specificFeedbacks$co === void 0 ? void 0 : _specificFeedbacks$co.map(function (spReward) {
144
+ return spReward.rewards;
145
+ }).flat()) || [];
146
+ var rewardsData = [].concat(_toConsumableArray(accRewards), _toConsumableArray(rewards), _toConsumableArray(specificRewards));
147
+ setTimeout(function () {
148
+ playSound('score');
149
+ closeFeedbackAndShowPoints(rewardsData);
150
+ }, 3000);
146
151
  };
147
152
 
148
153
  var handleFeedbackFuncionOnClose = function handleFeedbackFuncionOnClose() {
149
154
  if (feedbackResult) {
150
- setFinished(true);
151
- var rewards = info.solution.right.rewards;
152
- var rewardsData = [].concat(_toConsumableArray(accRewards), _toConsumableArray(rewards));
153
- playSound('score');
154
- closeFeedbackAndShowPoints(rewardsData);
155
+ endPuzzle();
155
156
  } else {
156
157
  setFeedbackResult(false);
157
158
  disableExit(false);
@@ -163,6 +164,10 @@ var CardsSelectorPuzzleComponent = function CardsSelectorPuzzleComponent(_ref) {
163
164
  }
164
165
 
165
166
  setFeedBackText('');
167
+
168
+ if (!feedbackResult && !rightPick) {
169
+ setForceFlipCard(true);
170
+ }
166
171
  };
167
172
 
168
173
  var handleSuccessPick = function handleSuccessPick(cardId) {
@@ -205,7 +210,6 @@ var CardsSelectorPuzzleComponent = function CardsSelectorPuzzleComponent(_ref) {
205
210
  if (failedCard !== null && failedCard !== void 0 && failedCard.desc) {
206
211
  setFeedBackText(failedCard.desc);
207
212
  setFeedbackIsShown(true);
208
- setRewards([].concat(_toConsumableArray(accRewards), _toConsumableArray(failedCard === null || failedCard === void 0 ? void 0 : failedCard.rewards)));
209
213
  } else {
210
214
  setFeedbackIsShown(true);
211
215
  setTimeout(function () {
@@ -216,6 +220,8 @@ var CardsSelectorPuzzleComponent = function CardsSelectorPuzzleComponent(_ref) {
216
220
  });
217
221
  }, 2000);
218
222
  }
223
+
224
+ setRewards([].concat(_toConsumableArray(accRewards), _toConsumableArray((failedCard === null || failedCard === void 0 ? void 0 : failedCard.rewards) || [])));
219
225
  } // si hay feedback definido
220
226
  else if (info.solution.wrong.desc) {
221
227
  setFeedBackText(info.solution.wrong.desc);
@@ -279,7 +285,9 @@ var CardsSelectorPuzzleComponent = function CardsSelectorPuzzleComponent(_ref) {
279
285
  feedbackIsShown: feedbackIsShown,
280
286
  resolvePuzzle: resolvePuzzle,
281
287
  soundActions: soundActions,
282
- handleSuccess: handleSuccessPick
288
+ handleSuccess: handleSuccessPick,
289
+ forceFlipCard: forceFlipCard,
290
+ setForceFlipCard: setForceFlipCard
283
291
  })), feedbackIsShown && /*#__PURE__*/_react.default.createElement(_feedbackComponent.default, {
284
292
  success: feedbackResult || rightPick,
285
293
  text: feedBackText,
@@ -227,7 +227,7 @@ var DialogComponent = function DialogComponent(_ref) {
227
227
  var animation = (_slot$character2 = slot.character) === null || _slot$character2 === void 0 ? void 0 : _slot$character2.resource.animations[slot.emotion];
228
228
  var mixer = element.userData.mixer;
229
229
 
230
- if (animation && animation.url) {
230
+ if (animation && animation.url && !element.isSeated) {
231
231
  loader.load(animation.url, function (anim) {
232
232
  var emotionClip = anim.animations[0];
233
233
  var defaultClip = element.userData.defaultAnim;
@@ -327,17 +327,15 @@ var DialogComponent = function DialogComponent(_ref) {
327
327
  return parseInt(edge.fromPointIndex) === currentId;
328
328
  });
329
329
  var destinationEdge = lines.findIndex(function (l) {
330
- return l.id === currentEdge.toId;
330
+ return l.id === (currentEdge === null || currentEdge === void 0 ? void 0 : currentEdge.toId);
331
331
  });
332
332
 
333
- if (destinationEdge) {
334
- if (currentEdge.fromId === currentEdge.toId) {
333
+ if (destinationEdge >= 0) {
334
+ if ((currentEdge === null || currentEdge === void 0 ? void 0 : currentEdge.fromId) === (currentEdge === null || currentEdge === void 0 ? void 0 : currentEdge.toId)) {
335
335
  reset();
336
- } else if (destinationEdge >= 0) {
336
+ } else {
337
337
  setCurrentMessage({});
338
338
  changeLine(destinationEdge);
339
- } else {
340
- finishConversation();
341
339
  }
342
340
  } else {
343
341
  finishConversation();
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.23",
5
+ "version": "1.4.26",
6
6
  "main": "dist/index.js",
7
7
  "files": [
8
8
  "dist",