zois-core 2.2.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/icons/toast-themes/abdl/bottle.svg +10 -0
- package/dist/assets/icons/toast-themes/abdl/diaper.svg +11 -0
- package/dist/assets/icons/toast-themes/abdl/heart.svg +7 -0
- package/dist/assets/icons/toast-themes/abdl/sparkle.svg +5 -0
- package/dist/assets/icons/toast-themes/abdl/star.svg +5 -0
- package/dist/assets/icons/toast-themes/abdl/teddy.svg +18 -0
- package/dist/assets/icons/toast-themes/anime/error.svg +20 -0
- package/dist/assets/icons/toast-themes/anime/info.svg +20 -0
- package/dist/assets/icons/toast-themes/anime/success.svg +16 -0
- package/dist/assets/icons/toast-themes/anime/warning.svg +19 -0
- package/dist/changelogs.js +628 -295
- package/dist/cssVars.js +46 -0
- package/dist/dialogs.js +523 -83
- package/dist/events.js +28 -6
- package/dist/index.js +27 -70
- package/dist/localization.js +250 -40
- package/dist/messaging.js +1 -1
- package/dist/migration.js +37 -0
- package/dist/modules/baseModule.js +110 -0
- package/dist/modules/index.js +4 -0
- package/dist/modules/loadingStrategy.js +20 -0
- package/dist/modules/moduleContext.js +56 -0
- package/dist/modules/modulesManager.js +175 -0
- package/dist/{modSdk.js → patching.js} +33 -9
- package/dist/rpc.js +139 -0
- package/dist/scripts/zois-core.js +18 -0
- package/dist/settings.js +90 -0
- package/dist/settingsDialog.js +1361 -0
- package/dist/shard-modules/{attributesModule.js → attributes.js} +2 -2
- package/dist/shard-modules/{shardModule.js → base.js} +2 -2
- package/dist/shard-modules/{centerModule.js → center.js} +4 -2
- package/dist/shard-modules/{clickModule.js → click.js} +2 -2
- package/dist/shard-modules/{counterUpModule.js → counterUp.js} +2 -2
- package/dist/shard-modules/{dynamicClassModule.js → dynamicClass.js} +2 -2
- package/dist/shard-modules/index.js +9 -9
- package/dist/shard-modules/{multiClickModule.js → multiClick.js} +2 -2
- package/dist/shard-modules/{styleModule.js → style.js} +2 -2
- package/dist/shard-modules/{typeModule.js → type.js} +2 -2
- package/dist/shards/backNextButton.js +173 -0
- package/dist/shards/{shard.js → base.js} +15 -15
- package/dist/shards/{buttonShard.js → button.js} +30 -52
- package/dist/shards/{cardShard.js → card.js} +4 -4
- package/dist/shards/{checkboxShard.js → checkbox.js} +6 -13
- package/dist/shards/{containerShard.js → container.js} +2 -2
- package/dist/shards/extensionsStorageBar.js +377 -0
- package/dist/shards/fileInput.js +180 -0
- package/dist/shards/flexContainer.js +30 -0
- package/dist/shards/gridContainer.js +34 -0
- package/dist/shards/{imageShard.js → image.js} +8 -6
- package/dist/shards/index.js +17 -13
- package/dist/shards/{inputShard.js → input.js} +4 -4
- package/dist/shards/{inputListShard.js → inputList.js} +22 -4
- package/dist/shards/select.js +201 -0
- package/dist/shards/svg.js +28 -0
- package/dist/shards/{tabsShard.js → tabs.js} +18 -19
- package/dist/shards/{textShard.js → text.js} +4 -4
- package/dist/shared.js +215 -0
- package/dist/styles.css +0 -51
- package/dist/subscreens/customTranslations.js +239 -0
- package/dist/subscreens/languageDetails.js +194 -0
- package/dist/subscreens/localization.js +115 -0
- package/dist/toast-themes/abdl.js +419 -0
- package/dist/toast-themes/anime.js +483 -0
- package/dist/toast-themes/base.js +40 -0
- package/dist/toast-themes/cyber.js +538 -0
- package/dist/toast-themes/default.js +282 -0
- package/dist/toastThemesDialog.js +274 -0
- package/dist/toasts.js +195 -174
- package/dist/types/cssVars.d.ts +1 -0
- package/dist/types/dialogs.d.ts +46 -18
- package/dist/types/events.d.ts +11 -2
- package/dist/types/global.d.ts +4 -3
- package/dist/types/index.d.ts +12 -19
- package/dist/types/localization.d.ts +25 -3
- package/dist/types/migration.d.ts +6 -0
- package/dist/types/modules/baseModule.d.ts +108 -0
- package/dist/types/modules/index.d.ts +4 -0
- package/dist/types/modules/loadingStrategy.d.ts +7 -0
- package/dist/types/modules/moduleContext.d.ts +9 -0
- package/dist/types/modules/modulesManager.d.ts +23 -0
- package/dist/types/{modSdk.d.ts → patching.d.ts} +2 -3
- package/dist/types/rpc.d.ts +72 -0
- package/dist/types/settings.d.ts +19 -0
- package/dist/types/settingsDialog.d.ts +4 -0
- package/dist/types/shard-modules/{attributesModule.d.ts → attributes.d.ts} +2 -2
- package/dist/types/shard-modules/{shardModule.d.ts → base.d.ts} +2 -2
- package/dist/types/shard-modules/{centerModule.d.ts → center.d.ts} +2 -1
- package/dist/types/shard-modules/{clickModule.d.ts → click.d.ts} +2 -2
- package/dist/types/shard-modules/{counterUpModule.d.ts → counterUp.d.ts} +2 -2
- package/dist/types/shard-modules/{dynamicClassModule.d.ts → dynamicClass.d.ts} +2 -2
- package/dist/types/shard-modules/index.d.ts +9 -9
- package/dist/types/shard-modules/{multiClickModule.d.ts → multiClick.d.ts} +2 -2
- package/dist/types/shard-modules/{styleModule.d.ts → style.d.ts} +2 -2
- package/dist/types/shard-modules/{typeModule.d.ts → type.d.ts} +2 -2
- package/dist/types/shards/{backNextButtonShard.d.ts → backNextButton.d.ts} +4 -3
- package/dist/types/shards/{shard.d.ts → base.d.ts} +3 -2
- package/dist/types/shards/{buttonShard.d.ts → button.d.ts} +6 -6
- package/dist/types/shards/{cardShard.d.ts → card.d.ts} +3 -3
- package/dist/types/shards/{checkboxShard.d.ts → checkbox.d.ts} +5 -5
- package/dist/types/shards/{containerShard.d.ts → container.d.ts} +2 -2
- package/dist/types/shards/extensionsStorageBar.d.ts +28 -0
- package/dist/types/shards/fileInput.d.ts +10 -0
- package/dist/types/shards/flexContainer.d.ts +14 -0
- package/dist/types/shards/gridContainer.d.ts +18 -0
- package/dist/types/shards/{imageShard.d.ts → image.d.ts} +2 -2
- package/dist/types/shards/index.d.ts +17 -13
- package/dist/types/shards/{inputShard.d.ts → input.d.ts} +3 -3
- package/dist/types/shards/{inputListShard.d.ts → inputList.d.ts} +3 -2
- package/dist/types/shards/{selectShard.d.ts → select.d.ts} +6 -4
- package/dist/types/shards/svg.d.ts +11 -0
- package/dist/types/shards/{tabsShard.d.ts → tabs.d.ts} +3 -6
- package/dist/types/shards/{textShard.d.ts → text.d.ts} +3 -3
- package/dist/types/shared.d.ts +7 -0
- package/dist/types/subscreens/customTranslations.d.ts +10 -0
- package/dist/types/subscreens/languageDetails.d.ts +14 -0
- package/dist/types/subscreens/localization.d.ts +5 -0
- package/dist/types/toast-themes/abdl.d.ts +9 -0
- package/dist/types/toast-themes/anime.d.ts +9 -0
- package/dist/types/toast-themes/base.d.ts +39 -0
- package/dist/types/toast-themes/cyber.d.ts +10 -0
- package/dist/types/toast-themes/default.d.ts +9 -0
- package/dist/types/toastThemesDialog.d.ts +1 -0
- package/dist/types/toasts.d.ts +48 -36
- package/dist/types/ui.d.ts +128 -49
- package/dist/types/validation.d.ts +5 -0
- package/dist/ui.js +414 -79
- package/dist/validation.js +79 -1
- package/dist/wardrobe.js +2 -2
- package/package.json +37 -15
- package/dist/core-subscreen/coreSubscreen.js +0 -81
- package/dist/core-subscreen/developmentSubscreen.js +0 -22
- package/dist/core-subscreen/generalSubscreen.js +0 -23
- package/dist/core-subscreen/mainSubscreen.js +0 -58
- package/dist/core-subscreen/shards/coreButtonShard.js +0 -30
- package/dist/core-subscreen/shards/coreCheckboxShard.js +0 -33
- package/dist/core-subscreen/shards/coreInputListShard.js +0 -38
- package/dist/core-subscreen/shards/coreSelectShard.js +0 -17
- package/dist/core-subscreen/shards/coreTextShard.js +0 -9
- package/dist/core-subscreen/shards/index.js +0 -5
- package/dist/core-subscreen/toastsSubscreen.js +0 -111
- package/dist/core.js +0 -192
- package/dist/shards/backNextButtonShard.js +0 -99
- package/dist/shards/selectShard.js +0 -131
- package/dist/shards/svgShard.js +0 -29
- package/dist/types/core-subscreen/coreSubscreen.d.ts +0 -15
- package/dist/types/core-subscreen/developmentSubscreen.d.ts +0 -5
- package/dist/types/core-subscreen/generalSubscreen.d.ts +0 -5
- package/dist/types/core-subscreen/mainSubscreen.d.ts +0 -6
- package/dist/types/core-subscreen/shards/coreButtonShard.d.ts +0 -5
- package/dist/types/core-subscreen/shards/coreCheckboxShard.d.ts +0 -6
- package/dist/types/core-subscreen/shards/coreInputListShard.d.ts +0 -6
- package/dist/types/core-subscreen/shards/coreSelectShard.d.ts +0 -5
- package/dist/types/core-subscreen/shards/coreTextShard.d.ts +0 -4
- package/dist/types/core-subscreen/shards/index.d.ts +0 -5
- package/dist/types/core-subscreen/toastsSubscreen.d.ts +0 -5
- package/dist/types/core.d.ts +0 -18
- package/dist/types/shards/svgShard.d.ts +0 -12
- package/scripts/zois-core.mjs +0 -184
package/dist/events.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { MOD_DATA } from ".";
|
|
2
2
|
import { logger } from "./logging";
|
|
3
|
+
import { getCurrentSubscreen, setSubscreen } from "./ui";
|
|
4
|
+
import { dialogsManager } from "./dialogs";
|
|
3
5
|
const listeners = /* @__PURE__ */ new Map();
|
|
4
6
|
const onceListeners = /* @__PURE__ */ new Map();
|
|
5
7
|
function parseEventSpec(spec) {
|
|
@@ -24,7 +26,7 @@ class EventBus {
|
|
|
24
26
|
const fullData = { ...data, sender: this.id };
|
|
25
27
|
const commonEventListeners = listeners.get(event);
|
|
26
28
|
if (commonEventListeners) {
|
|
27
|
-
for (const listener of commonEventListeners) {
|
|
29
|
+
for (const listener of [...commonEventListeners]) {
|
|
28
30
|
try {
|
|
29
31
|
if (listener.senderFilter) {
|
|
30
32
|
if (listener.senderFilter === this.id) listener.callback(fullData);
|
|
@@ -37,7 +39,7 @@ class EventBus {
|
|
|
37
39
|
}
|
|
38
40
|
const onceEventListeners = onceListeners.get(event);
|
|
39
41
|
if (onceEventListeners) {
|
|
40
|
-
for (const listener of onceEventListeners) {
|
|
42
|
+
for (const listener of [...onceEventListeners]) {
|
|
41
43
|
try {
|
|
42
44
|
if (listener.senderFilter) {
|
|
43
45
|
if (listener.senderFilter === this.id) {
|
|
@@ -101,16 +103,36 @@ function getEventBus(id) {
|
|
|
101
103
|
return bus;
|
|
102
104
|
}
|
|
103
105
|
let eventBus = null;
|
|
104
|
-
function
|
|
106
|
+
function initEventBus() {
|
|
105
107
|
try {
|
|
106
108
|
eventBus = window.ZOIS_CORE.getEventBus(MOD_DATA.name);
|
|
109
|
+
eventBus.on("setSubscreen", async (data) => {
|
|
110
|
+
const target = data.target;
|
|
111
|
+
const isTrusted = data.isTrusted;
|
|
112
|
+
if (target === void 0) return;
|
|
113
|
+
if (target.startsWith(MOD_DATA.key + ":")) {
|
|
114
|
+
let currentSubscreen = getCurrentSubscreen();
|
|
115
|
+
const mod = target.substring(0, MOD_DATA.key.length);
|
|
116
|
+
const subscreen = target.substring(MOD_DATA.key.length + 1);
|
|
117
|
+
if (currentSubscreen?.constructor?.name === subscreen) return;
|
|
118
|
+
const s = MOD_DATA.subscreens?.[subscreen];
|
|
119
|
+
if (s === void 0) return;
|
|
120
|
+
if (isTrusted || await dialogsManager.confirm({ message: `Confirm the redirecting to modded subscreen ${target}` })) {
|
|
121
|
+
await PreferenceOpenSubscreen("Extensions");
|
|
122
|
+
await PreferenceSubscreenExtensionsOpen(mod, ["Online", "ChatRoom"]);
|
|
123
|
+
currentSubscreen = getCurrentSubscreen();
|
|
124
|
+
if (currentSubscreen?.constructor?.name !== s.name) setSubscreen(new s());
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
logger.log("Initialized EventBus");
|
|
107
129
|
} catch (e) {
|
|
108
|
-
logger.error("Failed to
|
|
130
|
+
logger.error("Failed to initialize EventBus:", e);
|
|
109
131
|
}
|
|
110
132
|
}
|
|
111
133
|
export {
|
|
112
134
|
EventBus,
|
|
113
|
-
createEventBus,
|
|
114
135
|
eventBus,
|
|
115
|
-
getEventBus
|
|
136
|
+
getEventBus,
|
|
137
|
+
initEventBus
|
|
116
138
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,80 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dialogsManager } from "./dialogs";
|
|
3
|
-
import { createEventBus, eventBus } from "./events";
|
|
1
|
+
import { initEventBus } from "./events";
|
|
4
2
|
import { loadLocalization } from "./localization";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { initModSdk } from "./patching";
|
|
4
|
+
import { initShared } from "./shared";
|
|
7
5
|
import { version } from "../package.json";
|
|
6
|
+
import { ModuleLoadingStrategy, modulesManager } from "./modules";
|
|
7
|
+
import { initRPCBus } from "./rpc";
|
|
8
|
+
import { logger } from "./logging";
|
|
8
9
|
let MOD_DATA;
|
|
9
10
|
function bootstrap(modData) {
|
|
10
11
|
MOD_DATA = modData;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
return next(args);
|
|
27
|
-
});
|
|
28
|
-
eventBus?.on("setSubscreen", async (data) => {
|
|
29
|
-
const target = data.target;
|
|
30
|
-
const isTrusted = data.isTrusted;
|
|
31
|
-
if (target === void 0) return;
|
|
32
|
-
if (target.startsWith(MOD_DATA.key + ":")) {
|
|
33
|
-
const currentSubscreen = getCurrentSubscreen();
|
|
34
|
-
const mod = target.substring(0, MOD_DATA.key.length);
|
|
35
|
-
const subscreen = target.substring(MOD_DATA.key.length + 1);
|
|
36
|
-
if (currentSubscreen?.constructor?.name === subscreen) return;
|
|
37
|
-
const s = MOD_DATA.subscreens?.[subscreen];
|
|
38
|
-
if (s === void 0) return;
|
|
39
|
-
if (isTrusted || await dialogsManager.confirm({ message: `Confirm the redirecting to modded subscreen ${target}` })) {
|
|
40
|
-
await PreferenceOpenSubscreen("Extensions");
|
|
41
|
-
await PreferenceSubscreenExtensionsOpen(mod, ["Online", "ChatRoom"]);
|
|
42
|
-
setSubscreen(new s());
|
|
12
|
+
logger.log("Zzzzzz.... Waiting for GameReadyState.load");
|
|
13
|
+
GameReadyState.load.then(async () => {
|
|
14
|
+
initModSdk();
|
|
15
|
+
if (!window.ZOIS_CORE) initShared();
|
|
16
|
+
initEventBus();
|
|
17
|
+
initRPCBus();
|
|
18
|
+
window.ZOIS_CORE.addDependent({
|
|
19
|
+
coreVersion: version,
|
|
20
|
+
modData: {
|
|
21
|
+
...modData,
|
|
22
|
+
modules: void 0,
|
|
23
|
+
subscreens: void 0,
|
|
24
|
+
migrators: void 0,
|
|
25
|
+
onReady: void 0
|
|
43
26
|
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
27
|
+
});
|
|
28
|
+
modulesManager.registerModules();
|
|
29
|
+
modulesManager.loadByStrategy(ModuleLoadingStrategy.BEFORE_LOGIN);
|
|
30
|
+
await ServerIsLoggedInAsync();
|
|
31
|
+
await loadLocalization();
|
|
32
|
+
modulesManager.loadByStrategy(ModuleLoadingStrategy.AFTER_LOGIN);
|
|
33
|
+
if (modData.onReady) modData.onReady();
|
|
48
34
|
});
|
|
49
35
|
}
|
|
50
|
-
function formatString(text) {
|
|
51
|
-
if (!text || typeof text !== "string") {
|
|
52
|
-
return { isBeatifulString: false };
|
|
53
|
-
}
|
|
54
|
-
let result = text;
|
|
55
|
-
let hasChanges = false;
|
|
56
|
-
const markdownRegex = /\[([^\]]+?)\]\(([^)]+?)\)/g;
|
|
57
|
-
const newResult = result.replace(markdownRegex, (match, linkText, url) => {
|
|
58
|
-
hasChanges = true;
|
|
59
|
-
const escapedText = linkText.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
60
|
-
return `<a href="${url}" target="_blank" rel="noopener noreferrer">${escapedText}</a>`;
|
|
61
|
-
});
|
|
62
|
-
if (newResult !== result) {
|
|
63
|
-
result = newResult;
|
|
64
|
-
}
|
|
65
|
-
const zcRegex = /(?<!\S)zc:\/\/open[^\s<>"']*(?!\S)/gi;
|
|
66
|
-
result = result.replace(zcRegex, (match) => {
|
|
67
|
-
hasChanges = true;
|
|
68
|
-
return `<a href="${match}" target="_blank" rel="noopener noreferrer">${match}</a>`;
|
|
69
|
-
});
|
|
70
|
-
if (hasChanges) {
|
|
71
|
-
return {
|
|
72
|
-
html: result,
|
|
73
|
-
isBeatifulString: true
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
return { isBeatifulString: false };
|
|
77
|
-
}
|
|
78
36
|
function sleep(ms) {
|
|
79
37
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
80
38
|
}
|
|
@@ -148,7 +106,6 @@ export {
|
|
|
148
106
|
MOD_DATA,
|
|
149
107
|
bootstrap,
|
|
150
108
|
colorsEqual,
|
|
151
|
-
formatString,
|
|
152
109
|
getNickname,
|
|
153
110
|
getPlayer,
|
|
154
111
|
getRandomNumber,
|
package/dist/localization.js
CHANGED
|
@@ -1,21 +1,238 @@
|
|
|
1
1
|
import { MOD_DATA } from "./index";
|
|
2
2
|
import { logger } from "./logging";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { US, RU, UA, CN, JP, DE, FR, IN } from "country-flag-icons/string/3x2";
|
|
4
|
+
import { eventBus } from "./events";
|
|
5
|
+
const LANGUAGES = [
|
|
6
|
+
{ locale: "en", name: "English", flag: US },
|
|
7
|
+
{ locale: "ru", name: "\u0420\u0443\u0441\u0441\u043A\u0438\u0439", flag: RU },
|
|
8
|
+
{ locale: "uk", name: "\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430", flag: UA },
|
|
9
|
+
{ locale: "zh", name: "\u4E2D\u6587", flag: CN },
|
|
10
|
+
{ locale: "ja", name: "\u65E5\u672C\u8A9E", flag: JP },
|
|
11
|
+
{ locale: "de", name: "Deutsch", flag: DE },
|
|
12
|
+
{ locale: "fr", name: "Fran\xE7ais", flag: FR },
|
|
13
|
+
{ locale: "hi", name: "\u0939\u093F\u0928\u094D\u0926\u0940", flag: IN }
|
|
14
|
+
];
|
|
15
|
+
const SETTINGS_KEY = "ZC_LOCALE";
|
|
16
|
+
const IDB_NAME = "zc-custom-translations";
|
|
17
|
+
const IDB_VERSION = 2;
|
|
18
|
+
const IDB_STORE_TRANSLATIONS = "translations";
|
|
19
|
+
const IDB_STORE_ACTIVE = "active";
|
|
20
|
+
let officialTranslations = {};
|
|
21
|
+
let activeCustomTranslation = null;
|
|
22
|
+
function getLocale() {
|
|
23
|
+
const stored = Player?.ExtensionSettings?.[SETTINGS_KEY];
|
|
24
|
+
if (stored && LANGUAGES.some((l) => l.locale === stored)) {
|
|
25
|
+
return stored;
|
|
26
|
+
}
|
|
27
|
+
const gameLocale = TranslationLanguage.toLowerCase();
|
|
28
|
+
if (LANGUAGES.some((l) => l.locale === gameLocale)) {
|
|
29
|
+
return gameLocale;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
function setLocale(locale) {
|
|
34
|
+
Player.ExtensionSettings[SETTINGS_KEY] = locale;
|
|
35
|
+
ServerPlayerExtensionSettingsSync(SETTINGS_KEY);
|
|
36
|
+
eventBus?.emit("localeChanged", { locale });
|
|
37
|
+
}
|
|
38
|
+
function openTranslationsDb() {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
const request = indexedDB.open(IDB_NAME, IDB_VERSION);
|
|
41
|
+
request.onupgradeneeded = () => {
|
|
42
|
+
const db = request.result;
|
|
43
|
+
if (!db.objectStoreNames.contains(IDB_STORE_TRANSLATIONS)) {
|
|
44
|
+
const store = db.createObjectStore(IDB_STORE_TRANSLATIONS, {
|
|
45
|
+
keyPath: "name"
|
|
46
|
+
});
|
|
47
|
+
store.createIndex("modKey", "modKey", { unique: false });
|
|
48
|
+
}
|
|
49
|
+
if (!db.objectStoreNames.contains(IDB_STORE_ACTIVE)) {
|
|
50
|
+
db.createObjectStore(IDB_STORE_ACTIVE);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
request.onsuccess = () => resolve(request.result);
|
|
54
|
+
request.onerror = () => reject(request.error ?? new Error("Failed to open IndexedDB"));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function idbRequest(request) {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
request.onsuccess = () => resolve(request.result);
|
|
60
|
+
request.onerror = () => reject(request.error ?? new Error("IndexedDB request failed"));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async function addCustomTranslation(name, data, modKey) {
|
|
64
|
+
const record = { name, modKey, data };
|
|
65
|
+
const db = await openTranslationsDb();
|
|
66
|
+
try {
|
|
67
|
+
const tx = db.transaction(IDB_STORE_TRANSLATIONS, "readwrite");
|
|
68
|
+
const store = tx.objectStore(IDB_STORE_TRANSLATIONS);
|
|
69
|
+
await idbRequest(store.put(record));
|
|
70
|
+
} finally {
|
|
71
|
+
db.close();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function removeCustomTranslation(name) {
|
|
75
|
+
const db = await openTranslationsDb();
|
|
76
|
+
try {
|
|
77
|
+
const tx = db.transaction(
|
|
78
|
+
[IDB_STORE_TRANSLATIONS, IDB_STORE_ACTIVE],
|
|
79
|
+
"readwrite"
|
|
80
|
+
);
|
|
81
|
+
const translationsStore = tx.objectStore(IDB_STORE_TRANSLATIONS);
|
|
82
|
+
const activeStore = tx.objectStore(IDB_STORE_ACTIVE);
|
|
83
|
+
const record = await idbRequest(
|
|
84
|
+
translationsStore.get(name)
|
|
85
|
+
);
|
|
86
|
+
await idbRequest(translationsStore.delete(name));
|
|
87
|
+
if (!record) return;
|
|
88
|
+
const activeName = await idbRequest(
|
|
89
|
+
activeStore.get(record.modKey)
|
|
90
|
+
);
|
|
91
|
+
if (activeName === name) {
|
|
92
|
+
await idbRequest(activeStore.delete(record.modKey));
|
|
93
|
+
if (record.modKey === MOD_DATA.key) {
|
|
94
|
+
eventBus?.emit("customTranslationChanged", { targetMod: record.modKey });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} finally {
|
|
98
|
+
db.close();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async function getCustomTranslation(name) {
|
|
102
|
+
const db = await openTranslationsDb();
|
|
103
|
+
try {
|
|
104
|
+
const tx = db.transaction(IDB_STORE_TRANSLATIONS, "readonly");
|
|
105
|
+
const store = tx.objectStore(IDB_STORE_TRANSLATIONS);
|
|
106
|
+
const record = await idbRequest(store.get(name));
|
|
107
|
+
return record ?? null;
|
|
108
|
+
} finally {
|
|
109
|
+
db.close();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function getAllCustomTranslations() {
|
|
113
|
+
const db = await openTranslationsDb();
|
|
114
|
+
try {
|
|
115
|
+
const tx = db.transaction(IDB_STORE_TRANSLATIONS, "readonly");
|
|
116
|
+
const store = tx.objectStore(IDB_STORE_TRANSLATIONS);
|
|
117
|
+
return await idbRequest(store.getAll());
|
|
118
|
+
} finally {
|
|
119
|
+
db.close();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function setActiveCustomTranslation(name) {
|
|
123
|
+
const record = await getCustomTranslation(name);
|
|
124
|
+
if (!record) {
|
|
125
|
+
throw new Error(`Custom translation "${name}" was not found`);
|
|
126
|
+
}
|
|
127
|
+
const db = await openTranslationsDb();
|
|
128
|
+
try {
|
|
129
|
+
const tx = db.transaction(IDB_STORE_ACTIVE, "readwrite");
|
|
130
|
+
const store = tx.objectStore(IDB_STORE_ACTIVE);
|
|
131
|
+
await idbRequest(store.put(name, record.modKey));
|
|
132
|
+
} finally {
|
|
133
|
+
db.close();
|
|
134
|
+
}
|
|
135
|
+
eventBus?.emit("customTranslationChanged", { targetMod: record.modKey });
|
|
136
|
+
}
|
|
137
|
+
async function getActiveCustomTranslation(modKey) {
|
|
138
|
+
const db = await openTranslationsDb();
|
|
139
|
+
try {
|
|
140
|
+
const tx = db.transaction(IDB_STORE_ACTIVE, "readonly");
|
|
141
|
+
const store = tx.objectStore(IDB_STORE_ACTIVE);
|
|
142
|
+
const name = await idbRequest(store.get(modKey));
|
|
143
|
+
if (!name) return null;
|
|
144
|
+
return getCustomTranslation(name);
|
|
145
|
+
} finally {
|
|
146
|
+
db.close();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async function clearActiveCustomTranslation(name) {
|
|
150
|
+
const record = await getCustomTranslation(name);
|
|
151
|
+
if (!record) {
|
|
152
|
+
throw new Error(`Custom translation "${name}" was not found`);
|
|
153
|
+
}
|
|
154
|
+
const db = await openTranslationsDb();
|
|
155
|
+
try {
|
|
156
|
+
const tx = db.transaction(IDB_STORE_ACTIVE, "readwrite");
|
|
157
|
+
const store = tx.objectStore(IDB_STORE_ACTIVE);
|
|
158
|
+
const activeName = await idbRequest(
|
|
159
|
+
store.get(record.modKey)
|
|
160
|
+
);
|
|
161
|
+
if (activeName === name) {
|
|
162
|
+
await idbRequest(store.delete(record.modKey));
|
|
163
|
+
eventBus?.emit("customTranslationChanged", { targetMod: record.modKey });
|
|
164
|
+
}
|
|
165
|
+
} finally {
|
|
166
|
+
db.close();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async function fetchTranslation(locale) {
|
|
170
|
+
if (!MOD_DATA.localization) {
|
|
171
|
+
throw new Error("Localization is not configured");
|
|
172
|
+
}
|
|
173
|
+
const response = await fetch(
|
|
174
|
+
`${MOD_DATA.localization.translationsFolderPath}/${locale}.json?=${Date.now()}`
|
|
175
|
+
);
|
|
176
|
+
if (!response.ok) {
|
|
177
|
+
throw new Error(
|
|
178
|
+
`Failed to fetch ${locale} translation at ${response.url}`
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
const data = await response.json();
|
|
182
|
+
officialTranslations[locale] = data;
|
|
183
|
+
logger.log(`Fetched official translations for locale: ${locale}`, data);
|
|
184
|
+
return data;
|
|
185
|
+
}
|
|
186
|
+
async function loadOfficialTranslation() {
|
|
187
|
+
if (!MOD_DATA.localization) return;
|
|
188
|
+
const supportedLocales = MOD_DATA.localization.locales.supported;
|
|
189
|
+
const defaultLocale = MOD_DATA.localization.locales.default;
|
|
190
|
+
const locale = getLocale() ?? defaultLocale;
|
|
191
|
+
if (!officialTranslations[defaultLocale]) {
|
|
192
|
+
try {
|
|
193
|
+
await fetchTranslation(defaultLocale);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
logger.error("Failed to load default official translations", error);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (locale !== defaultLocale && supportedLocales.includes(locale) && !officialTranslations[locale]) {
|
|
199
|
+
try {
|
|
200
|
+
await fetchTranslation(locale);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
logger.error(
|
|
203
|
+
`Failed to load official translations for ${locale}`,
|
|
204
|
+
error
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async function loadCustomTranslation() {
|
|
210
|
+
activeCustomTranslation = await getActiveCustomTranslation(MOD_DATA.key);
|
|
211
|
+
}
|
|
212
|
+
async function loadLocalization() {
|
|
6
213
|
if (MOD_DATA.localization === void 0) {
|
|
7
|
-
logger.
|
|
8
|
-
return
|
|
214
|
+
logger.log("Skip localization procedure because it is not configured");
|
|
215
|
+
return;
|
|
9
216
|
}
|
|
217
|
+
const supportedLocales = MOD_DATA.localization.locales.supported;
|
|
10
218
|
const defaultLocale = MOD_DATA.localization.locales.default;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return
|
|
219
|
+
if (!supportedLocales.includes(defaultLocale)) {
|
|
220
|
+
logger.warn(
|
|
221
|
+
`Default locale ${defaultLocale} isn't supported, fix configuration`
|
|
222
|
+
);
|
|
223
|
+
return;
|
|
16
224
|
}
|
|
17
|
-
|
|
18
|
-
|
|
225
|
+
eventBus?.on("localeChanged", (event) => {
|
|
226
|
+
logger.log("Reloading official translation");
|
|
227
|
+
loadOfficialTranslation();
|
|
228
|
+
});
|
|
229
|
+
eventBus?.on("customTranslationChanged", (event) => {
|
|
230
|
+
if (event.targetMod !== MOD_DATA.key) return;
|
|
231
|
+
logger.log("Reloading custom translation");
|
|
232
|
+
loadCustomTranslation();
|
|
233
|
+
});
|
|
234
|
+
await loadOfficialTranslation();
|
|
235
|
+
await loadCustomTranslation();
|
|
19
236
|
}
|
|
20
237
|
function getNestedValue(obj, path) {
|
|
21
238
|
if (!obj || !path) return void 0;
|
|
@@ -32,40 +249,33 @@ function processReplacements(text, replacements) {
|
|
|
32
249
|
}
|
|
33
250
|
return text;
|
|
34
251
|
}
|
|
35
|
-
|
|
252
|
+
function getText(tag, replacements) {
|
|
36
253
|
if (MOD_DATA.localization === void 0) {
|
|
37
|
-
logger.
|
|
38
|
-
return;
|
|
254
|
+
logger.warn("Attempt to call getText() without configuring localization");
|
|
255
|
+
return tag;
|
|
39
256
|
}
|
|
40
|
-
const supportedLocales = MOD_DATA.localization.locales.supported;
|
|
41
257
|
const defaultLocale = MOD_DATA.localization.locales.default;
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
hookFunction("TranslationSwitchLanguage", HookPriority.OBSERVE, (args, next) => {
|
|
48
|
-
const value = next(args);
|
|
49
|
-
if (supportedLocales.includes(TranslationLanguage.toLowerCase()) && !(TranslationLanguage.toLowerCase() in translations)) {
|
|
50
|
-
fetchTranslationsForLocale(TranslationLanguage.toLowerCase());
|
|
51
|
-
}
|
|
52
|
-
return value;
|
|
53
|
-
});
|
|
54
|
-
await fetchTranslationsForLocale(defaultLocale);
|
|
55
|
-
if (preferredLocale !== defaultLocale && supportedLocales.includes(preferredLocale)) {
|
|
56
|
-
await fetchTranslationsForLocale(preferredLocale);
|
|
258
|
+
const locale = getLocale() ?? defaultLocale;
|
|
259
|
+
const value = getNestedValue(activeCustomTranslation?.data ?? null, tag) ?? getNestedValue(officialTranslations[locale], tag) ?? getNestedValue(officialTranslations[defaultLocale], tag);
|
|
260
|
+
if (!value || typeof value !== "string") {
|
|
261
|
+
logger.warn("Unknown translation tag:", tag);
|
|
262
|
+
return tag;
|
|
57
263
|
}
|
|
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;
|
|
264
|
+
return replacements ? processReplacements(value, replacements) : value;
|
|
65
265
|
}
|
|
66
266
|
export {
|
|
67
|
-
|
|
267
|
+
LANGUAGES,
|
|
268
|
+
addCustomTranslation,
|
|
269
|
+
clearActiveCustomTranslation,
|
|
270
|
+
fetchTranslation,
|
|
271
|
+
getActiveCustomTranslation,
|
|
272
|
+
getAllCustomTranslations,
|
|
273
|
+
getCustomTranslation,
|
|
274
|
+
getLocale,
|
|
68
275
|
getText,
|
|
69
276
|
loadLocalization,
|
|
70
|
-
processReplacements
|
|
277
|
+
processReplacements,
|
|
278
|
+
removeCustomTranslation,
|
|
279
|
+
setActiveCustomTranslation,
|
|
280
|
+
setLocale
|
|
71
281
|
};
|
package/dist/messaging.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getPlayer, MOD_DATA } from "./index";
|
|
2
|
-
import { hookFunction, HookPriority } from "./
|
|
2
|
+
import { hookFunction, HookPriority } from "./patching";
|
|
3
3
|
import { setFontFamily } from "./ui";
|
|
4
4
|
import { validateData } from "./validation";
|
|
5
5
|
import { logger } from "./logging";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { isVersionNewer, MOD_DATA } from ".";
|
|
2
|
+
import { logger } from "./logging";
|
|
3
|
+
class BaseMigrator {
|
|
4
|
+
}
|
|
5
|
+
function runMigrations(savedVersion) {
|
|
6
|
+
const migrations = Object.values(
|
|
7
|
+
MOD_DATA.migrators ?? {}
|
|
8
|
+
).map((Migrator) => new Migrator());
|
|
9
|
+
migrations.sort((a, b) => {
|
|
10
|
+
if (isVersionNewer(a.migrationVersion, b.migrationVersion)) {
|
|
11
|
+
return 1;
|
|
12
|
+
}
|
|
13
|
+
if (isVersionNewer(b.migrationVersion, a.migrationVersion)) {
|
|
14
|
+
return -1;
|
|
15
|
+
}
|
|
16
|
+
return 0;
|
|
17
|
+
});
|
|
18
|
+
for (const migrator of migrations) {
|
|
19
|
+
if (!isVersionNewer(migrator.migrationVersion, savedVersion)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (isVersionNewer(migrator.migrationVersion, MOD_DATA.version)) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
migrator.migrate();
|
|
27
|
+
logger.log(`Applied migration to version "${migrator.migrationVersion}"`);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
logger.error(`Failed to apply migration to version "${migrator.migrationVersion}":`, error);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
BaseMigrator,
|
|
36
|
+
runMigrations
|
|
37
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { modulesManager } from "./modulesManager";
|
|
2
|
+
const DISABLED_MODULES = /* @__PURE__ */ new WeakSet();
|
|
3
|
+
function Disabled(constructor) {
|
|
4
|
+
DISABLED_MODULES.add(constructor);
|
|
5
|
+
return constructor;
|
|
6
|
+
}
|
|
7
|
+
class BaseModule {
|
|
8
|
+
/**
|
|
9
|
+
* Indicates whether this module is allowed to be loaded.
|
|
10
|
+
*
|
|
11
|
+
* Returns false if the module class has been decorated with @Disabled.
|
|
12
|
+
*/
|
|
13
|
+
get enabled() {
|
|
14
|
+
return !DISABLED_MODULES.has(this.constructor);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Requests initialization of this module through the ModulesManager.
|
|
18
|
+
*
|
|
19
|
+
* Calls onInit() once, before the module's first successful load.
|
|
20
|
+
*/
|
|
21
|
+
init() {
|
|
22
|
+
modulesManager.init(this.constructor.name);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Requests loading of this module through the ModulesManager.
|
|
26
|
+
*
|
|
27
|
+
* The manager creates a ModuleContext and passes it to onLoad().
|
|
28
|
+
*/
|
|
29
|
+
load() {
|
|
30
|
+
modulesManager.load(this.constructor.name);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Requests unloading of this module through the ModulesManager.
|
|
34
|
+
*
|
|
35
|
+
* The manager calls onUnload() and disposes the module's ModuleContext.
|
|
36
|
+
*/
|
|
37
|
+
unload() {
|
|
38
|
+
modulesManager.unload(this.constructor.name);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Requests a safeword event for this module through the ModulesManager.
|
|
42
|
+
*
|
|
43
|
+
* The manager calls onSafeword() if the module is currently loaded.
|
|
44
|
+
*/
|
|
45
|
+
safeword() {
|
|
46
|
+
modulesManager.safeword(this.constructor.name);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Requests reloading of this module through the ModulesManager.
|
|
50
|
+
*
|
|
51
|
+
* The manager unloads the module, calls onReload(), and loads it again.
|
|
52
|
+
*/
|
|
53
|
+
reload() {
|
|
54
|
+
modulesManager.reload(this.constructor.name);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Initializes the module before its first load.
|
|
58
|
+
*
|
|
59
|
+
* Called only once by the ModulesManager.
|
|
60
|
+
* Use this method to prepare resources and register persistent event listeners
|
|
61
|
+
* required by the module.
|
|
62
|
+
*/
|
|
63
|
+
onInit() {
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Loads the module and activates its functionality.
|
|
67
|
+
*
|
|
68
|
+
* Called whenever the module is loaded.
|
|
69
|
+
* Use this method to enable features, register temporary event listeners,
|
|
70
|
+
* and initialize resources that should remain active only while the module
|
|
71
|
+
* is loaded.
|
|
72
|
+
*
|
|
73
|
+
* @param context - The ModuleContext used to register hooks and patches.
|
|
74
|
+
*/
|
|
75
|
+
onLoad(context) {
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Unloads the module and deactivates its functionality.
|
|
79
|
+
*
|
|
80
|
+
* Called when the module is unloaded.
|
|
81
|
+
* Use this method to perform module-specific cleanup before the
|
|
82
|
+
* ModuleContext is disposed.
|
|
83
|
+
*/
|
|
84
|
+
onUnload() {
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Handles a safeword event for the module.
|
|
88
|
+
*
|
|
89
|
+
* Called by the ModulesManager when a safeword event is dispatched
|
|
90
|
+
* to this module.
|
|
91
|
+
* Use this method to immediately stop or safely terminate active
|
|
92
|
+
* module functionality.
|
|
93
|
+
*/
|
|
94
|
+
onSafeword() {
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Performs module-specific reload operations.
|
|
98
|
+
*
|
|
99
|
+
* Called by the ModulesManager after onUnload() and before onLoad()
|
|
100
|
+
* during a reload operation.
|
|
101
|
+
* Use this method to refresh configuration, recreate resources,
|
|
102
|
+
* or reset internal state.
|
|
103
|
+
*/
|
|
104
|
+
onReload() {
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export {
|
|
108
|
+
BaseModule,
|
|
109
|
+
Disabled
|
|
110
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var ModuleLoadingStrategy = /* @__PURE__ */ ((ModuleLoadingStrategy2) => {
|
|
2
|
+
ModuleLoadingStrategy2["BEFORE_LOGIN"] = "beforeLogin";
|
|
3
|
+
ModuleLoadingStrategy2["AFTER_LOGIN"] = "afterLogin";
|
|
4
|
+
ModuleLoadingStrategy2["MANUAL"] = "manual";
|
|
5
|
+
return ModuleLoadingStrategy2;
|
|
6
|
+
})(ModuleLoadingStrategy || {});
|
|
7
|
+
const MODULE_LOADING_STRATEGIES = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
function LoadingStrategy(strategy) {
|
|
9
|
+
return (constructor) => {
|
|
10
|
+
MODULE_LOADING_STRATEGIES.set(constructor, strategy);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function getLoadingStrategy(constructor) {
|
|
14
|
+
return MODULE_LOADING_STRATEGIES.get(constructor);
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
LoadingStrategy,
|
|
18
|
+
ModuleLoadingStrategy,
|
|
19
|
+
getLoadingStrategy
|
|
20
|
+
};
|