@gamelearn/arcade-components 2.14.6 → 2.14.9

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.
@@ -58,6 +58,8 @@ var WriterPuzzleComponent = function WriterPuzzleComponent(_ref) {
58
58
  retry = _ref.retry,
59
59
  skip = _ref.skip,
60
60
  type = _ref.type,
61
+ info = _ref.info,
62
+ setResolveAction = _ref.setResolveAction,
61
63
  documentTitle = _ref.documentTitle,
62
64
  documentTitleLabel = _ref.documentTitle_labelId,
63
65
  texts = _ref.texts,
@@ -139,11 +141,6 @@ var WriterPuzzleComponent = function WriterPuzzleComponent(_ref) {
139
141
  playSound = _soundActions[0];
140
142
 
141
143
  var rewardedCorrectAnswers = (0, _react.useRef)({});
142
- (0, _react.useEffect)(function () {
143
- if (finished) {
144
- setDisableExit(false);
145
- }
146
- }, [finished]);
147
144
 
148
145
  var getCorrectElection = function getCorrectElection(element) {
149
146
  var electionIndex;
@@ -155,14 +152,13 @@ var WriterPuzzleComponent = function WriterPuzzleComponent(_ref) {
155
152
  return electionIndex;
156
153
  };
157
154
 
158
- var getFullTextFormDecisionList = function getFullTextFormDecisionList(indexOfText) {
155
+ var getFullTextFormDecisionList = (0, _react.useCallback)(function (indexOfText) {
159
156
  var currentDecision = decisionsList.filter(function (obj) {
160
157
  return obj.currenTextParagraph === indexOfText;
161
158
  });
162
159
  return currentDecision[0].fullText_labelId;
163
- };
164
-
165
- var createLecture = function createLecture() {
160
+ }, [decisionsList]);
161
+ var createLecture = (0, _react.useCallback)(function () {
166
162
  return texts.map(function (element, indexOfText) {
167
163
  if (element.type === 'fixed') {
168
164
  var _element$fullText_lab;
@@ -183,8 +179,7 @@ var WriterPuzzleComponent = function WriterPuzzleComponent(_ref) {
183
179
 
184
180
  return '';
185
181
  });
186
- };
187
-
182
+ }, [getFullTextFormDecisionList, texts]);
188
183
  var fixedDelay = 12;
189
184
 
190
185
  var checkAllDecisionsRightWrong = function checkAllDecisionsRightWrong() {
@@ -204,7 +199,7 @@ var WriterPuzzleComponent = function WriterPuzzleComponent(_ref) {
204
199
  return true;
205
200
  };
206
201
 
207
- var checkAllDecisionsAreCorrect = function checkAllDecisionsAreCorrect() {
202
+ var checkAllDecisionsAreCorrect = (0, _react.useCallback)(function () {
208
203
  if (decisionsList) {
209
204
  var maxCounter = decisionsList.length;
210
205
  var rightCounter = 0;
@@ -219,7 +214,7 @@ var WriterPuzzleComponent = function WriterPuzzleComponent(_ref) {
219
214
  }
220
215
 
221
216
  return true;
222
- };
217
+ }, [decisionsList]);
223
218
 
224
219
  var checkIfFeedbackNeeded = function checkIfFeedbackNeeded() {
225
220
  return !!(decisionsList && decisionsList.length);
@@ -232,7 +227,7 @@ var WriterPuzzleComponent = function WriterPuzzleComponent(_ref) {
232
227
  });
233
228
  };
234
229
 
235
- var handleLectures = function handleLectures() {
230
+ var handleLectures = (0, _react.useCallback)(function () {
236
231
  var text = createLecture();
237
232
  emitEvent({
238
233
  type: 'finishMedia',
@@ -243,10 +238,10 @@ var WriterPuzzleComponent = function WriterPuzzleComponent(_ref) {
243
238
  type: 'text'
244
239
  }
245
240
  });
246
- };
247
-
248
- var endGame = function endGame() {
249
- var AllDecisionsCorrect = checkAllDecisionsAreCorrect(); // if any is wrong count as wrong if there are no individual points assigned
241
+ }, [createLecture, documentTitleLabel, emitEvent, type]);
242
+ var endGame = (0, _react.useCallback)(function (reward) {
243
+ // if any is wrong count as wrong if there are no individual points assigned
244
+ var AllDecisionsCorrect = checkAllDecisionsAreCorrect();
250
245
 
251
246
  if (failed) {
252
247
  playSound('fail');
@@ -258,13 +253,22 @@ var WriterPuzzleComponent = function WriterPuzzleComponent(_ref) {
258
253
  type: 'addPoints',
259
254
  complex: true,
260
255
  finish: true,
261
- payload: rewardsStack,
256
+ payload: reward || rewardsStack,
262
257
  onFinish: type !== 'view' ? handleLectures : null
263
258
  });
264
259
  emitEvent({
265
260
  type: 'passPuzzle'
266
261
  });
267
- };
262
+ }, [checkAllDecisionsAreCorrect, emitEvent, failed, handleLectures, playSound, rewardsStack, type]);
263
+ (0, _react.useEffect)(function () {
264
+ if (finished) {
265
+ setDisableExit(false);
266
+ }
267
+
268
+ setResolveAction(function () {
269
+ endGame(info.resolve.rewards);
270
+ });
271
+ }, [emitEvent, endGame, finished, handleLectures, info.resolve.rewards, setResolveAction, type]);
268
272
 
269
273
  var retryPuzzle = function retryPuzzle() {
270
274
  setFinished(false);
@@ -56,6 +56,7 @@ exports.messages = messages;
56
56
  var mock = {
57
57
  emitEvent: _mocker.emitEvent,
58
58
  soundActions: _mocker.soundActions,
59
+ setResolveAction: function setResolveAction() {},
59
60
  keyboardControl: _mocker.keyboardControl,
60
61
  texts: [{
61
62
  type: 'fixed',
@@ -165,6 +166,7 @@ exports.mock = mock;
165
166
  var mock2 = {
166
167
  emitEvent: _mocker.emitEvent,
167
168
  soundActions: _mocker.soundActions,
169
+ setResolveAction: function setResolveAction() {},
168
170
  keyboardControl: _mocker.keyboardControl,
169
171
  texts: [{
170
172
  type: 'fixed',
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.14.6",
5
+ "version": "2.14.9",
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.10.6",
17
+ "@gamelearn/arcade-styles": "2.10.7",
18
18
  "@gamelearn/arcade-three-core": "1.17.2",
19
19
  "@react-three/drei": "9.4.3",
20
20
  "@react-three/fiber": "8.0.17",