zois-core 1.0.2 → 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.
- package/README.md +19 -0
- package/dist/index.d.ts +1 -0
- package/dist/messaging.d.ts +8 -0
- package/dist/messaging.js +44 -2
- package/dist/modsApi.js +20 -1
- package/dist/styles.css +26 -20
- package/dist/ui.d.ts +28 -11
- package/dist/ui.js +89 -32
- package/package.json +23 -2
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
⠀⠀⠀⠀⠀⢀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
|
2
|
+
⠀⠀⠀⠀⠀⡟⠈⠛⢦⣄⠀⠀⠀⠀⠀⣀⡴⠚⠩⠘⡇⠀⠀
|
|
3
|
+
⠀⠀⠀⠀⠀⣧⠀⡀⠄⠈⠛⠛⠛⠛⢛⠁⠌⠀⠀⠀⡇⠀⠀
|
|
4
|
+
⠀⠀⠀⠀⠀⣿⠞⠁⠀⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣧
|
|
5
|
+
⠀⠀⠀⠀⣼⠃⢠⠤⢤⠀⠀⠀⠀⢀⡤⢤⡀⠀⠀⠀⠘⣧
|
|
6
|
+
⠀⢀⣤⣤⣧⡄⠀⠀⠀⠀⣤⡀⠀⠀⠀⠀⠁⣤⣤⣤⣤⣼⣦⡄
|
|
7
|
+
⠀⢀⣠⡤⣷⠶⠀⠀⠀⠦⠜⠤⠄⠀⠀⠀⠰⠦⣤⣄⣀⣸⠃
|
|
8
|
+
⠀⠀⠀⠀⠘⢧⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣽⣋⠁
|
|
9
|
+
⠀⠀⠀⠀⠀⠀⠈⠙⢳⡶⠶⠶⠶⠶⠶⠶⠖⠛⠛⠍⠀⠉⠛
|
|
10
|
+
⠀⠀⠀⠀⠀⠀⠀⢠⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣦⡀
|
|
11
|
+
⠀⠀⠀⠀⠀⠀⠀⣾⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢷⡀
|
|
12
|
+
⠀⠀⠀⠀⠀⠀⠀⣏⠀⠀⠀⠀⢠⠆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇
|
|
13
|
+
⠀⠀⠀⠀⠀⠀⠀⢻⡀⠀⠀⠀⣿⠀⠀⠀⠀⢠⡾⠋⠁⠀⠀⠀⠀⠀⠀⢸⡇
|
|
14
|
+
⠀⠀⠀⠀⠀⠀⠀⠈⢷⡀⠀⠀⣿⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠃
|
|
15
|
+
⠀⠀⠀⠀⠀⠀⠀⠀⠈⢧⣀⣠⣼⣧⣀⣀⣰⣟⡀⠀⠀⠀⠀⠀⢀⣀⣼⢿⡀
|
|
16
|
+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣟⠁⠀⠉⠉⠉⠉⠙⠛⠛⠛⠻⠿⠛⠛⠉⠁⣼⠁
|
|
17
|
+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⡴⠞⠁
|
|
18
|
+
|
|
19
|
+
## The core for the my mods, which contains a shared code reused in all my mods
|
package/dist/index.d.ts
CHANGED
package/dist/messaging.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
interface RequestResponse<T> {
|
|
2
|
+
data?: T;
|
|
3
|
+
isError: boolean;
|
|
4
|
+
}
|
|
1
5
|
export declare function chatSendLocal(message: string | Node): void;
|
|
2
6
|
export declare function chatSendActionMessage(msg: string, target?: undefined | number, dictionary?: ChatMessageDictionaryEntry[]): void;
|
|
3
7
|
export declare function chatSendModMessage<T>(msg: string, _data?: T, targetNumber?: any): void;
|
|
4
8
|
export declare function chatSendBeep(data: any, targetId: number): void;
|
|
9
|
+
export declare function sendRequest<T>(message: string, data: any, target: number): Promise<RequestResponse<T>>;
|
|
5
10
|
export declare function handleRequestResponse(requestId: number, data: any): void;
|
|
11
|
+
export declare function handleRequest(requestId: number, message: string, _data: any, sender: Character): void;
|
|
12
|
+
export declare function addRequestListener(message: string, listener: (data: any, sender: Character) => any): void;
|
|
13
|
+
export {};
|
package/dist/messaging.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { MOD_DATA } from "./index";
|
|
1
|
+
import { getRandomNumber, MOD_DATA } from "./index";
|
|
2
2
|
const pendingRequests = /* @__PURE__ */ new Map();
|
|
3
|
+
const requestListeners = /* @__PURE__ */ new Map();
|
|
3
4
|
function chatSendLocal(message) {
|
|
4
5
|
if (!ServerPlayerIsInChatRoom()) return;
|
|
5
6
|
const div = document.createElement("div");
|
|
@@ -57,6 +58,29 @@ function chatSendBeep(data, targetId) {
|
|
|
57
58
|
};
|
|
58
59
|
ServerSend("AccountBeep", beep);
|
|
59
60
|
}
|
|
61
|
+
function sendRequest(message, data, target) {
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
const requestId = parseInt(`${Date.now()}${getRandomNumber(1e3, 1e4)}`);
|
|
64
|
+
pendingRequests.set(requestId, {
|
|
65
|
+
message,
|
|
66
|
+
data,
|
|
67
|
+
target,
|
|
68
|
+
resolve,
|
|
69
|
+
reject
|
|
70
|
+
});
|
|
71
|
+
chatSendModMessage("request", {
|
|
72
|
+
requestId,
|
|
73
|
+
message,
|
|
74
|
+
data
|
|
75
|
+
}, target);
|
|
76
|
+
setTimeout(() => {
|
|
77
|
+
pendingRequests.delete(requestId);
|
|
78
|
+
resolve({
|
|
79
|
+
isError: true
|
|
80
|
+
});
|
|
81
|
+
}, 6e3);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
60
84
|
function handleRequestResponse(requestId, data) {
|
|
61
85
|
const request = pendingRequests.get(requestId);
|
|
62
86
|
if (!request) return;
|
|
@@ -64,10 +88,28 @@ function handleRequestResponse(requestId, data) {
|
|
|
64
88
|
data
|
|
65
89
|
});
|
|
66
90
|
}
|
|
91
|
+
function handleRequest(requestId, message, _data, sender) {
|
|
92
|
+
const listener = requestListeners.get(message);
|
|
93
|
+
if (!listener) return;
|
|
94
|
+
const data = listener(_data, sender);
|
|
95
|
+
if (data !== void 0) {
|
|
96
|
+
chatSendModMessage("requestResponse", {
|
|
97
|
+
requestId,
|
|
98
|
+
message,
|
|
99
|
+
data
|
|
100
|
+
}, sender.MemberNumber);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function addRequestListener(message, listener) {
|
|
104
|
+
requestListeners.set(message, listener);
|
|
105
|
+
}
|
|
67
106
|
export {
|
|
107
|
+
addRequestListener,
|
|
68
108
|
chatSendActionMessage,
|
|
69
109
|
chatSendBeep,
|
|
70
110
|
chatSendLocal,
|
|
71
111
|
chatSendModMessage,
|
|
72
|
-
|
|
112
|
+
handleRequest,
|
|
113
|
+
handleRequestResponse,
|
|
114
|
+
sendRequest
|
|
73
115
|
};
|
package/dist/modsApi.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import bcModSdk from "bondage-club-mod-sdk";
|
|
2
|
-
import { MOD_DATA } from "./index";
|
|
2
|
+
import { getPlayer, MOD_DATA } from "./index";
|
|
3
3
|
import { getCurrentSubscreen } from "./ui";
|
|
4
|
+
import { handleRequest, handleRequestResponse } from "./messaging";
|
|
4
5
|
var HookPriority = /* @__PURE__ */ ((HookPriority2) => {
|
|
5
6
|
HookPriority2[HookPriority2["OBSERVE"] = 0] = "OBSERVE";
|
|
6
7
|
HookPriority2[HookPriority2["ADD_BEHAVIOR"] = 1] = "ADD_BEHAVIOR";
|
|
@@ -21,6 +22,24 @@ function registerMod() {
|
|
|
21
22
|
if (CommonKey.IsPressed(args[0], "Escape") && getCurrentSubscreen()) getCurrentSubscreen().exit();
|
|
22
23
|
return next(args);
|
|
23
24
|
});
|
|
25
|
+
hookFunction("ChatRoomMessage", 1 /* ADD_BEHAVIOR */, (args, next) => {
|
|
26
|
+
const message = args[0];
|
|
27
|
+
const sender = getPlayer(message.Sender);
|
|
28
|
+
if (!sender) return next(args);
|
|
29
|
+
if (message.Content === MOD_DATA.key && !sender.IsPlayer()) {
|
|
30
|
+
const msg = message.Dictionary.msg;
|
|
31
|
+
const data = message.Dictionary.data;
|
|
32
|
+
console.log("message.Dictionary.data", data);
|
|
33
|
+
if (msg === "request") {
|
|
34
|
+
if (typeof data.requestId !== "number" || typeof data.message !== "string") return;
|
|
35
|
+
handleRequest(data.requestId, data.message, data.data, sender);
|
|
36
|
+
}
|
|
37
|
+
if (msg === "requestResponse") {
|
|
38
|
+
if (typeof data.requestId !== "number") return;
|
|
39
|
+
handleRequestResponse(data.requestId, data.data);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
24
43
|
}
|
|
25
44
|
function hookFunction(functionName, priority, hook) {
|
|
26
45
|
if (!modSdk) throw new Error("zois-core is not registered");
|
package/dist/styles.css
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
@import "https://fonts.googleapis.com/css2?family=Emilys+Candy&display=swap";
|
|
2
1
|
* {
|
|
3
2
|
margin: 0;
|
|
4
3
|
padding: 0;
|
|
@@ -7,7 +6,6 @@
|
|
|
7
6
|
.zcButton {
|
|
8
7
|
cursor: pointer;
|
|
9
8
|
background: var(--tmd-element, white);
|
|
10
|
-
font-family: "Emilys Candy";
|
|
11
9
|
color: var(--tmd-text, black);
|
|
12
10
|
border: 2px solid var(--tmd-accent, black);
|
|
13
11
|
border-radius: 4px;
|
|
@@ -17,26 +15,47 @@
|
|
|
17
15
|
border-color: var(--tmd-accent-hover, #7dd3fc);
|
|
18
16
|
color: var(--tmd-accent-hover, #015a8c);
|
|
19
17
|
}
|
|
20
|
-
.zcButton
|
|
18
|
+
.zcButton .tooltip {
|
|
19
|
+
position: absolute;
|
|
20
|
+
color: black;
|
|
21
|
+
text-align: center;
|
|
22
|
+
padding: 4px;
|
|
23
|
+
border-radius: 4px;
|
|
24
|
+
background: #FFFF88;
|
|
25
|
+
border: 2px solid #e7e787;
|
|
26
|
+
width: max-content;
|
|
27
|
+
min-height: 100%;
|
|
28
|
+
visibility: hidden;
|
|
29
|
+
z-index: 10;
|
|
30
|
+
}
|
|
31
|
+
.zcButton .tooltip[position=left] {
|
|
32
|
+
right: calc(100% + 1vw);
|
|
33
|
+
}
|
|
34
|
+
.zcButton .tooltip[position=right] {
|
|
35
|
+
left: calc(100% + 1vw);
|
|
36
|
+
}
|
|
37
|
+
.zcButton:hover .tooltip {
|
|
38
|
+
visibility: visible;
|
|
39
|
+
}
|
|
40
|
+
.zcButton[data-zc-style=green] {
|
|
21
41
|
background: rgb(124, 255, 124);
|
|
22
42
|
border-color: rgb(82, 204, 82);
|
|
23
43
|
color: black;
|
|
24
44
|
}
|
|
25
|
-
.zcButton[data-
|
|
45
|
+
.zcButton[data-zc-style=green]:hover {
|
|
26
46
|
background: rgb(94, 197, 94);
|
|
27
47
|
color: black;
|
|
28
48
|
}
|
|
29
|
-
.zcButton[data-
|
|
49
|
+
.zcButton[data-zc-style=inverted] {
|
|
30
50
|
background: var(--tmd-accent, #303030);
|
|
31
51
|
border: none;
|
|
32
52
|
color: var(--tmd-text, white);
|
|
33
53
|
}
|
|
34
|
-
.zcButton[data-
|
|
54
|
+
.zcButton[data-zc-style=inverted]:hover {
|
|
35
55
|
background: var(--tmd-accent-hover, #474747);
|
|
36
56
|
}
|
|
37
57
|
.zcInput {
|
|
38
58
|
background: var(--tmd-element, white);
|
|
39
|
-
font-family: Emilys Candy;
|
|
40
59
|
color: var(--tmd-text, black);
|
|
41
60
|
padding: 2vw;
|
|
42
61
|
border: 2px solid var(--tmd-accent, black);
|
|
@@ -51,23 +70,10 @@
|
|
|
51
70
|
justify-content: center;
|
|
52
71
|
align-items: center;
|
|
53
72
|
background: var(--tmd-element, white);
|
|
54
|
-
font-family: Emilys Candy;
|
|
55
73
|
color: var(--tmd-text, black);
|
|
56
74
|
border: 2px solid var(--tmd-accent, black);
|
|
57
75
|
border-radius: 4px;
|
|
58
76
|
}
|
|
59
|
-
.zcBackNextButton button {
|
|
60
|
-
cursor: pointer;
|
|
61
|
-
background: var(--tmd-element, rgb(240, 240, 240));
|
|
62
|
-
border-radius: 4px;
|
|
63
|
-
height: 140%;
|
|
64
|
-
aspect-ratio: 1/1;
|
|
65
|
-
border: 2px solid var(--tmd-accent, black);
|
|
66
|
-
font-size: 3.5vw;
|
|
67
|
-
}
|
|
68
|
-
.zcBackNextButton button:hover {
|
|
69
|
-
background: var(--tmd-element-hover, rgb(222, 222, 222));
|
|
70
|
-
}
|
|
71
77
|
.zcDisabled {
|
|
72
78
|
pointer-events: none;
|
|
73
79
|
opacity: 0.6;
|
package/dist/ui.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
type Anchor = "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
1
2
|
interface CreateButtonArgs {
|
|
2
3
|
text?: string;
|
|
3
4
|
x?: number;
|
|
@@ -7,11 +8,17 @@ interface CreateButtonArgs {
|
|
|
7
8
|
height?: number;
|
|
8
9
|
padding?: number;
|
|
9
10
|
style?: "default" | "green" | "inverted";
|
|
10
|
-
anchor?:
|
|
11
|
+
anchor?: Anchor;
|
|
11
12
|
place?: boolean;
|
|
12
13
|
icon?: string;
|
|
13
14
|
iconAbsolutePosition?: boolean;
|
|
14
15
|
iconWidth?: string;
|
|
16
|
+
tooltip?: {
|
|
17
|
+
text: string;
|
|
18
|
+
position: "left" | "right";
|
|
19
|
+
};
|
|
20
|
+
onClick?: () => void;
|
|
21
|
+
isDisabled?: () => boolean;
|
|
15
22
|
}
|
|
16
23
|
interface CreateTextArgs {
|
|
17
24
|
text?: string;
|
|
@@ -23,7 +30,7 @@ interface CreateTextArgs {
|
|
|
23
30
|
width?: number;
|
|
24
31
|
height?: number;
|
|
25
32
|
padding?: number;
|
|
26
|
-
anchor?:
|
|
33
|
+
anchor?: Anchor;
|
|
27
34
|
place?: boolean;
|
|
28
35
|
}
|
|
29
36
|
interface CreateInputArgs {
|
|
@@ -35,9 +42,12 @@ interface CreateInputArgs {
|
|
|
35
42
|
height?: number;
|
|
36
43
|
textArea?: boolean;
|
|
37
44
|
fontSize?: number | "auto";
|
|
38
|
-
anchor?:
|
|
45
|
+
anchor?: Anchor;
|
|
39
46
|
padding?: number;
|
|
40
47
|
place?: boolean;
|
|
48
|
+
onChange?: () => void;
|
|
49
|
+
onInput?: () => void;
|
|
50
|
+
isDisabled?: () => boolean;
|
|
41
51
|
}
|
|
42
52
|
interface CreateCheckboxArgs {
|
|
43
53
|
isChecked: boolean;
|
|
@@ -45,8 +55,10 @@ interface CreateCheckboxArgs {
|
|
|
45
55
|
y?: number;
|
|
46
56
|
width?: number;
|
|
47
57
|
text: string;
|
|
48
|
-
anchor?:
|
|
58
|
+
anchor?: Anchor;
|
|
49
59
|
place?: boolean;
|
|
60
|
+
onChange?: () => void;
|
|
61
|
+
isDisabled?: () => boolean;
|
|
50
62
|
}
|
|
51
63
|
interface CreateScrollViewArgs {
|
|
52
64
|
scroll: "x" | "y" | "all";
|
|
@@ -54,7 +66,7 @@ interface CreateScrollViewArgs {
|
|
|
54
66
|
y: number;
|
|
55
67
|
width: number;
|
|
56
68
|
height?: number;
|
|
57
|
-
anchor?:
|
|
69
|
+
anchor?: Anchor;
|
|
58
70
|
}
|
|
59
71
|
interface CreateInputListArgs {
|
|
60
72
|
value?: string[] | number[];
|
|
@@ -64,16 +76,19 @@ interface CreateInputListArgs {
|
|
|
64
76
|
width: number;
|
|
65
77
|
height?: number;
|
|
66
78
|
fontSize?: number | "auto";
|
|
67
|
-
anchor?:
|
|
79
|
+
anchor?: Anchor;
|
|
68
80
|
padding?: number;
|
|
69
81
|
place?: boolean;
|
|
70
82
|
numbersOnly?: boolean;
|
|
83
|
+
onChange?: (value: string[] | number[]) => void;
|
|
84
|
+
isDisabled?: () => boolean;
|
|
71
85
|
}
|
|
72
86
|
interface CreateImageArgs {
|
|
73
87
|
src: string;
|
|
74
88
|
x: number;
|
|
75
89
|
y: number;
|
|
76
90
|
width: number;
|
|
91
|
+
anchor?: Anchor;
|
|
77
92
|
}
|
|
78
93
|
interface CreateBackNextButtonArgs {
|
|
79
94
|
x: number;
|
|
@@ -82,7 +97,9 @@ interface CreateBackNextButtonArgs {
|
|
|
82
97
|
height: number;
|
|
83
98
|
items: [string, any?][];
|
|
84
99
|
currentIndex: number;
|
|
100
|
+
anchor?: Anchor;
|
|
85
101
|
onChange?: (value: any) => void;
|
|
102
|
+
isDisabled?: () => boolean;
|
|
86
103
|
}
|
|
87
104
|
export declare function setPreviousSubscreen(): void;
|
|
88
105
|
export declare function setSubscreen(subscreen: BaseSubscreen | null): void;
|
|
@@ -100,14 +117,14 @@ export declare abstract class BaseSubscreen {
|
|
|
100
117
|
update?(): void;
|
|
101
118
|
setPreviousSubscreen(): void;
|
|
102
119
|
setSubscreen(subscreen: BaseSubscreen | null): void;
|
|
103
|
-
createButton({ text, x, y, width, height, fontSize, anchor, padding, style, place, icon, iconAbsolutePosition, iconWidth }: CreateButtonArgs): HTMLButtonElement;
|
|
120
|
+
createButton({ text, x, y, width, height, fontSize, anchor, padding, style, place, icon, iconAbsolutePosition, iconWidth, tooltip, onClick, isDisabled }: CreateButtonArgs): HTMLButtonElement;
|
|
104
121
|
createText({ text, color, x, y, width, height, withBackground, fontSize, anchor, padding, place }: CreateTextArgs): HTMLParagraphElement;
|
|
105
|
-
createInput({ value, placeholder, x, y, width, height, textArea, fontSize, anchor, padding, place }: CreateInputArgs): HTMLInputElement | HTMLTextAreaElement;
|
|
106
|
-
createCheckbox({ text, x, y, isChecked, width, anchor, place }: CreateCheckboxArgs): HTMLInputElement;
|
|
122
|
+
createInput({ value, placeholder, x, y, width, height, textArea, fontSize, anchor, padding, place, onChange, onInput, isDisabled }: CreateInputArgs): HTMLInputElement | HTMLTextAreaElement;
|
|
123
|
+
createCheckbox({ text, x, y, isChecked, width, anchor, place, isDisabled, onChange }: CreateCheckboxArgs): HTMLInputElement;
|
|
107
124
|
createScrollView({ scroll, x, y, width, height, anchor }: CreateScrollViewArgs): HTMLDivElement;
|
|
108
|
-
createInputList({ x, y, width, height, title, value, anchor, place, numbersOnly, }: CreateInputListArgs):
|
|
125
|
+
createInputList({ x, y, width, height, title, value, anchor, place, numbersOnly, isDisabled, onChange }: CreateInputListArgs): HTMLDivElement;
|
|
109
126
|
createImage({ x, y, width, src, }: CreateImageArgs): HTMLImageElement;
|
|
110
|
-
createBackNextButton({ x, y, width, height, items, currentIndex, onChange }: CreateBackNextButtonArgs): HTMLDivElement;
|
|
127
|
+
createBackNextButton({ x, y, width, height, items, currentIndex, onChange, isDisabled }: CreateBackNextButtonArgs): HTMLDivElement;
|
|
111
128
|
}
|
|
112
129
|
export declare function hookSubscreen(subscreenName: string, hook: (subscreen: BaseSubscreen) => void): void;
|
|
113
130
|
export {};
|
package/dist/ui.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MOD_DATA } from "./index";
|
|
1
2
|
function getRelativeHeight(height) {
|
|
2
3
|
return height * (MainCanvas.canvas.clientHeight / 1e3);
|
|
3
4
|
}
|
|
@@ -6,15 +7,15 @@ function getRelativeWidth(width) {
|
|
|
6
7
|
}
|
|
7
8
|
function getRelativeY(yPos, anchorPosition = "top") {
|
|
8
9
|
const scaleY = MainCanvas.canvas.clientHeight / 1e3;
|
|
9
|
-
return anchorPosition === "top" ? MainCanvas.canvas.offsetTop + yPos * scaleY : MainCanvas.canvas.offsetTop + MainCanvas.canvas.clientHeight
|
|
10
|
+
return anchorPosition === "top" ? MainCanvas.canvas.offsetTop + yPos * scaleY : window.innerHeight - (MainCanvas.canvas.offsetTop + MainCanvas.canvas.clientHeight) + yPos * scaleY;
|
|
10
11
|
}
|
|
11
12
|
function getRelativeX(xPos, anchorPosition = "left") {
|
|
12
13
|
const scaleX = MainCanvas.canvas.clientWidth / 2e3;
|
|
13
|
-
return anchorPosition === "left" ? MainCanvas.canvas.offsetLeft + xPos * scaleX : MainCanvas.canvas.offsetLeft + MainCanvas.canvas.clientWidth
|
|
14
|
+
return anchorPosition === "left" ? MainCanvas.canvas.offsetLeft + xPos * scaleX : window.innerWidth - (MainCanvas.canvas.offsetLeft + MainCanvas.canvas.clientWidth) + xPos * scaleX;
|
|
14
15
|
}
|
|
15
|
-
function setPosition(element, xPos, yPos,
|
|
16
|
-
const yAnchor =
|
|
17
|
-
const xAnchor =
|
|
16
|
+
function setPosition(element, xPos, yPos, anchor = "top-left") {
|
|
17
|
+
const yAnchor = anchor === "top-left" || anchor === "top-right" ? "top" : "bottom";
|
|
18
|
+
const xAnchor = anchor === "top-left" || anchor === "bottom-left" ? "left" : "right";
|
|
18
19
|
const y = getRelativeY(yPos, yAnchor);
|
|
19
20
|
const x = getRelativeX(xPos, xAnchor);
|
|
20
21
|
Object.assign(element.style, {
|
|
@@ -24,11 +25,9 @@ function setPosition(element, xPos, yPos, anchorPosition = "top-left") {
|
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
27
|
function setSize(element, width, height) {
|
|
27
|
-
const w = getRelativeWidth(width);
|
|
28
|
-
const h = getRelativeHeight(height);
|
|
29
28
|
Object.assign(element.style, {
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
width: getRelativeWidth(width) + "px",
|
|
30
|
+
height: getRelativeHeight(height) + "px"
|
|
32
31
|
});
|
|
33
32
|
}
|
|
34
33
|
function setFontSize(element, targetFontSize) {
|
|
@@ -40,6 +39,9 @@ function setFontSize(element, targetFontSize) {
|
|
|
40
39
|
fontSize: fontSize + "px"
|
|
41
40
|
});
|
|
42
41
|
}
|
|
42
|
+
function setFontFamily(element, fontFamily) {
|
|
43
|
+
element.style.fontFamily = fontFamily ?? "sans-serif";
|
|
44
|
+
}
|
|
43
45
|
function setPadding(element, targetPadding) {
|
|
44
46
|
const canvasWidth = MainCanvas.canvas.clientWidth;
|
|
45
47
|
const canvasHeight = MainCanvas.canvas.clientHeight;
|
|
@@ -63,7 +65,6 @@ function loadSubscreen(subscreen) {
|
|
|
63
65
|
height: 90,
|
|
64
66
|
icon: "Icons/Exit.png"
|
|
65
67
|
}).addEventListener("click", () => subscreen.exit());
|
|
66
|
-
CommonSetScreen("Character", "InformationSheet");
|
|
67
68
|
subscreen.load();
|
|
68
69
|
if (subscreenHooks[subscreen.name]) {
|
|
69
70
|
subscreenHooks[subscreen.name].forEach((hook) => hook(subscreen));
|
|
@@ -130,7 +131,10 @@ class BaseSubscreen {
|
|
|
130
131
|
place = true,
|
|
131
132
|
icon,
|
|
132
133
|
iconAbsolutePosition = true,
|
|
133
|
-
iconWidth
|
|
134
|
+
iconWidth,
|
|
135
|
+
tooltip,
|
|
136
|
+
onClick,
|
|
137
|
+
isDisabled
|
|
134
138
|
}) {
|
|
135
139
|
const btn = document.createElement("button");
|
|
136
140
|
btn.classList.add("zcButton");
|
|
@@ -139,6 +143,7 @@ class BaseSubscreen {
|
|
|
139
143
|
btn.style.alignItems = "center";
|
|
140
144
|
btn.style.justifyContent = "center";
|
|
141
145
|
btn.style.columnGap = "1.25vw";
|
|
146
|
+
setFontFamily(btn, MOD_DATA.fontFamily);
|
|
142
147
|
if (icon) {
|
|
143
148
|
const img = document.createElement("img");
|
|
144
149
|
img.src = icon;
|
|
@@ -160,14 +165,28 @@ class BaseSubscreen {
|
|
|
160
165
|
}
|
|
161
166
|
btn.append(span);
|
|
162
167
|
}
|
|
168
|
+
if (tooltip) {
|
|
169
|
+
const tooltipEl = document.createElement("span");
|
|
170
|
+
tooltipEl.classList.add("tooltip");
|
|
171
|
+
tooltipEl.setAttribute("position", tooltip.position);
|
|
172
|
+
tooltipEl.textContent = tooltip.text;
|
|
173
|
+
btn.append(tooltipEl);
|
|
174
|
+
}
|
|
163
175
|
const setProperties = () => {
|
|
164
|
-
if (x && y) setPosition(btn, x, y, anchor);
|
|
176
|
+
if (typeof x === "number" && typeof y === "number") setPosition(btn, x, y, anchor);
|
|
165
177
|
setSize(btn, width, height);
|
|
166
178
|
if (padding) setPadding(btn, padding);
|
|
167
179
|
if (fontSize === "auto") autosetFontSize(btn);
|
|
168
180
|
else setFontSize(btn, fontSize);
|
|
169
181
|
};
|
|
170
182
|
setProperties();
|
|
183
|
+
if (typeof isDisabled === "function" && isDisabled()) btn.classList.add("zcDisabled");
|
|
184
|
+
btn.addEventListener("click", () => {
|
|
185
|
+
if (typeof isDisabled === "function" && !isDisabled() && typeof onClick === "function") {
|
|
186
|
+
onClick();
|
|
187
|
+
}
|
|
188
|
+
if (typeof isDisabled === "function" && isDisabled()) btn.classList.add("zcDisabled");
|
|
189
|
+
});
|
|
171
190
|
window.addEventListener("resize", setProperties);
|
|
172
191
|
if (place) document.body.append(btn);
|
|
173
192
|
this.resizeEventListeners.push(setProperties);
|
|
@@ -191,9 +210,9 @@ class BaseSubscreen {
|
|
|
191
210
|
p.innerHTML = text;
|
|
192
211
|
p.style.color = color ?? "var(--tmd-text, black)";
|
|
193
212
|
if (withBackground) p.style.background = "var(--tmd-element,rgb(239, 239, 239))";
|
|
194
|
-
p
|
|
213
|
+
setFontFamily(p);
|
|
195
214
|
const setProperties = () => {
|
|
196
|
-
if (x && y) setPosition(p, x, y, anchor);
|
|
215
|
+
if (typeof x === "number" && typeof y === "number") setPosition(p, x, y, anchor);
|
|
197
216
|
setSize(p, width, height);
|
|
198
217
|
if (padding) setPadding(p, padding);
|
|
199
218
|
if (fontSize === "auto") autosetFontSize(p);
|
|
@@ -217,20 +236,37 @@ class BaseSubscreen {
|
|
|
217
236
|
fontSize = "auto",
|
|
218
237
|
anchor = "top-left",
|
|
219
238
|
padding,
|
|
220
|
-
place = true
|
|
239
|
+
place = true,
|
|
240
|
+
onChange,
|
|
241
|
+
onInput,
|
|
242
|
+
isDisabled
|
|
221
243
|
}) {
|
|
222
244
|
const input = document.createElement(textArea ? "textarea" : "input");
|
|
223
245
|
input.classList.add("zcInput");
|
|
224
246
|
if (placeholder) input.placeholder = placeholder;
|
|
225
247
|
if (value) input.value = value;
|
|
248
|
+
setFontFamily(input, MOD_DATA.fontFamily);
|
|
226
249
|
const setProperties = () => {
|
|
227
|
-
if (x && y) setPosition(input, x, y, anchor);
|
|
250
|
+
if (typeof x === "number" && typeof y === "number") setPosition(input, x, y, anchor);
|
|
228
251
|
setSize(input, width, height);
|
|
229
252
|
if (padding) setPadding(input, padding);
|
|
230
253
|
if (fontSize === "auto") autosetFontSize(input);
|
|
231
254
|
else setFontSize(input, fontSize);
|
|
232
255
|
};
|
|
233
256
|
setProperties();
|
|
257
|
+
if (typeof isDisabled === "function" && isDisabled()) input.classList.add("zcDisabled");
|
|
258
|
+
input.addEventListener("change", () => {
|
|
259
|
+
if (typeof isDisabled === "function" && !isDisabled() && typeof onChange === "function") {
|
|
260
|
+
onChange();
|
|
261
|
+
}
|
|
262
|
+
if (typeof isDisabled === "function" && isDisabled()) input.classList.add("zcDisabled");
|
|
263
|
+
});
|
|
264
|
+
input.addEventListener("input", () => {
|
|
265
|
+
if (typeof isDisabled === "function" && !isDisabled() && typeof onInput === "function") {
|
|
266
|
+
onInput();
|
|
267
|
+
}
|
|
268
|
+
if (typeof isDisabled === "function" && isDisabled()) input.classList.add("zcDisabled");
|
|
269
|
+
});
|
|
234
270
|
window.addEventListener("resize", setProperties);
|
|
235
271
|
if (place) document.body.append(input);
|
|
236
272
|
this.resizeEventListeners.push(setProperties);
|
|
@@ -244,7 +280,9 @@ class BaseSubscreen {
|
|
|
244
280
|
isChecked,
|
|
245
281
|
width,
|
|
246
282
|
anchor = "top-left",
|
|
247
|
-
place = true
|
|
283
|
+
place = true,
|
|
284
|
+
isDisabled,
|
|
285
|
+
onChange
|
|
248
286
|
}) {
|
|
249
287
|
const checkbox = document.createElement("input");
|
|
250
288
|
checkbox.type = "checkbox";
|
|
@@ -253,15 +291,22 @@ class BaseSubscreen {
|
|
|
253
291
|
const p = document.createElement("p");
|
|
254
292
|
p.textContent = text;
|
|
255
293
|
p.style.color = "var(--tmd-text, black)";
|
|
256
|
-
p
|
|
294
|
+
setFontFamily(p);
|
|
257
295
|
const setProperties = () => {
|
|
258
|
-
if (x && y) setPosition(checkbox, x, y, anchor);
|
|
296
|
+
if (typeof x === "number" && typeof y === "number") setPosition(checkbox, x, y, anchor);
|
|
259
297
|
setPosition(p, x + 100, y, anchor);
|
|
260
298
|
setSize(checkbox, 65, 65);
|
|
261
299
|
if (width) setSize(p, width, null);
|
|
262
300
|
setFontSize(p, 5);
|
|
263
301
|
};
|
|
264
302
|
setProperties();
|
|
303
|
+
if (typeof isDisabled === "function" && isDisabled()) checkbox.classList.add("zcDisabled");
|
|
304
|
+
checkbox.addEventListener("change", () => {
|
|
305
|
+
if (typeof isDisabled === "function" && !isDisabled() && typeof onChange === "function") {
|
|
306
|
+
onChange();
|
|
307
|
+
}
|
|
308
|
+
if (typeof isDisabled === "function" && isDisabled()) checkbox.classList.add("zcDisabled");
|
|
309
|
+
});
|
|
265
310
|
window.addEventListener("resize", setProperties);
|
|
266
311
|
if (place) document.body.append(checkbox, p);
|
|
267
312
|
this.resizeEventListeners.push(setProperties);
|
|
@@ -281,7 +326,7 @@ class BaseSubscreen {
|
|
|
281
326
|
if (scroll === "x") div.style.overflowX = "scroll";
|
|
282
327
|
if (scroll === "y") div.style.overflowY = "scroll";
|
|
283
328
|
const setProperties = () => {
|
|
284
|
-
if (x && y) setPosition(div, x, y, anchor);
|
|
329
|
+
if (typeof x === "number" && typeof y === "number") setPosition(div, x, y, anchor);
|
|
285
330
|
setSize(div, width, height);
|
|
286
331
|
};
|
|
287
332
|
setProperties();
|
|
@@ -300,14 +345,17 @@ class BaseSubscreen {
|
|
|
300
345
|
value,
|
|
301
346
|
anchor = "top-left",
|
|
302
347
|
place = true,
|
|
303
|
-
numbersOnly = false
|
|
348
|
+
numbersOnly = false,
|
|
349
|
+
isDisabled,
|
|
350
|
+
onChange
|
|
304
351
|
}) {
|
|
305
352
|
const items = [];
|
|
306
353
|
const div = document.createElement("div");
|
|
307
354
|
div.style.cssText = `
|
|
308
355
|
display: flex; flex-direction: column; gap: 1vw; border: 2px solid var(--tmd-accent, black);
|
|
309
|
-
|
|
356
|
+
border-radius: 4px; padding: 0.75vw;
|
|
310
357
|
`;
|
|
358
|
+
setFontFamily(div, MOD_DATA.fontFamily);
|
|
311
359
|
const buttonsElement = document.createElement("div");
|
|
312
360
|
buttonsElement.style.cssText = "display: flex; justify-content: center; column-gap: 1vw; width: 100%;";
|
|
313
361
|
const titleElement = document.createElement("b");
|
|
@@ -328,6 +376,7 @@ class BaseSubscreen {
|
|
|
328
376
|
b.addEventListener("click", onClick);
|
|
329
377
|
};
|
|
330
378
|
const addItem = (text) => {
|
|
379
|
+
if (typeof isDisabled === "function" && isDisabled()) return div.classList.add("zcDisabled");
|
|
331
380
|
const item = document.createElement("div");
|
|
332
381
|
item.style.cssText = "cursor: pointer; background: var(--tmd-element-hover, rgb(206, 206, 206)); color: var(--tmd-text, black); height: fit-content; padding: 0.8vw; border-radius: 0.8vw; font-size: clamp(8px, 2vw, 20px);";
|
|
333
382
|
item.textContent = text;
|
|
@@ -338,18 +387,21 @@ class BaseSubscreen {
|
|
|
338
387
|
e.stopPropagation();
|
|
339
388
|
});
|
|
340
389
|
items.push(text);
|
|
390
|
+
onChange(numbersOnly ? items.map((i) => parseInt(i)) : items);
|
|
341
391
|
};
|
|
342
392
|
const setProperties = () => {
|
|
343
|
-
if (x && y) setPosition(div, x, y, anchor);
|
|
393
|
+
if (typeof x === "number" && typeof y === "number") setPosition(div, x, y, anchor);
|
|
344
394
|
setSize(div, width, height);
|
|
345
395
|
};
|
|
346
396
|
addButton("Icons/Cancel.png", () => {
|
|
397
|
+
if (typeof isDisabled === "function" && isDisabled()) return div.classList.add("zcDisabled");
|
|
347
398
|
itemsElement.innerHTML = "";
|
|
348
399
|
items.splice(0, items.length);
|
|
349
400
|
itemsElement.append(input);
|
|
350
401
|
value.forEach((v) => addItem(String(v)));
|
|
351
402
|
});
|
|
352
403
|
addButton("Icons/Trash.png", () => {
|
|
404
|
+
if (typeof isDisabled === "function" && isDisabled()) div.classList.add("zcDisabled");
|
|
353
405
|
for (const c of [...itemsElement.children]) {
|
|
354
406
|
if (c.getAttribute("style").includes("border: 2px solid red;")) {
|
|
355
407
|
items.splice(items.indexOf(c.textContent), 1);
|
|
@@ -358,6 +410,7 @@ class BaseSubscreen {
|
|
|
358
410
|
}
|
|
359
411
|
});
|
|
360
412
|
setProperties();
|
|
413
|
+
if (typeof isDisabled === "function" && isDisabled()) div.classList.add("zcDisabled");
|
|
361
414
|
window.addEventListener("resize", setProperties);
|
|
362
415
|
input.addEventListener("keypress", (e) => {
|
|
363
416
|
if (document.activeElement === input) {
|
|
@@ -380,10 +433,7 @@ class BaseSubscreen {
|
|
|
380
433
|
this.resizeEventListeners.push(setProperties);
|
|
381
434
|
this.htmlElements.push(div);
|
|
382
435
|
value.forEach((v) => addItem(String(v)));
|
|
383
|
-
return
|
|
384
|
-
div,
|
|
385
|
-
() => numbersOnly ? items.map((i) => parseInt(i)) : items
|
|
386
|
-
];
|
|
436
|
+
return div;
|
|
387
437
|
}
|
|
388
438
|
createImage({
|
|
389
439
|
x,
|
|
@@ -394,7 +444,7 @@ class BaseSubscreen {
|
|
|
394
444
|
const img = document.createElement("img");
|
|
395
445
|
img.src = src;
|
|
396
446
|
const setProperties = () => {
|
|
397
|
-
if (x && y) setPosition(img, x, y);
|
|
447
|
+
if (typeof x === "number" && typeof y === "number") setPosition(img, x, y);
|
|
398
448
|
setSize(img, width, 0);
|
|
399
449
|
img.style.height = "auto";
|
|
400
450
|
};
|
|
@@ -412,23 +462,29 @@ class BaseSubscreen {
|
|
|
412
462
|
height,
|
|
413
463
|
items,
|
|
414
464
|
currentIndex,
|
|
415
|
-
onChange
|
|
465
|
+
onChange,
|
|
466
|
+
isDisabled
|
|
416
467
|
}) {
|
|
417
468
|
const div = document.createElement("div");
|
|
418
469
|
div.classList.add("zcBackNextButton");
|
|
470
|
+
setFontFamily(div, MOD_DATA.fontFamily);
|
|
419
471
|
const backBtn = document.createElement("button");
|
|
420
|
-
backBtn.style.cssText = "position: absolute; left: 1vw;";
|
|
472
|
+
backBtn.style.cssText = "position: absolute; left: 1vw; font-size: 3.5vw; aspect-ratio: 1/1; height: 140%;";
|
|
473
|
+
backBtn.classList.add("zcButton");
|
|
421
474
|
backBtn.textContent = "\u{1F844}";
|
|
422
475
|
backBtn.addEventListener("click", () => {
|
|
476
|
+
if (typeof isDisabled === "function" && isDisabled()) return div.classList.add("zcDisabled");
|
|
423
477
|
if (currentIndex === 0) return;
|
|
424
478
|
currentIndex--;
|
|
425
479
|
text.textContent = items[currentIndex][0];
|
|
426
480
|
if (typeof onChange === "function") onChange(items[currentIndex][1]);
|
|
427
481
|
});
|
|
428
482
|
const nextBtn = document.createElement("button");
|
|
429
|
-
nextBtn.style.cssText = "position: absolute; right: 1vw;";
|
|
483
|
+
nextBtn.style.cssText = "position: absolute; right: 1vw; font-size: 3.5vw; aspect-ratio: 1/1; height: 140%;";
|
|
484
|
+
nextBtn.classList.add("zcButton");
|
|
430
485
|
nextBtn.textContent = "\u{1F846}";
|
|
431
486
|
nextBtn.addEventListener("click", () => {
|
|
487
|
+
if (typeof isDisabled === "function" && isDisabled()) return div.classList.add("zcDisabled");
|
|
432
488
|
if (currentIndex === items.length - 1) return;
|
|
433
489
|
currentIndex++;
|
|
434
490
|
text.textContent = items[currentIndex][0];
|
|
@@ -438,11 +494,12 @@ class BaseSubscreen {
|
|
|
438
494
|
text.textContent = items[currentIndex][0];
|
|
439
495
|
div.append(backBtn, text, nextBtn);
|
|
440
496
|
const setProperties = () => {
|
|
441
|
-
if (x && y) setPosition(div, x, y);
|
|
497
|
+
if (typeof x === "number" && typeof y === "number") setPosition(div, x, y);
|
|
442
498
|
setSize(div, width, height);
|
|
443
499
|
autosetFontSize(text);
|
|
444
500
|
};
|
|
445
501
|
setProperties();
|
|
502
|
+
if (typeof isDisabled === "function" && isDisabled()) div.classList.add("zcDisabled");
|
|
446
503
|
window.addEventListener("resize", setProperties);
|
|
447
504
|
document.body.append(div);
|
|
448
505
|
this.resizeEventListeners.push(setProperties);
|
package/package.json
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zois-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "The core for the my mods, which contains a shared code reused in all my mods",
|
|
5
5
|
"author": "Zoi",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
|
-
"
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./messaging": {
|
|
16
|
+
"import": "./dist/messaging.js",
|
|
17
|
+
"types": "./dist/messaging.d.ts"
|
|
18
|
+
},
|
|
19
|
+
"./modsApi": {
|
|
20
|
+
"import": "./dist/modsApi.js",
|
|
21
|
+
"types": "./dist/modsApi.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./ui": {
|
|
24
|
+
"import": "./dist/ui.js",
|
|
25
|
+
"types": "./dist/ui.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"./wardrobe": {
|
|
28
|
+
"import": "./dist/wardrobe.js",
|
|
29
|
+
"types": "./dist/wardrobe.d.ts"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
11
32
|
"dependencies": {
|
|
12
33
|
"bondage-club-mod-sdk": "^1.2.0"
|
|
13
34
|
},
|