bc-deeplib 1.0.1 → 1.0.3
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/.types/declarations.d.ts +15 -0
- package/.types/elements.d.ts +38 -0
- package/.types/type-override.d.ts +3 -0
- package/README.md +1 -1
- package/package.json +28 -12
- package/public/styles/DeepLib.css +206 -0
- package/public/styles/Gratitude.css +23 -0
- package/src/Base/BaseModule.ts +45 -0
- package/src/Base/BaseSubscreen.ts +198 -0
- package/src/Base/Initialization.ts +83 -0
- package/src/Base/Modules.ts +16 -0
- package/src/Base/SettingDefinitions.ts +14 -0
- package/src/DeepLib.ts +33 -0
- package/src/Migrators/BaseMigrator.ts +4 -0
- package/src/Models/Base.ts +4 -0
- package/src/Models/Settings.ts +7 -0
- package/src/Modules/GUI.ts +123 -0
- package/src/Modules/Version.ts +89 -0
- package/src/Screens/Debug.ts +99 -0
- package/src/Screens/MainMenu.ts +138 -0
- package/src/Screens/Support.ts +99 -0
- package/src/Utilities/Data.ts +40 -0
- package/src/Utilities/Elements/.AdvancedElements.ts +70 -0
- package/src/Utilities/Elements/.ElementHelpers.ts +100 -0
- package/src/Utilities/Elements/Button.ts +54 -0
- package/src/Utilities/Elements/Checkbox.ts +63 -0
- package/src/Utilities/Elements/Input.ts +72 -0
- package/src/Utilities/Elements/Label.ts +50 -0
- package/src/Utilities/Elements/Tooltip.ts +30 -0
- package/src/Utilities/Logger.ts +79 -0
- package/src/Utilities/Messages.ts +36 -0
- package/src/Utilities/SDK.ts +104 -0
- package/src/Utilities/String.ts +31 -0
- package/src/Utilities/Style.ts +24 -0
- package/src/Utilities/Translation.ts +59 -0
- package/dist/Base/BaseModule.d.ts +0 -13
- package/dist/Base/BaseModule.js +0 -41
- package/dist/Base/BaseSetting.d.ts +0 -29
- package/dist/Base/BaseSetting.js +0 -152
- package/dist/Base/Modules.d.ts +0 -5
- package/dist/Base/Modules.js +0 -17
- package/dist/Base/SettingDefinitions.d.ts +0 -8
- package/dist/Base/SettingDefinitions.js +0 -19
- package/dist/Base/SettingUtils.d.ts +0 -17
- package/dist/Base/SettingUtils.js +0 -68
- package/dist/DeepLib.d.ts +0 -5
- package/dist/DeepLib.js +0 -21
- package/dist/Models/Base.d.ts +0 -4
- package/dist/Models/Base.js +0 -2
- package/dist/Models/Settings.d.ts +0 -6
- package/dist/Models/Settings.js +0 -2
- package/dist/Modules/Version.d.ts +0 -14
- package/dist/Modules/Version.js +0 -62
- package/dist/Screens/MainMenu.d.ts +0 -11
- package/dist/Screens/MainMenu.js +0 -80
- package/dist/Screens/Support.d.ts +0 -14
- package/dist/Screens/Support.js +0 -99
- package/dist/Utils/Data.d.ts +0 -5
- package/dist/Utils/Data.js +0 -42
- package/dist/Utils/Logger.d.ts +0 -4
- package/dist/Utils/Logger.js +0 -6
- package/dist/Utils/Messages.d.ts +0 -2
- package/dist/Utils/Messages.js +0 -32
- package/dist/Utils/RibbonMenu.d.ts +0 -9
- package/dist/Utils/RibbonMenu.js +0 -32
- package/dist/Utils/SDK.d.ts +0 -21
- package/dist/Utils/SDK.js +0 -75
- package/dist/Utils/String.d.ts +0 -5
- package/dist/Utils/String.js +0 -30
- package/dist/Utils/Translation.d.ts +0 -10
- package/dist/Utils/Translation.js +0 -43
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export function elementCreateSubscreenDiv() {
|
|
2
|
+
const subscreenDiv = elementGetSubscreenDiv();
|
|
3
|
+
if (subscreenDiv) {
|
|
4
|
+
console.error('Subscreen already exists');
|
|
5
|
+
return subscreenDiv;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const div = document.createElement('div');
|
|
9
|
+
div.id = 'deeplib-subscreen';
|
|
10
|
+
div.classList.add('deeplib-subscreen', 'HideOnPopup');
|
|
11
|
+
|
|
12
|
+
return document.body.appendChild(div);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function elementGetSubscreenDiv() {
|
|
16
|
+
return document.getElementById('deeplib-subscreen') ?? undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function elementRemoveSubscreenDiv() {
|
|
20
|
+
return elementGetSubscreenDiv()?.remove();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function elementAppendToSubscreenDiv(element: HTMLElement) {
|
|
24
|
+
return elementGetSubscreenDiv()?.appendChild(element);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function elementCreateSettingsDiv() {
|
|
28
|
+
const settingsDiv = elementGetSettingsDiv();
|
|
29
|
+
if (settingsDiv) {
|
|
30
|
+
console.error('Settings screen already exists');
|
|
31
|
+
return settingsDiv;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const div = document.createElement('div');
|
|
35
|
+
div.id = 'deeplib-settings';
|
|
36
|
+
div.classList.add('deeplib-settings');
|
|
37
|
+
|
|
38
|
+
return div;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function elementGetSettingsDiv() {
|
|
42
|
+
return document.getElementById('deeplib-settings') ?? undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function elementAppendToSettingsDiv(element: HTMLElement) {
|
|
46
|
+
return elementGetSettingsDiv()?.appendChild(element);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function elementCreateMiscDiv() {
|
|
50
|
+
const miscDiv = elementGetMiscDiv();
|
|
51
|
+
if (miscDiv) {
|
|
52
|
+
console.error('Settings screen already exists');
|
|
53
|
+
return miscDiv;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const div = document.createElement('div');
|
|
57
|
+
div.id = 'deeplib-misc';
|
|
58
|
+
div.classList.add('deeplib-misc');
|
|
59
|
+
|
|
60
|
+
return div;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function elementGetMiscDiv() {
|
|
64
|
+
return document.getElementById('deeplib-misc');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function elementAppendToMiscDiv(element: HTMLElement) {
|
|
68
|
+
return elementGetMiscDiv()?.appendChild(element);
|
|
69
|
+
}
|
|
70
|
+
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { deepLibLogger } from '../../DeepLib';
|
|
2
|
+
|
|
3
|
+
type ElementOrId = { elementId?: string; element?: HTMLElement; };
|
|
4
|
+
|
|
5
|
+
const mainCanvasHeight = 1000;
|
|
6
|
+
const mainCanvasWidth = 2000;
|
|
7
|
+
|
|
8
|
+
export function getRelativeHeight(height: number) {
|
|
9
|
+
return height * (MainCanvas.canvas.clientHeight / mainCanvasHeight);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getRelativeWidth(width: number) {
|
|
13
|
+
return width * (MainCanvas.canvas.clientWidth / mainCanvasWidth);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getRelativeY(yPos: number) {
|
|
17
|
+
return MainCanvas.canvas.offsetTop + yPos * (MainCanvas.canvas.clientHeight / mainCanvasHeight);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function getRelativeX(xPos: number) {
|
|
21
|
+
return MainCanvas.canvas.offsetLeft + xPos * (MainCanvas.canvas.clientWidth / mainCanvasWidth);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function elementSetPosition(_: ElementOrId, xPos: number, yPos: number) {
|
|
25
|
+
const element = elementGet(_, 'elementSetPosition');
|
|
26
|
+
if (!element) return;
|
|
27
|
+
|
|
28
|
+
const Top = getRelativeY(yPos);
|
|
29
|
+
const Left = getRelativeX(xPos);
|
|
30
|
+
|
|
31
|
+
Object.assign(element.style, {
|
|
32
|
+
position: 'fixed',
|
|
33
|
+
left: Left + 'px',
|
|
34
|
+
top: Top + 'px'
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function elementSetSize(_: ElementOrId, width: number, height: number) {
|
|
39
|
+
const element = elementGet(_, 'elementSetSize');
|
|
40
|
+
if (!element) return;
|
|
41
|
+
|
|
42
|
+
const Height = getRelativeHeight(height);
|
|
43
|
+
const Width = getRelativeWidth(width);
|
|
44
|
+
|
|
45
|
+
Object.assign(element.style, {
|
|
46
|
+
width: Width + 'px',
|
|
47
|
+
height: Height + 'px',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function elementAdjustFontSize(_: ElementOrId) {
|
|
52
|
+
const element = elementGet(_, 'elementAdjustFontSize');
|
|
53
|
+
if (!element) return;
|
|
54
|
+
|
|
55
|
+
const Font = MainCanvas.canvas.clientWidth <= MainCanvas.canvas.clientHeight * 2 ? MainCanvas.canvas.clientWidth / 50 : MainCanvas.canvas.clientHeight / 25;
|
|
56
|
+
|
|
57
|
+
Object.assign(element.style, {
|
|
58
|
+
fontSize: Font + 'px',
|
|
59
|
+
fontFamily: CommonGetFontName()
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function elementSetPosSizeFont(_: ElementOrId, xPos: number, yPos: number, width: number, height: number) {
|
|
64
|
+
if (elementGet(_, 'elementSetPosSizeFont') === null) return;
|
|
65
|
+
|
|
66
|
+
elementSetPosition(_, xPos, yPos);
|
|
67
|
+
elementSetSize(_, width, height);
|
|
68
|
+
elementAdjustFontSize(_);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function elementHide(_: ElementOrId) {
|
|
72
|
+
const element = elementGet(_, 'elementHide');
|
|
73
|
+
if (!element) return;
|
|
74
|
+
|
|
75
|
+
element.style.display = 'none';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function elementUnhide(_: ElementOrId) {
|
|
79
|
+
const element = elementGet(_, 'elementUnhide');
|
|
80
|
+
if (!element) return;
|
|
81
|
+
|
|
82
|
+
element.style.display = '';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function elementGet(_: ElementOrId, funcName: string) {
|
|
86
|
+
if (!_) {
|
|
87
|
+
deepLibLogger.warn(`${funcName} called without an elementId or element`);
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const elementId = _.elementId ?? _.element?.id;
|
|
92
|
+
const element = _.element ?? document.getElementById(_.elementId!);
|
|
93
|
+
|
|
94
|
+
if (!element) {
|
|
95
|
+
deepLibLogger.warn(`A call to ${funcName} was made on non-existent element with id ${elementId}`);
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return element;
|
|
100
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Button } from 'Types/elements';
|
|
2
|
+
import { BaseSubscreen, getRelativeHeight, getRelativeWidth, getRelativeX, getRelativeY } from '../../DeepLib';
|
|
3
|
+
|
|
4
|
+
export function elementCreateButton(options: Button) {
|
|
5
|
+
const width = options.size ? getRelativeWidth(options.size[0]) + 'px' : '';
|
|
6
|
+
const height = options.size ? getRelativeHeight(options.size[1]) + 'px' : '';
|
|
7
|
+
const left = options.position ? getRelativeX(options.position[0]) + 'px' : '';
|
|
8
|
+
const top = options.position ? getRelativeY(options.position[1]) + 'px' : '';
|
|
9
|
+
const position = options.position ? 'fixed' : '';
|
|
10
|
+
|
|
11
|
+
const button = ElementButton.Create(options.id, () => options.onClick(),
|
|
12
|
+
{
|
|
13
|
+
tooltip: options.tooltip,
|
|
14
|
+
label: options.label,
|
|
15
|
+
labelPosition: 'center',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
button: {
|
|
19
|
+
classList: ['deeplib-button'],
|
|
20
|
+
children: [
|
|
21
|
+
{
|
|
22
|
+
tag: 'img',
|
|
23
|
+
attributes: {
|
|
24
|
+
id: `${options.id}-image`,
|
|
25
|
+
alt: '',
|
|
26
|
+
disabled: options.disabled,
|
|
27
|
+
decoding: 'async',
|
|
28
|
+
loading: 'lazy',
|
|
29
|
+
src: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' // 1x1 transparent image to get rid of broken image
|
|
30
|
+
},
|
|
31
|
+
dataAttributes: {
|
|
32
|
+
'size': options.size?.join('x'),
|
|
33
|
+
'position': options.position?.join('x'),
|
|
34
|
+
},
|
|
35
|
+
style: {
|
|
36
|
+
'--image': `url("${options.image}")`,
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
style: {
|
|
41
|
+
width: width,
|
|
42
|
+
height: height,
|
|
43
|
+
left: left,
|
|
44
|
+
top: top,
|
|
45
|
+
position: position,
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
BaseSubscreen.currentElements.push([button, options]);
|
|
52
|
+
|
|
53
|
+
return button;
|
|
54
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Checkbox } from 'Types/elements';
|
|
2
|
+
import { BaseSubscreen, elementSetTooltip, getRelativeHeight, getRelativeWidth, getRelativeX, getRelativeY } from '../../DeepLib';
|
|
3
|
+
|
|
4
|
+
export function elementCreateCheckbox(options: Checkbox) {
|
|
5
|
+
const elem = document.getElementById(options.id);
|
|
6
|
+
|
|
7
|
+
if (elem) return elem;
|
|
8
|
+
|
|
9
|
+
const width = options.size ? getRelativeWidth(options.size[0]) + 'px' : '';
|
|
10
|
+
const height = options.size ? getRelativeHeight(options.size[1]) + 'px' : '';
|
|
11
|
+
const left = options.position ? getRelativeX(options.position[0]) + 'px' : '';
|
|
12
|
+
const top = options.position ? getRelativeY(options.position[1]) + 'px' : '';
|
|
13
|
+
const position = options.position ? 'fixed' : '';
|
|
14
|
+
|
|
15
|
+
const retElem = ElementCreate({
|
|
16
|
+
tag: 'div',
|
|
17
|
+
classList: ['deeplib-checkbox-container'],
|
|
18
|
+
style: {
|
|
19
|
+
width: width,
|
|
20
|
+
height: height,
|
|
21
|
+
left: left,
|
|
22
|
+
top: top,
|
|
23
|
+
position: position,
|
|
24
|
+
},
|
|
25
|
+
dataAttributes: {
|
|
26
|
+
'size': options.size?.join('x'),
|
|
27
|
+
'position': options.position?.join('x'),
|
|
28
|
+
},
|
|
29
|
+
children: [
|
|
30
|
+
{
|
|
31
|
+
tag: 'input',
|
|
32
|
+
classList: ['deeplib-input'],
|
|
33
|
+
attributes: {
|
|
34
|
+
type: 'checkbox',
|
|
35
|
+
id: options.id,
|
|
36
|
+
checked: options.getSettingValue() || undefined,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
tag: 'label',
|
|
41
|
+
classList: ['deeplib-text'],
|
|
42
|
+
attributes: {
|
|
43
|
+
for: options.id,
|
|
44
|
+
},
|
|
45
|
+
children: [options.label]
|
|
46
|
+
},
|
|
47
|
+
]
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (options.description) {
|
|
51
|
+
retElem.addEventListener('mouseover', () => {
|
|
52
|
+
elementSetTooltip(options.description);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
retElem.addEventListener('mouseout', () => {
|
|
56
|
+
elementSetTooltip('');
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
BaseSubscreen.currentElements.push([retElem, options]);
|
|
61
|
+
|
|
62
|
+
return retElem;
|
|
63
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Input } from 'Types/elements';
|
|
2
|
+
import { BaseSubscreen, elementSetTooltip, getRelativeHeight, getRelativeWidth, getRelativeX, getRelativeY } from '../../DeepLib';
|
|
3
|
+
|
|
4
|
+
export function elementCreateInput(options: Input) {
|
|
5
|
+
const elem = document.getElementById(options.id);
|
|
6
|
+
|
|
7
|
+
if (elem) return elem;
|
|
8
|
+
|
|
9
|
+
const width = options.size ? getRelativeWidth(options.size[0]) + 'px' : '';
|
|
10
|
+
const height = options.size ? getRelativeHeight(options.size[1]) + 'px' : '';
|
|
11
|
+
const left = options.position ? getRelativeX(options.position[0]) + 'px' : '';
|
|
12
|
+
const top = options.position ? getRelativeY(options.position[1]) + 'px' : '';
|
|
13
|
+
const position = options.position ? 'fixed' : '';
|
|
14
|
+
|
|
15
|
+
const retElem = ElementCreate({
|
|
16
|
+
tag: 'div',
|
|
17
|
+
classList: ['deeplib-input-container'],
|
|
18
|
+
style: {
|
|
19
|
+
width: width,
|
|
20
|
+
height: height,
|
|
21
|
+
left: left,
|
|
22
|
+
top: top,
|
|
23
|
+
position: position,
|
|
24
|
+
},
|
|
25
|
+
dataAttributes: {
|
|
26
|
+
'size': options.size?.join('x'),
|
|
27
|
+
'position': options.position?.join('x'),
|
|
28
|
+
},
|
|
29
|
+
children: [
|
|
30
|
+
{
|
|
31
|
+
tag: 'input',
|
|
32
|
+
classList: ['deeplib-input'],
|
|
33
|
+
attributes: {
|
|
34
|
+
type: options.type,
|
|
35
|
+
id: options.id,
|
|
36
|
+
placeholder: ' ',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
tag: 'label',
|
|
41
|
+
classList: ['deeplib-text'],
|
|
42
|
+
attributes: {
|
|
43
|
+
for: options.id,
|
|
44
|
+
},
|
|
45
|
+
children: [options.label]
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
tag: 'div',
|
|
49
|
+
classList: ['deeplib-underline'],
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (options.getElementValue?.()) {
|
|
55
|
+
const input = document.getElementById(options.id) as HTMLInputElement;
|
|
56
|
+
if (input) input.value = options.getElementValue();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (options.description) {
|
|
60
|
+
retElem.addEventListener('mouseover', () => {
|
|
61
|
+
elementSetTooltip(options.description);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
retElem.addEventListener('mouseout', () => {
|
|
65
|
+
elementSetTooltip('');
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
BaseSubscreen.currentElements.push([retElem, options]);
|
|
70
|
+
|
|
71
|
+
return retElem;
|
|
72
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Label } from 'Types/elements';
|
|
2
|
+
import { BaseSubscreen, elementSetTooltip, getRelativeHeight, getRelativeWidth, getRelativeX, getRelativeY } from '../../DeepLib';
|
|
3
|
+
|
|
4
|
+
export function elementCreateLabel(options: Label) {
|
|
5
|
+
const elem = document.getElementById(options.id);
|
|
6
|
+
|
|
7
|
+
if (elem) return elem;
|
|
8
|
+
|
|
9
|
+
const width = options.size ? getRelativeWidth(options.size[0]) + 'px' : '';
|
|
10
|
+
const height = options.size ? getRelativeHeight(options.size[1]) + 'px' : '';
|
|
11
|
+
const left = options.position ? getRelativeX(options.position[0]) + 'px' : '';
|
|
12
|
+
const top = options.position ? getRelativeY(options.position[1]) + 'px' : '';
|
|
13
|
+
const position = options.position ? 'fixed' : '';
|
|
14
|
+
|
|
15
|
+
const retElem = ElementCreate({
|
|
16
|
+
tag: 'span',
|
|
17
|
+
classList: ['deeplib-label', 'deeplib-text'],
|
|
18
|
+
attributes: {
|
|
19
|
+
id: options.id
|
|
20
|
+
},
|
|
21
|
+
style: {
|
|
22
|
+
width: width,
|
|
23
|
+
height: height,
|
|
24
|
+
left: left,
|
|
25
|
+
top: top,
|
|
26
|
+
position: position,
|
|
27
|
+
},
|
|
28
|
+
dataAttributes: {
|
|
29
|
+
'size': options.size?.join('x'),
|
|
30
|
+
'position': options.position?.join('x'),
|
|
31
|
+
},
|
|
32
|
+
children: [
|
|
33
|
+
options.label,
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (options.description) {
|
|
38
|
+
retElem.addEventListener('mouseover', () => {
|
|
39
|
+
elementSetTooltip(options.description as string);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
retElem.addEventListener('mouseout', () => {
|
|
43
|
+
elementSetTooltip('');
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
BaseSubscreen.currentElements.push([retElem, options]);
|
|
48
|
+
|
|
49
|
+
return retElem;
|
|
50
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function elementCreateTooltip() {
|
|
2
|
+
const element = ElementCreate({
|
|
3
|
+
tag: 'div',
|
|
4
|
+
classList: ['deeplib-tooltip'],
|
|
5
|
+
attributes: {
|
|
6
|
+
id: 'deeplib-tooltip'
|
|
7
|
+
},
|
|
8
|
+
style: {
|
|
9
|
+
display: 'none'
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return element;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function elementGetTooltip() {
|
|
17
|
+
return document.getElementById('deeplib-tooltip') ?? undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function elementSetTooltip(text: string) {
|
|
21
|
+
const element = document.getElementById('deeplib-tooltip');
|
|
22
|
+
|
|
23
|
+
if (!element) return false;
|
|
24
|
+
|
|
25
|
+
element.innerHTML = text;
|
|
26
|
+
if (text === '') element.style.display = 'none';
|
|
27
|
+
else element.style.display = '';
|
|
28
|
+
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
type LogLevel = 'info' | 'log' | 'warn' | 'error' | 'debug';
|
|
2
|
+
|
|
3
|
+
interface LogEntry {
|
|
4
|
+
readonly args: readonly any[];
|
|
5
|
+
readonly date: Date;
|
|
6
|
+
readonly logLevel: LogLevel;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class Logger extends Array<LogEntry> {
|
|
10
|
+
private ModName: string = 'DeepLib';
|
|
11
|
+
|
|
12
|
+
constructor(modName?: string) {
|
|
13
|
+
super();
|
|
14
|
+
|
|
15
|
+
if (modName) {
|
|
16
|
+
this.ModName = modName;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private _Log(level: LogLevel, ...args: any[]): void {
|
|
21
|
+
const logEntry: LogEntry = {
|
|
22
|
+
logLevel: level,
|
|
23
|
+
args: [...args],
|
|
24
|
+
// trace: arguments.callee.caller.toString().split('\n'),
|
|
25
|
+
date: new Date(Date.now())
|
|
26
|
+
// `[${this.ModName}] ${formattedArgs}`
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const userAgent = navigator.userAgent.toLowerCase();
|
|
30
|
+
if (userAgent.includes('chrome') || userAgent.includes('firefox')) {
|
|
31
|
+
const color = Logger.colorizeLog(level);
|
|
32
|
+
args.forEach(arg => {
|
|
33
|
+
if (typeof arg === 'string') {
|
|
34
|
+
arg = `\n%c${arg}`;
|
|
35
|
+
// args.splice(args.indexOf(arg), 1, arg, color);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
console.log(`%c${this.ModName}:`, color, ...args);
|
|
39
|
+
} else {
|
|
40
|
+
console.log(`${this.ModName}:`, ...args);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.push(logEntry);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
info(...args: any[]): void {
|
|
47
|
+
this._Log('info', ...args);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
log(...args: any[]): void {
|
|
51
|
+
this._Log('log', ...args);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
warn(...args: any[]): void {
|
|
55
|
+
this._Log('warn', ...args);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
error(...args: any[]): void {
|
|
59
|
+
this._Log('error', ...args);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
debug(...args: any[]): void {
|
|
63
|
+
this._Log('debug', ...args);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static colorizeLog(logLevel: LogLevel): string {
|
|
67
|
+
const colors: Record<LogLevel, string> = {
|
|
68
|
+
info: 'color: #32CCCC',
|
|
69
|
+
log: 'color: #CCCC32',
|
|
70
|
+
warn: 'color: #eec355',
|
|
71
|
+
error: 'color: #750b0b',
|
|
72
|
+
debug: 'color: #9E4BCF',
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return colors[logLevel];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const deepLibLogger = new Logger();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function sendLocalMessage(id: string, message: string, timeoutInSeconds?: number) {
|
|
2
|
+
const div = document.createElement('div');
|
|
3
|
+
div.id = id;
|
|
4
|
+
const specialId = id + Date.now();
|
|
5
|
+
div.classList.add('ChatMessage', 'deeplib-message', specialId);
|
|
6
|
+
div.setAttribute('data-time', ChatRoomCurrentTime());
|
|
7
|
+
div.setAttribute('data-sender', Player?.MemberNumber + '');
|
|
8
|
+
|
|
9
|
+
const messageContent = message.replaceAll('\n\t', '') + '<br>';
|
|
10
|
+
const closeButton = document.createElement('a');
|
|
11
|
+
closeButton.classList.add('deeplib-text');
|
|
12
|
+
closeButton.addEventListener('click', () => {
|
|
13
|
+
div?.remove();
|
|
14
|
+
});
|
|
15
|
+
closeButton.innerHTML = '<b>Close (Click)</b>';
|
|
16
|
+
|
|
17
|
+
div.innerHTML = messageContent;
|
|
18
|
+
div.append(closeButton);
|
|
19
|
+
|
|
20
|
+
ChatRoomAppendChat(div);
|
|
21
|
+
if (!timeoutInSeconds) return;
|
|
22
|
+
setTimeout(() => div?.remove(), timeoutInSeconds * 1000);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function sendActionMessage(msg: string, target: undefined | number = undefined, dictionary: ChatMessageDictionaryEntry[] = []) {
|
|
26
|
+
if (!msg) return;
|
|
27
|
+
ServerSend('ChatRoomChat', {
|
|
28
|
+
Content: 'DEEPLIB_CUSTOM_ACTION',
|
|
29
|
+
Type: 'Action',
|
|
30
|
+
Target: target ?? undefined,
|
|
31
|
+
Dictionary: [
|
|
32
|
+
{ Tag: 'MISSING TEXT IN "Interface.csv": DEEPLIB_CUSTOM_ACTION', Text: msg },
|
|
33
|
+
...dictionary,
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import bcModSdkRef, { ModSDKModAPI, ModSDKModInfo, ModSDKModOptions } from 'bondage-club-mod-sdk';
|
|
2
|
+
|
|
3
|
+
export enum HookPriority {
|
|
4
|
+
Observe = 0,
|
|
5
|
+
AddBehavior = 1,
|
|
6
|
+
ModifyBehavior = 5,
|
|
7
|
+
OverrideBehavior = 10,
|
|
8
|
+
Top = 100
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type ModuleCategory = number;
|
|
12
|
+
|
|
13
|
+
export declare type AnyFunction = (...args: any) => any;
|
|
14
|
+
type PatchHook<TFunction extends AnyFunction = AnyFunction> = (args: [...Parameters<TFunction>], next: (args: [...Parameters<TFunction>]) => ReturnType<TFunction>) => ReturnType<TFunction>;
|
|
15
|
+
|
|
16
|
+
interface IPatchedFunctionData {
|
|
17
|
+
name: string;
|
|
18
|
+
hooks: {
|
|
19
|
+
hook: PatchHook;
|
|
20
|
+
priority: number;
|
|
21
|
+
module: ModuleCategory | null;
|
|
22
|
+
removeCallback: () => void;
|
|
23
|
+
}[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type GetDotedPathType<Base, DotedKey extends string> = DotedKey extends `${infer Key1}.${infer Key2}` ? GetDotedPathType<GetDotedPathType<Base, Key1>, Key2> : DotedKey extends keyof Base ? Base[DotedKey] : never;
|
|
27
|
+
|
|
28
|
+
export class bcSdkMod {
|
|
29
|
+
private static SDK: ModSDKModAPI;
|
|
30
|
+
private static patchedFunctions: Map<string, IPatchedFunctionData> = new Map();
|
|
31
|
+
|
|
32
|
+
public static ModInfo: ModSDKModInfo;
|
|
33
|
+
|
|
34
|
+
constructor(info: ModSDKModInfo, options?: ModSDKModOptions) {
|
|
35
|
+
bcSdkMod.SDK = bcModSdkRef.registerMod(info, options);
|
|
36
|
+
bcSdkMod.ModInfo = info;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
initPatchableFunction(target: string): IPatchedFunctionData {
|
|
40
|
+
let result = bcSdkMod.patchedFunctions.get(target);
|
|
41
|
+
if (!result) {
|
|
42
|
+
result = {
|
|
43
|
+
name: target,
|
|
44
|
+
hooks: []
|
|
45
|
+
};
|
|
46
|
+
bcSdkMod.patchedFunctions.set(target, result);
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
hookFunction<TargetName extends string>(
|
|
52
|
+
target: TargetName,
|
|
53
|
+
priority: number,
|
|
54
|
+
hook: PatchHook<GetDotedPathType<typeof globalThis, TargetName>>,
|
|
55
|
+
module: ModuleCategory | null = null
|
|
56
|
+
): () => void {
|
|
57
|
+
const data = this.initPatchableFunction(target);
|
|
58
|
+
|
|
59
|
+
if (data.hooks.some((h) => h.hook === hook)) {
|
|
60
|
+
return () => null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const removeCallback = bcSdkMod.SDK?.hookFunction(target, priority, hook);
|
|
64
|
+
|
|
65
|
+
data.hooks.push({
|
|
66
|
+
hook,
|
|
67
|
+
priority,
|
|
68
|
+
module,
|
|
69
|
+
removeCallback
|
|
70
|
+
});
|
|
71
|
+
data.hooks.sort((a, b) => b.priority - a.priority);
|
|
72
|
+
return removeCallback;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
patchFunction(target: string, patches: Record<string, string>): void {
|
|
76
|
+
this.patchFunction(target, patches);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
removeHookByModule(target: string, module: ModuleCategory): boolean {
|
|
80
|
+
const data = this.initPatchableFunction(target);
|
|
81
|
+
|
|
82
|
+
for (let i = data.hooks.length - 1; i >= 0; i--) {
|
|
83
|
+
if (data.hooks[i].module === module) {
|
|
84
|
+
data.hooks[i].removeCallback();
|
|
85
|
+
data.hooks.splice(i, 1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
removeAllHooksByModule(module: ModuleCategory): boolean {
|
|
93
|
+
for (const data of bcSdkMod.patchedFunctions.values()) {
|
|
94
|
+
for (let i = data.hooks.length - 1; i >= 0; i--) {
|
|
95
|
+
if (data.hooks[i].module === module) {
|
|
96
|
+
data.hooks[i].removeCallback();
|
|
97
|
+
data.hooks.splice(i, 1);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { deepLibLogger } from './Logger';
|
|
2
|
+
|
|
3
|
+
export class _String {
|
|
4
|
+
static encode(string: string | object) {
|
|
5
|
+
return LZString.compressToBase64(JSON.stringify(string));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static decode(string: string | undefined) {
|
|
9
|
+
const d = LZString.decompressFromBase64(string as string);
|
|
10
|
+
let data = {};
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const decoded = JSON.parse(d as string);
|
|
14
|
+
data = decoded;
|
|
15
|
+
} catch (error) {
|
|
16
|
+
deepLibLogger.error(error);
|
|
17
|
+
}
|
|
18
|
+
if (data) return data;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static shuffle(string: string[]) {
|
|
22
|
+
const temp: string[] = JSON.parse(JSON.stringify(string));
|
|
23
|
+
const ret: string[] = [];
|
|
24
|
+
while (temp.length > 0) {
|
|
25
|
+
const d = Math.floor(Math.random() * temp.length);
|
|
26
|
+
ret.push(temp[d]);
|
|
27
|
+
temp.splice(d, 1);
|
|
28
|
+
}
|
|
29
|
+
return ret;
|
|
30
|
+
}
|
|
31
|
+
}
|