@gamelearn/arcade-components 1.27.13 → 1.28.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.
@@ -634,6 +634,16 @@ var mockProps3 = {
634
634
  points: [1150.0742574257429, 217.48228650990103, 1570.95297029703, 65.42288056930694, 1704.0049504950498, 195.7595142326733, 1576.383663366337, 421.13327660891093, 1247.8267326732675, 510.73971225247533],
635
635
  stroke: 'rgb(101,154,93)',
636
636
  closed: true
637
+ }, {
638
+ id: 'Dos',
639
+ name: 'Dos',
640
+ x: 0,
641
+ y: 0,
642
+ fill: 'rgba(255, 255, 255, 0.1)',
643
+ draggable: true,
644
+ points: [121.11881188118804, 1017.7722772277228, 254.1881188118811, 856.1881188118813, 637.5544554455446, 1144.5049504950496, 406.2673267326732, 1264.90099009901],
645
+ stroke: 'rgb(101,154,93)',
646
+ closed: true
637
647
  }],
638
648
  badAreas: [{
639
649
  id: 'AllArea',
@@ -648,7 +658,7 @@ var mockProps3 = {
648
658
  closed: true
649
659
  }],
650
660
  hasClickOrder: false,
651
- timer: 4,
661
+ timer: 15,
652
662
  hasHighlights: true,
653
663
  specificFeedbacks: {
654
664
  correctFeedbacks: [{
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ var CountDown = function CountDown(_ref) {
13
+ var time = _ref.time;
14
+ var minutes = Math.floor(time / 60);
15
+ var seconds = time % 60;
16
+ return /*#__PURE__*/_react.default.createElement("div", {
17
+ className: "count-down count-down--in-puzzle-frame ".concat(time < 10 ? 'count-down--finalseconds' : '')
18
+ }, /*#__PURE__*/_react.default.createElement("div", null, minutes < 10 ? "0".concat(minutes) : minutes, " : ", seconds < 10 ? "0".concat(Math.floor(seconds)) : Math.floor(seconds)));
19
+ };
20
+
21
+ var _default = CountDown;
22
+ exports.default = _default;
@@ -15,6 +15,8 @@ var _FeedbackComponent = _interopRequireDefault(require("../../feedback-componen
15
15
 
16
16
  var _TimerDialog = _interopRequireDefault(require("./TimerDialog"));
17
17
 
18
+ var _CountDown = _interopRequireDefault(require("./CountDown"));
19
+
18
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
21
 
20
22
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -131,6 +133,12 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
131
133
  var pauseDate = (0, _react.useRef)(null);
132
134
  var whenCloseFeedbackDate = (0, _react.useRef)(null);
133
135
  var remainingTime = (0, _react.useRef)(null);
136
+ var intervalForCountDown = (0, _react.useRef)(null);
137
+
138
+ var _useState13 = (0, _react.useState)(timer),
139
+ _useState14 = _slicedToArray(_useState13, 2),
140
+ countDownTime = _useState14[0],
141
+ setCountDownTime = _useState14[1];
134
142
 
135
143
  var translate = function translate(id) {
136
144
  if (translateFromParent) return translateFromParent(id); // when there is no emitEvent pass the Translate
@@ -158,6 +166,14 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
158
166
  shape: 'poly'
159
167
  }, area);
160
168
  });
169
+ var startCountDown = (0, _react.useCallback)(function () {
170
+ var timeout = setInterval(function () {
171
+ setCountDownTime(function (t) {
172
+ return t - 1;
173
+ });
174
+ }, 1000);
175
+ intervalForCountDown.current = timeout;
176
+ }, []);
161
177
  var handleFinish = (0, _react.useCallback)(function (rewards, success) {
162
178
  if (emitFinish) {
163
179
  emitFinish(rewards, success);
@@ -179,6 +195,9 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
179
195
  var clearListenerForActualDate = (0, _react.useCallback)(function () {
180
196
  clearInterval(intervalForActualDate.current);
181
197
  }, []);
198
+ var clearIntervalForCountDown = (0, _react.useCallback)(function () {
199
+ clearInterval(intervalForCountDown.current);
200
+ }, []);
182
201
  var pauseTheCounter = (0, _react.useCallback)(function () {
183
202
  pauseDate.current = Date.now();
184
203
  remainingTime.current = finalDate.current - pauseDate.current;
@@ -201,10 +220,11 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
201
220
  };
202
221
  });
203
222
  setTimeExpired(true);
223
+ clearIntervalForCountDown();
204
224
  clearListenerForActualDate();
205
225
  }
206
226
  }, 250);
207
- }, [clearListenerForActualDate, info === null || info === void 0 ? void 0 : (_info$timerFeedback3 = info.timerFeedback) === null || _info$timerFeedback3 === void 0 ? void 0 : _info$timerFeedback3.desc, info === null || info === void 0 ? void 0 : (_info$timerFeedback4 = info.timerFeedback) === null || _info$timerFeedback4 === void 0 ? void 0 : _info$timerFeedback4.rewards]);
227
+ }, [clearListenerForActualDate, clearIntervalForCountDown, (_info$timerFeedback3 = info.timerFeedback) === null || _info$timerFeedback3 === void 0 ? void 0 : _info$timerFeedback3.desc, (_info$timerFeedback4 = info.timerFeedback) === null || _info$timerFeedback4 === void 0 ? void 0 : _info$timerFeedback4.rewards]);
208
228
  (0, _react.useEffect)(function () {
209
229
  if ((areas.length === clickedZones.length || hasClickOnce && clickedZones.length > 0) && !completed) {
210
230
  var _specificFeedbacks$co;
@@ -236,6 +256,7 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
236
256
  (0, _react.useEffect)(function () {
237
257
  setResolveAction(function (resolve) {
238
258
  if (timer) {
259
+ clearIntervalForCountDown();
239
260
  setDialogForTimer(false);
240
261
 
241
262
  if (feedbackData.show) {
@@ -262,7 +283,7 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
262
283
  }
263
284
  }, 4000);
264
285
  });
265
- }, [setResolveAction, emitResolve, playSound, timer, feedbackData.show, clearListenerForActualDate]);
286
+ }, [setResolveAction, emitResolve, playSound, timer, feedbackData.show, clearListenerForActualDate, clearIntervalForCountDown]);
266
287
  (0, _react.useEffect)(function () {
267
288
  if (finished) {
268
289
  disableExit(true);
@@ -301,6 +322,7 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
301
322
  }
302
323
 
303
324
  if (timer) {
325
+ clearIntervalForCountDown();
304
326
  pauseTheCounter();
305
327
  }
306
328
 
@@ -327,7 +349,11 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
327
349
  setClickedZones([]);
328
350
  setDialogForTimer(true);
329
351
  emitResetPuzzle();
352
+ } else if (areas.length === clickedZones.length || hasClickOnce && clickedZones.length > 0) {
353
+ clearIntervalForCountDown();
330
354
  } else {
355
+ setCountDownTime(remainingTime.current * 0.001);
356
+ startCountDown();
331
357
  listenerForActualDate();
332
358
  }
333
359
  }
@@ -342,7 +368,7 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
342
368
  rewards: []
343
369
  });
344
370
  });
345
- }, [emitResetPuzzle, feedbackData.rewards, feedbackData.success, handleFinish, listenerForActualDate, playSound, timeExpired, timer]);
371
+ }, [timer, timeExpired, handleFinish, feedbackData.rewards, feedbackData.success, playSound, areas.length, clickedZones.length, hasClickOnce, emitResetPuzzle, clearIntervalForCountDown, startCountDown, listenerForActualDate]);
346
372
 
347
373
  var handleCorrectAreaClick = function handleCorrectAreaClick(area) {
348
374
  if (!clickedZones.some(function (zone) {
@@ -381,6 +407,7 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
381
407
  });
382
408
 
383
409
  if (timer) {
410
+ clearIntervalForCountDown();
384
411
  pauseTheCounter();
385
412
  }
386
413
  }
@@ -394,6 +421,10 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
394
421
  };
395
422
 
396
423
  var createStartAndEndDate = (0, _react.useCallback)(function () {
424
+ clearIntervalForCountDown();
425
+ setCountDownTime(timer);
426
+ startCountDown();
427
+
397
428
  if (!popupCounterVisible.current && firstTryForFrame) {
398
429
  emitOpenPopupCounterInfo();
399
430
  }
@@ -402,7 +433,7 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
402
433
  startDate.current = Date.now();
403
434
  finalDate.current = startDate.current + timer * 1000;
404
435
  listenerForActualDate();
405
- }, [emitOpenPopupCounterInfo, firstTryForFrame, listenerForActualDate, timer]);
436
+ }, [clearIntervalForCountDown, timer, startCountDown, firstTryForFrame, listenerForActualDate, emitOpenPopupCounterInfo]);
406
437
  (0, _react.useEffect)(function () {
407
438
  // start automatically the time
408
439
  if (timer && slideNumber > 0) {
@@ -438,6 +469,8 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
438
469
  retry: firstTryForFrame || puzzlesAutoCompleted[slideNumber - 1],
439
470
  translate: translate,
440
471
  onInit: createStartAndEndDate
472
+ }) : null, timer ? /*#__PURE__*/_react.default.createElement(_CountDown.default, {
473
+ time: countDownTime
441
474
  }) : null);
442
475
  };
443
476
 
@@ -134,7 +134,7 @@ var Container = function Container(_ref) {
134
134
  className: "test--questions__count"
135
135
  }, (0, _LangIsRtl.default)() ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, currentQuestionId + 1, "/", questions.length, " ", /*#__PURE__*/_react.default.createElement("span", null, translate('tests.question'))) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", null, translate('tests.question')), " ", currentQuestionId + 1, "/", questions.length)), time >= 0 ? /*#__PURE__*/_react.default.createElement("div", {
136
136
  dir: "ltr",
137
- className: "test--timer ".concat(time < 10 ? 'test--timer--finalseconds' : '')
137
+ className: "count-down ".concat(time < 10 ? 'count-down--finalseconds' : '')
138
138
  }, /*#__PURE__*/_react.default.createElement("div", {
139
139
  id: "test-time"
140
140
  }, minutes < 10 ? "0".concat(minutes) : minutes, " : ", seconds < 10 ? "0".concat(seconds) : seconds)) : null), /*#__PURE__*/_react.default.createElement(_Questions.default, {
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.27.13",
5
+ "version": "1.28.1",
6
6
  "main": "dist/index.js",
7
7
  "files": [
8
8
  "dist",
@@ -13,7 +13,7 @@
13
13
  "url": "https://github.com/gamelearn/arcade-components"
14
14
  },
15
15
  "dependencies": {
16
- "@gamelearn/arcade-styles": "0.13.2",
16
+ "@gamelearn/arcade-styles": "0.14.0",
17
17
  "@gamelearn/arcade-three-core": "1.14.5",
18
18
  "@react-three/drei": "9.4.3",
19
19
  "@react-three/fiber": "8.0.17",