@react-text-game/core 0.1.0
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 +744 -0
- package/dist/baseGameObject.d.ts +90 -0
- package/dist/baseGameObject.d.ts.map +1 -0
- package/dist/baseGameObject.js +109 -0
- package/dist/baseGameObject.js.map +1 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +12 -0
- package/dist/constants.js.map +1 -0
- package/dist/game.d.ts +294 -0
- package/dist/game.d.ts.map +1 -0
- package/dist/game.js +489 -0
- package/dist/game.js.map +1 -0
- package/dist/helpers.d.ts +2 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +6 -0
- package/dist/helpers.js.map +1 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useCurrentPassage.d.ts +10 -0
- package/dist/hooks/useCurrentPassage.d.ts.map +1 -0
- package/dist/hooks/useCurrentPassage.js +17 -0
- package/dist/hooks/useCurrentPassage.js.map +1 -0
- package/dist/hooks/useGameEntity.d.ts +21 -0
- package/dist/hooks/useGameEntity.d.ts.map +1 -0
- package/dist/hooks/useGameEntity.js +70 -0
- package/dist/hooks/useGameEntity.js.map +1 -0
- package/dist/hooks/useGameIsStarted.d.ts +12 -0
- package/dist/hooks/useGameIsStarted.d.ts.map +1 -0
- package/dist/hooks/useGameIsStarted.js +18 -0
- package/dist/hooks/useGameIsStarted.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +36 -0
- package/dist/logger.js.map +1 -0
- package/dist/options.d.ts +13 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +15 -0
- package/dist/options.js.map +1 -0
- package/dist/passages/interactiveMap/fabric.d.ts +4 -0
- package/dist/passages/interactiveMap/fabric.d.ts.map +1 -0
- package/dist/passages/interactiveMap/fabric.js +3 -0
- package/dist/passages/interactiveMap/fabric.js.map +1 -0
- package/dist/passages/interactiveMap/index.d.ts +4 -0
- package/dist/passages/interactiveMap/index.d.ts.map +1 -0
- package/dist/passages/interactiveMap/index.js +4 -0
- package/dist/passages/interactiveMap/index.js.map +1 -0
- package/dist/passages/interactiveMap/interactiveMap.d.ts +89 -0
- package/dist/passages/interactiveMap/interactiveMap.d.ts.map +1 -0
- package/dist/passages/interactiveMap/interactiveMap.js +103 -0
- package/dist/passages/interactiveMap/interactiveMap.js.map +1 -0
- package/dist/passages/interactiveMap/types.d.ts +822 -0
- package/dist/passages/interactiveMap/types.d.ts.map +1 -0
- package/dist/passages/interactiveMap/types.js +2 -0
- package/dist/passages/interactiveMap/types.js.map +1 -0
- package/dist/passages/passage.d.ts +57 -0
- package/dist/passages/passage.d.ts.map +1 -0
- package/dist/passages/passage.js +64 -0
- package/dist/passages/passage.js.map +1 -0
- package/dist/passages/story/fabric.d.ts +4 -0
- package/dist/passages/story/fabric.d.ts.map +1 -0
- package/dist/passages/story/fabric.js +3 -0
- package/dist/passages/story/fabric.js.map +1 -0
- package/dist/passages/story/index.d.ts +5 -0
- package/dist/passages/story/index.d.ts.map +1 -0
- package/dist/passages/story/index.js +5 -0
- package/dist/passages/story/index.js.map +1 -0
- package/dist/passages/story/start.d.ts +14 -0
- package/dist/passages/story/start.d.ts.map +1 -0
- package/dist/passages/story/start.js +22 -0
- package/dist/passages/story/start.js.map +1 -0
- package/dist/passages/story/story.d.ts +84 -0
- package/dist/passages/story/story.d.ts.map +1 -0
- package/dist/passages/story/story.js +88 -0
- package/dist/passages/story/story.js.map +1 -0
- package/dist/passages/story/types.d.ts +911 -0
- package/dist/passages/story/types.d.ts.map +1 -0
- package/dist/passages/story/types.js +2 -0
- package/dist/passages/story/types.js.map +1 -0
- package/dist/passages/types/index.d.ts +3 -0
- package/dist/passages/types/index.d.ts.map +1 -0
- package/dist/passages/types/index.js +2 -0
- package/dist/passages/types/index.js.map +1 -0
- package/dist/passages/widget.d.ts +62 -0
- package/dist/passages/widget.d.ts.map +1 -0
- package/dist/passages/widget.js +66 -0
- package/dist/passages/widget.js.map +1 -0
- package/dist/saves/constants.d.ts +17 -0
- package/dist/saves/constants.d.ts.map +1 -0
- package/dist/saves/constants.js +17 -0
- package/dist/saves/constants.js.map +1 -0
- package/dist/saves/db.d.ts +119 -0
- package/dist/saves/db.d.ts.map +1 -0
- package/dist/saves/db.js +231 -0
- package/dist/saves/db.js.map +1 -0
- package/dist/saves/helpers.d.ts +28 -0
- package/dist/saves/helpers.d.ts.map +1 -0
- package/dist/saves/helpers.js +84 -0
- package/dist/saves/helpers.js.map +1 -0
- package/dist/saves/hooks/index.d.ts +10 -0
- package/dist/saves/hooks/index.d.ts.map +1 -0
- package/dist/saves/hooks/index.js +10 -0
- package/dist/saves/hooks/index.js.map +1 -0
- package/dist/saves/hooks/useDeleteAllSlots.d.ts +18 -0
- package/dist/saves/hooks/useDeleteAllSlots.d.ts.map +1 -0
- package/dist/saves/hooks/useDeleteAllSlots.js +18 -0
- package/dist/saves/hooks/useDeleteAllSlots.js.map +1 -0
- package/dist/saves/hooks/useDeleteGame.d.ts +22 -0
- package/dist/saves/hooks/useDeleteGame.d.ts.map +1 -0
- package/dist/saves/hooks/useDeleteGame.js +33 -0
- package/dist/saves/hooks/useDeleteGame.js.map +1 -0
- package/dist/saves/hooks/useExportSaves.d.ts +27 -0
- package/dist/saves/hooks/useExportSaves.d.ts.map +1 -0
- package/dist/saves/hooks/useExportSaves.js +54 -0
- package/dist/saves/hooks/useExportSaves.js.map +1 -0
- package/dist/saves/hooks/useImportSaves.d.ts +29 -0
- package/dist/saves/hooks/useImportSaves.d.ts.map +1 -0
- package/dist/saves/hooks/useImportSaves.js +108 -0
- package/dist/saves/hooks/useImportSaves.js.map +1 -0
- package/dist/saves/hooks/useLastLoadGame.d.ts +39 -0
- package/dist/saves/hooks/useLastLoadGame.d.ts.map +1 -0
- package/dist/saves/hooks/useLastLoadGame.js +72 -0
- package/dist/saves/hooks/useLastLoadGame.js.map +1 -0
- package/dist/saves/hooks/useLoadGame.d.ts +22 -0
- package/dist/saves/hooks/useLoadGame.d.ts.map +1 -0
- package/dist/saves/hooks/useLoadGame.js +40 -0
- package/dist/saves/hooks/useLoadGame.js.map +1 -0
- package/dist/saves/hooks/useRestartGame.d.ts +20 -0
- package/dist/saves/hooks/useRestartGame.d.ts.map +1 -0
- package/dist/saves/hooks/useRestartGame.js +29 -0
- package/dist/saves/hooks/useRestartGame.js.map +1 -0
- package/dist/saves/hooks/useSaveGame.d.ts +22 -0
- package/dist/saves/hooks/useSaveGame.d.ts.map +1 -0
- package/dist/saves/hooks/useSaveGame.js +34 -0
- package/dist/saves/hooks/useSaveGame.js.map +1 -0
- package/dist/saves/hooks/useSaveSlots.d.ts +45 -0
- package/dist/saves/hooks/useSaveSlots.d.ts.map +1 -0
- package/dist/saves/hooks/useSaveSlots.js +42 -0
- package/dist/saves/hooks/useSaveSlots.js.map +1 -0
- package/dist/saves/index.d.ts +4 -0
- package/dist/saves/index.d.ts.map +1 -0
- package/dist/saves/index.js +3 -0
- package/dist/saves/index.js.map +1 -0
- package/dist/saves/types.d.ts +52 -0
- package/dist/saves/types.d.ts.map +1 -0
- package/dist/saves/types.js +2 -0
- package/dist/saves/types.js.map +1 -0
- package/dist/storage.d.ts +124 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +229 -0
- package/dist/storage.js.map +1 -0
- package/dist/tests/game.test.d.ts +2 -0
- package/dist/tests/game.test.d.ts.map +1 -0
- package/dist/tests/game.test.js +602 -0
- package/dist/tests/game.test.js.map +1 -0
- package/dist/tests/interactiveMap.test.d.ts +2 -0
- package/dist/tests/interactiveMap.test.d.ts.map +1 -0
- package/dist/tests/interactiveMap.test.js +1003 -0
- package/dist/tests/interactiveMap.test.js.map +1 -0
- package/dist/tests/storage.test.d.ts +2 -0
- package/dist/tests/storage.test.d.ts.map +1 -0
- package/dist/tests/storage.test.js +328 -0
- package/dist/tests/storage.test.js.map +1 -0
- package/dist/tests/story.test.d.ts +2 -0
- package/dist/tests/story.test.d.ts.map +1 -0
- package/dist/tests/story.test.js +698 -0
- package/dist/tests/story.test.js.map +1 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/passages/story/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EACH,WAAW,EACX,aAAa,EACb,WAAW,EACX,YAAY,EACf,MAAM,QAAQ,CAAC;AAEhB;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC1B;;;;;;;;OAQG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;;;;;;;;;;;OAYG;IACH,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,YAAY,CAAC;CACxD;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,aAAc,SAAQ,aAAa;IAChD;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;OAIG;IACH,OAAO,EAAE,SAAS,CAAC;IAEnB;;OAEG;IACH,KAAK,CAAC,EAAE;QACJ;;;;;;;;WAQG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACL;AAED;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEhD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,eAAgB,SAAQ,aAAa;IAClD;;OAEG;IACH,IAAI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AAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACL;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GACf,aAAa,GACb,eAAe,GACf,cAAc,GACd,cAAc,GACd,gBAAgB,GAChB,qBAAqB,GACrB,qBAAqB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,SAAS,YAAY,GAAG,WAAW,EAC5D,KAAK,EAAE,CAAC,KACP,KAAK,CAAC,SAAS,CAAC,CAAC;AAEtB;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,YAAY,GAAG;IACvB;;OAEG;IACH,UAAU,CAAC,EAAE;QACT;;;;;;;;;;;;;;WAcG;QACH,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;KACnC,CAAC;IAEF;;OAEG;IACH,UAAU,CAAC,EAAE;QACT;;;;;;;;WAQG;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;QAEd;;;;;;;;WAQG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/passages/story/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/passages/types/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,yBAAyB,CAAC;AAC7C,mBAAmB,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/passages/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { Passage } from "../passages/passage";
|
|
3
|
+
/**
|
|
4
|
+
* Custom React component passage for fully customized UI.
|
|
5
|
+
*
|
|
6
|
+
* Widget passages allow you to use any React component as a game passage,
|
|
7
|
+
* providing complete control over the UI when the built-in passage types
|
|
8
|
+
* (Story, InteractiveMap) don't meet your needs.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { newWidget } from '@react-text-game/core';
|
|
13
|
+
*
|
|
14
|
+
* const inventoryUI = newWidget('inventory', (
|
|
15
|
+
* <div className="inventory">
|
|
16
|
+
* <h2>Your Inventory</h2>
|
|
17
|
+
* <InventoryGrid items={player.inventory} />
|
|
18
|
+
* <button onClick={() => Game.jumpTo('game')}>Close</button>
|
|
19
|
+
* </div>
|
|
20
|
+
* ));
|
|
21
|
+
*
|
|
22
|
+
* // Navigate to custom UI
|
|
23
|
+
* Game.jumpTo(inventoryUI);
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @see newWidget - Factory function for creating Widget instances
|
|
27
|
+
*/
|
|
28
|
+
export declare class Widget extends Passage {
|
|
29
|
+
/**
|
|
30
|
+
* The React component/element to render.
|
|
31
|
+
*/
|
|
32
|
+
private readonly content;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new Widget passage.
|
|
35
|
+
*
|
|
36
|
+
* @param id - Unique identifier for this widget
|
|
37
|
+
* @param content - React node (element, component, etc.) to display
|
|
38
|
+
*/
|
|
39
|
+
constructor(id: string, content: ReactNode);
|
|
40
|
+
/**
|
|
41
|
+
* Returns the React node for rendering.
|
|
42
|
+
*
|
|
43
|
+
* @returns The React content to be rendered
|
|
44
|
+
*/
|
|
45
|
+
display(): ReactNode;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Factory function for creating Widget passages.
|
|
49
|
+
*
|
|
50
|
+
* @param id - Unique identifier for the widget
|
|
51
|
+
* @param content - React node to display
|
|
52
|
+
* @returns New Widget instance
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const customMenu = newWidget('menu', (
|
|
57
|
+
* <CustomMenuComponent />
|
|
58
|
+
* ));
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare const newWidget: (id: string, content: ReactNode) => Widget;
|
|
62
|
+
//# sourceMappingURL=widget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../../src/passages/widget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,MAAO,SAAQ,OAAO;IAC/B;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAY;IAEpC;;;;;OAKG;gBACS,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS;IAK1C;;;;OAIG;IACH,OAAO;CAGV;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,SAAS,GAAI,IAAI,MAAM,EAAE,SAAS,SAAS,WAC7B,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Passage } from "../passages/passage";
|
|
2
|
+
/**
|
|
3
|
+
* Custom React component passage for fully customized UI.
|
|
4
|
+
*
|
|
5
|
+
* Widget passages allow you to use any React component as a game passage,
|
|
6
|
+
* providing complete control over the UI when the built-in passage types
|
|
7
|
+
* (Story, InteractiveMap) don't meet your needs.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { newWidget } from '@react-text-game/core';
|
|
12
|
+
*
|
|
13
|
+
* const inventoryUI = newWidget('inventory', (
|
|
14
|
+
* <div className="inventory">
|
|
15
|
+
* <h2>Your Inventory</h2>
|
|
16
|
+
* <InventoryGrid items={player.inventory} />
|
|
17
|
+
* <button onClick={() => Game.jumpTo('game')}>Close</button>
|
|
18
|
+
* </div>
|
|
19
|
+
* ));
|
|
20
|
+
*
|
|
21
|
+
* // Navigate to custom UI
|
|
22
|
+
* Game.jumpTo(inventoryUI);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @see newWidget - Factory function for creating Widget instances
|
|
26
|
+
*/
|
|
27
|
+
export class Widget extends Passage {
|
|
28
|
+
/**
|
|
29
|
+
* The React component/element to render.
|
|
30
|
+
*/
|
|
31
|
+
content;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new Widget passage.
|
|
34
|
+
*
|
|
35
|
+
* @param id - Unique identifier for this widget
|
|
36
|
+
* @param content - React node (element, component, etc.) to display
|
|
37
|
+
*/
|
|
38
|
+
constructor(id, content) {
|
|
39
|
+
super(id, "widget");
|
|
40
|
+
this.content = content;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns the React node for rendering.
|
|
44
|
+
*
|
|
45
|
+
* @returns The React content to be rendered
|
|
46
|
+
*/
|
|
47
|
+
display() {
|
|
48
|
+
return this.content;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Factory function for creating Widget passages.
|
|
53
|
+
*
|
|
54
|
+
* @param id - Unique identifier for the widget
|
|
55
|
+
* @param content - React node to display
|
|
56
|
+
* @returns New Widget instance
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const customMenu = newWidget('menu', (
|
|
61
|
+
* <CustomMenuComponent />
|
|
62
|
+
* ));
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export const newWidget = (id, content) => new Widget(id, content);
|
|
66
|
+
//# sourceMappingURL=widget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.js","sourceRoot":"","sources":["../../src/passages/widget.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,OAAO,MAAO,SAAQ,OAAO;IAC/B;;OAEG;IACc,OAAO,CAAY;IAEpC;;;;;OAKG;IACH,YAAY,EAAU,EAAE,OAAkB;QACtC,KAAK,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,OAAO;QACH,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;CACJ;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAU,EAAE,OAAkB,EAAE,EAAE,CACxD,IAAI,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File extension used for encrypted save files
|
|
3
|
+
*/
|
|
4
|
+
export declare const SAFE_FILE_EXTENSION = ".sx";
|
|
5
|
+
/**
|
|
6
|
+
* Postfix appended to game ID when generating encryption passwords
|
|
7
|
+
*/
|
|
8
|
+
export declare const SAVE_POSTFIX = "txt-game";
|
|
9
|
+
/**
|
|
10
|
+
* Key size in words (256 bits / 32 bits per word = 8 words) for AES encryption
|
|
11
|
+
*/
|
|
12
|
+
export declare const KEY_SIZE: number;
|
|
13
|
+
/**
|
|
14
|
+
* Number of iterations for PBKDF2 key derivation function
|
|
15
|
+
*/
|
|
16
|
+
export declare const ITERATIONS = 1000;
|
|
17
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/saves/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC;;GAEG;AACH,eAAO,MAAM,YAAY,aAAa,CAAC;AAEvC;;GAEG;AACH,eAAO,MAAM,QAAQ,QAAW,CAAC;AAEjC;;GAEG;AACH,eAAO,MAAM,UAAU,OAAO,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File extension used for encrypted save files
|
|
3
|
+
*/
|
|
4
|
+
export const SAFE_FILE_EXTENSION = ".sx";
|
|
5
|
+
/**
|
|
6
|
+
* Postfix appended to game ID when generating encryption passwords
|
|
7
|
+
*/
|
|
8
|
+
export const SAVE_POSTFIX = "txt-game";
|
|
9
|
+
/**
|
|
10
|
+
* Key size in words (256 bits / 32 bits per word = 8 words) for AES encryption
|
|
11
|
+
*/
|
|
12
|
+
export const KEY_SIZE = 256 / 32;
|
|
13
|
+
/**
|
|
14
|
+
* Number of iterations for PBKDF2 key derivation function
|
|
15
|
+
*/
|
|
16
|
+
export const ITERATIONS = 1000;
|
|
17
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/saves/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,GAAG,EAAE,CAAC;AAEjC;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import Dexie, { EntityTable } from "dexie";
|
|
2
|
+
import { GameSave, GameSettings } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Special save name used for the system initial state.
|
|
5
|
+
* This save is marked as a system save and won't be shown in the UI.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SYSTEM_SAVE_NAME: "__SYSTEM_INITIAL_STATE__";
|
|
8
|
+
/**
|
|
9
|
+
* Dexie database class for managing game saves and settings.
|
|
10
|
+
* Uses IndexedDB for browser-based persistent storage.
|
|
11
|
+
*/
|
|
12
|
+
export declare class GameDatabase extends Dexie {
|
|
13
|
+
/** Table for storing game saves */
|
|
14
|
+
saves: EntityTable<GameSave, "id">;
|
|
15
|
+
/** Table for storing game settings */
|
|
16
|
+
settings: EntityTable<GameSettings, "id">;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new GameDatabase instance
|
|
19
|
+
* @param gameId - Unique identifier for the game, used as database name prefix
|
|
20
|
+
*/
|
|
21
|
+
constructor(gameId: string);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the database instance for a specific game ID
|
|
25
|
+
* @param gameId - The unique identifier for the game
|
|
26
|
+
* @returns GameDatabase instance
|
|
27
|
+
*/
|
|
28
|
+
export declare function getGameDatabase(gameId: string): GameDatabase;
|
|
29
|
+
/**
|
|
30
|
+
* Get the default database instance for the current game
|
|
31
|
+
* @returns GameDatabase instance for the current game
|
|
32
|
+
*/
|
|
33
|
+
export declare function getDatabase(): GameDatabase;
|
|
34
|
+
/**
|
|
35
|
+
* Default database instance for the current game.
|
|
36
|
+
* Automatically uses the game ID from game options.
|
|
37
|
+
*/
|
|
38
|
+
export declare const db: GameDatabase;
|
|
39
|
+
/**
|
|
40
|
+
* Save game data to the database
|
|
41
|
+
* @param name - Name of the save (e.g., slot number or custom name)
|
|
42
|
+
* @param gameData - Game state data to save
|
|
43
|
+
* @param description - Optional description
|
|
44
|
+
* @param screenshot - Optional base64 encoded screenshot
|
|
45
|
+
* @returns Promise<number> - The ID of the save
|
|
46
|
+
*/
|
|
47
|
+
export declare function saveGame(name: string | number, gameData: Record<string, unknown>, description?: string, screenshot?: string): Promise<number>;
|
|
48
|
+
/**
|
|
49
|
+
* Load game data from the database
|
|
50
|
+
* @param id - ID of the save to load
|
|
51
|
+
* @returns Promise<GameSave | undefined> - The save data or undefined if not found
|
|
52
|
+
*/
|
|
53
|
+
export declare function loadGame(id: number): Promise<GameSave | undefined>;
|
|
54
|
+
/**
|
|
55
|
+
* Load a game save by its name
|
|
56
|
+
* @param name - Name of the save to load
|
|
57
|
+
* @returns Promise<GameSave | undefined> - The save data or undefined if not found
|
|
58
|
+
*/
|
|
59
|
+
export declare function loadGameByName(name: string): Promise<GameSave | undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves all saved games from the database (excluding system saves).
|
|
62
|
+
*
|
|
63
|
+
* @return {Promise<GameSave[]>} A promise that resolves to an array of game save objects.
|
|
64
|
+
*/
|
|
65
|
+
export declare function getAllSaves(): Promise<GameSave[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Delete a save
|
|
68
|
+
* @param id - ID of the save to delete
|
|
69
|
+
* @returns Promise<void>
|
|
70
|
+
*/
|
|
71
|
+
export declare function deleteSave(id: number): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Set a game setting
|
|
74
|
+
* @param key - Setting key
|
|
75
|
+
* @param value - Setting value
|
|
76
|
+
* @returns Promise<number> - The ID of the setting
|
|
77
|
+
*/
|
|
78
|
+
export declare function setSetting(key: string, value: string | number | boolean | object): Promise<number>;
|
|
79
|
+
/**
|
|
80
|
+
* Deletes all game save data from the database.
|
|
81
|
+
*
|
|
82
|
+
* This method clears all records within the "saves" table or collection,
|
|
83
|
+
* resulting in the complete removal of stored game save data.
|
|
84
|
+
*
|
|
85
|
+
* @return {Promise<void>} A promise that resolves when the game save data has been successfully deleted.
|
|
86
|
+
*/
|
|
87
|
+
export declare function deleteAllGameSaves(): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Get a game setting
|
|
90
|
+
* @param key - Setting key
|
|
91
|
+
* @param defaultValue - Default value if setting doesn't exist
|
|
92
|
+
* @returns Promise<T> - The setting value or default value
|
|
93
|
+
*/
|
|
94
|
+
export declare function getSetting<T>(key: string, defaultValue: T): Promise<T>;
|
|
95
|
+
/**
|
|
96
|
+
* Get all settings as a key-value object
|
|
97
|
+
* @returns Promise<Record<string, any>> - Object with all settings
|
|
98
|
+
*/
|
|
99
|
+
export declare function getAllSettings(): Promise<Record<string, string | number | boolean | object>>;
|
|
100
|
+
/**
|
|
101
|
+
* Delete a setting
|
|
102
|
+
* @param key - Setting key to delete
|
|
103
|
+
* @returns Promise<void>
|
|
104
|
+
*/
|
|
105
|
+
export declare function deleteSetting(key: string): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Retrieves the system save from the database.
|
|
108
|
+
*
|
|
109
|
+
* @return {Promise<GameSave | undefined>} A promise that resolves to the system save or undefined if not found.
|
|
110
|
+
*/
|
|
111
|
+
export declare function getSystemSave(): Promise<GameSave | undefined>;
|
|
112
|
+
/**
|
|
113
|
+
* Creates or updates the system save with the provided game data.
|
|
114
|
+
*
|
|
115
|
+
* @param {Record<string, unknown>} gameData - The game state data to save as the system initial state.
|
|
116
|
+
* @return {Promise<number>} A promise that resolves to the ID of the system save.
|
|
117
|
+
*/
|
|
118
|
+
export declare function createOrUpdateSystemSave(gameData: Record<string, unknown>): Promise<number>;
|
|
119
|
+
//# sourceMappingURL=db.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/saves/db.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAI3C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAG,0BAAmC,CAAC;AAEpE;;;GAGG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACnC,mCAAmC;IACnC,KAAK,EAAG,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACpC,sCAAsC;IACtC,QAAQ,EAAG,WAAW,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAE3C;;;OAGG;gBACS,MAAM,EAAE,MAAM;CAc7B;AAOD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAM5D;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,YAAY,CAE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M,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9D;AAED;;;;GAIG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAEnE;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC1C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,OAAO,CAAC,MAAM,CAAC,CAuBjB"}
|
package/dist/saves/db.js
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import Dexie from "dexie";
|
|
2
|
+
import { _getOptions } from "../options";
|
|
3
|
+
/**
|
|
4
|
+
* Special save name used for the system initial state.
|
|
5
|
+
* This save is marked as a system save and won't be shown in the UI.
|
|
6
|
+
*/
|
|
7
|
+
export const SYSTEM_SAVE_NAME = "__SYSTEM_INITIAL_STATE__";
|
|
8
|
+
/**
|
|
9
|
+
* Dexie database class for managing game saves and settings.
|
|
10
|
+
* Uses IndexedDB for browser-based persistent storage.
|
|
11
|
+
*/
|
|
12
|
+
export class GameDatabase extends Dexie {
|
|
13
|
+
/** Table for storing game saves */
|
|
14
|
+
saves;
|
|
15
|
+
/** Table for storing game settings */
|
|
16
|
+
settings;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new GameDatabase instance
|
|
19
|
+
* @param gameId - Unique identifier for the game, used as database name prefix
|
|
20
|
+
*/
|
|
21
|
+
constructor(gameId) {
|
|
22
|
+
super(`${gameId}-gamedb`);
|
|
23
|
+
this.version(1).stores({
|
|
24
|
+
saves: "++id, name, timestamp", // Auto-incrementing id, indexed name and timestamp
|
|
25
|
+
settings: "++id, &key, timestamp", // Auto-incrementing id, unique key, indexed timestamp
|
|
26
|
+
});
|
|
27
|
+
// Migration to version 2: Add isSystemSave field
|
|
28
|
+
this.version(2).stores({
|
|
29
|
+
saves: "++id, name, timestamp, isSystemSave", // Add isSystemSave to indexed fields
|
|
30
|
+
settings: "++id, &key, timestamp",
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Cache for database instances to prevent creating multiple instances for the same game ID
|
|
36
|
+
*/
|
|
37
|
+
const dbCache = new Map();
|
|
38
|
+
/**
|
|
39
|
+
* Get the database instance for a specific game ID
|
|
40
|
+
* @param gameId - The unique identifier for the game
|
|
41
|
+
* @returns GameDatabase instance
|
|
42
|
+
*/
|
|
43
|
+
export function getGameDatabase(gameId) {
|
|
44
|
+
if (!dbCache.has(gameId)) {
|
|
45
|
+
const db = new GameDatabase(gameId);
|
|
46
|
+
dbCache.set(gameId, db);
|
|
47
|
+
}
|
|
48
|
+
return dbCache.get(gameId);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get the default database instance for the current game
|
|
52
|
+
* @returns GameDatabase instance for the current game
|
|
53
|
+
*/
|
|
54
|
+
export function getDatabase() {
|
|
55
|
+
return getGameDatabase(_getOptions().gameId);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Default database instance for the current game.
|
|
59
|
+
* Automatically uses the game ID from game options.
|
|
60
|
+
*/
|
|
61
|
+
export const db = getDatabase();
|
|
62
|
+
/**
|
|
63
|
+
* Save game data to the database
|
|
64
|
+
* @param name - Name of the save (e.g., slot number or custom name)
|
|
65
|
+
* @param gameData - Game state data to save
|
|
66
|
+
* @param description - Optional description
|
|
67
|
+
* @param screenshot - Optional base64 encoded screenshot
|
|
68
|
+
* @returns Promise<number> - The ID of the save
|
|
69
|
+
*/
|
|
70
|
+
export async function saveGame(name, gameData, description, screenshot) {
|
|
71
|
+
// Create new save with the given name
|
|
72
|
+
const id = await db.saves.add({
|
|
73
|
+
name: `${name}`,
|
|
74
|
+
gameData,
|
|
75
|
+
timestamp: new Date(),
|
|
76
|
+
version: _getOptions().gameVersion,
|
|
77
|
+
description: String(description),
|
|
78
|
+
screenshot: String(screenshot),
|
|
79
|
+
});
|
|
80
|
+
if (id === undefined) {
|
|
81
|
+
throw new Error("Failed to save game");
|
|
82
|
+
}
|
|
83
|
+
return id;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Load game data from the database
|
|
87
|
+
* @param id - ID of the save to load
|
|
88
|
+
* @returns Promise<GameSave | undefined> - The save data or undefined if not found
|
|
89
|
+
*/
|
|
90
|
+
export async function loadGame(id) {
|
|
91
|
+
return db.saves.where({ name: `${id}` }).first();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Load a game save by its name
|
|
95
|
+
* @param name - Name of the save to load
|
|
96
|
+
* @returns Promise<GameSave | undefined> - The save data or undefined if not found
|
|
97
|
+
*/
|
|
98
|
+
export async function loadGameByName(name) {
|
|
99
|
+
return db.saves.where("name").equals(name).first();
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Retrieves all saved games from the database (excluding system saves).
|
|
103
|
+
*
|
|
104
|
+
* @return {Promise<GameSave[]>} A promise that resolves to an array of game save objects.
|
|
105
|
+
*/
|
|
106
|
+
export async function getAllSaves() {
|
|
107
|
+
return db.saves.filter((save) => !save.isSystemSave).toArray();
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Delete a save
|
|
111
|
+
* @param id - ID of the save to delete
|
|
112
|
+
* @returns Promise<void>
|
|
113
|
+
*/
|
|
114
|
+
export async function deleteSave(id) {
|
|
115
|
+
await db.saves.where({ name: `${id}` }).delete();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Set a game setting
|
|
119
|
+
* @param key - Setting key
|
|
120
|
+
* @param value - Setting value
|
|
121
|
+
* @returns Promise<number> - The ID of the setting
|
|
122
|
+
*/
|
|
123
|
+
export async function setSetting(key, value) {
|
|
124
|
+
// Try to update existing setting first
|
|
125
|
+
const existing = await db.settings.where("key").equals(key).first();
|
|
126
|
+
if (existing) {
|
|
127
|
+
await db.settings.update(existing.id, {
|
|
128
|
+
value,
|
|
129
|
+
timestamp: new Date(),
|
|
130
|
+
version: _getOptions().gameVersion,
|
|
131
|
+
});
|
|
132
|
+
return existing.id;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
// Create new setting
|
|
136
|
+
const id = await db.settings.add({
|
|
137
|
+
key,
|
|
138
|
+
value,
|
|
139
|
+
timestamp: new Date(),
|
|
140
|
+
version: _getOptions().gameVersion,
|
|
141
|
+
});
|
|
142
|
+
if (id === undefined) {
|
|
143
|
+
throw new Error("Failed to create setting");
|
|
144
|
+
}
|
|
145
|
+
return id;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Deletes all game save data from the database.
|
|
150
|
+
*
|
|
151
|
+
* This method clears all records within the "saves" table or collection,
|
|
152
|
+
* resulting in the complete removal of stored game save data.
|
|
153
|
+
*
|
|
154
|
+
* @return {Promise<void>} A promise that resolves when the game save data has been successfully deleted.
|
|
155
|
+
*/
|
|
156
|
+
export async function deleteAllGameSaves() {
|
|
157
|
+
const systemSave = await getSystemSave();
|
|
158
|
+
await db.saves.clear();
|
|
159
|
+
if (systemSave) {
|
|
160
|
+
await createOrUpdateSystemSave(systemSave.gameData);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Get a game setting
|
|
165
|
+
* @param key - Setting key
|
|
166
|
+
* @param defaultValue - Default value if setting doesn't exist
|
|
167
|
+
* @returns Promise<T> - The setting value or default value
|
|
168
|
+
*/
|
|
169
|
+
export async function getSetting(key, defaultValue) {
|
|
170
|
+
const setting = await db.settings.where("key").equals(key).first();
|
|
171
|
+
return setting ? setting.value : defaultValue;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get all settings as a key-value object
|
|
175
|
+
* @returns Promise<Record<string, any>> - Object with all settings
|
|
176
|
+
*/
|
|
177
|
+
export async function getAllSettings() {
|
|
178
|
+
const settings = await db.settings.toArray();
|
|
179
|
+
const result = {};
|
|
180
|
+
for (const setting of settings) {
|
|
181
|
+
result[setting.key] = setting.value;
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Delete a setting
|
|
187
|
+
* @param key - Setting key to delete
|
|
188
|
+
* @returns Promise<void>
|
|
189
|
+
*/
|
|
190
|
+
export async function deleteSetting(key) {
|
|
191
|
+
await db.settings.where("key").equals(key).delete();
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Retrieves the system save from the database.
|
|
195
|
+
*
|
|
196
|
+
* @return {Promise<GameSave | undefined>} A promise that resolves to the system save or undefined if not found.
|
|
197
|
+
*/
|
|
198
|
+
export async function getSystemSave() {
|
|
199
|
+
return db.saves.where("name").equals(SYSTEM_SAVE_NAME).first();
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Creates or updates the system save with the provided game data.
|
|
203
|
+
*
|
|
204
|
+
* @param {Record<string, unknown>} gameData - The game state data to save as the system initial state.
|
|
205
|
+
* @return {Promise<number>} A promise that resolves to the ID of the system save.
|
|
206
|
+
*/
|
|
207
|
+
export async function createOrUpdateSystemSave(gameData) {
|
|
208
|
+
const existingSave = await getSystemSave();
|
|
209
|
+
if (existingSave?.id) {
|
|
210
|
+
await db.saves.update(existingSave.id, {
|
|
211
|
+
gameData,
|
|
212
|
+
timestamp: new Date(),
|
|
213
|
+
version: _getOptions().gameVersion,
|
|
214
|
+
});
|
|
215
|
+
return existingSave.id;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
const id = await db.saves.add({
|
|
219
|
+
name: SYSTEM_SAVE_NAME,
|
|
220
|
+
gameData,
|
|
221
|
+
timestamp: new Date(),
|
|
222
|
+
version: _getOptions().gameVersion,
|
|
223
|
+
isSystemSave: true,
|
|
224
|
+
});
|
|
225
|
+
if (id === undefined) {
|
|
226
|
+
throw new Error("Failed to create system save");
|
|
227
|
+
}
|
|
228
|
+
return id;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=db.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.js","sourceRoot":"","sources":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,MAAM,CAAC,YAAY,CAAC,EAAE,EAAE;YACnC,QAAQ;YACR,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,OAAO,EAAE,WAAW,EAAE,CAAC,WAAW;SACrC,CAAC,CAAC;QACH,OAAO,YAAY,CAAC,EAAE,CAAC;IAC3B,CAAC;SAAM,CAAC;QACJ,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC;YAC1B,IAAI,EAAE,gBAAgB;YACtB,QAAQ;YACR,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,OAAO,EAAE,WAAW,EAAE,CAAC,WAAW;YAClC,YAAY,EAAE,IAAI;SACrB,CAAC,CAAC;QACH,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,EAAE,CAAC;IACd,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes (encrypts) data using AES encryption with PBKDF2 key derivation.
|
|
3
|
+
* The output is a byte array that can be saved to a file.
|
|
4
|
+
*
|
|
5
|
+
* @template T - Type of data to encode
|
|
6
|
+
* @param data - Data to encrypt
|
|
7
|
+
* @returns Uint8Array containing encrypted data with salt and IV prepended
|
|
8
|
+
*/
|
|
9
|
+
export declare const encodeSf: <T>(data: T) => Uint8Array<ArrayBuffer>;
|
|
10
|
+
/**
|
|
11
|
+
* Decodes (decrypts) data that was encrypted using encodeSf.
|
|
12
|
+
* Extracts salt and IV from the encrypted data and uses them to decrypt.
|
|
13
|
+
*
|
|
14
|
+
* @template T - Expected type of the decrypted data
|
|
15
|
+
* @param data - ArrayBuffer containing encrypted data
|
|
16
|
+
* @returns Decrypted data of type T
|
|
17
|
+
* @throws Error if decryption fails (corrupted data or password mismatch)
|
|
18
|
+
*/
|
|
19
|
+
export declare const decodeSf: <T>(data: ArrayBuffer) => T;
|
|
20
|
+
/**
|
|
21
|
+
* Formats a Date object into a human-readable string.
|
|
22
|
+
* Format: "DD of MONTH, YYYY HH:MM" (24-hour format)
|
|
23
|
+
*
|
|
24
|
+
* @param timestamp - Date to format
|
|
25
|
+
* @returns Formatted date string (e.g., "15 of January, 2025 14:30")
|
|
26
|
+
*/
|
|
27
|
+
export declare const getDateString: (timestamp: Date) => string;
|
|
28
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/saves/helpers.ts"],"names":[],"mappings":"AAYA;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,MAAM,CAAC,4BAkBlC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,MAAM,WAAW,KAAG,CA6B/C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAI,WAAW,IAAI,WAY5C,CAAC"}
|