zois-core 1.2.1 → 2.0.1
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 +23 -2
- package/dist/assets/icons/exit.svg +17 -0
- package/dist/changelogs.js +153 -0
- package/dist/core-subscreen/coreSubscreen.js +81 -0
- package/dist/core-subscreen/developmentSubscreen.js +22 -0
- package/dist/core-subscreen/generalSubscreen.js +23 -0
- package/dist/core-subscreen/mainSubscreen.js +58 -0
- package/dist/core-subscreen/shards/coreButtonShard.js +30 -0
- package/dist/core-subscreen/shards/coreCheckboxShard.js +33 -0
- package/dist/core-subscreen/shards/coreInputListShard.js +38 -0
- package/dist/core-subscreen/shards/coreSelectShard.js +17 -0
- package/dist/core-subscreen/shards/coreTextShard.js +9 -0
- package/dist/core-subscreen/shards/index.js +5 -0
- package/dist/core-subscreen/toastsSubscreen.js +112 -0
- package/dist/core.js +178 -0
- package/dist/dialogs.js +110 -0
- package/dist/index.js +201 -1
- package/dist/localization.js +71 -0
- package/dist/logging.js +31 -0
- package/dist/messaging.js +234 -1
- package/dist/modSdk.js +63 -0
- package/dist/shard-modules/attributesModule.js +16 -0
- package/dist/shard-modules/centerModule.js +12 -0
- package/dist/shard-modules/clickModule.js +14 -0
- package/dist/shard-modules/counterUpModule.js +37 -0
- package/dist/shard-modules/dynamicClassModule.js +15 -0
- package/dist/shard-modules/index.js +9 -0
- package/dist/shard-modules/multiClickModule.js +41 -0
- package/dist/shard-modules/shardModule.js +12 -0
- package/dist/shard-modules/styleModule.js +20 -0
- package/dist/shard-modules/typeModule.js +37 -0
- package/dist/shards/backNextButtonShard.js +99 -0
- package/dist/shards/buttonShard.js +150 -0
- package/dist/shards/cardShard.js +35 -0
- package/dist/shards/checkboxShard.js +139 -0
- package/dist/shards/containerShard.js +16 -0
- package/dist/shards/imageShard.js +98 -0
- package/dist/shards/index.js +13 -0
- package/dist/shards/inputListShard.js +162 -0
- package/dist/shards/inputShard.js +33 -0
- package/dist/shards/selectShard.js +126 -0
- package/dist/shards/shard.js +79 -0
- package/dist/shards/svgShard.js +29 -0
- package/dist/shards/tabsShard.js +59 -0
- package/dist/shards/textShard.js +27 -0
- package/dist/styles.css +209 -1
- package/dist/toasts.js +189 -0
- package/dist/types/changelogs.d.ts +1 -0
- package/dist/types/core-subscreen/coreSubscreen.d.ts +15 -0
- package/dist/types/core-subscreen/developmentSubscreen.d.ts +5 -0
- package/dist/types/core-subscreen/generalSubscreen.d.ts +5 -0
- package/dist/types/core-subscreen/mainSubscreen.d.ts +6 -0
- package/dist/types/core-subscreen/shards/coreButtonShard.d.ts +5 -0
- package/dist/types/core-subscreen/shards/coreCheckboxShard.d.ts +6 -0
- package/dist/types/core-subscreen/shards/coreInputListShard.d.ts +6 -0
- package/dist/types/core-subscreen/shards/coreSelectShard.d.ts +5 -0
- package/dist/types/core-subscreen/shards/coreTextShard.d.ts +4 -0
- package/dist/types/core-subscreen/shards/index.d.ts +5 -0
- package/dist/types/core-subscreen/toastsSubscreen.d.ts +5 -0
- package/dist/types/core.d.ts +18 -0
- package/dist/types/dialogs.d.ts +29 -0
- package/dist/types/globals.d.ts +6 -0
- package/dist/types/index.d.ts +62 -6
- package/dist/types/localization.d.ts +4 -0
- package/dist/types/logging.d.ts +16 -0
- package/dist/types/messaging.d.ts +5 -3
- package/dist/types/{modsApi.d.ts → modSdk.d.ts} +2 -2
- package/dist/types/shard-modules/attributesModule.d.ts +7 -0
- package/dist/types/shard-modules/centerModule.d.ts +5 -0
- package/dist/types/shard-modules/clickModule.d.ts +7 -0
- package/dist/types/shard-modules/counterUpModule.d.ts +13 -0
- package/dist/types/shard-modules/dynamicClassModule.d.ts +8 -0
- package/dist/types/{ui-modules → shard-modules}/index.d.ts +2 -0
- package/dist/types/shard-modules/multiClickModule.d.ts +12 -0
- package/dist/types/shard-modules/shardModule.d.ts +7 -0
- package/dist/types/shard-modules/styleModule.d.ts +8 -0
- package/dist/types/shard-modules/typeModule.d.ts +11 -0
- package/dist/types/shards/backNextButtonShard.d.ts +14 -0
- package/dist/types/shards/buttonShard.d.ts +21 -0
- package/dist/types/shards/cardShard.d.ts +10 -0
- package/dist/types/shards/checkboxShard.d.ts +19 -0
- package/dist/types/shards/containerShard.d.ts +7 -0
- package/dist/types/shards/imageShard.d.ts +11 -0
- package/dist/types/shards/index.d.ts +13 -0
- package/dist/types/shards/inputListShard.d.ts +16 -0
- package/dist/types/shards/inputShard.d.ts +14 -0
- package/dist/types/shards/selectShard.d.ts +17 -0
- package/dist/types/shards/shard.d.ts +21 -0
- package/dist/types/shards/svgShard.d.ts +12 -0
- package/dist/types/shards/tabsShard.d.ts +17 -0
- package/dist/types/shards/textShard.d.ts +13 -0
- package/dist/types/toasts.d.ts +21 -0
- package/dist/types/ui.d.ts +35 -148
- package/dist/ui.js +375 -11
- package/dist/validation.js +31 -1
- package/dist/wardrobe.js +167 -1
- package/package.json +47 -26
- package/scripts/zois-core.mjs +126 -0
- package/dist/modsApi.js +0 -1
- package/dist/modules.js +0 -1
- package/dist/popups.js +0 -1
- package/dist/types/modules.d.ts +0 -18
- package/dist/types/popups.d.ts +0 -63
- package/dist/types/ui-modules/attributesModule.d.ts +0 -6
- package/dist/types/ui-modules/centerModule.d.ts +0 -4
- package/dist/types/ui-modules/clickModule.d.ts +0 -6
- package/dist/types/ui-modules/counterUpModule.d.ts +0 -12
- package/dist/types/ui-modules/dynamicClassModule.d.ts +0 -7
- package/dist/types/ui-modules/styleModule.d.ts +0 -7
- package/dist/types/ui-modules/typeModule.d.ts +0 -10
- package/dist/ui-modules/attributesModule.js +0 -1
- package/dist/ui-modules/centerModule.js +0 -1
- package/dist/ui-modules/clickModule.js +0 -1
- package/dist/ui-modules/counterUpModule.js +0 -1
- package/dist/ui-modules/dynamicClassModule.js +0 -1
- package/dist/ui-modules/index.js +0 -1
- package/dist/ui-modules/styleModule.js +0 -1
- package/dist/ui-modules/typeModule.js +0 -1
package/dist/core.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import styles from "./styles.css";
|
|
2
|
+
import { formatString, version, CoreSettingsChangedEvent, waitFor, SetSubscreenEvent } from "./index";
|
|
3
|
+
import { hookFunction, HookPriority } from "./modSdk";
|
|
4
|
+
import { getCurrentSubscreen, setSubscreen } from "./ui";
|
|
5
|
+
import { MainSubscreen } from "./core-subscreen/mainSubscreen";
|
|
6
|
+
import { createElement, Terminal } from "lucide";
|
|
7
|
+
import { ButtonShard, ContainerShard } from "./shards";
|
|
8
|
+
import { StyleModule } from "./shard-modules";
|
|
9
|
+
import { dialogsManager } from "./dialogs";
|
|
10
|
+
let coreSettings = {};
|
|
11
|
+
function syncSettings() {
|
|
12
|
+
if (typeof coreSettings !== "object") return;
|
|
13
|
+
Player.ExtensionSettings.ZOIS_CORE = LZString.compressToBase64(JSON.stringify(coreSettings));
|
|
14
|
+
ServerPlayerExtensionSettingsSync("ZOIS_CORE");
|
|
15
|
+
document.dispatchEvent(new CoreSettingsChangedEvent());
|
|
16
|
+
}
|
|
17
|
+
function registerSubscreen() {
|
|
18
|
+
PreferenceRegisterExtensionSetting({
|
|
19
|
+
Identifier: "ZOIS_CORE",
|
|
20
|
+
Image: () => {
|
|
21
|
+
const serializer = new XMLSerializer();
|
|
22
|
+
const svgString = serializer.serializeToString(createElement(Terminal));
|
|
23
|
+
return "data:image/svg+xml," + svgString;
|
|
24
|
+
},
|
|
25
|
+
ButtonText: () => "Zoi's Modding Core",
|
|
26
|
+
load: () => {
|
|
27
|
+
setSubscreen(new MainSubscreen());
|
|
28
|
+
},
|
|
29
|
+
run: () => {
|
|
30
|
+
getCurrentSubscreen()?.run();
|
|
31
|
+
},
|
|
32
|
+
click: () => {
|
|
33
|
+
getCurrentSubscreen()?.click();
|
|
34
|
+
},
|
|
35
|
+
exit: () => {
|
|
36
|
+
getCurrentSubscreen()?.exit();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
let loginScreenElements = [];
|
|
41
|
+
async function registerCore() {
|
|
42
|
+
const style = document.createElement("style");
|
|
43
|
+
style.innerHTML = styles;
|
|
44
|
+
document.head.append(style);
|
|
45
|
+
if (localStorage.getItem("autoConnectToDevServer") === "true") {
|
|
46
|
+
hookFunction("CommonGetServer", HookPriority.OVERRIDE_BEHAVIOR, (args, next) => {
|
|
47
|
+
return "https://bondage-club-server-test.herokuapp.com/";
|
|
48
|
+
});
|
|
49
|
+
const containerShard = new ContainerShard({
|
|
50
|
+
x: 1250,
|
|
51
|
+
y: 900,
|
|
52
|
+
modules: {
|
|
53
|
+
base: [
|
|
54
|
+
new StyleModule({
|
|
55
|
+
display: "flex"
|
|
56
|
+
})
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const container = containerShard.mount();
|
|
61
|
+
new ButtonShard({
|
|
62
|
+
padding: 1,
|
|
63
|
+
parent: container,
|
|
64
|
+
text: "You connected to dev server"
|
|
65
|
+
}).mount();
|
|
66
|
+
new ButtonShard({
|
|
67
|
+
width: 90,
|
|
68
|
+
height: 90,
|
|
69
|
+
padding: 1,
|
|
70
|
+
icon: "Icons/Cancel.png",
|
|
71
|
+
parent: container,
|
|
72
|
+
onClick: () => {
|
|
73
|
+
localStorage.removeItem("autoConnectToDevServer");
|
|
74
|
+
location.reload();
|
|
75
|
+
}
|
|
76
|
+
}).mount();
|
|
77
|
+
loginScreenElements.push(container);
|
|
78
|
+
hookFunction("LoginUnload", HookPriority.OVERRIDE_BEHAVIOR, (args, next) => {
|
|
79
|
+
loginScreenElements.forEach((e) => e.remove());
|
|
80
|
+
return next(args);
|
|
81
|
+
});
|
|
82
|
+
ServerURL = CommonGetServer();
|
|
83
|
+
ServerInit();
|
|
84
|
+
}
|
|
85
|
+
await waitFor(() => typeof Player?.MemberNumber === "number");
|
|
86
|
+
if (typeof Player.ExtensionSettings.ZOIS_CORE === "string") {
|
|
87
|
+
coreSettings = JSON.parse(LZString.decompressFromBase64(Player.ExtensionSettings.ZOIS_CORE) ?? "{}");
|
|
88
|
+
}
|
|
89
|
+
if (coreSettings.devMode) registerSubscreen();
|
|
90
|
+
window.ZOIS_CORE = Object.freeze({
|
|
91
|
+
version,
|
|
92
|
+
enableDevMode: () => {
|
|
93
|
+
coreSettings.devMode = true;
|
|
94
|
+
syncSettings();
|
|
95
|
+
registerSubscreen();
|
|
96
|
+
},
|
|
97
|
+
getSettings: () => {
|
|
98
|
+
return JSON.parse(JSON.stringify(coreSettings));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
hookFunction("ChatRoomMessageCreateReplyMessageElement", HookPriority.OVERRIDE_BEHAVIOR, (args, next) => {
|
|
102
|
+
const [msgId, displayMessage, data] = args;
|
|
103
|
+
const r = formatString(displayMessage);
|
|
104
|
+
if (!r.isBeatifulString) return next(args);
|
|
105
|
+
if (!msgId) {
|
|
106
|
+
return [displayMessage];
|
|
107
|
+
}
|
|
108
|
+
const metadata = ChatRoomGetMetadataElem(data.time, data.sender);
|
|
109
|
+
metadata.setAttribute("aria-hidden", "true");
|
|
110
|
+
return [
|
|
111
|
+
ElementCreate({
|
|
112
|
+
tag: "span",
|
|
113
|
+
classList: ["chat-room-message-content"],
|
|
114
|
+
attributes: { "msgid": msgId },
|
|
115
|
+
innerHTML: r.html
|
|
116
|
+
}),
|
|
117
|
+
ElementMenu.Create(
|
|
118
|
+
ElementGenerateID(),
|
|
119
|
+
[
|
|
120
|
+
metadata,
|
|
121
|
+
ElementButton.Create(
|
|
122
|
+
null,
|
|
123
|
+
() => ChatRoomMessageSetReply(msgId),
|
|
124
|
+
{ noStyling: true, tooltip: "Reply" },
|
|
125
|
+
{ button: { attributes: { name: "reply" } } }
|
|
126
|
+
)
|
|
127
|
+
],
|
|
128
|
+
{ direction: "rtl", role: "menu" },
|
|
129
|
+
{ menu: { classList: ["chat-room-message-popup"], attributes: { "aria-direction": "horizontal" } } }
|
|
130
|
+
)
|
|
131
|
+
];
|
|
132
|
+
});
|
|
133
|
+
document.addEventListener("click", async (event) => {
|
|
134
|
+
const link = event.target.closest("a");
|
|
135
|
+
if (link && link.href) {
|
|
136
|
+
try {
|
|
137
|
+
const url = new URL(link.href);
|
|
138
|
+
if (url.protocol === "zc:") {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
if (link.href.startsWith("zc://open")) {
|
|
141
|
+
const target = url.pathname.split("/").filter(Boolean)[1];
|
|
142
|
+
if (target === void 0) return;
|
|
143
|
+
switch (target) {
|
|
144
|
+
case "Admin": {
|
|
145
|
+
if (await dialogsManager.confirm({ message: "This deep link wants to redirect you to Admin subscreen. Confirm the redirecting." })) {
|
|
146
|
+
ChatRoomOpenAdminScreen();
|
|
147
|
+
}
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case "Wardrobe": {
|
|
151
|
+
if (await dialogsManager.confirm({ message: "This deep link wants to redirect you to Wardrobe subscreen. Confirm the redirecting." })) {
|
|
152
|
+
ChatRoomOpenWardrobeScreen();
|
|
153
|
+
}
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
case "Information": {
|
|
157
|
+
if (await dialogsManager.confirm({ message: "This deep link wants to redirect you to Information subscreen. Confirm the redirecting." })) {
|
|
158
|
+
ChatRoomOpenInformationScreen();
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
default: {
|
|
163
|
+
window.dispatchEvent(new SetSubscreenEvent({ target, isTrusted: false }));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
} catch (e) {
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}, true);
|
|
172
|
+
}
|
|
173
|
+
export {
|
|
174
|
+
coreSettings,
|
|
175
|
+
registerCore,
|
|
176
|
+
registerSubscreen,
|
|
177
|
+
syncSettings
|
|
178
|
+
};
|
package/dist/dialogs.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
function createDialog(dialog) {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
let inputOrSelectElement = null;
|
|
4
|
+
const clear = () => {
|
|
5
|
+
_dialog.remove();
|
|
6
|
+
background.remove();
|
|
7
|
+
document.removeEventListener("keydown", handleKeyDown, { capture: true });
|
|
8
|
+
};
|
|
9
|
+
const submit = () => {
|
|
10
|
+
clear();
|
|
11
|
+
if (dialog.type === "prompt") {
|
|
12
|
+
resolve(inputOrSelectElement.value);
|
|
13
|
+
}
|
|
14
|
+
if (dialog.type === "confirm") {
|
|
15
|
+
resolve(true);
|
|
16
|
+
}
|
|
17
|
+
if (dialog.type === "pick") {
|
|
18
|
+
resolve(inputOrSelectElement.value);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const cancel = () => {
|
|
22
|
+
clear();
|
|
23
|
+
resolve(false);
|
|
24
|
+
};
|
|
25
|
+
const handleKeyDown = (e) => {
|
|
26
|
+
if (e.key === "Enter" || e.key === "Escape") {
|
|
27
|
+
e.preventDefault();
|
|
28
|
+
e.stopPropagation();
|
|
29
|
+
}
|
|
30
|
+
if (e.key === "Enter") submit();
|
|
31
|
+
if (e.key === "Escape") cancel();
|
|
32
|
+
};
|
|
33
|
+
document.addEventListener("keydown", handleKeyDown, { capture: true });
|
|
34
|
+
const background = document.createElement("div");
|
|
35
|
+
background.style.cssText = "position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 20; opacity: 0.5; background: black;";
|
|
36
|
+
const _dialog = document.createElement("div");
|
|
37
|
+
_dialog.classList.add("zcDialog");
|
|
38
|
+
_dialog.setAttribute("data-zc-dialog-type", dialog.type);
|
|
39
|
+
_dialog.style.fontFamily = CommonGetFontName();
|
|
40
|
+
const message = document.createElement("p");
|
|
41
|
+
message.textContent = dialog.message;
|
|
42
|
+
_dialog.append(message);
|
|
43
|
+
switch (dialog.type) {
|
|
44
|
+
case "confirm": {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "prompt": {
|
|
48
|
+
const input = document.createElement("input");
|
|
49
|
+
input.style.cssText = "color: white; margin-top: 1px; width: 90%; background: rgb(82, 89, 104); border: none; border-radius: 4px; padding: 0.45em;";
|
|
50
|
+
inputOrSelectElement = input;
|
|
51
|
+
_dialog.append(input);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case "pick": {
|
|
55
|
+
const select = document.createElement("select");
|
|
56
|
+
select.style.cssText = "cursor: pointer; width: 90%; background: rgb(82, 89, 104); border: none; padding: 0.4em; color: white; border-radius: 4px;";
|
|
57
|
+
dialog.options.forEach((o) => {
|
|
58
|
+
const option = document.createElement("option");
|
|
59
|
+
option.setAttribute("key", o.name);
|
|
60
|
+
option.text = o.name;
|
|
61
|
+
select.append(option);
|
|
62
|
+
});
|
|
63
|
+
inputOrSelectElement = select;
|
|
64
|
+
_dialog.append(select);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const buttons = document.createElement("div");
|
|
69
|
+
buttons.style.cssText = "display: flex; justify-content: end; column-gap: 0.75em; width: 90%; padding: 0.9em 0;";
|
|
70
|
+
const cancelBtn = document.createElement("button");
|
|
71
|
+
cancelBtn.textContent = "Cancel";
|
|
72
|
+
cancelBtn.addEventListener("click", cancel);
|
|
73
|
+
const submitBtn = document.createElement("button");
|
|
74
|
+
submitBtn.textContent = "Ok";
|
|
75
|
+
submitBtn.addEventListener("click", submit);
|
|
76
|
+
buttons.append(cancelBtn, submitBtn);
|
|
77
|
+
_dialog.append(buttons);
|
|
78
|
+
document.body.append(_dialog, background);
|
|
79
|
+
if (inputOrSelectElement) inputOrSelectElement.focus();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
class DialogsManager {
|
|
83
|
+
process(dialogProps) {
|
|
84
|
+
return createDialog(dialogProps);
|
|
85
|
+
}
|
|
86
|
+
prompt({ message }) {
|
|
87
|
+
return this.process({
|
|
88
|
+
type: "prompt",
|
|
89
|
+
message
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
confirm({ message }) {
|
|
93
|
+
return this.process({
|
|
94
|
+
type: "confirm",
|
|
95
|
+
message
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
pick({ message, options }) {
|
|
99
|
+
return this.process({
|
|
100
|
+
type: "pick",
|
|
101
|
+
message,
|
|
102
|
+
options
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const dialogsManager = new DialogsManager();
|
|
107
|
+
export {
|
|
108
|
+
DialogsManager,
|
|
109
|
+
dialogsManager
|
|
110
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1 +1,201 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { registerCore } from "./core";
|
|
2
|
+
import { dialogsManager } from "./dialogs";
|
|
3
|
+
import { loadLocalization } from "./localization";
|
|
4
|
+
import { createModSdk, findModByName, hookFunction, HookPriority } from "./modSdk";
|
|
5
|
+
import { getCurrentSubscreen, setSubscreen } from "./ui";
|
|
6
|
+
import { version } from "../package.json";
|
|
7
|
+
let MOD_DATA;
|
|
8
|
+
function bootstrap(modData) {
|
|
9
|
+
if (!window.ZOIS_CORE) registerCore();
|
|
10
|
+
MOD_DATA = modData;
|
|
11
|
+
createModSdk();
|
|
12
|
+
loadLocalization();
|
|
13
|
+
hookFunction("GameKeyDown", HookPriority.ADD_BEHAVIOR, (args, next) => {
|
|
14
|
+
const currentSubscreen = getCurrentSubscreen();
|
|
15
|
+
if (CommonKey.IsPressed(args[0], "Escape") && !!currentSubscreen) {
|
|
16
|
+
currentSubscreen.exit();
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const zcDialog = document.querySelector(".zcDialog");
|
|
20
|
+
if (zcDialog instanceof HTMLDivElement) {
|
|
21
|
+
zcDialog.focus();
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return next(args);
|
|
25
|
+
});
|
|
26
|
+
window.addEventListener(
|
|
27
|
+
"zois-core:setsubscreen",
|
|
28
|
+
async (_event) => {
|
|
29
|
+
const event = _event;
|
|
30
|
+
const target = event.detail.target;
|
|
31
|
+
const isTrusted = event.detail.isTrusted;
|
|
32
|
+
if (target === void 0) return;
|
|
33
|
+
if (target.startsWith(MOD_DATA.key + ":")) {
|
|
34
|
+
const currentSubscreen = getCurrentSubscreen();
|
|
35
|
+
const mod = target.substring(0, MOD_DATA.key.length);
|
|
36
|
+
const subscreen = target.substring(MOD_DATA.key.length + 1);
|
|
37
|
+
if (currentSubscreen?.constructor?.name === subscreen) return;
|
|
38
|
+
const s = MOD_DATA.subscreens?.[subscreen];
|
|
39
|
+
if (s === void 0) return;
|
|
40
|
+
if (isTrusted || await dialogsManager.confirm({ message: `Confirm the redirecting to modded subscreen ${target}` })) {
|
|
41
|
+
await PreferenceOpenSubscreen("Extensions");
|
|
42
|
+
await PreferenceSubscreenExtensionsOpen(mod, ["Online", "ChatRoom"]);
|
|
43
|
+
setSubscreen(new s());
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
ServerIsLoggedInAsync().then(() => {
|
|
49
|
+
if (modData.onReady) setTimeout(modData.onReady, getRandomNumber(3e3, 6e3));
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function formatString(text) {
|
|
53
|
+
if (!text || typeof text !== "string") {
|
|
54
|
+
return { isBeatifulString: false };
|
|
55
|
+
}
|
|
56
|
+
let result = text;
|
|
57
|
+
let hasChanges = false;
|
|
58
|
+
const markdownRegex = /\[([^\]]+?)\]\(([^)]+?)\)/g;
|
|
59
|
+
const newResult = result.replace(markdownRegex, (match, linkText, url) => {
|
|
60
|
+
hasChanges = true;
|
|
61
|
+
const escapedText = linkText.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
62
|
+
return `<a href="${url}" target="_blank" rel="noopener noreferrer">${escapedText}</a>`;
|
|
63
|
+
});
|
|
64
|
+
if (newResult !== result) {
|
|
65
|
+
result = newResult;
|
|
66
|
+
}
|
|
67
|
+
const zcRegex = /(?<!\S)zc:\/\/open[^\s<>"']*(?!\S)/gi;
|
|
68
|
+
result = result.replace(zcRegex, (match) => {
|
|
69
|
+
hasChanges = true;
|
|
70
|
+
return `<a href="${match}" target="_blank" rel="noopener noreferrer">${match}</a>`;
|
|
71
|
+
});
|
|
72
|
+
if (hasChanges) {
|
|
73
|
+
return {
|
|
74
|
+
html: result,
|
|
75
|
+
isBeatifulString: true
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return { isBeatifulString: false };
|
|
79
|
+
}
|
|
80
|
+
class SetSubscreenEvent extends CustomEvent {
|
|
81
|
+
constructor(detail) {
|
|
82
|
+
super(`zois-core:setsubscreen`, { detail });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
class SubscreenLoadedEvent extends CustomEvent {
|
|
86
|
+
constructor(detail) {
|
|
87
|
+
super(`zois-core:subscreenloaded`, { detail });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
class SubscreenUnloadedEvent extends CustomEvent {
|
|
91
|
+
constructor(detail) {
|
|
92
|
+
super(`zois-core:subscreenunloaded`, { detail });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
class CoreSettingsChangedEvent extends CustomEvent {
|
|
96
|
+
constructor() {
|
|
97
|
+
super(`zois-core:coresettingschanged`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function sleep(ms) {
|
|
101
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
102
|
+
}
|
|
103
|
+
async function waitFor(func, cancelFunc = () => false) {
|
|
104
|
+
while (!func()) {
|
|
105
|
+
if (cancelFunc()) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
await sleep(10);
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
function getRandomNumber(min, max) {
|
|
113
|
+
min = Math.ceil(min);
|
|
114
|
+
max = Math.floor(max);
|
|
115
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
116
|
+
}
|
|
117
|
+
function isVersionNewer(version1, version2) {
|
|
118
|
+
const v1Parts = version1.split(".");
|
|
119
|
+
const v2Parts = version2.split(".");
|
|
120
|
+
for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
|
|
121
|
+
const v1Part = parseInt(v1Parts[i] || "0", 10);
|
|
122
|
+
const v2Part = parseInt(v2Parts[i] || "0", 10);
|
|
123
|
+
if (v1Part > v2Part) {
|
|
124
|
+
return true;
|
|
125
|
+
} else if (v1Part < v2Part) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
function colorsEqual(c1, c2) {
|
|
132
|
+
if (!c1 && !c2) return true;
|
|
133
|
+
if (!c1 && c2 === "Default" || !c2 && c1 === "Default") return true;
|
|
134
|
+
if (c1 === "Default" && Array.isArray(c2) && c2.filter((d) => d === "Default").length === c2.length) return true;
|
|
135
|
+
if (c2 === "Default" && Array.isArray(c1) && c1.filter((d) => d === "Default").length === c1.length) return true;
|
|
136
|
+
return JSON.stringify(c1) === JSON.stringify(c2);
|
|
137
|
+
}
|
|
138
|
+
function getSizeInKbytes(b) {
|
|
139
|
+
if (typeof b === "string") {
|
|
140
|
+
return Math.round(new TextEncoder().encode(b).byteLength / 100) / 10;
|
|
141
|
+
} else {
|
|
142
|
+
return Math.round(new TextEncoder().encode(JSON.stringify(b)).byteLength / 100) / 10;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function getPlayer(value) {
|
|
146
|
+
if (!value) return null;
|
|
147
|
+
return ChatRoomCharacter.find((Character) => {
|
|
148
|
+
return Character.MemberNumber == value || Character.Name.toLowerCase() === value || Character.Nickname?.toLowerCase() === value;
|
|
149
|
+
}) ?? null;
|
|
150
|
+
}
|
|
151
|
+
function getNickname(target) {
|
|
152
|
+
return CharacterNickname(target);
|
|
153
|
+
}
|
|
154
|
+
function getThemedColorsModule() {
|
|
155
|
+
if (!findModByName("Themed")) return null;
|
|
156
|
+
const data = LZString.decompressFromBase64(Player.ExtensionSettings.Themed ?? "") ?? "{}";
|
|
157
|
+
let themedData;
|
|
158
|
+
try {
|
|
159
|
+
themedData = JSON.parse(data);
|
|
160
|
+
} catch {
|
|
161
|
+
}
|
|
162
|
+
;
|
|
163
|
+
if (!themedData?.GlobalModule?.themedEnabled || !themedData?.GlobalModule?.doVanillaGuiOverhaul) return null;
|
|
164
|
+
return themedData.ColorsModule;
|
|
165
|
+
}
|
|
166
|
+
function injectStyles(stylesToInject) {
|
|
167
|
+
const style = document.createElement("style");
|
|
168
|
+
style.innerHTML = stylesToInject;
|
|
169
|
+
document.head.append(style);
|
|
170
|
+
}
|
|
171
|
+
function normalizeObject(obj) {
|
|
172
|
+
if (!CommonIsObject(obj)) return obj;
|
|
173
|
+
if (Array.isArray(obj)) {
|
|
174
|
+
return obj.map(normalizeObject).sort();
|
|
175
|
+
}
|
|
176
|
+
return Object.keys(obj).sort().reduce((acc, key) => {
|
|
177
|
+
acc[key] = normalizeObject(obj[key]);
|
|
178
|
+
return acc;
|
|
179
|
+
}, {});
|
|
180
|
+
}
|
|
181
|
+
export {
|
|
182
|
+
CoreSettingsChangedEvent,
|
|
183
|
+
MOD_DATA,
|
|
184
|
+
SetSubscreenEvent,
|
|
185
|
+
SubscreenLoadedEvent,
|
|
186
|
+
SubscreenUnloadedEvent,
|
|
187
|
+
bootstrap,
|
|
188
|
+
colorsEqual,
|
|
189
|
+
formatString,
|
|
190
|
+
getNickname,
|
|
191
|
+
getPlayer,
|
|
192
|
+
getRandomNumber,
|
|
193
|
+
getSizeInKbytes,
|
|
194
|
+
getThemedColorsModule,
|
|
195
|
+
injectStyles,
|
|
196
|
+
isVersionNewer,
|
|
197
|
+
normalizeObject,
|
|
198
|
+
sleep,
|
|
199
|
+
version,
|
|
200
|
+
waitFor
|
|
201
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { MOD_DATA } from "./index";
|
|
2
|
+
import { logger } from "./logging";
|
|
3
|
+
import { hookFunction, HookPriority } from "./modSdk";
|
|
4
|
+
let translations = {};
|
|
5
|
+
function getText(tag, replacements) {
|
|
6
|
+
if (MOD_DATA.localization === void 0) {
|
|
7
|
+
logger.warn("Attempt to call getText() without configuring localization");
|
|
8
|
+
return tag;
|
|
9
|
+
}
|
|
10
|
+
const defaultLocale = MOD_DATA.localization.locales.default;
|
|
11
|
+
const preferredLocale = TranslationLanguage;
|
|
12
|
+
const value = getNestedValue(translations[preferredLocale], tag) ?? getNestedValue(translations[defaultLocale], tag);
|
|
13
|
+
if (!value) {
|
|
14
|
+
logger.warn("Unknown translation tag:", tag);
|
|
15
|
+
return tag;
|
|
16
|
+
}
|
|
17
|
+
;
|
|
18
|
+
return replacements ? processReplacements(value, replacements) : value;
|
|
19
|
+
}
|
|
20
|
+
function getNestedValue(obj, path) {
|
|
21
|
+
if (!obj || !path) return void 0;
|
|
22
|
+
return path.split(".").reduce((current, key) => {
|
|
23
|
+
if (current && typeof current === "object" && key in current) {
|
|
24
|
+
return current[key];
|
|
25
|
+
}
|
|
26
|
+
return void 0;
|
|
27
|
+
}, obj);
|
|
28
|
+
}
|
|
29
|
+
function processReplacements(text, replacements) {
|
|
30
|
+
for (const [key, value] of Object.entries(replacements)) {
|
|
31
|
+
text = text.replaceAll("$" + key, value.toString());
|
|
32
|
+
}
|
|
33
|
+
return text;
|
|
34
|
+
}
|
|
35
|
+
async function loadLocalization() {
|
|
36
|
+
if (MOD_DATA.localization === void 0) {
|
|
37
|
+
logger.log("Skip localization procedure because its not configured");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const supportedLocales = MOD_DATA.localization.locales.supported;
|
|
41
|
+
const defaultLocale = MOD_DATA.localization.locales.default;
|
|
42
|
+
const preferredLocale = TranslationLanguage;
|
|
43
|
+
if (!supportedLocales.includes(defaultLocale)) {
|
|
44
|
+
logger.warn(`Default locale ${defaultLocale} isn't supported, fix configuration`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
hookFunction("TranslationSwitchLanguage", HookPriority.OBSERVE, (args, next) => {
|
|
48
|
+
const value = next(args);
|
|
49
|
+
if (supportedLocales.includes(TranslationLanguage) && !(TranslationLanguage in translations)) {
|
|
50
|
+
fetchTranslationsForLocale(TranslationLanguage);
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
53
|
+
});
|
|
54
|
+
await fetchTranslationsForLocale(defaultLocale);
|
|
55
|
+
if (preferredLocale !== defaultLocale && supportedLocales.includes(preferredLocale)) {
|
|
56
|
+
await fetchTranslationsForLocale(preferredLocale);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function fetchTranslationsForLocale(locale) {
|
|
60
|
+
const response = await fetch(MOD_DATA.localization.translationsFolderPath + "/" + locale + ".json?=" + Date.now());
|
|
61
|
+
if (!response.ok) return logger.error(`Failed to fetch ${locale} translations at ${response.url}` + locale);
|
|
62
|
+
const data = await response.json();
|
|
63
|
+
logger.log(`Fetched translations for locale: ${locale}`, data);
|
|
64
|
+
translations[locale] = data;
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
fetchTranslationsForLocale,
|
|
68
|
+
getText,
|
|
69
|
+
loadLocalization,
|
|
70
|
+
processReplacements
|
|
71
|
+
};
|
package/dist/logging.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MOD_DATA } from "./index";
|
|
2
|
+
const logs = [];
|
|
3
|
+
class Logger {
|
|
4
|
+
get logs() {
|
|
5
|
+
return logs;
|
|
6
|
+
}
|
|
7
|
+
pushLog(level, message) {
|
|
8
|
+
this.logs.push({
|
|
9
|
+
level,
|
|
10
|
+
message,
|
|
11
|
+
timestamp: Date.now()
|
|
12
|
+
});
|
|
13
|
+
console[level](`%c${MOD_DATA.key}:`, "color: #00ffe7;", ...message);
|
|
14
|
+
}
|
|
15
|
+
debug(...message) {
|
|
16
|
+
this.pushLog("debug", message);
|
|
17
|
+
}
|
|
18
|
+
log(...message) {
|
|
19
|
+
this.pushLog("log", message);
|
|
20
|
+
}
|
|
21
|
+
warn(...message) {
|
|
22
|
+
this.pushLog("warn", message);
|
|
23
|
+
}
|
|
24
|
+
error(...message) {
|
|
25
|
+
this.pushLog("error", message);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const logger = new Logger();
|
|
29
|
+
export {
|
|
30
|
+
logger
|
|
31
|
+
};
|