bc-deeplib 1.0.3 → 1.0.4

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.
@@ -1,198 +0,0 @@
1
- import { SettingElement } from '../../.types/elements';
2
- import { BaseModule, BaseSettingsModel, SupportHelper, bcSdkMod, dataStore, elementAdjustFontSize, elementAppendToSettingsDiv, elementAppendToSubscreenDiv, elementCreateButton, elementCreateCheckbox, elementCreateInput, elementCreateLabel, elementCreateSettingsDiv, elementCreateSubscreenDiv, elementCreateTooltip, elementGetSettingsDiv, elementGetSubscreenDiv, elementGetTooltip, elementHide, elementRemoveSubscreenDiv, elementSetPosSizeFont, elementSetPosition, elementSetSize, getText, modules, setSubscreen } from '../DeepLib';
3
-
4
- export abstract class BaseSubscreen {
5
- static currentElements: [HTMLElement, SettingElement][] = [];
6
- static currentPage: number = 1;
7
- readonly module!: BaseModule;
8
-
9
- constructor(module?: BaseModule) {
10
- if (module) this.module = module;
11
- }
12
-
13
- get name(): string {
14
- return 'UNKNOWN';
15
- }
16
-
17
- get icon(): string {
18
- return '';
19
- }
20
-
21
- get subscreenName(): string {
22
- return this.constructor.name;
23
- }
24
-
25
- setSubscreen(screen: BaseSubscreen | string | null) {
26
- return setSubscreen(screen);
27
- }
28
-
29
- get settings(): BaseSettingsModel {
30
- return this.module.settings as BaseSettingsModel;
31
- }
32
-
33
- get pageStructure(): SettingElement[][] {
34
- return [[]];
35
- }
36
-
37
- get currentPage(): SettingElement[] {
38
- return this.pageStructure[Math.min(PreferencePageCurrent - 1, this.pageStructure.length - 1)];
39
- }
40
-
41
- hideElements() {
42
- this.pageStructure.forEach((item, ix) => {
43
- if (ix != PreferencePageCurrent - 1) {
44
- item.forEach((setting) => {
45
- elementHide({ elementId: setting.id });
46
- });
47
- }
48
- });
49
- }
50
-
51
- load() {
52
- for (const module of modules()) {
53
- if (!module.settingsScreen) continue;
54
- if (!module.settings || !Object.keys(module.settings).length) module.registerDefaultSettings();
55
- }
56
-
57
- elementCreateSubscreenDiv();
58
- const settingsElement = elementCreateSettingsDiv();
59
- elementAppendToSubscreenDiv(settingsElement);
60
-
61
- const subscreenTitle = elementCreateLabel({
62
- type: 'label',
63
- id: 'deeplib-subscreen-title',
64
- label: getText('mainmenu.title').replace('$ModVersion', bcSdkMod.ModInfo.version) + ' ' + SupportHelper.getSupporter(),
65
- });
66
- elementAppendToSubscreenDiv(subscreenTitle);
67
-
68
- if (this.name !== 'mainmenu') {
69
- const exitButton = elementCreateButton({
70
- type: 'button',
71
- id: 'deeplib-exit',
72
- position: [1815, 75],
73
- size: [90, 90],
74
- image: 'Icons/Exit.png',
75
- onClick: () => {
76
- setSubscreen('mainmenu');
77
- },
78
- tooltip: getText('settings.button.back_button_hint')
79
- });
80
- elementAppendToSubscreenDiv(exitButton);
81
- }
82
-
83
- const tooltip = elementCreateTooltip();
84
- elementAppendToSubscreenDiv(tooltip);
85
-
86
- this.pageStructure.forEach((s) =>
87
- s.forEach((item) => {
88
- let element: HTMLElement;
89
- switch (item.type) {
90
- case 'text':
91
- case 'number':
92
- element = elementCreateInput(item);
93
- break;
94
- case 'checkbox':
95
- element = elementCreateCheckbox(item);
96
- break;
97
- case 'button':
98
- element = elementCreateButton(item);
99
- break;
100
- case 'label':
101
- element = elementCreateLabel(item);
102
- break;
103
- }
104
- elementAppendToSettingsDiv(element);
105
- })
106
- );
107
-
108
- CharacterAppearanceForceUpCharacter = Player.MemberNumber ?? -1;
109
- }
110
-
111
- run() {
112
- const newTitle = getText('mainmenu.title').replace('$ModVersion', bcSdkMod.ModInfo.version) + ' ' + SupportHelper.getSupporter();
113
- const oldTitle = ElementContent('deeplib-subscreen-title');
114
- if (newTitle !== oldTitle) {
115
- ElementContent('deeplib-subscreen-title', newTitle);
116
- }
117
- DrawCharacter(Player, 50, 50, 0.9, false);
118
-
119
- if (this.pageStructure.length > 1) {
120
- MainCanvas.textAlign = 'center';
121
- PreferencePageChangeDraw(1595, 75, this.pageStructure.length);
122
- MainCanvas.textAlign = 'left';
123
- }
124
-
125
- this.hideElements();
126
- }
127
-
128
- click() {
129
- if (this.pageStructure.length > 1) PreferencePageChangeClick(1595, 75, this.pageStructure.length);
130
- }
131
-
132
- exit() {
133
- CharacterAppearanceForceUpCharacter = -1;
134
- CharacterLoadCanvas(Player);
135
-
136
- setSubscreen('mainmenu');
137
- dataStore();
138
- }
139
-
140
- resize(onLoad: boolean = false) {
141
- elementSetPosSizeFont({ element: elementGetSubscreenDiv() }, 0, 0, 2000, 1000);
142
- if (this.name === 'mainmenu') {
143
- elementSetPosSizeFont({ element: elementGetSettingsDiv() }, 530, 170, 800, 660);
144
- } else {
145
- elementSetPosSizeFont({ element: elementGetSettingsDiv() }, 530, 170, 1000, 660);
146
- }
147
-
148
- elementSetPosSizeFont({ elementId: 'deeplib-subscreen-title' }, 530, 75, 800, 60);
149
-
150
- elementSetPosition({ element: elementGetTooltip() }, 250, 850);
151
- elementSetSize({ element: elementGetTooltip() }, 1500, 60);
152
-
153
- BaseSubscreen.currentElements.forEach((item) => {
154
- const options = item[1];
155
- const elementDataAttrs = item[0].dataset;
156
-
157
- if (options.position || elementDataAttrs.position) {
158
- const position = elementDataAttrs?.position?.split('x');
159
- const xPos = options?.position?.[0] || parseInt(position?.[0] || 0);
160
- const yPos = options?.position?.[1] || parseInt(position?.[1] || 0);
161
-
162
- elementSetPosition({ elementId: options.id }, xPos, yPos);
163
- }
164
-
165
- if (options.size || elementDataAttrs.size) {
166
- const size = elementDataAttrs?.size?.split('x');
167
- const width = options?.size?.[0] || parseInt(size?.[0] || 0);
168
- const height = options?.size?.[1] || parseInt(size?.[1] || 0);
169
-
170
- elementSetSize({ elementId: options.id }, width, height);
171
- }
172
-
173
- elementAdjustFontSize({ elementId: options.id });
174
- });
175
- }
176
-
177
- unload() {
178
- this.pageStructure.forEach((s) =>
179
- s.forEach((item) => {
180
- switch (item.type) {
181
- case 'text':
182
- item.setSettingValue(ElementValue(item.id));
183
- break;
184
- case 'checkbox': {
185
- const elem = document.getElementById(item.id) as HTMLInputElement;
186
- const checked = elem.checked;
187
- item.setSettingValue(checked);
188
- break;
189
- }
190
- }
191
- })
192
- );
193
- BaseSubscreen.currentElements = [];
194
-
195
- elementRemoveSubscreenDiv();
196
- }
197
- }
198
-
@@ -1,83 +0,0 @@
1
- import { BaseModule, bcSdkMod, dataTake, deepLibLogger, Localization, modules, registerModule, VersionModule } from '../DeepLib';
2
-
3
- export function initMod(initFunction: (() => void) | (() => Promise<void>), modules: BaseModule[], pathToTranslationsFolder: string) {
4
- const MOD_NAME = bcSdkMod.ModInfo.name;
5
- deepLibLogger.debug(`Init wait for ${MOD_NAME}`);
6
- if (CurrentScreen == null || CurrentScreen === 'Login') {
7
- bcSdkMod.prototype.hookFunction('LoginResponse', 0, (args, next) => {
8
- deepLibLogger.debug(`Init for ${MOD_NAME}! LoginResponse caught: `, args);
9
- next(args);
10
- const response = args[0];
11
- if (response === 'InvalidNamePassword') return next(args);
12
- if (response && typeof response.Name === 'string' && typeof response.AccountName === 'string') {
13
- init(initFunction, modules, pathToTranslationsFolder);
14
- }
15
- });
16
- } else {
17
- deepLibLogger.debug(`Already logged in, initing ${MOD_NAME}`);
18
- init(initFunction, modules, pathToTranslationsFolder);
19
- }
20
- }
21
-
22
- export async function init(initFunction: (() => void) | (() => Promise<void>), modules: BaseModule[], pathToTranslationsFolder: string) {
23
- const MOD_NAME = bcSdkMod.ModInfo.name;
24
- const MOD_VERSION = bcSdkMod.ModInfo.version;
25
-
26
- if ((window as any)[MOD_NAME + 'Loaded']) return;
27
-
28
- dataTake();
29
-
30
- new Localization({ pathToTranslationsFolder: pathToTranslationsFolder });
31
- await Localization.init();
32
-
33
- if (!initModules(modules)) {
34
- unloadMod();
35
- return;
36
- }
37
-
38
- await initFunction();
39
-
40
- VersionModule.checkVersionUpdate();
41
- VersionModule.checkVersionMigration();
42
-
43
- (window as any)[MOD_NAME + 'Loaded'] = true;
44
- deepLibLogger.log(`Loaded ${MOD_NAME}! Version: ${MOD_VERSION}`);
45
- }
46
-
47
- function initModules(modulesToRegister: BaseModule[]): boolean {
48
- const MOD_NAME = bcSdkMod.ModInfo.name;
49
-
50
- for (const module of modulesToRegister) {
51
- registerModule(module);
52
- }
53
-
54
- for (const module of modules()) {
55
- module.init();
56
- }
57
-
58
- for (const module of modules()) {
59
- module.load();
60
- }
61
-
62
- for (const module of modules()) {
63
- module.run();
64
- }
65
-
66
- deepLibLogger.debug(`Modules Loaded for ${MOD_NAME}.`);
67
- return true;
68
- }
69
-
70
- export function unloadMod(): true {
71
- const MOD_NAME = bcSdkMod.ModInfo.name;
72
- unloadModules();
73
-
74
- delete (window as any)[MOD_NAME + 'Loaded'];
75
- deepLibLogger.debug(`Unloaded ${MOD_NAME}.`);
76
- return true;
77
- }
78
-
79
- function unloadModules() {
80
- for (const module of modules()) {
81
- module.unload();
82
- }
83
- }
@@ -1,16 +0,0 @@
1
- import { BaseModule } from '../DeepLib';
2
-
3
- export const modulesMap: Map<string, BaseModule> = new Map<string, BaseModule>();
4
-
5
- export function modules(): BaseModule[] {
6
- return [...modulesMap.values()];
7
- }
8
-
9
- export function registerModule<T extends BaseModule>(module: T): T {
10
- modulesMap.set(module.constructor.name, module);
11
- return module;
12
- }
13
-
14
- export function getModule<T extends BaseModule>(moduleType: string): T {
15
- return modulesMap.get(moduleType) as T;
16
- }
@@ -1,14 +0,0 @@
1
- import { BaseSubscreen, GUI } from '../DeepLib';
2
-
3
- export function getCurrentSubscreen(): BaseSubscreen | null {
4
- return GUI.instance && GUI.instance.currentSubscreen;
5
- }
6
-
7
- export function setSubscreen(subscreen: BaseSubscreen | string | null): BaseSubscreen | null {
8
- if (!GUI.instance) {
9
- throw new Error('Attempt to set subscreen before init');
10
- }
11
- GUI.instance.currentSubscreen = subscreen;
12
-
13
- return GUI.instance.currentSubscreen;
14
- }
@@ -1,4 +0,0 @@
1
- export abstract class BaseMigrator {
2
- abstract get MigrationVersion(): string;
3
- abstract Migrate(): boolean;
4
- }
@@ -1,4 +0,0 @@
1
- export type BaseSettingsModel = {
2
- modEnabled: boolean;
3
- doShowNewVersionMessage: boolean;
4
- };
@@ -1,7 +0,0 @@
1
- import { BaseSettingsModel } from '../DeepLib';
2
-
3
- export type SettingsModel = {
4
- [x: string]: any;
5
- GlobalModule: BaseSettingsModel;
6
- Version: string;
7
- };
@@ -1,123 +0,0 @@
1
- import { BaseModule, BaseSubscreen, MainMenu, modules, setSubscreen } from '../DeepLib';
2
-
3
- type ModButtonOptions = {
4
- Identifier: string;
5
- ButtonText: string | (()=>string);
6
- Image: string | (()=>string);
7
-
8
- load?: () => void;
9
- click?: () => void;
10
- run?: () => void;
11
- unload?: () => void;
12
- exit?: () => boolean | void;
13
- };
14
-
15
- export class GUI extends BaseModule {
16
- static instance: GUI | null = null;
17
-
18
- private _subscreens: BaseSubscreen[];
19
- private _mainMenu: MainMenu;
20
- private _currentSubscreen: BaseSubscreen | null = null;
21
- private _modButtonOptions: ModButtonOptions;
22
-
23
- get subscreens(): BaseSubscreen[] {
24
- return this._subscreens;
25
- }
26
-
27
- get mainMenu(): MainMenu {
28
- return this._mainMenu;
29
- }
30
-
31
- get currentSubscreen(): BaseSubscreen | null {
32
- return this._currentSubscreen;
33
- }
34
-
35
- set currentSubscreen(subscreen: BaseSubscreen | string | null) {
36
- if (this._currentSubscreen) {
37
- this._currentSubscreen.unload();
38
- }
39
-
40
- if (typeof subscreen === 'string') {
41
- const scr = this._subscreens?.find((s) => s.name === subscreen);
42
- if (!scr) throw `Failed to find screen name ${subscreen}`;
43
- this._currentSubscreen = scr;
44
- } else {
45
- this._currentSubscreen = subscreen;
46
- }
47
-
48
- PreferenceMessage = '';
49
- PreferencePageCurrent = 1;
50
-
51
- if (this._currentSubscreen) {
52
- this._currentSubscreen.load();
53
- this._currentSubscreen.resize(true);
54
- }
55
- }
56
-
57
- constructor(modButtonOptions: ModButtonOptions) {
58
- super();
59
- if (GUI.instance) {
60
- throw new Error('Duplicate initialization');
61
- }
62
-
63
- for (const module of modules()) {
64
- if (!module.settingsScreen) continue;
65
- }
66
-
67
- this._mainMenu = new MainMenu(this);
68
- this._subscreens = [this._mainMenu];
69
- this._modButtonOptions = modButtonOptions;
70
-
71
- GUI.instance = this;
72
- }
73
-
74
- get defaultSettings(): null {
75
- return null;
76
- }
77
-
78
- load(): void {
79
- for (const module of modules()) {
80
- if (!module.settingsScreen) continue;
81
-
82
- this._subscreens.push(new module.settingsScreen(module));
83
- }
84
-
85
- this._mainMenu.subscreens = this._subscreens;
86
- PreferenceRegisterExtensionSetting({
87
- Identifier: this._modButtonOptions.Identifier,
88
- ButtonText: this._modButtonOptions.ButtonText,
89
- Image: this._modButtonOptions.Image,
90
- load: this._modButtonOptions.load || (() => {
91
- setSubscreen(new MainMenu(this));
92
- }),
93
- run: this._modButtonOptions.run || (() => {
94
- if (this._currentSubscreen) {
95
- MainCanvas.textAlign = 'left';
96
- this._currentSubscreen.run();
97
- MainCanvas.textAlign = 'center';
98
-
99
- const newCanvasPosition: RectTuple = [MainCanvas.canvas.offsetLeft, MainCanvas.canvas.offsetTop, MainCanvas.canvas.clientWidth, MainCanvas.canvas.clientHeight];
100
- if (!CommonArraysEqual(newCanvasPosition, DrawCanvasPosition)) {
101
- DrawCanvasPosition = newCanvasPosition;
102
- this._currentSubscreen.resize(false);
103
- }
104
- }
105
- }),
106
- click: this._modButtonOptions.click || (() => {
107
- if (this._currentSubscreen) {
108
- this._currentSubscreen.click();
109
- }
110
- }),
111
- exit: this._modButtonOptions.exit || (() => {
112
- if (this._currentSubscreen) {
113
- this._currentSubscreen.exit();
114
- }
115
- }),
116
- unload: this._modButtonOptions.unload || (() => {
117
- if (this._currentSubscreen) {
118
- this._currentSubscreen.unload();
119
- }
120
- })
121
- });
122
- }
123
- }
@@ -1,89 +0,0 @@
1
- import { BaseMigrator, BaseModule, HookPriority, PlayerStorage, bcSdkMod, dataStore, deepLibLogger, sendLocalMessage } from '../DeepLib';
2
-
3
- export class VersionModule extends BaseModule {
4
- private static isItNewVersion: boolean = false;
5
- static Version: string;
6
- static NewVersionMessage: string = '';
7
- private static Migrators: BaseMigrator[] = [];
8
-
9
- load(): void {
10
- VersionModule.Version = bcSdkMod.ModInfo.version;
11
-
12
- bcSdkMod.prototype.hookFunction(
13
- 'ChatRoomSync',
14
- HookPriority.Observe,
15
- (args, next) => {
16
- next(args);
17
- if (PlayerStorage().GlobalModule.doShowNewVersionMessage && VersionModule.isItNewVersion) {
18
- VersionModule.sendNewVersionMessage();
19
- }
20
- },
21
- 999
22
- );
23
- }
24
-
25
- static checkVersionUpdate() {
26
- const PreviousVersion = VersionModule.loadVersion();
27
- const CurrentVersion = VersionModule.Version;
28
-
29
- if (VersionModule.isNewVersion(PreviousVersion, CurrentVersion)) {
30
- VersionModule.isItNewVersion = true;
31
- VersionModule.saveVersion();
32
- }
33
- }
34
-
35
- static checkVersionMigration() {
36
- const PreviousVersion = VersionModule.loadVersion();
37
-
38
- let saveRequired = false;
39
- for (const migrator of VersionModule.Migrators) {
40
- if (VersionModule.isNewVersion(PreviousVersion, migrator.MigrationVersion)) {
41
- saveRequired = saveRequired || migrator.Migrate();
42
- deepLibLogger.info(`Migrating ${bcSdkMod.ModInfo.name} from ${PreviousVersion} to ${migrator.MigrationVersion} with ${migrator.constructor.name}`);
43
- }
44
- }
45
-
46
- if (saveRequired) {
47
- dataStore();
48
- }
49
- }
50
-
51
- static registerMigrator(migrator: BaseMigrator) {
52
- VersionModule.Migrators.push(migrator);
53
- }
54
-
55
- static setNewVersionMessage(newVersionMessage: string) {
56
- VersionModule.NewVersionMessage = newVersionMessage;
57
- }
58
-
59
- static sendNewVersionMessage() {
60
- sendLocalMessage('deeplib-new-version', VersionModule.NewVersionMessage);
61
- }
62
-
63
- private static isNewVersion(current: string | undefined, candidate: string) {
64
- if (current !== undefined) {
65
- const CURRENT_ = current.split('.'),
66
- CANDIDATE_ = candidate.split('.');
67
- for (let i = 0; i < 3; i++) {
68
- if (CURRENT_[i] === CANDIDATE_[i]) {
69
- continue;
70
- }
71
- return CANDIDATE_[i] > CURRENT_[i];
72
- }
73
- }
74
- if (current === undefined || current === '' || !current) {
75
- return true;
76
- }
77
- return false;
78
- }
79
-
80
- private static saveVersion() {
81
- if (PlayerStorage()) {
82
- Player[bcSdkMod.ModInfo.name].Version = VersionModule.Version;
83
- }
84
- }
85
-
86
- private static loadVersion() {
87
- return PlayerStorage()?.Version;
88
- }
89
- }
@@ -1,99 +0,0 @@
1
-
2
- import { Button, Checkbox, Input, Label, SettingElement } from 'Types/elements';
3
- import { BaseSubscreen, deepLibLogger } from '../DeepLib';
4
-
5
- export class GuiDebug extends BaseSubscreen {
6
-
7
- get name(): string {
8
- return 'debug';
9
- }
10
-
11
- get pageStructure(): SettingElement[][] {
12
- return [[
13
- <Button>{
14
- type: 'button',
15
- roundness: 50,
16
- id: 'test-deeplib-big-button',
17
- size: [405, 80],
18
- label: 'Big Button',
19
- tooltip: 'This is a big button',
20
- image: 'Icons/Exit.png',
21
- onClick() {
22
- deepLibLogger.info('Big Button Clicked');
23
- }
24
- },
25
- <Button>{
26
- type: 'button',
27
- roundness: 5,
28
- id: 'test-deeplib-small-button',
29
- size: [90, 90],
30
- tooltip: 'This is a small button',
31
- image: 'Icons/Exit.png',
32
- onClick() {
33
- deepLibLogger.info('Small Button Clicked');
34
- }
35
- },
36
- <Checkbox>{
37
- type: 'checkbox',
38
- id: 'test-deeplib-checkbox',
39
- label: 'Checkbox',
40
- description: 'This is a checkbox',
41
- checked: false,
42
- getSettingValue() {
43
- return true;
44
- },
45
- setSettingValue(val: boolean) {
46
- deepLibLogger.info('Checkbox value:', val);
47
- },
48
- },
49
- <Input>{
50
- type: 'text',
51
- id: 'test-deeplib-text-input',
52
- label: 'Input',
53
- description: 'This is a text input',
54
- getElementValue() {
55
- return 'Input Value';
56
- },
57
- setSettingValue(val: string) {
58
- deepLibLogger.info('Input value:', val);
59
- },
60
- },
61
- <Input>{
62
- type: 'number',
63
- id: 'test-deeplib-number-input',
64
- label: 'Input',
65
- description: 'This is a number input',
66
- getElementValue() {
67
- return '123';
68
- },
69
- setSettingValue(val: string) {
70
- deepLibLogger.info('Input value:', val);
71
- },
72
- },
73
- <Label>{
74
- type: 'label',
75
- id: 'test-deeplib-label',
76
- label: 'Label',
77
- description: 'This is a label',
78
- }
79
- ]];
80
- }
81
-
82
- load(): void {
83
- super.load();
84
- }
85
-
86
- run() {
87
- super.run();
88
- }
89
-
90
- click() { }
91
-
92
- exit(): void {
93
- super.exit();
94
- }
95
-
96
- resize(): void {
97
- super.resize();
98
- }
99
- }