bc-deeplib 1.1.3 → 1.2.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 CHANGED
@@ -1,2 +1,26 @@
1
- ## Deep Lib
2
- Package for easier development of BC mods.
1
+ # ${{\color{#440171}\Large{\textsf{DeepLib}}}}$
2
+ ## Active development (there might be a lot of breaking changes)
3
+
4
+ ## What is DeepLib?
5
+
6
+ DeepLib is an opinionated library for easier development of BC mods, which strives to be a framework :D
7
+
8
+ ## What it has to offer
9
+
10
+ * **Mod Initialization**: The `initMod()` function allows you to initialize a mod, which includes setting up the Mod SDK, initializing localization, and registering modules and migrators.
11
+
12
+ * **Modules**: provides a modular architecture, allowing you to create modules for different aspects of your mod.
13
+
14
+ * **Settings GUI**: provides an easily configurable HTML-based GUI system for creating different sorts of settings screens with a lot of built-in features.
15
+
16
+ * **Localization**: provides a localization system for creating different languages for your mod.
17
+
18
+ * **Migrators**: provides a migrator system for creating different migrations for your mod for easy transition between versions.
19
+
20
+ * **Hidden Events**: provides a hidden event system for sending and listening to events with help of `EventChannel`.
21
+
22
+ * **Out-Of-Box Themed Support**: custom elements support Themed customizations.
23
+
24
+ * **Build System**: provides a build system for easily building your mod with `esbuild`.
25
+
26
+ Take a look at [QUICKSTART.md](docs/QUICKSTART.md) for more information on how to get started.
package/dist/deeplib.d.ts CHANGED
@@ -153,6 +153,7 @@ declare module 'bc-deeplib/base/base_subscreen' {
153
153
  get pageStructure(): SettingElement[][];
154
154
  /** Gets the currently visible page's settings elements. */
155
155
  get currentPage(): SettingElement[];
156
+ getPageLabel(): string;
156
157
  /**
157
158
  * Changes the visible page in a multi-page subscreen.
158
159
  * Automatically wraps around when going past the first or last page.
@@ -214,20 +215,13 @@ declare module 'bc-deeplib/base/elements_typings' {
214
215
  position?: [x: number, y: number] | (() => [x: number, y: number]);
215
216
  disabled?: boolean | (() => boolean);
216
217
  };
217
- type CustomButtonOptions = {
218
- id?: Parameters<typeof ElementButton.Create>[0];
218
+ export type Button = Omit<BaseElementModel, 'id'> & {
219
+ id: Parameters<typeof ElementButton.Create>[0];
220
+ type: 'button';
219
221
  onClick?: Parameters<typeof ElementButton.Create>[1];
220
222
  options?: Parameters<typeof ElementButton.Create>[2];
221
223
  htmlOptions?: Parameters<typeof ElementButton.Create>[3];
222
224
  };
223
- export type Button = BaseElementModel & {
224
- type: 'button';
225
- image?: string;
226
- label?: string;
227
- tooltip?: string;
228
- onClick?: () => void;
229
- htmlOptions?: CustomButtonOptions;
230
- };
231
225
  export type Checkbox = BaseElementModel & {
232
226
  type: 'checkbox';
233
227
  label?: string;
@@ -254,7 +248,6 @@ declare module 'bc-deeplib/base/elements_typings' {
254
248
  type: 'custom';
255
249
  htmlOptions: HTMLOptions<keyof HTMLElementTagNameMap>;
256
250
  };
257
- export {};
258
251
 
259
252
  }
260
253
  declare module 'bc-deeplib/base/initialization' {
@@ -300,6 +293,11 @@ declare module 'bc-deeplib/base/initialization' {
300
293
  * Initialized by `initMod()` and mod data loaded by `init()`.
301
294
  */
302
295
  export let modStorage: ModStorage;
296
+ /**
297
+ * Global Mod SDK manager.
298
+ * Initialized by `initMod()`.
299
+ */
300
+ export let sdk: ModSdkManager;
303
301
  /**
304
302
  * Entry point for initializing a mod. Handles:
305
303
  * - Setting up the Mod SDK
@@ -307,9 +305,7 @@ declare module 'bc-deeplib/base/initialization' {
307
305
  * - Injecting required styles
308
306
  * - Delaying initialization until login (if necessary)
309
307
  */
310
- export function initMod(options: InitOptions): {
311
- sdk: ModSdkManager;
312
- };
308
+ export function initMod(options: InitOptions): void;
313
309
  /**
314
310
  * Fully initializes the mod after login.
315
311
  * Handles:
@@ -415,6 +411,7 @@ declare module 'bc-deeplib/deeplib' {
415
411
  export * from 'bc-deeplib/utilities/sdk';
416
412
  export * from 'bc-deeplib/utilities/style';
417
413
  export * from 'bc-deeplib/utilities/translation';
414
+ export * from 'bc-deeplib/utilities/event_channel';
418
415
 
419
416
  }
420
417
  declare module 'bc-deeplib/migrators/base_migrator' {
@@ -694,6 +691,10 @@ declare module 'bc-deeplib/screens/main_menu' {
694
691
  * Provides tools to import or export data to or from the mod.
695
692
  */
696
693
  importExportSubscreen?: GuiImportExport;
694
+ /**
695
+ * Optional boolean flag to enable the mod storage fullness indicator.
696
+ */
697
+ storageFullnessIndicator?: boolean;
697
698
  };
698
699
  export class MainMenu extends BaseSubscreen {
699
700
  subscreens: BaseSubscreen[];
@@ -739,6 +740,10 @@ declare module 'bc-deeplib/utilities/common' {
739
740
  export function hasGetter<T extends object>(obj: T, prop: keyof T | string): boolean;
740
741
  /** Checks if the given property has a setter defined on the object or its prototype chain. */
741
742
  export function hasSetter<T extends object>(obj: T, prop: keyof T | string): boolean;
743
+ /**
744
+ * Converts bytes to kilobytes.
745
+ */
746
+ export const byteToKB: (nByte: number) => number;
742
747
 
743
748
  }
744
749
  declare module 'bc-deeplib/utilities/data' {
@@ -768,6 +773,7 @@ declare module 'bc-deeplib/utilities/data' {
768
773
  save(): void;
769
774
  static dataDecompress<T = object>(string: string): T | null;
770
775
  static dataCompress(object: object): string;
776
+ static measureSize(data: unknown): number;
771
777
  }
772
778
 
773
779
  }
@@ -832,7 +838,7 @@ declare module 'bc-deeplib/utilities/elements/elements' {
832
838
  };
833
839
  export type ModalOptions<T extends string = string> = {
834
840
  /** Content or DOM node displayed in the modal header. */
835
- prompt: string | Node;
841
+ prompt: ElementButton.StaticNode;
836
842
  /** Optional input configuration. */
837
843
  input?: ModalInputOptions;
838
844
  /** Buttons to display in the modal. */
@@ -841,6 +847,10 @@ declare module 'bc-deeplib/utilities/elements/elements' {
841
847
  closeOnBackdrop?: boolean;
842
848
  /** Auto-close timeout in milliseconds. */
843
849
  timeoutMs?: number;
850
+ /** Action sent when Escape key is pressed. */
851
+ escapeAction?: T;
852
+ /** Action sent when Enter key is pressed. */
853
+ enterAction?: T;
844
854
  };
845
855
  /**
846
856
  * Modal dialog implementation with queuing, buttons, optional input, and focus trapping.
@@ -864,17 +874,17 @@ declare module 'bc-deeplib/utilities/elements/elements' {
864
874
  /**
865
875
  * Shows a simple alert modal with a single "OK" button.
866
876
  */
867
- static alert(msg: string, timeoutMs?: number): Promise<void>;
877
+ static alert(msg: ElementButton.StaticNode, timeoutMs?: number): Promise<void>;
868
878
  /**
869
879
  * Shows a confirmation modal with "Cancel" and "OK" buttons.
870
880
  * Returns true if "OK" is clicked.
871
881
  */
872
- static confirm(msg: string): Promise<boolean>;
882
+ static confirm(msg: ElementButton.StaticNode): Promise<boolean>;
873
883
  /**
874
884
  * Shows a prompt modal with an input field and "Submit"/"Cancel" buttons.
875
885
  * Returns the input value if submitted, otherwise null.
876
886
  */
877
- static prompt(msg: string, defaultValue?: string): Promise<string | null>;
887
+ static prompt(msg: ElementButton.StaticNode, defaultValue?: string): Promise<string | null>;
878
888
  /** Creates the input element for the modal, applying configuration and validation. */
879
889
  private renderInput;
880
890
  /** Creates modal action buttons from configuration. */
@@ -971,6 +981,45 @@ declare module 'bc-deeplib/utilities/elements/layout' {
971
981
  function elementRemoveMiscDiv(): void | undefined;
972
982
  export {};
973
983
 
984
+ }
985
+ declare module 'bc-deeplib/utilities/event_channel' {
986
+ type DeepLibMessageDictionaryEntry<Type extends string, Data> = {
987
+ type: Type;
988
+ data: Data;
989
+ };
990
+ type Listener<Payload> = (data: Payload, sender: Character) => void;
991
+ export interface UnverifiedMessage extends ServerChatRoomMessageBase {
992
+ Target?: number;
993
+ Content: ServerChatRoomMessageContentType;
994
+ Type: ServerChatRoomMessageType;
995
+ Dictionary?: {
996
+ type: string;
997
+ data?: any;
998
+ }[];
999
+ Timeout?: number;
1000
+ }
1001
+ export interface EventChannelMessage<TEvents extends Record<string, unknown> = Record<string, unknown>, TEvent extends keyof TEvents & string = keyof TEvents & string> extends ServerChatRoomMessageBase {
1002
+ Target?: number;
1003
+ Content: string;
1004
+ Type: 'Hidden';
1005
+ Dictionary: [
1006
+ DeepLibMessageDictionaryEntry<TEvent, TEvents[TEvent]>
1007
+ ];
1008
+ Timeout?: number;
1009
+ Sender: number;
1010
+ }
1011
+ export class EventChannel<TEvents extends Record<string, unknown>, TChannelName extends string> {
1012
+ private channelName;
1013
+ private listeners;
1014
+ constructor(channelName: TChannelName);
1015
+ unload(): void;
1016
+ sendEvent<K extends keyof TEvents & string>(type: K, data: TEvents[K], target?: number | null): void;
1017
+ registerListener<K extends keyof TEvents & string>(event: K, listener: Listener<TEvents[K]>): () => void;
1018
+ unregisterListener<K extends keyof TEvents & string>(event: K, listener: Listener<TEvents[K]>): void;
1019
+ private isChannelMessage;
1020
+ }
1021
+ export {};
1022
+
974
1023
  }
975
1024
  declare module 'bc-deeplib/utilities/logger' {
976
1025
  type LogLevel = 'info' | 'log' | 'warn' | 'error' | 'debug';