bc-deeplib 1.1.0 → 1.1.2

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/dist/deeplib.d.ts CHANGED
@@ -1,15 +1,82 @@
1
1
  declare module 'bc-deeplib/base/base_module' {
2
2
  import { BaseSettingsModel, Subscreen } from 'bc-deeplib/deeplib';
3
+ /**
4
+ * An abstract foundation for modular systems that require:
5
+ * - Optional settings screens
6
+ * - Persistent settings storage per module
7
+ * - Default settings registration
8
+ * - Lifecycle hooks for loading, running, and unloading
9
+ *
10
+ * ### Responsibilities
11
+ * This class defines the base contract for all modules in the system:
12
+ * - Provides a standardized interface for retrieving and storing settings
13
+ * - Ensures default settings are registered if missing
14
+ * - Integrates with the module storage system (`modStorage`)
15
+ * - Offers overridable lifecycle methods (`init`, `load`, `run`, `unload`)
16
+ *
17
+ * **Subclass Requirements:**
18
+ * - Must extend `BaseModule`
19
+ * - Should override `defaultSettings` to define defaults for its settings, if any
20
+ * - May override `settingsScreen` to provide a UI component
21
+ * - May override lifecycle methods as needed
22
+ */
3
23
  export abstract class BaseModule {
24
+ /**
25
+ * An optional UI screen for configuring this module's settings.
26
+ * Subclasses can override this getter to provide a `Subscreen` instance.
27
+ * Modules with screens are automatically registered to the main menu.
28
+ */
4
29
  get settingsScreen(): Subscreen | null;
30
+ /**
31
+ * The storage key under which this module's settings will be saved.
32
+ * Defaults to the class name.
33
+ *
34
+ * Subclasses can override this if they require a custom storage key.
35
+ */
5
36
  get settingsStorage(): string | null;
37
+ /**
38
+ * Retrieves the current settings for this module.
39
+ * If no settings exist yet, registers default settings first.
40
+ */
6
41
  get settings(): BaseSettingsModel;
42
+ /**
43
+ * Persists new settings for this module.
44
+ * Automatically initializes storage and defaults if they don't exist.
45
+ */
7
46
  set settings(value: BaseSettingsModel);
47
+ /**
48
+ * Initializes the module.
49
+ * Default implementation registers default settings immediately.
50
+ * Subclasses can override to perform additional setup.
51
+ */
8
52
  init(): void;
53
+ /**
54
+ * Registers default settings for this module in persistent storage.
55
+ * Only runs if a storage key and default settings are defined.
56
+ *
57
+ * If some settings already exist, they will be merged with defaults.
58
+ * Existing values will NOT be overwritten.
59
+ */
9
60
  registerDefaultSettings(): void;
61
+ /**
62
+ * Provides default settings for this module.
63
+ * Subclasses should override this getter to return their defaults.
64
+ */
10
65
  get defaultSettings(): BaseSettingsModel | null;
66
+ /**
67
+ * Called when the module is loaded into the system.
68
+ * Subclasses should override to perform data loading or initialization.
69
+ */
11
70
  load(): void;
71
+ /**
72
+ * By default doesn't get called each frame, only once when the module is loaded.
73
+ * Subclasses can override to implement runtime logic.
74
+ */
12
75
  run(): void;
76
+ /**
77
+ * Called when the module is being removed.
78
+ * Subclasses can override to perform cleanup or save final state.
79
+ */
13
80
  unload(): void;
14
81
  }
15
82
 
@@ -17,33 +84,125 @@ declare module 'bc-deeplib/base/base_module' {
17
84
  declare module 'bc-deeplib/base/base_subscreen' {
18
85
  import { BaseModule, BaseSettingsModel } from 'bc-deeplib/deeplib';
19
86
  import { SettingElement } from 'bc-deeplib/base/elements_typings';
87
+ /** Optional configuration flags for a `BaseSubscreen` instance. */
20
88
  type SubscreenOptions = {
89
+ /**
90
+ * If `true`, the subscreen will draw the player's character model
91
+ * in the UI when `run()` is called.
92
+ * Also shift the UI to the right to make room for the character.
93
+ */
21
94
  drawCharacter?: boolean;
22
95
  };
96
+ /**
97
+ * Represents a constructor type for a subscreen.
98
+ * Allows dynamic instantiation of subscreen classes with optional
99
+ * configuration options and a parent module reference.
100
+ */
23
101
  export type Subscreen = new (subscreenOptions?: SubscreenOptions, module?: BaseModule) => BaseSubscreen;
102
+ /** Retrieves the currently active subscreen from the global `GUI` instance. */
24
103
  export function getCurrentSubscreen(): BaseSubscreen | null;
104
+ /** Switches the active subscreen in the global `GUI` instance. */
25
105
  export function setSubscreen(subscreen: BaseSubscreen | string | null): BaseSubscreen | null;
106
+ /**
107
+ * Abstract base class for creating settings/configuration subscreens in a module.
108
+ *
109
+ * ### Responsibilities
110
+ * This class defines the base contract for all modules in the system:
111
+ * - Provides a standardized interface for retrieving and storing settings
112
+ * - Ensures default settings are registered if missing
113
+ * - Integrates with the module storage system (`modStorage`)
114
+ * - Offers overridable lifecycle methods (`init`, `load`, `run`, `unload`)
115
+ *
116
+ * **Subclass Requirements:**
117
+ * - Must extend `BaseSubscreen`
118
+ * - Should override `name`, `icon` to define subscreen metadata
119
+ * - May override `pageStructure` to define UI layout and controls
120
+ * - May override lifecycle methods as needed
121
+ */
26
122
  export abstract class BaseSubscreen {
123
+ /** Global registry of currently rendered elements and their definitions. */
27
124
  static currentElements: [HTMLElement, SettingElement][];
125
+ /** Tracks the currently visible page number (1-based index). */
28
126
  static currentPage: number;
127
+ /** Runtime options for this subscreen. */
29
128
  readonly options: SubscreenOptions;
129
+ /** Reference to the module this subscreen belongs to. */
30
130
  readonly module: BaseModule;
31
131
  constructor(subscreenOptions?: SubscreenOptions, module?: BaseModule);
132
+ /**
133
+ * Logical name of this subscreen.
134
+ * Used for localization key resolution in `load()`.
135
+ * Subclasses should override this with a meaningful identifier.
136
+ */
32
137
  get name(): string;
138
+ /**
139
+ * Path to or Base64 data for an icon representing this subscreen.
140
+ * Defaults to empty string (no icon).
141
+ */
33
142
  get icon(): string;
34
- get subscreenName(): string;
143
+ /** Changes the currently active subscreen. */
35
144
  setSubscreen(screen: BaseSubscreen | string | null): BaseSubscreen | null;
145
+ /** Gets this subscreen's settings object from its parent module. */
36
146
  get settings(): BaseSettingsModel;
147
+ /** Updates this subscreen's settings in its parent module. */
37
148
  set settings(value: BaseSettingsModel);
149
+ /**
150
+ * Defines the paginated layout of the subscreen's settings UI.
151
+ * Each element in the outer array is a page; each page contains `SettingElement`s.
152
+ *
153
+ * Subclasses should override to define their actual UI structure.
154
+ */
38
155
  get pageStructure(): SettingElement[][];
156
+ /** Gets the currently visible page's settings elements. */
39
157
  get currentPage(): SettingElement[];
158
+ /**
159
+ * Changes the visible page in a multi-page subscreen.
160
+ * Automatically wraps around when going past the first or last page.
161
+ */
40
162
  changePage(page: number, setLabel: (label: string) => void): void;
163
+ /**
164
+ * Updates the DOM to show only elements belonging to the current page.
165
+ * All elements on other pages are hidden.
166
+ */
41
167
  managePageElementsVisibility(): void;
168
+ /**
169
+ * Called when this subscreen is first displayed.
170
+ * Builds the layout, initializes navigation, and renders all settings elements.
171
+ *
172
+ * Handles:
173
+ * - Ensuring each module with a settings screen has its defaults loaded
174
+ * - Creating navigation menus and back/next page controls
175
+ * - Building and appending UI elements based on `pageStructure`
176
+ * - Setting up exit button and tooltip
177
+ * - Resetting to page 1
178
+ */
42
179
  load(): void;
180
+ /**
181
+ * Called each frame while this subscreen is active.
182
+ * Default behavior draws the player's character if `drawCharacter` is enabled.
183
+ */
43
184
  run(): void;
185
+ /**
186
+ * Handles mouse clicks *on canvas* while the subscreen is active.
187
+ * Default implementation is empty — subclasses may override.
188
+ */
44
189
  click(): void;
190
+ /**
191
+ * Exits this subscreen, returning to the main menu.
192
+ * Also saves persistent storage changes.
193
+ * Called after the `unload`.
194
+ */
45
195
  exit(): void;
196
+ /**
197
+ * Called when the window is resized.
198
+ * Also checks for overflow in the settings div and applies styling accordingly.
199
+ */
46
200
  resize(onLoad?: boolean): void;
201
+ /**
202
+ * Called when this subscreen is being removed.
203
+ * Resets the static element registry and removes the subscreen from the layout.
204
+ * Called before `exit`.
205
+ */
47
206
  unload(): void;
48
207
  }
49
208
  export {};
@@ -101,33 +260,137 @@ declare module 'bc-deeplib/base/elements_typings' {
101
260
 
102
261
  }
103
262
  declare module 'bc-deeplib/base/initialization' {
104
- import { BaseModule, ModSdkManager, BaseMigrator, ModStorage, MainMenuOptions } from 'bc-deeplib/deeplib';
263
+ import { BaseModule, ModSdkManager, BaseMigrator, ModStorage, MainMenuOptions, TranslationOptions } from 'bc-deeplib/deeplib';
264
+ /** Configuration object for initializing a mod via `initMod`. */
105
265
  interface InitOptions {
266
+ /**
267
+ * Information about the mod being initialized.
268
+ * - `info` — Required metadata describing the mod.
269
+ * - `options` — Optional runtime configuration for the Mod SDK.
270
+ */
106
271
  modInfo: {
107
272
  info: ModSDKModInfo;
108
273
  options?: ModSDKModOptions;
109
274
  };
275
+ /**
276
+ * List of modules (`BaseModule` subclasses) to register with the mod system.
277
+ * Modules are initialized, loaded, and run in order.
278
+ */
110
279
  modules?: BaseModule[];
280
+ /**
281
+ * List of data migration handlers to register with the `VersionModule`.
282
+ * Each `BaseMigrator` handles upgrading data from one version to another.
283
+ */
111
284
  migrators?: BaseMigrator[];
285
+ /** Configuration for customizing the main menu when the mod is active. */
112
286
  mainMenuOptions?: MainMenuOptions;
287
+ /**
288
+ * Optional hook executed *before* login when the player is not yet authenticated.
289
+ * Useful for pre-login setup or display changes.
290
+ */
113
291
  beforeLogin?: () => (void);
292
+ /**
293
+ * Optional async/sync function run after modules and translations are initialized.
294
+ * Can be used to perform additional setup tasks.
295
+ */
114
296
  initFunction?: () => (void | Promise<void>);
115
- pathToTranslationsFolder?: string;
297
+ /** Options for initializing the localization/translation system. */
298
+ translationOptions?: TranslationOptions;
116
299
  }
300
+ /**
301
+ * Global storage handler for mod.
302
+ * Initialized by `initMod()` and mod data loaded by `init()`.
303
+ */
117
304
  export let modStorage: ModStorage;
305
+ /**
306
+ * Entry point for initializing a mod. Handles:
307
+ * - Setting up the Mod SDK
308
+ * - Preparing persistent storage
309
+ * - Injecting required styles
310
+ * - Delaying initialization until login (if necessary)
311
+ */
118
312
  export function initMod(options: InitOptions): {
119
313
  sdk: ModSdkManager;
120
314
  };
315
+ /**
316
+ * Fully initializes the mod after login.
317
+ * Handles:
318
+ * - Preventing double-load
319
+ * - Loading mod data
320
+ * - Initializing localization
321
+ * - Registering modules and migrators
322
+ * - Running optional init functions
323
+ * - Applying main menu changes
324
+ * - Merging default settings into module settings
325
+ *
326
+ * @param options {InitOptions} Configuration for mod initialization.
327
+ */
121
328
  export function init(options: InitOptions): Promise<void>;
329
+ /**
330
+ * Cleans up and removes the mod from memory.
331
+ * Calls `unload()` on all modules and removes the global loaded flag.
332
+ */
122
333
  export function unloadMod(): true;
123
334
  export {};
124
335
 
125
336
  }
126
337
  declare module 'bc-deeplib/base/modules' {
127
338
  import { BaseModule } from 'bc-deeplib/deeplib';
339
+ /**
340
+ * Global registry of all loaded modules, keyed by their class name.
341
+ *
342
+ * The map is populated via {@link registerModule} and accessed via {@link modules} or {@link getModule}.
343
+ * This is the central storage for active `BaseModule` instances during the mod lifecycle.
344
+ */
128
345
  export const modulesMap: Map<string, BaseModule>;
346
+ /**
347
+ * Retrieves all registered module instances.
348
+ *
349
+ * @returns An array containing every module currently stored in {@link modulesMap}.
350
+ *
351
+ * @remarks
352
+ * The returned array is a **shallow copy** of the `Map` values, meaning that
353
+ * changes to the array do not affect the registry itself.
354
+ *
355
+ * @example
356
+ * ```ts
357
+ * for (const mod of modules()) {
358
+ * mod.run();
359
+ * }
360
+ * ```
361
+ */
129
362
  export function modules(): BaseModule[];
363
+ /**
364
+ * Registers a module instance in the global registry.
365
+ *
366
+ * @returns The same module instance passed in, for chaining or immediate use.
367
+ *
368
+ * @remarks
369
+ * - If a module with the same constructor name already exists, it will be **overwritten**.
370
+ * - Keys are based on the class name (`module.constructor.name`), so name collisions are possible
371
+ * if two different classes share the same name.
372
+ *
373
+ * @example
374
+ * ```ts
375
+ * registerModule(new MyGlobalModule());
376
+ * ```
377
+ */
130
378
  export function registerModule<T extends BaseModule>(module: T): T;
379
+ /**
380
+ * Retrieves a registered module by its type name.
381
+ *
382
+ * @returns The matching module instance cast to type `T`, or `undefined` if not found.
383
+ *
384
+ * @remarks
385
+ * This function does not perform runtime type checks. If the type parameter `T`
386
+ * does not match the actual module type, you may get runtime errors when using the result.
387
+ *
388
+ * @example
389
+ * ```ts
390
+ * const themeModule = getModule<ThemeModule>('ThemeModule');
391
+ * themeModule?.reloadTheme();
392
+ * ```
393
+ */
131
394
  export function getModule<T extends BaseModule>(moduleType: string): T;
132
395
 
133
396
  }
@@ -145,9 +408,9 @@ declare module 'bc-deeplib/deeplib' {
145
408
  export * from 'bc-deeplib/screens/main_menu';
146
409
  export * from 'bc-deeplib/screens/import_export';
147
410
  export * from 'bc-deeplib/utilities/data';
148
- export * from 'bc-deeplib/utilities/elements/advanced_elements';
149
- export * from 'bc-deeplib/utilities/elements/element_helpers';
150
- export * from 'bc-deeplib/utilities/elements/layout_elements';
411
+ export * from 'bc-deeplib/utilities/elements/elements';
412
+ export * from 'bc-deeplib/utilities/elements/helpers';
413
+ export * from 'bc-deeplib/utilities/elements/layout';
151
414
  export * from 'bc-deeplib/utilities/common';
152
415
  export * from 'bc-deeplib/utilities/logger';
153
416
  export * from 'bc-deeplib/utilities/messages';
@@ -157,9 +420,38 @@ declare module 'bc-deeplib/deeplib' {
157
420
 
158
421
  }
159
422
  declare module 'bc-deeplib/migrators/base_migrator' {
423
+ /**
424
+ * Abstract base class for versioned migration handlers.
425
+ *
426
+ * A migrator is responsible for upgrading or transforming stored data
427
+ * when the mod version changes. Each migrator targets a specific version
428
+ * and executes its {@link Migrate} method once when needed.
429
+ *
430
+ * @remarks
431
+ * To create a new migrator:
432
+ * 1. Extend `BaseMigrator`.
433
+ * 2. Implement the {@link MigrationVersion} getter to return the target version string.
434
+ * 3. Implement {@link Migrate} with the migration logic (e.g., data structure changes).
435
+ */
160
436
  export abstract class BaseMigrator {
437
+ /**
438
+ * Gets the target version string for this migration.
439
+ *
440
+ * @remarks
441
+ * - This should exactly match the version format used by the mod
442
+ * - Used by the migration system to determine if this migration should be executed.
443
+ */
161
444
  abstract get MigrationVersion(): string;
162
- abstract Migrate(): boolean;
445
+ /**
446
+ * Executes the migration logic for this version.
447
+ *
448
+ * @remarks
449
+ * - Called once when upgrading from a version earlier than {@link MigrationVersion}.
450
+ * - Should handle any necessary data transformations, cleanup, or initialization
451
+ * to bring the mod's state up to date with the new version.
452
+ * - Must be idempotent — running it multiple times should not cause data corruption.
453
+ */
454
+ abstract Migrate(): void;
163
455
  }
164
456
 
165
457
  }
@@ -239,8 +531,11 @@ declare module 'bc-deeplib/screens/debug' {
239
531
  declare module 'bc-deeplib/screens/import_export' {
240
532
  import { BaseSubscreen } from 'bc-deeplib/deeplib';
241
533
  export type ImportExportOptions = {
534
+ /** A custom save file extension. */
242
535
  customFileExtension: string;
536
+ /** A callback to be called after data is imported. */
243
537
  onImport?: () => void;
538
+ /** A callback to be called after data is exported. */
244
539
  onExport?: () => void;
245
540
  };
246
541
  type DataTransferMethod = 'clipboard' | 'file';
@@ -287,6 +582,7 @@ declare module 'bc-deeplib/utilities/common' {
287
582
  export function deepMerge(target: any, source: any): any;
288
583
  export function shuffleArray(array: string[]): string[];
289
584
  export function exportToGlobal(name: string, value: any): void;
585
+ /** Merges matching properties from `mergeFrom` into `mergeTo`. */
290
586
  export function deepMergeMatchingProperties<T extends object>(mergeTo: T, mergeFrom: T): T;
291
587
  export function hasGetter<T extends object>(obj: T, prop: keyof T | string): boolean;
292
588
  export function hasSetter<T extends object>(obj: T, prop: keyof T | string): boolean;
@@ -311,9 +607,9 @@ declare module 'bc-deeplib/utilities/data' {
311
607
  }
312
608
 
313
609
  }
314
- declare module 'bc-deeplib/utilities/elements/advanced_elements' {
610
+ declare module 'bc-deeplib/utilities/elements/elements' {
315
611
  import { Button, Checkbox, Custom, Input, Label } from 'bc-deeplib/base/elements_typings';
316
- export const advancedElement: {
612
+ export const advElement: {
317
613
  createButton: typeof elementCreateButton;
318
614
  createCheckbox: typeof elementCreateCheckbox;
319
615
  createInput: typeof elementCreateInput;
@@ -362,7 +658,6 @@ declare module 'bc-deeplib/utilities/elements/advanced_elements' {
362
658
  prompt: string | Node;
363
659
  input?: ModalInputOptions;
364
660
  buttons?: ModalButton<T>[];
365
- custom?: readonly (string | Node | HTMLOptions<keyof HTMLElementTagNameMap> | null | undefined)[] | undefined;
366
661
  closeOnBackdrop?: boolean;
367
662
  timeoutMs?: number;
368
663
  };
@@ -384,14 +679,19 @@ declare module 'bc-deeplib/utilities/elements/advanced_elements' {
384
679
  private createBlocker;
385
680
  private setupFocusTrap;
386
681
  private close;
682
+ /**
683
+ * An internal function where we will save promise function.
684
+ */
387
685
  private resolve;
686
+ /** A function that adds a modal to the queue and returns a promise */
388
687
  private static enqueue;
688
+ /** A function that processes the queue, removing the first modal */
389
689
  private static dequeue;
390
690
  }
391
691
  export {};
392
692
 
393
693
  }
394
- declare module 'bc-deeplib/utilities/elements/element_helpers' {
694
+ declare module 'bc-deeplib/utilities/elements/helpers' {
395
695
  import { SettingElement } from 'bc-deeplib/base/elements_typings';
396
696
  export const domUtil: {
397
697
  autoSetPosition: typeof autoSetPosition;
@@ -412,12 +712,12 @@ declare module 'bc-deeplib/utilities/elements/element_helpers' {
412
712
  export {};
413
713
 
414
714
  }
415
- declare module 'bc-deeplib/utilities/elements/layout_elements' {
416
- export const layoutElement: {
417
- createSubscreenDiv: typeof elementCreateSubscreenDiv;
418
- getSubscreenDiv: typeof elementGetSubscreenDiv;
419
- appendToSubscreenDiv: typeof elementAppendToSubscreenDiv;
420
- removeSubscreenDiv: typeof elementRemoveSubscreenDiv;
715
+ declare module 'bc-deeplib/utilities/elements/layout' {
716
+ export const layout: {
717
+ createSubscreen: typeof elementCreateSubscreenDiv;
718
+ getSubscreen: typeof elementGetSubscreenDiv;
719
+ appendToSubscreen: typeof elementAppendToSubscreenDiv;
720
+ removeSubscreen: typeof elementRemoveSubscreenDiv;
421
721
  createSettingsDiv: typeof elementCreateSettingsDiv;
422
722
  getSettingsDiv: typeof elementGetSettingsDiv;
423
723
  appendToSettingsDiv: typeof elementAppendToSettingsDiv;
@@ -513,23 +813,28 @@ declare module 'bc-deeplib/utilities/style' {
513
813
 
514
814
  }
515
815
  declare module 'bc-deeplib/utilities/translation' {
516
- interface InitOptions {
517
- pathToTranslationsFolder: string;
816
+ export interface TranslationOptions {
817
+ /** The path to the folder where the translations are stored. */
818
+ pathToTranslationsFolder?: string;
819
+ /** The default language to use. */
820
+ defaultLanguage?: string;
821
+ /** If true, the localization will be fixed to the default language. */
822
+ fixedLanguage?: boolean;
518
823
  }
519
824
  export class Localization {
520
825
  private static LibTranslation;
521
826
  private static ModTranslation;
522
827
  private static PathToModTranslation;
523
828
  private static PathToLibTranslation;
829
+ private static DefaultLanguage;
524
830
  private static initialized;
525
- static init(initOptions: InitOptions): Promise<void>;
831
+ static init(initOptions?: TranslationOptions): Promise<void>;
526
832
  static getTextMod(srcTag: string): string | undefined;
527
833
  static getTextLib(srcTag: string): string | undefined;
528
834
  private static fetchLanguageFile;
529
835
  private static parseLanguageFile;
530
836
  }
531
837
  export const getText: (srcTag: string) => string;
532
- export {};
533
838
 
534
839
  }
535
840
  declare module 'bc-deeplib' {