tiny-essentials 1.27.1 → 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.
- package/README.md +1 -0
- package/changelog/1/28/0.md +16 -0
- package/changelog/1/28/1.md +23 -0
- package/dist/v1/TinyAdvancedRaffle.min.js +1 -1
- package/dist/v1/TinyAfterScrollWatcher.min.js +1 -1
- package/dist/v1/TinyAnalogClock.min.js +1 -1
- package/dist/v1/TinyBasicsEs.min.js +1 -2
- package/dist/v1/TinyDayNightCycle.min.js +1 -1
- package/dist/v1/TinyDragDropDetector.min.js +1 -1
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyElementObserver.min.js +1 -1
- package/dist/v1/TinyEssentials.min.js +1 -2
- package/dist/v1/TinyGamepad.min.js +1 -1
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinyI18.min.js +1 -1
- package/dist/v1/TinyIframeEvents.min.js +1 -1
- package/dist/v1/TinyLocalStorage.min.js +1 -1
- package/dist/v1/TinyMediaPlayer.min.js +1 -1
- package/dist/v1/TinyNewWinEvents.min.js +1 -1
- package/dist/v1/TinyNotifyCenter.min.js +1 -1
- package/dist/v1/TinyRadioFm.min.js +1 -1
- package/dist/v1/TinyRateLimiter.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyTextDiffer.min.js +1 -1
- package/dist/v1/TinyTextarea.min.js +1 -1
- package/dist/v1/TinyTimeout.min.js +1 -1
- package/dist/v1/TinyToastNotify.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -2
- package/dist/v1/UltraRandomMsgGen.min.js +1 -1
- package/dist/v1/basics/array.cjs +57 -9
- package/dist/v1/basics/array.d.mts +27 -11
- package/dist/v1/basics/array.mjs +51 -9
- package/dist/v1/basics/clock.cjs +94 -42
- package/dist/v1/basics/clock.d.mts +10 -10
- package/dist/v1/basics/clock.mjs +91 -54
- package/dist/v1/basics/deprecated/html.cjs +246 -0
- package/dist/v1/basics/deprecated/html.d.mts +63 -0
- package/dist/v1/basics/deprecated/html.mjs +190 -0
- package/dist/v1/basics/extendObjType/Buffer.cjs +13 -0
- package/dist/v1/basics/extendObjType/Buffer.d.mts +4 -0
- package/dist/v1/basics/extendObjType/Buffer.mjs +8 -0
- package/dist/v1/basics/html.cjs +149 -130
- package/dist/v1/basics/html.d.mts +26 -61
- package/dist/v1/basics/html.mjs +113 -105
- package/dist/v1/basics/index.cjs +2 -0
- package/dist/v1/basics/index.d.mts +3 -1
- package/dist/v1/basics/index.mjs +3 -3
- package/dist/v1/basics/mediaContent.cjs +51 -9
- package/dist/v1/basics/mediaContent.d.mts +0 -87
- package/dist/v1/basics/mediaContent.mjs +40 -10
- package/dist/v1/basics/objChecker.cjs +7 -5
- package/dist/v1/basics/objChecker.d.mts +3 -2
- package/dist/v1/basics/objChecker.mjs +6 -6
- package/dist/v1/basics/objFilter.cjs +40 -18
- package/dist/v1/basics/objFilter.d.mts +6 -6
- package/dist/v1/basics/objFilter.mjs +32 -17
- package/dist/v1/basics/simpleMath.cjs +81 -25
- package/dist/v1/basics/simpleMath.d.mts +2 -2
- package/dist/v1/basics/simpleMath.mjs +70 -27
- package/dist/v1/basics/text.cjs +76 -31
- package/dist/v1/basics/text.d.mts +69 -7
- package/dist/v1/basics/text.mjs +62 -31
- package/dist/v1/index.cjs +4 -2
- package/dist/v1/index.d.mts +4 -2
- package/dist/v1/index.mjs +4 -4
- package/dist/v1/libs/TinyAdvancedRaffle.cjs +71 -255
- package/dist/v1/libs/TinyAdvancedRaffle.d.mts +6 -134
- package/dist/v1/libs/TinyAdvancedRaffle.mjs +69 -228
- package/dist/v1/libs/TinyAfterScrollWatcher.cjs +17 -1
- package/dist/v1/libs/TinyAfterScrollWatcher.d.mts +4 -1
- package/dist/v1/libs/TinyAfterScrollWatcher.mjs +15 -1
- package/dist/v1/libs/TinyAnalogClock.cjs +60 -0
- package/dist/v1/libs/TinyAnalogClock.d.mts +6 -0
- package/dist/v1/libs/TinyAnalogClock.mjs +57 -0
- package/dist/v1/libs/TinyClipboard.cjs +2 -0
- package/dist/v1/libs/TinyClipboard.d.mts +4 -2
- package/dist/v1/libs/TinyClipboard.mjs +2 -0
- package/dist/v1/libs/TinyColorConverter.cjs +1 -0
- package/dist/v1/libs/TinyColorConverter.d.mts +2 -1
- package/dist/v1/libs/TinyColorConverter.mjs +1 -0
- package/dist/v1/libs/TinyDayNightCycle.cjs +67 -42
- package/dist/v1/libs/TinyDayNightCycle.d.mts +2 -7
- package/dist/v1/libs/TinyDayNightCycle.mjs +65 -41
- package/dist/v1/libs/TinyDragDropDetector.cjs +25 -0
- package/dist/v1/libs/TinyDragDropDetector.d.mts +6 -0
- package/dist/v1/libs/TinyDragDropDetector.mjs +22 -0
- package/dist/v1/libs/TinyDragger.cjs +46 -19
- package/dist/v1/libs/TinyDragger.mjs +45 -18
- package/dist/v1/libs/TinyElementObserver.cjs +39 -0
- package/dist/v1/libs/TinyElementObserver.d.mts +6 -0
- package/dist/v1/libs/TinyElementObserver.mjs +36 -0
- package/dist/v1/libs/TinyGamepad.cjs +131 -1
- package/dist/v1/libs/TinyGamepad.mjs +129 -1
- package/dist/v1/libs/TinyHtml.cjs +1 -1
- package/dist/v1/libs/TinyHtml.mjs +2 -2
- package/dist/v1/libs/TinyI18.cjs +61 -0
- package/dist/v1/libs/TinyI18.d.mts +14 -0
- package/dist/v1/libs/TinyI18.mjs +55 -0
- package/dist/v1/libs/TinyIframeEvents.cjs +26 -196
- package/dist/v1/libs/TinyIframeEvents.d.mts +3 -122
- package/dist/v1/libs/TinyIframeEvents.mjs +26 -171
- package/dist/v1/libs/TinyLocalStorage.cjs +53 -205
- package/dist/v1/libs/TinyLocalStorage.d.mts +6 -127
- package/dist/v1/libs/TinyLocalStorage.mjs +50 -178
- package/dist/v1/libs/TinyMediaPlayer.cjs +74 -2
- package/dist/v1/libs/TinyMediaPlayer.d.mts +12 -2
- package/dist/v1/libs/TinyMediaPlayer.mjs +68 -2
- package/dist/v1/libs/TinyNewWinEvents.cjs +39 -197
- package/dist/v1/libs/TinyNewWinEvents.d.mts +6 -119
- package/dist/v1/libs/TinyNewWinEvents.mjs +36 -172
- package/dist/v1/libs/TinyNotifyCenter.cjs +36 -0
- package/dist/v1/libs/TinyNotifyCenter.d.mts +6 -0
- package/dist/v1/libs/TinyNotifyCenter.mjs +32 -0
- package/dist/v1/libs/TinyRadioFm.cjs +40 -3
- package/dist/v1/libs/TinyRadioFm.d.mts +3 -3
- package/dist/v1/libs/TinyRadioFm.mjs +37 -3
- package/dist/v1/libs/TinyRateLimiter.cjs +52 -0
- package/dist/v1/libs/TinyRateLimiter.d.mts +6 -0
- package/dist/v1/libs/TinyRateLimiter.mjs +48 -0
- package/dist/v1/libs/TinySmartScroller.cjs +56 -205
- package/dist/v1/libs/TinySmartScroller.d.mts +19 -152
- package/dist/v1/libs/TinySmartScroller.mjs +55 -181
- package/dist/v1/libs/TinyTextDiffer.cjs +19 -18
- package/dist/v1/libs/TinyTextDiffer.d.mts +1 -0
- package/dist/v1/libs/TinyTextDiffer.mjs +16 -17
- package/dist/v1/libs/TinyTextarea.cjs +19 -0
- package/dist/v1/libs/TinyTextarea.d.mts +6 -0
- package/dist/v1/libs/TinyTextarea.mjs +17 -0
- package/dist/v1/libs/TinyTimeout.cjs +11 -1
- package/dist/v1/libs/TinyTimeout.mjs +9 -1
- package/dist/v1/libs/TinyToastNotify.cjs +35 -0
- package/dist/v1/libs/TinyToastNotify.d.mts +6 -0
- package/dist/v1/libs/TinyToastNotify.mjs +31 -0
- package/dist/v1/libs/TinyUploadClicker.cjs +20 -0
- package/dist/v1/libs/TinyUploadClicker.d.mts +6 -0
- package/dist/v1/libs/TinyUploadClicker.mjs +17 -0
- package/dist/v1/libs/UltraRandomMsgGen.cjs +148 -35
- package/dist/v1/libs/UltraRandomMsgGen.d.mts +17 -3
- package/dist/v1/libs/UltraRandomMsgGen.mjs +133 -34
- package/dist/v1/libs/utils.cjs +21 -0
- package/dist/v1/libs/utils.d.mts +2 -0
- package/dist/v1/libs/utils.mjs +16 -0
- package/docs/v1/Exports.md +0 -1
- package/docs/v1/README.md +1 -1
- package/docs/v1/basics/array.md +2 -2
- package/docs/v1/basics/deprecated/html.md +17 -0
- package/docs/v1/basics/fullScreen.md +1 -1
- package/docs/v1/basics/html.md +12 -26
- package/docs/v1/basics/mediaContent.md +1 -1
- package/docs/v1/basics/objChecker.md +1 -1
- package/docs/v1/basics/objFilter.md +1 -1
- package/docs/v1/basics/text.md +2 -2
- package/docs/v1/fileManager/main.md +1 -1
- package/docs/v1/libs/ColorSafeStringify.md +1 -1
- package/docs/v1/libs/TinyAfterScrollWatcher.md +1 -1
- package/docs/v1/libs/TinyAnalogClock.md +1 -1
- package/docs/v1/libs/TinyArrayComparator.md +1 -1
- package/docs/v1/libs/TinyArrayPaginator.md +1 -1
- package/docs/v1/libs/TinyClassManager/TinyPluginInliner.md +2 -2
- package/docs/v1/libs/TinyClassManager.md +1 -1
- package/docs/v1/libs/TinyClipboard.md +1 -1
- package/docs/v1/libs/TinyCookieConsent.md +1 -1
- package/docs/v1/libs/TinyDomReadyManager.md +1 -1
- package/docs/v1/libs/TinyDragDropDetector.md +1 -1
- package/docs/v1/libs/TinyDragger.md +1 -1
- package/docs/v1/libs/TinyElementObserver.md +1 -1
- package/docs/v1/libs/TinyHtml.md +1 -1
- package/docs/v1/libs/TinyIframeEvents.md +10 -10
- package/docs/v1/libs/TinyLevelUp.md +1 -1
- package/docs/v1/libs/TinyLoadingScreen.md +1 -1
- package/docs/v1/libs/TinyLocalStorage.md +3 -3
- package/docs/v1/libs/TinyNewWinEvents.md +10 -11
- package/docs/v1/libs/TinyNotifications.md +1 -1
- package/docs/v1/libs/TinyPromiseQueue.md +2 -2
- package/docs/v1/libs/TinyTextDiffer.md +1 -1
- package/docs/v1/libs/TinyTextarea.md +1 -1
- package/package.json +15 -5
- package/dist/v1/TinyBasicsEs.min.js.LICENSE.txt +0 -8
- package/dist/v1/TinyEssentials.min.js.LICENSE.txt +0 -8
- package/dist/v1/TinyEvents.min.js +0 -1
- package/dist/v1/TinyUploadClicker.min.js.LICENSE.txt +0 -8
- package/dist/v1/build/TinyEvents.cjs +0 -7
- package/dist/v1/build/TinyEvents.d.mts +0 -3
- package/dist/v1/build/TinyEvents.mjs +0 -2
- package/dist/v1/libs/TinyEvents.cjs +0 -395
- package/dist/v1/libs/TinyEvents.d.mts +0 -164
- package/dist/v1/libs/TinyEvents.mjs +0 -360
- package/docs/v1/libs/TinyEvents.md +0 -187
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var utils = require('./utils.cjs');
|
|
4
|
+
|
|
5
|
+
const checkDestroy = utils.createCheckDestroyed('TinyDayNightCycle');
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* Represents a mapping of weather type names to their selected values.
|
|
5
9
|
* Each key is the name of a weather type, and the value is either:
|
|
@@ -244,6 +248,7 @@ class TinyDayNightCycle {
|
|
|
244
248
|
* @returns {number}
|
|
245
249
|
*/
|
|
246
250
|
get daySize() {
|
|
251
|
+
checkDestroy(this.#isDestroyed);
|
|
247
252
|
return this.#daySize;
|
|
248
253
|
}
|
|
249
254
|
|
|
@@ -252,6 +257,7 @@ class TinyDayNightCycle {
|
|
|
252
257
|
* @returns {boolean}
|
|
253
258
|
*/
|
|
254
259
|
get autoSizeAdjuste() {
|
|
260
|
+
checkDestroy(this.#isDestroyed);
|
|
255
261
|
return this.#autoSizeAdjuste;
|
|
256
262
|
}
|
|
257
263
|
|
|
@@ -261,6 +267,7 @@ class TinyDayNightCycle {
|
|
|
261
267
|
* @throws {TypeError} If `value` is not a boolean.
|
|
262
268
|
*/
|
|
263
269
|
set autoSizeAdjuste(value) {
|
|
270
|
+
checkDestroy(this.#isDestroyed);
|
|
264
271
|
if (typeof value !== 'boolean') throw new TypeError('autoSizeAdjuste must be a boolean.');
|
|
265
272
|
this.#autoSizeAdjuste = value;
|
|
266
273
|
}
|
|
@@ -272,6 +279,7 @@ class TinyDayNightCycle {
|
|
|
272
279
|
* @throws {Error} If `value` is not a positive finite number.
|
|
273
280
|
*/
|
|
274
281
|
set daySize(value) {
|
|
282
|
+
checkDestroy(this.#isDestroyed);
|
|
275
283
|
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0)
|
|
276
284
|
throw new Error('daySize must be a positive finite number.');
|
|
277
285
|
|
|
@@ -290,6 +298,7 @@ class TinyDayNightCycle {
|
|
|
290
298
|
* @returns {number}
|
|
291
299
|
*/
|
|
292
300
|
get hourSize() {
|
|
301
|
+
checkDestroy(this.#isDestroyed);
|
|
293
302
|
return this.#hourSize;
|
|
294
303
|
}
|
|
295
304
|
|
|
@@ -300,6 +309,7 @@ class TinyDayNightCycle {
|
|
|
300
309
|
* @throws {Error} If `value` is not a positive finite number.
|
|
301
310
|
*/
|
|
302
311
|
set hourSize(value) {
|
|
312
|
+
checkDestroy(this.#isDestroyed);
|
|
303
313
|
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0)
|
|
304
314
|
throw new Error('hourSize must be a positive finite number.');
|
|
305
315
|
|
|
@@ -318,6 +328,7 @@ class TinyDayNightCycle {
|
|
|
318
328
|
* @returns {number}
|
|
319
329
|
*/
|
|
320
330
|
get minuteSize() {
|
|
331
|
+
checkDestroy(this.#isDestroyed);
|
|
321
332
|
return this.#minuteSize;
|
|
322
333
|
}
|
|
323
334
|
|
|
@@ -328,6 +339,7 @@ class TinyDayNightCycle {
|
|
|
328
339
|
* @throws {Error} If `value` is not a positive finite number.
|
|
329
340
|
*/
|
|
330
341
|
set minuteSize(value) {
|
|
342
|
+
checkDestroy(this.#isDestroyed);
|
|
331
343
|
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0)
|
|
332
344
|
throw new Error('minuteSize must be a positive finite number.');
|
|
333
345
|
|
|
@@ -354,6 +366,7 @@ class TinyDayNightCycle {
|
|
|
354
366
|
* @returns {number} Current seconds (0 to 86399).
|
|
355
367
|
*/
|
|
356
368
|
get currentSeconds() {
|
|
369
|
+
checkDestroy(this.#isDestroyed);
|
|
357
370
|
return this.#currentSeconds;
|
|
358
371
|
}
|
|
359
372
|
|
|
@@ -365,7 +378,7 @@ class TinyDayNightCycle {
|
|
|
365
378
|
* @throws {RangeError} If the value is outside the valid range.
|
|
366
379
|
*/
|
|
367
380
|
set currentSeconds(value) {
|
|
368
|
-
this
|
|
381
|
+
checkDestroy(this.#isDestroyed);
|
|
369
382
|
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
370
383
|
throw new TypeError(`currentSeconds must be a finite number, received ${typeof value}`);
|
|
371
384
|
if (value < 0 || value >= this.#daySize)
|
|
@@ -380,6 +393,7 @@ class TinyDayNightCycle {
|
|
|
380
393
|
* @returns {number} Current minutes (0 to 1439).
|
|
381
394
|
*/
|
|
382
395
|
get currentMinutes() {
|
|
396
|
+
checkDestroy(this.#isDestroyed);
|
|
383
397
|
return this.#currentMinutes;
|
|
384
398
|
}
|
|
385
399
|
|
|
@@ -391,7 +405,7 @@ class TinyDayNightCycle {
|
|
|
391
405
|
* @throws {RangeError} If the value is outside the valid range.
|
|
392
406
|
*/
|
|
393
407
|
set currentMinutes(value) {
|
|
394
|
-
this
|
|
408
|
+
checkDestroy(this.#isDestroyed);
|
|
395
409
|
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
396
410
|
throw new TypeError(`currentMinutes must be a finite number, received ${typeof value}`);
|
|
397
411
|
if (value < 0 || value >= 1440)
|
|
@@ -407,6 +421,7 @@ class TinyDayNightCycle {
|
|
|
407
421
|
* @returns {number} Current hours (0 to less than 24).
|
|
408
422
|
*/
|
|
409
423
|
get currentHours() {
|
|
424
|
+
checkDestroy(this.#isDestroyed);
|
|
410
425
|
return this.#currentHours;
|
|
411
426
|
}
|
|
412
427
|
|
|
@@ -419,7 +434,7 @@ class TinyDayNightCycle {
|
|
|
419
434
|
* @throws {RangeError} If the value is outside the valid range.
|
|
420
435
|
*/
|
|
421
436
|
set currentHours(value) {
|
|
422
|
-
this
|
|
437
|
+
checkDestroy(this.#isDestroyed);
|
|
423
438
|
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
424
439
|
throw new TypeError(`currentHours must be a finite number, received ${typeof value}`);
|
|
425
440
|
if (value < 0 || value >= 24)
|
|
@@ -434,6 +449,7 @@ class TinyDayNightCycle {
|
|
|
434
449
|
* @returns {MoonData[]} Array of moons including their name, current phase index, phase name, and cycle length.
|
|
435
450
|
*/
|
|
436
451
|
get moons() {
|
|
452
|
+
checkDestroy(this.#isDestroyed);
|
|
437
453
|
return this.#moons.map((moon) => this.getMoon(moon));
|
|
438
454
|
}
|
|
439
455
|
|
|
@@ -442,41 +458,49 @@ class TinyDayNightCycle {
|
|
|
442
458
|
* @returns {string[]} Array of season names.
|
|
443
459
|
*/
|
|
444
460
|
get seasons() {
|
|
461
|
+
checkDestroy(this.#isDestroyed);
|
|
445
462
|
return Array.from(this.#seasons.keys());
|
|
446
463
|
}
|
|
447
464
|
|
|
448
465
|
/** @returns {number} Hour at which day starts (0-23). */
|
|
449
466
|
get dayStart() {
|
|
467
|
+
checkDestroy(this.#isDestroyed);
|
|
450
468
|
return this.#dayStart;
|
|
451
469
|
}
|
|
452
470
|
|
|
453
471
|
/** @returns {number} Hour at which night starts (0-23). */
|
|
454
472
|
get nightStart() {
|
|
473
|
+
checkDestroy(this.#isDestroyed);
|
|
455
474
|
return this.#nightStart;
|
|
456
475
|
}
|
|
457
476
|
|
|
458
477
|
/** @returns {SelectedWeather} Currently active weather types or nulls if none. */
|
|
459
478
|
get weather() {
|
|
479
|
+
checkDestroy(this.#isDestroyed);
|
|
460
480
|
return { ...this.#weather };
|
|
461
481
|
}
|
|
462
482
|
|
|
463
483
|
/** @returns {string} Currently active season name. */
|
|
464
484
|
get currentSeason() {
|
|
485
|
+
checkDestroy(this.#isDestroyed);
|
|
465
486
|
return this.#currentSeason;
|
|
466
487
|
}
|
|
467
488
|
|
|
468
489
|
/** @returns {number} Current day of the month. */
|
|
469
490
|
get currentDay() {
|
|
491
|
+
checkDestroy(this.#isDestroyed);
|
|
470
492
|
return this.#currentDay;
|
|
471
493
|
}
|
|
472
494
|
|
|
473
495
|
/** @returns {number} Current month number. */
|
|
474
496
|
get currentMonth() {
|
|
497
|
+
checkDestroy(this.#isDestroyed);
|
|
475
498
|
return this.#currentMonth;
|
|
476
499
|
}
|
|
477
500
|
|
|
478
501
|
/** @returns {number} Current year count. */
|
|
479
502
|
get currentYear() {
|
|
503
|
+
checkDestroy(this.#isDestroyed);
|
|
480
504
|
return this.#currentYear;
|
|
481
505
|
}
|
|
482
506
|
|
|
@@ -486,6 +510,7 @@ class TinyDayNightCycle {
|
|
|
486
510
|
* @returns {number[]} Object mapping month number to days.
|
|
487
511
|
*/
|
|
488
512
|
get monthDays() {
|
|
513
|
+
checkDestroy(this.#isDestroyed);
|
|
489
514
|
return [...this.#monthDays];
|
|
490
515
|
}
|
|
491
516
|
|
|
@@ -494,11 +519,13 @@ class TinyDayNightCycle {
|
|
|
494
519
|
* @returns {{min: number, max: number}} Object with min and max weather duration.
|
|
495
520
|
*/
|
|
496
521
|
get weatherDuration() {
|
|
522
|
+
checkDestroy(this.#isDestroyed);
|
|
497
523
|
return { ...this.#weatherDuration };
|
|
498
524
|
}
|
|
499
525
|
|
|
500
526
|
/** @returns {number} Minutes left until current weather expires. */
|
|
501
527
|
get weatherTimeLeft() {
|
|
528
|
+
checkDestroy(this.#isDestroyed);
|
|
502
529
|
return this.#weatherTimeLeft;
|
|
503
530
|
}
|
|
504
531
|
|
|
@@ -508,7 +535,7 @@ class TinyDayNightCycle {
|
|
|
508
535
|
* @throws {TypeError} If value is not a number.
|
|
509
536
|
*/
|
|
510
537
|
set dayStart(value) {
|
|
511
|
-
this
|
|
538
|
+
checkDestroy(this.#isDestroyed);
|
|
512
539
|
if (typeof value !== 'number' || value < 1)
|
|
513
540
|
throw new TypeError(`dayStart must be a positive non-zero number, received ${typeof value}`);
|
|
514
541
|
this.#dayStart = value;
|
|
@@ -520,7 +547,7 @@ class TinyDayNightCycle {
|
|
|
520
547
|
* @throws {TypeError} If value is not a number.
|
|
521
548
|
*/
|
|
522
549
|
set nightStart(value) {
|
|
523
|
-
this
|
|
550
|
+
checkDestroy(this.#isDestroyed);
|
|
524
551
|
if (typeof value !== 'number' || value < 1)
|
|
525
552
|
throw new TypeError(
|
|
526
553
|
`nightStart must be a positive non-zero number, received ${typeof value}`,
|
|
@@ -534,7 +561,7 @@ class TinyDayNightCycle {
|
|
|
534
561
|
* @throws {TypeError} If value is not a string or null.
|
|
535
562
|
*/
|
|
536
563
|
set weather(value) {
|
|
537
|
-
this
|
|
564
|
+
checkDestroy(this.#isDestroyed);
|
|
538
565
|
if (
|
|
539
566
|
typeof value !== 'object' ||
|
|
540
567
|
value === null ||
|
|
@@ -552,7 +579,7 @@ class TinyDayNightCycle {
|
|
|
552
579
|
* @throws {TypeError} If value is not a string or not a configured season.
|
|
553
580
|
*/
|
|
554
581
|
set currentSeason(value) {
|
|
555
|
-
this
|
|
582
|
+
checkDestroy(this.#isDestroyed);
|
|
556
583
|
if (typeof value !== 'string' || !this.#seasons.has(value)) {
|
|
557
584
|
throw new TypeError(
|
|
558
585
|
`currentSeason must be one of ${Array.from(this.#seasons)
|
|
@@ -569,7 +596,7 @@ class TinyDayNightCycle {
|
|
|
569
596
|
* @throws {TypeError} If value is not a number.
|
|
570
597
|
*/
|
|
571
598
|
set currentDay(value) {
|
|
572
|
-
this
|
|
599
|
+
checkDestroy(this.#isDestroyed);
|
|
573
600
|
if (typeof value !== 'number' || value < 1 || value > this.#monthDays[this.#currentMonth - 1])
|
|
574
601
|
throw new TypeError(`currentDay must be a valid day number, received ${typeof value}`);
|
|
575
602
|
this.#currentDay = value;
|
|
@@ -581,7 +608,7 @@ class TinyDayNightCycle {
|
|
|
581
608
|
* @throws {TypeError} If value is not a number.
|
|
582
609
|
*/
|
|
583
610
|
set currentMonth(value) {
|
|
584
|
-
this
|
|
611
|
+
checkDestroy(this.#isDestroyed);
|
|
585
612
|
if (typeof value !== 'number' || typeof this.#monthDays[value - 1] !== 'number')
|
|
586
613
|
throw new TypeError(`currentMonth must be a valid month number, received ${typeof value}`);
|
|
587
614
|
this.#currentMonth = value;
|
|
@@ -593,7 +620,7 @@ class TinyDayNightCycle {
|
|
|
593
620
|
* @throws {TypeError} If value is not a number.
|
|
594
621
|
*/
|
|
595
622
|
set currentYear(value) {
|
|
596
|
-
this
|
|
623
|
+
checkDestroy(this.#isDestroyed);
|
|
597
624
|
if (typeof value !== 'number' || value < 1)
|
|
598
625
|
throw new TypeError(
|
|
599
626
|
`currentYear must be a positive number non-zero, received ${typeof value}`,
|
|
@@ -607,7 +634,7 @@ class TinyDayNightCycle {
|
|
|
607
634
|
* @param {number[]} value - An object where keys are month numbers and values are the number of days.
|
|
608
635
|
*/
|
|
609
636
|
set monthDays(value) {
|
|
610
|
-
this
|
|
637
|
+
checkDestroy(this.#isDestroyed);
|
|
611
638
|
if (!Array.isArray(value)) throw new TypeError(`monthDays must be a array`);
|
|
612
639
|
if (!value.every((n) => typeof n === 'number'))
|
|
613
640
|
throw new TypeError(`monthDays must have number values`);
|
|
@@ -620,7 +647,7 @@ class TinyDayNightCycle {
|
|
|
620
647
|
* @throws {TypeError} If value or its min/max are invalid.
|
|
621
648
|
*/
|
|
622
649
|
set weatherDuration(value) {
|
|
623
|
-
this
|
|
650
|
+
checkDestroy(this.#isDestroyed);
|
|
624
651
|
if (typeof value !== 'object' || value === null)
|
|
625
652
|
throw new TypeError(`weatherDuration must be a non-null object`);
|
|
626
653
|
if (typeof value.min !== 'number' || typeof value.max !== 'number')
|
|
@@ -634,7 +661,7 @@ class TinyDayNightCycle {
|
|
|
634
661
|
* @throws {TypeError} If value is not a number.
|
|
635
662
|
*/
|
|
636
663
|
set weatherTimeLeft(value) {
|
|
637
|
-
this
|
|
664
|
+
checkDestroy(this.#isDestroyed);
|
|
638
665
|
if (typeof value !== 'number')
|
|
639
666
|
throw new TypeError(`weatherTimeLeft must be a number, received ${typeof value}`);
|
|
640
667
|
this.#weatherTimeLeft = value;
|
|
@@ -646,6 +673,7 @@ class TinyDayNightCycle {
|
|
|
646
673
|
* @returns {WeatherCfgs} Deep copy of the weather configuration.
|
|
647
674
|
*/
|
|
648
675
|
get weatherConfig() {
|
|
676
|
+
checkDestroy(this.#isDestroyed);
|
|
649
677
|
/** @type {Record<string, WeatherCfg>} */
|
|
650
678
|
const hours = {};
|
|
651
679
|
/** @type {Record<string, WeatherCfg>} */
|
|
@@ -672,7 +700,7 @@ class TinyDayNightCycle {
|
|
|
672
700
|
* @throws {TypeError} If the provided value is not a valid object or contains invalid data types.
|
|
673
701
|
*/
|
|
674
702
|
set weatherConfig(config) {
|
|
675
|
-
this
|
|
703
|
+
checkDestroy(this.#isDestroyed);
|
|
676
704
|
if (typeof config !== 'object' || config === null)
|
|
677
705
|
throw new TypeError(`weatherConfig must be a non-null object, received ${config}`);
|
|
678
706
|
|
|
@@ -750,7 +778,7 @@ class TinyDayNightCycle {
|
|
|
750
778
|
* @throws {TypeError} If `name` is not a string or `values` is not an array of numbers.
|
|
751
779
|
*/
|
|
752
780
|
addSeason(name, values) {
|
|
753
|
-
this
|
|
781
|
+
checkDestroy(this.#isDestroyed);
|
|
754
782
|
if (typeof name !== 'string')
|
|
755
783
|
throw new TypeError(`Season name must be a string, received ${typeof name}`);
|
|
756
784
|
if (!Array.isArray(values) || !values.every((v) => typeof v === 'number'))
|
|
@@ -765,7 +793,7 @@ class TinyDayNightCycle {
|
|
|
765
793
|
* @throws {TypeError} If `name` is not a string.
|
|
766
794
|
*/
|
|
767
795
|
removeSeason(name) {
|
|
768
|
-
this
|
|
796
|
+
checkDestroy(this.#isDestroyed);
|
|
769
797
|
if (typeof name !== 'string')
|
|
770
798
|
throw new TypeError(`Season name must be a string, received ${typeof name}`);
|
|
771
799
|
this.#seasons.delete(name);
|
|
@@ -780,6 +808,7 @@ class TinyDayNightCycle {
|
|
|
780
808
|
* @throws {TypeError} If `name` is not a string.
|
|
781
809
|
*/
|
|
782
810
|
hasSeason(name) {
|
|
811
|
+
checkDestroy(this.#isDestroyed);
|
|
783
812
|
if (typeof name !== 'string')
|
|
784
813
|
throw new TypeError(`Season name must be a string, received ${typeof name}`);
|
|
785
814
|
return this.#seasons.has(name);
|
|
@@ -794,6 +823,7 @@ class TinyDayNightCycle {
|
|
|
794
823
|
* @throws {Error} If the season does not exist.
|
|
795
824
|
*/
|
|
796
825
|
getSeason(name) {
|
|
826
|
+
checkDestroy(this.#isDestroyed);
|
|
797
827
|
if (typeof name !== 'string')
|
|
798
828
|
throw new TypeError(`Season name must be a string, received ${typeof name}`);
|
|
799
829
|
const result = this.#seasons.get(name);
|
|
@@ -811,7 +841,7 @@ class TinyDayNightCycle {
|
|
|
811
841
|
* @param {number} [settings.second=0] - 0 to 59
|
|
812
842
|
*/
|
|
813
843
|
setTime({ hour = 0, minute = 0, second = 0 }) {
|
|
814
|
-
this
|
|
844
|
+
checkDestroy(this.#isDestroyed);
|
|
815
845
|
this.currentSeconds =
|
|
816
846
|
(hour * this.#hourSize + minute * this.#minuteSize + second) % this.#daySize;
|
|
817
847
|
}
|
|
@@ -824,7 +854,7 @@ class TinyDayNightCycle {
|
|
|
824
854
|
* @param {number} [settings.seconds=0]
|
|
825
855
|
*/
|
|
826
856
|
addTime({ hours = 0, minutes = 0, seconds = 0 }) {
|
|
827
|
-
this
|
|
857
|
+
checkDestroy(this.#isDestroyed);
|
|
828
858
|
let total = this.currentSeconds + hours * this.#hourSize + minutes * this.#minuteSize + seconds;
|
|
829
859
|
|
|
830
860
|
while (total >= this.#daySize) {
|
|
@@ -858,6 +888,7 @@ class TinyDayNightCycle {
|
|
|
858
888
|
* }} An object containing the hour, minute, second, and the formatted time string.
|
|
859
889
|
*/
|
|
860
890
|
getTime({ withSeconds = false, hourSize = this.#hourSize, minuteSize = this.#minuteSize } = {}) {
|
|
891
|
+
checkDestroy(this.#isDestroyed);
|
|
861
892
|
const hour = Math.floor(this.currentSeconds / hourSize);
|
|
862
893
|
const minute = Math.floor((this.currentSeconds % hourSize) / minuteSize);
|
|
863
894
|
const second = this.currentSeconds % minuteSize;
|
|
@@ -879,6 +910,7 @@ class TinyDayNightCycle {
|
|
|
879
910
|
* @returns {boolean} True if current time is day, false otherwise.
|
|
880
911
|
*/
|
|
881
912
|
isDay() {
|
|
913
|
+
checkDestroy(this.#isDestroyed);
|
|
882
914
|
if (this.#dayStart < this.#nightStart) {
|
|
883
915
|
return (
|
|
884
916
|
this.#currentMinutes >= this.#dayStart * this.#minuteSize &&
|
|
@@ -951,7 +983,7 @@ class TinyDayNightCycle {
|
|
|
951
983
|
* @returns {number} Time until target hour, in the specified unit.
|
|
952
984
|
*/
|
|
953
985
|
timeUntil(targetHour, unit) {
|
|
954
|
-
this
|
|
986
|
+
checkDestroy(this.#isDestroyed);
|
|
955
987
|
const targetSeconds = targetHour * this.#hourSize; // 1 hour = 3600 seconds
|
|
956
988
|
let diffSeconds = targetSeconds - this.#currentSeconds;
|
|
957
989
|
if (diffSeconds <= 0) diffSeconds += this.#daySize; // 24h = 86400 seconds (wrap to next day)
|
|
@@ -972,7 +1004,7 @@ class TinyDayNightCycle {
|
|
|
972
1004
|
* @param {"day"|"night"} phase - The phase to set the time to.
|
|
973
1005
|
*/
|
|
974
1006
|
setTo(phase) {
|
|
975
|
-
this
|
|
1007
|
+
checkDestroy(this.#isDestroyed);
|
|
976
1008
|
if (phase === 'day') this.setTime({ hour: this.#dayStart });
|
|
977
1009
|
else if (phase === 'night') this.setTime({ hour: this.#nightStart });
|
|
978
1010
|
}
|
|
@@ -986,7 +1018,7 @@ class TinyDayNightCycle {
|
|
|
986
1018
|
* @param {number} [amount=1] - Number of days to move forward.
|
|
987
1019
|
*/
|
|
988
1020
|
nextDay(amount = 1) {
|
|
989
|
-
this
|
|
1021
|
+
checkDestroy(this.#isDestroyed);
|
|
990
1022
|
for (let i = 0; i < amount; i++) {
|
|
991
1023
|
this.#currentDay++;
|
|
992
1024
|
const monthDays = this.#monthDays[this.#currentMonth - 1];
|
|
@@ -1012,7 +1044,7 @@ class TinyDayNightCycle {
|
|
|
1012
1044
|
* @param {number} [amount=1] - Number of days to move backward.
|
|
1013
1045
|
*/
|
|
1014
1046
|
prevDay(amount = 1) {
|
|
1015
|
-
this
|
|
1047
|
+
checkDestroy(this.#isDestroyed);
|
|
1016
1048
|
for (let i = 0; i < amount; i++) {
|
|
1017
1049
|
this.#currentDay--;
|
|
1018
1050
|
if (this.#currentDay < 1) {
|
|
@@ -1032,7 +1064,7 @@ class TinyDayNightCycle {
|
|
|
1032
1064
|
* Updates the current season based on the month.
|
|
1033
1065
|
*/
|
|
1034
1066
|
updateSeason() {
|
|
1035
|
-
this
|
|
1067
|
+
checkDestroy(this.#isDestroyed);
|
|
1036
1068
|
this.#seasons.forEach((seasonMonths, name) => {
|
|
1037
1069
|
if (seasonMonths.includes(this.#currentMonth)) this.#currentSeason = name;
|
|
1038
1070
|
});
|
|
@@ -1046,7 +1078,7 @@ class TinyDayNightCycle {
|
|
|
1046
1078
|
* An object defining default probabilities, time-based probabilities, day/night differences, and seasonal probabilities.
|
|
1047
1079
|
*/
|
|
1048
1080
|
setWeatherConfig(config) {
|
|
1049
|
-
this
|
|
1081
|
+
checkDestroy(this.#isDestroyed);
|
|
1050
1082
|
this.#weatherConfig = { ...this.#weatherConfig, ...config };
|
|
1051
1083
|
}
|
|
1052
1084
|
|
|
@@ -1056,7 +1088,7 @@ class TinyDayNightCycle {
|
|
|
1056
1088
|
* @param {number} maxMinutes - Maximum duration in minutes.
|
|
1057
1089
|
*/
|
|
1058
1090
|
setWeatherDuration(minMinutes, maxMinutes) {
|
|
1059
|
-
this
|
|
1091
|
+
checkDestroy(this.#isDestroyed);
|
|
1060
1092
|
this.#weatherDuration.min = minMinutes;
|
|
1061
1093
|
this.#weatherDuration.max = maxMinutes;
|
|
1062
1094
|
}
|
|
@@ -1067,7 +1099,7 @@ class TinyDayNightCycle {
|
|
|
1067
1099
|
* @param {number} minutesPassed - Number of in-game minutes passed since last update.
|
|
1068
1100
|
*/
|
|
1069
1101
|
updateWeatherTimer(minutesPassed) {
|
|
1070
|
-
this
|
|
1102
|
+
checkDestroy(this.#isDestroyed);
|
|
1071
1103
|
this.#weatherTimeLeft -= minutesPassed;
|
|
1072
1104
|
if (this.#weatherTimeLeft <= 0) {
|
|
1073
1105
|
this.chooseNewWeather();
|
|
@@ -1082,7 +1114,7 @@ class TinyDayNightCycle {
|
|
|
1082
1114
|
* @param {number|null} [settings.duration=null] - Duration in minutes. If null, a random duration is used.
|
|
1083
1115
|
*/
|
|
1084
1116
|
forceWeather({ where = 'main', type, duration = null }) {
|
|
1085
|
-
this
|
|
1117
|
+
checkDestroy(this.#isDestroyed);
|
|
1086
1118
|
const weather = this.#weather;
|
|
1087
1119
|
weather[where] = type;
|
|
1088
1120
|
this.weather = weather;
|
|
@@ -1105,7 +1137,7 @@ class TinyDayNightCycle {
|
|
|
1105
1137
|
* @returns {string|null} - The selected weather type, or null if none selected.
|
|
1106
1138
|
*/
|
|
1107
1139
|
chooseNewWeather({ customWeather, where = 'main' } = {}) {
|
|
1108
|
-
this
|
|
1140
|
+
checkDestroy(this.#isDestroyed);
|
|
1109
1141
|
/** @type {WeatherData} */
|
|
1110
1142
|
let probabilities = {};
|
|
1111
1143
|
|
|
@@ -1202,6 +1234,7 @@ class TinyDayNightCycle {
|
|
|
1202
1234
|
* @param {number} min - Minimum value.
|
|
1203
1235
|
* @param {number} max - Maximum value.
|
|
1204
1236
|
* @returns {number} - A random integer between min and max.
|
|
1237
|
+
* @private
|
|
1205
1238
|
*/
|
|
1206
1239
|
_randomInRange(min, max) {
|
|
1207
1240
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
@@ -1218,7 +1251,7 @@ class TinyDayNightCycle {
|
|
|
1218
1251
|
* @returns {number} - The moon index.
|
|
1219
1252
|
*/
|
|
1220
1253
|
addMoon(name, cycleLength, phaseNames, startingPhase = 0) {
|
|
1221
|
-
this
|
|
1254
|
+
checkDestroy(this.#isDestroyed);
|
|
1222
1255
|
const length = Math.max(1, cycleLength);
|
|
1223
1256
|
this.#moons.push({
|
|
1224
1257
|
name,
|
|
@@ -1234,7 +1267,7 @@ class TinyDayNightCycle {
|
|
|
1234
1267
|
* @param {string} name
|
|
1235
1268
|
*/
|
|
1236
1269
|
removeMoon(name) {
|
|
1237
|
-
this
|
|
1270
|
+
checkDestroy(this.#isDestroyed);
|
|
1238
1271
|
this.#moons = this.#moons.filter((m) => m.name !== name);
|
|
1239
1272
|
}
|
|
1240
1273
|
|
|
@@ -1261,7 +1294,7 @@ class TinyDayNightCycle {
|
|
|
1261
1294
|
* @throws {RangeError} If the moonIndex is invalid.
|
|
1262
1295
|
*/
|
|
1263
1296
|
advanceMoon(moonIndex, days = 1) {
|
|
1264
|
-
this
|
|
1297
|
+
checkDestroy(this.#isDestroyed);
|
|
1265
1298
|
const moon = this.#moons[moonIndex];
|
|
1266
1299
|
if (!moon) throw new RangeError(`No moon found at index ${moonIndex}`);
|
|
1267
1300
|
moon.currentPhase = (moon.currentPhase + days) % moon.cycleLength;
|
|
@@ -1274,7 +1307,7 @@ class TinyDayNightCycle {
|
|
|
1274
1307
|
* @throws {RangeError} If the moonIndex is invalid.
|
|
1275
1308
|
*/
|
|
1276
1309
|
rewindMoon(moonIndex, days = 1) {
|
|
1277
|
-
this
|
|
1310
|
+
checkDestroy(this.#isDestroyed);
|
|
1278
1311
|
const moon = this.#moons[moonIndex];
|
|
1279
1312
|
if (!moon) throw new RangeError(`No moon found at index ${moonIndex}`);
|
|
1280
1313
|
moon.currentPhase = (moon.currentPhase - days + moon.cycleLength) % moon.cycleLength;
|
|
@@ -1287,6 +1320,7 @@ class TinyDayNightCycle {
|
|
|
1287
1320
|
* @returns {boolean} `true` if a moon exists at the given index, otherwise `false`.
|
|
1288
1321
|
*/
|
|
1289
1322
|
moonExists(index) {
|
|
1323
|
+
checkDestroy(this.#isDestroyed);
|
|
1290
1324
|
if (!this.#moons[index]) return false;
|
|
1291
1325
|
return true;
|
|
1292
1326
|
}
|
|
@@ -1301,6 +1335,7 @@ class TinyDayNightCycle {
|
|
|
1301
1335
|
* @throws {Error} If `index` is a `MoonRaw` object but required properties are missing or invalid.
|
|
1302
1336
|
*/
|
|
1303
1337
|
getMoon(index) {
|
|
1338
|
+
checkDestroy(this.#isDestroyed);
|
|
1304
1339
|
let moon;
|
|
1305
1340
|
|
|
1306
1341
|
if (typeof index === 'number') {
|
|
@@ -1329,16 +1364,6 @@ class TinyDayNightCycle {
|
|
|
1329
1364
|
};
|
|
1330
1365
|
}
|
|
1331
1366
|
|
|
1332
|
-
/**
|
|
1333
|
-
* Checks if the instance has been destroyed and throws an error if so.
|
|
1334
|
-
* @private
|
|
1335
|
-
* @throws {Error} If the instance has already been destroyed.
|
|
1336
|
-
*/
|
|
1337
|
-
_checkDestroyed() {
|
|
1338
|
-
if (this.#isDestroyed)
|
|
1339
|
-
throw new Error('This instance has been destroyed and can no longer be used.');
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
1367
|
/**
|
|
1343
1368
|
* Destroys all stored data and marks the instance as unusable.
|
|
1344
1369
|
* Clears all internal maps, arrays, and resets primitive values to defaults.
|
|
@@ -598,8 +598,9 @@ declare class TinyDayNightCycle {
|
|
|
598
598
|
* @param {number} min - Minimum value.
|
|
599
599
|
* @param {number} max - Maximum value.
|
|
600
600
|
* @returns {number} - A random integer between min and max.
|
|
601
|
+
* @private
|
|
601
602
|
*/
|
|
602
|
-
_randomInRange
|
|
603
|
+
private _randomInRange;
|
|
603
604
|
/** --------------------- MOON SYSTEM --------------------- */
|
|
604
605
|
/**
|
|
605
606
|
* Add a new moon to the system.
|
|
@@ -656,12 +657,6 @@ declare class TinyDayNightCycle {
|
|
|
656
657
|
* @throws {Error} If `index` is a `MoonRaw` object but required properties are missing or invalid.
|
|
657
658
|
*/
|
|
658
659
|
getMoon(index: number | MoonRaw): MoonData;
|
|
659
|
-
/**
|
|
660
|
-
* Checks if the instance has been destroyed and throws an error if so.
|
|
661
|
-
* @private
|
|
662
|
-
* @throws {Error} If the instance has already been destroyed.
|
|
663
|
-
*/
|
|
664
|
-
private _checkDestroyed;
|
|
665
660
|
/**
|
|
666
661
|
* Destroys all stored data and marks the instance as unusable.
|
|
667
662
|
* Clears all internal maps, arrays, and resets primitive values to defaults.
|