zois-core 2.2.1 → 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 +14 -14
- 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 +36 -14
- 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
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addCustomTranslation,
|
|
3
|
+
removeCustomTranslation,
|
|
4
|
+
getCustomTranslation,
|
|
5
|
+
getActiveCustomTranslation,
|
|
6
|
+
setActiveCustomTranslation,
|
|
7
|
+
clearActiveCustomTranslation,
|
|
8
|
+
getAllCustomTranslations
|
|
9
|
+
} from "../localization";
|
|
10
|
+
import { BaseSubscreen, u } from "../ui";
|
|
11
|
+
import { StyleModule } from "../shard-modules";
|
|
12
|
+
import { dialogsManager } from "../dialogs";
|
|
13
|
+
function downloadJson(filename, data) {
|
|
14
|
+
const blob = new Blob([JSON.stringify(data, null, 2)], {
|
|
15
|
+
type: "application/json"
|
|
16
|
+
});
|
|
17
|
+
const url = URL.createObjectURL(blob);
|
|
18
|
+
const a = document.createElement("a");
|
|
19
|
+
a.href = url;
|
|
20
|
+
a.download = filename.endsWith(".json") ? filename : `${filename}.json`;
|
|
21
|
+
a.click();
|
|
22
|
+
URL.revokeObjectURL(url);
|
|
23
|
+
}
|
|
24
|
+
class CustomTranslationsSubscreen extends BaseSubscreen {
|
|
25
|
+
get name() {
|
|
26
|
+
return "Custom Translations";
|
|
27
|
+
}
|
|
28
|
+
translationsContainer = null;
|
|
29
|
+
onLoad() {
|
|
30
|
+
this.translationsContainer = this.createContainer({
|
|
31
|
+
x: 200,
|
|
32
|
+
y: 200,
|
|
33
|
+
width: 900,
|
|
34
|
+
height: 700,
|
|
35
|
+
scroll: "y",
|
|
36
|
+
modules: {
|
|
37
|
+
content: [
|
|
38
|
+
new StyleModule({
|
|
39
|
+
display: "flex",
|
|
40
|
+
flexDirection: "column",
|
|
41
|
+
gap: u(2),
|
|
42
|
+
padding: u(1),
|
|
43
|
+
boxSizing: "border-box"
|
|
44
|
+
})
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
this.createText({
|
|
49
|
+
x: 1180,
|
|
50
|
+
y: 220,
|
|
51
|
+
width: 620,
|
|
52
|
+
text: "Upload a JSON translation file to create a custom translation for a specific mod of Zoi's ecosystem. Custom translations are stored locally and persist after reload. You can download, activate, deactivate or delete them at any time."
|
|
53
|
+
});
|
|
54
|
+
this.createFileInput({
|
|
55
|
+
x: 1180,
|
|
56
|
+
y: 750,
|
|
57
|
+
width: 620,
|
|
58
|
+
height: 160,
|
|
59
|
+
title: "Upload translation file",
|
|
60
|
+
accept: ".json,application/json",
|
|
61
|
+
onFile: (file) => {
|
|
62
|
+
this.createCustomTranslation(file);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
this.renderTranslationList();
|
|
66
|
+
}
|
|
67
|
+
async renderTranslationList() {
|
|
68
|
+
if (!this.translationsContainer) return;
|
|
69
|
+
this.translationsContainer.replaceChildren();
|
|
70
|
+
const records = await getAllCustomTranslations();
|
|
71
|
+
if (records.length === 0) {
|
|
72
|
+
this.createText({
|
|
73
|
+
parent: this.translationsContainer,
|
|
74
|
+
text: "No custom translations yet.",
|
|
75
|
+
width: 840
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
for (const record of records) {
|
|
80
|
+
const active = await getActiveCustomTranslation(record.modKey);
|
|
81
|
+
const isActive = active?.name === record.name;
|
|
82
|
+
const card = document.createElement("div");
|
|
83
|
+
Object.assign(card.style, {
|
|
84
|
+
display: "flex",
|
|
85
|
+
flexDirection: "column",
|
|
86
|
+
gap: u(1.2),
|
|
87
|
+
padding: u(1.6),
|
|
88
|
+
boxSizing: "border-box",
|
|
89
|
+
width: "100%",
|
|
90
|
+
height: "auto",
|
|
91
|
+
borderRadius: u(1),
|
|
92
|
+
border: isActive ? "2px solid var(--tmd-accent-hover, rgb(30, 139, 255))" : "1px solid var(--tmd-accent, black)",
|
|
93
|
+
background: "var(--tmd-element, white)"
|
|
94
|
+
});
|
|
95
|
+
this.translationsContainer.append(card);
|
|
96
|
+
this.createText({
|
|
97
|
+
parent: card,
|
|
98
|
+
text: record.name,
|
|
99
|
+
fontSize: 3.6,
|
|
100
|
+
modules: {
|
|
101
|
+
base: [
|
|
102
|
+
new StyleModule({
|
|
103
|
+
width: "100%",
|
|
104
|
+
fontWeight: "bold"
|
|
105
|
+
})
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
this.createText({
|
|
110
|
+
parent: card,
|
|
111
|
+
text: record.modKey,
|
|
112
|
+
fontSize: 2.8,
|
|
113
|
+
width: 800,
|
|
114
|
+
modules: {
|
|
115
|
+
base: [
|
|
116
|
+
new StyleModule({
|
|
117
|
+
position: "relative",
|
|
118
|
+
left: "auto",
|
|
119
|
+
top: "auto",
|
|
120
|
+
width: "100%",
|
|
121
|
+
opacity: "0.85"
|
|
122
|
+
})
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
const actions = this.createContainer({
|
|
127
|
+
parent: card,
|
|
128
|
+
modules: {
|
|
129
|
+
content: [
|
|
130
|
+
new StyleModule({
|
|
131
|
+
display: "flex",
|
|
132
|
+
flexDirection: "row",
|
|
133
|
+
justifyContent: "flex-end",
|
|
134
|
+
alignItems: "center",
|
|
135
|
+
gap: u(1.2),
|
|
136
|
+
marginTop: u(0.5),
|
|
137
|
+
width: "100%",
|
|
138
|
+
height: "auto"
|
|
139
|
+
})
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
this.createButton({
|
|
144
|
+
parent: actions,
|
|
145
|
+
text: "Download",
|
|
146
|
+
variant: "filled",
|
|
147
|
+
padding: 0.6,
|
|
148
|
+
onClick: () => {
|
|
149
|
+
downloadJson(record.name, record.data);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
this.createButton({
|
|
153
|
+
parent: actions,
|
|
154
|
+
text: isActive ? "Deactivate" : "Activate",
|
|
155
|
+
variant: "filled",
|
|
156
|
+
padding: 0.6,
|
|
157
|
+
onClick: () => {
|
|
158
|
+
this.toggleActive(record, isActive);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
this.createButton({
|
|
162
|
+
parent: actions,
|
|
163
|
+
text: "Delete",
|
|
164
|
+
variant: "filled",
|
|
165
|
+
padding: 0.6,
|
|
166
|
+
onClick: () => {
|
|
167
|
+
this.deleteCustomTranslation(record);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async toggleActive(record, isActive) {
|
|
173
|
+
try {
|
|
174
|
+
if (isActive) {
|
|
175
|
+
await clearActiveCustomTranslation(record.name);
|
|
176
|
+
} else {
|
|
177
|
+
await setActiveCustomTranslation(record.name);
|
|
178
|
+
}
|
|
179
|
+
await this.renderTranslationList();
|
|
180
|
+
} catch (error) {
|
|
181
|
+
await dialogsManager.confirm({
|
|
182
|
+
message: `Failed to update translation: ${error instanceof Error ? error.message : String(error)}`
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async createCustomTranslation(file) {
|
|
187
|
+
try {
|
|
188
|
+
const parsed = JSON.parse(await file.text());
|
|
189
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
190
|
+
throw new Error("JSON root must be an object");
|
|
191
|
+
}
|
|
192
|
+
const mods = (window.ZOIS_CORE?.getDependents() ?? []).filter((item) => item.modData.localization !== void 0).map((item) => ({
|
|
193
|
+
name: `${item.modData.fullName} (${item.modData.key})`,
|
|
194
|
+
value: item.modData.key
|
|
195
|
+
}));
|
|
196
|
+
if (mods.length === 0) {
|
|
197
|
+
await dialogsManager.confirm({
|
|
198
|
+
message: "No zois-core mods with localization found"
|
|
199
|
+
});
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const modKey = await dialogsManager.pick({
|
|
203
|
+
message: "Select a mod for this custom translation",
|
|
204
|
+
options: mods
|
|
205
|
+
});
|
|
206
|
+
if (modKey === false) return;
|
|
207
|
+
const name = await dialogsManager.prompt({
|
|
208
|
+
message: "Enter a name for this custom translation"
|
|
209
|
+
});
|
|
210
|
+
if (name === false) return;
|
|
211
|
+
const trimmed = name.trim();
|
|
212
|
+
if (!trimmed) return;
|
|
213
|
+
const existing = await getCustomTranslation(trimmed);
|
|
214
|
+
if (existing) {
|
|
215
|
+
await dialogsManager.confirm({
|
|
216
|
+
message: `Translation "${trimmed}" already exists`
|
|
217
|
+
});
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
await addCustomTranslation(trimmed, parsed, modKey);
|
|
221
|
+
await this.renderTranslationList();
|
|
222
|
+
} catch (error) {
|
|
223
|
+
await dialogsManager.confirm({
|
|
224
|
+
message: `Failed to create translation: ${error instanceof Error ? error.message : String(error)}`
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async deleteCustomTranslation(record) {
|
|
229
|
+
const ok = await dialogsManager.confirm({
|
|
230
|
+
message: `Delete custom translation "${record.name}"?`
|
|
231
|
+
});
|
|
232
|
+
if (!ok) return;
|
|
233
|
+
await removeCustomTranslation(record.name);
|
|
234
|
+
await this.renderTranslationList();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
export {
|
|
238
|
+
CustomTranslationsSubscreen
|
|
239
|
+
};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getLocale,
|
|
3
|
+
LANGUAGES,
|
|
4
|
+
setLocale
|
|
5
|
+
} from "../localization";
|
|
6
|
+
import { BaseSubscreen, u } from "../ui";
|
|
7
|
+
import { StyleModule } from "../shard-modules";
|
|
8
|
+
import { dialogsManager } from "../dialogs";
|
|
9
|
+
function downloadJson(filename, data) {
|
|
10
|
+
const blob = new Blob([JSON.stringify(data, null, 2)], {
|
|
11
|
+
type: "application/json"
|
|
12
|
+
});
|
|
13
|
+
const url = URL.createObjectURL(blob);
|
|
14
|
+
const a = document.createElement("a");
|
|
15
|
+
a.href = url;
|
|
16
|
+
a.download = filename.endsWith(".json") ? filename : `${filename}.json`;
|
|
17
|
+
a.click();
|
|
18
|
+
URL.revokeObjectURL(url);
|
|
19
|
+
}
|
|
20
|
+
class LanguageDetailsSubscreen extends BaseSubscreen {
|
|
21
|
+
locale;
|
|
22
|
+
get name() {
|
|
23
|
+
return LANGUAGES.find((l) => l.locale === this.locale)?.name ?? this.locale;
|
|
24
|
+
}
|
|
25
|
+
constructor(locale) {
|
|
26
|
+
super();
|
|
27
|
+
this.locale = locale;
|
|
28
|
+
}
|
|
29
|
+
onLoad() {
|
|
30
|
+
const language = LANGUAGES.find((l) => l.locale === this.locale);
|
|
31
|
+
if (!language) {
|
|
32
|
+
this.createText({
|
|
33
|
+
x: 200,
|
|
34
|
+
y: 220,
|
|
35
|
+
width: 1600,
|
|
36
|
+
text: `Unknown locale: ${this.locale}`,
|
|
37
|
+
fontSize: 5
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this.createSvg({
|
|
42
|
+
x: 160,
|
|
43
|
+
y: 200,
|
|
44
|
+
svg: language.flag,
|
|
45
|
+
width: 500,
|
|
46
|
+
recolor: false,
|
|
47
|
+
modules: {
|
|
48
|
+
base: [
|
|
49
|
+
new StyleModule({
|
|
50
|
+
border: "1px solid var(--tmd-accent, black)"
|
|
51
|
+
})
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
this.createButton({
|
|
56
|
+
x: 160,
|
|
57
|
+
y: 600,
|
|
58
|
+
width: 500,
|
|
59
|
+
text: "Use Language",
|
|
60
|
+
variant: "filled",
|
|
61
|
+
padding: 1,
|
|
62
|
+
isDisabled: () => getLocale() === this.locale,
|
|
63
|
+
onClick: () => {
|
|
64
|
+
setLocale(this.locale);
|
|
65
|
+
this.exit();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const list = this.createContainer({
|
|
69
|
+
x: 900,
|
|
70
|
+
y: 200,
|
|
71
|
+
width: 900,
|
|
72
|
+
height: 700,
|
|
73
|
+
scroll: "y",
|
|
74
|
+
modules: {
|
|
75
|
+
content: [
|
|
76
|
+
new StyleModule({
|
|
77
|
+
display: "flex",
|
|
78
|
+
flexDirection: "column",
|
|
79
|
+
gap: u(2)
|
|
80
|
+
})
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
this.renderModSupport(list);
|
|
85
|
+
}
|
|
86
|
+
async renderModSupport(container) {
|
|
87
|
+
const dependents = (window.ZOIS_CORE?.getDependents() ?? []).filter((item) => item.modData.localization !== void 0);
|
|
88
|
+
if (dependents.length === 0) return;
|
|
89
|
+
for (const { modData } of dependents) {
|
|
90
|
+
const localization = modData.localization;
|
|
91
|
+
const percent = await this.getModSupportPercent(
|
|
92
|
+
modData,
|
|
93
|
+
this.locale
|
|
94
|
+
);
|
|
95
|
+
this.createText({
|
|
96
|
+
parent: container,
|
|
97
|
+
text: `${modData.fullName} (${modData.key})`,
|
|
98
|
+
fontSize: 4,
|
|
99
|
+
width: 840,
|
|
100
|
+
padding: 1,
|
|
101
|
+
withBackground: true
|
|
102
|
+
});
|
|
103
|
+
this.createText({
|
|
104
|
+
parent: container,
|
|
105
|
+
text: `Language support: ${percent}%`,
|
|
106
|
+
fontSize: 3.3,
|
|
107
|
+
width: 840
|
|
108
|
+
});
|
|
109
|
+
this.createButton({
|
|
110
|
+
parent: container,
|
|
111
|
+
text: "Download Language File",
|
|
112
|
+
padding: 1,
|
|
113
|
+
modules: {
|
|
114
|
+
base: [new StyleModule({ width: "100%" })]
|
|
115
|
+
},
|
|
116
|
+
isDisabled: () => !localization.locales.supported.includes(this.locale),
|
|
117
|
+
onClick: () => {
|
|
118
|
+
this.downloadModLanguageFile(
|
|
119
|
+
localization.translationsFolderPath,
|
|
120
|
+
modData.key
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async downloadModLanguageFile(folderPath, modKey) {
|
|
127
|
+
try {
|
|
128
|
+
const data = await this.fetchModTranslation(folderPath, this.locale);
|
|
129
|
+
if (!data) {
|
|
130
|
+
throw new Error(
|
|
131
|
+
`Translation file for "${this.locale}" was not found for mod "${modKey}"`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
downloadJson(`${modKey}-${this.locale}.json`, data);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
await dialogsManager.confirm({
|
|
137
|
+
message: `Failed to download translation: ${error instanceof Error ? error.message : String(error)}`
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
getLeafKeys(value, prefix = "", result = []) {
|
|
142
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
for (const [key, child] of Object.entries(
|
|
146
|
+
value
|
|
147
|
+
)) {
|
|
148
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
149
|
+
if (typeof child === "string") result.push(path);
|
|
150
|
+
else this.getLeafKeys(child, path, result);
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
async fetchModTranslation(folderPath, locale) {
|
|
155
|
+
try {
|
|
156
|
+
const response = await fetch(
|
|
157
|
+
`${folderPath}/${locale}.json?=${Date.now()}`
|
|
158
|
+
);
|
|
159
|
+
if (!response.ok) return null;
|
|
160
|
+
return await response.json();
|
|
161
|
+
} catch {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
coveragePercent(reference, candidate) {
|
|
166
|
+
const referenceKeys = this.getLeafKeys(reference);
|
|
167
|
+
if (referenceKeys.length === 0) return candidate ? 100 : 0;
|
|
168
|
+
if (!candidate) return 0;
|
|
169
|
+
const candidateKeys = new Set(this.getLeafKeys(candidate));
|
|
170
|
+
const matched = referenceKeys.filter(
|
|
171
|
+
(key) => candidateKeys.has(key)
|
|
172
|
+
).length;
|
|
173
|
+
return Math.round(matched / referenceKeys.length * 100);
|
|
174
|
+
}
|
|
175
|
+
async getModSupportPercent(modData, locale) {
|
|
176
|
+
const localization = modData.localization;
|
|
177
|
+
if (!localization) return 0;
|
|
178
|
+
if (!localization.locales.supported.includes(locale)) {
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
const defaultData = await this.fetchModTranslation(
|
|
182
|
+
localization.translationsFolderPath,
|
|
183
|
+
localization.locales.default
|
|
184
|
+
);
|
|
185
|
+
const localeData = await this.fetchModTranslation(
|
|
186
|
+
localization.translationsFolderPath,
|
|
187
|
+
locale
|
|
188
|
+
);
|
|
189
|
+
return this.coveragePercent(defaultData, localeData);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
export {
|
|
193
|
+
LanguageDetailsSubscreen
|
|
194
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LANGUAGES,
|
|
3
|
+
getLocale
|
|
4
|
+
} from "../localization";
|
|
5
|
+
import { BaseSubscreen, svgFromString, u } from "../ui";
|
|
6
|
+
import { StyleModule } from "../shard-modules";
|
|
7
|
+
import { LanguageDetailsSubscreen } from "./languageDetails";
|
|
8
|
+
import { CustomTranslationsSubscreen } from "./customTranslations";
|
|
9
|
+
class LocalizationSubscreen extends BaseSubscreen {
|
|
10
|
+
get name() {
|
|
11
|
+
return "Localization";
|
|
12
|
+
}
|
|
13
|
+
onLoad() {
|
|
14
|
+
const languagesContainer = this.createContainer({
|
|
15
|
+
x: 200,
|
|
16
|
+
y: 200,
|
|
17
|
+
width: 800,
|
|
18
|
+
height: 620,
|
|
19
|
+
scroll: "y",
|
|
20
|
+
modules: {
|
|
21
|
+
content: [
|
|
22
|
+
new StyleModule({
|
|
23
|
+
display: "flex",
|
|
24
|
+
flexDirection: "column",
|
|
25
|
+
gap: u(2)
|
|
26
|
+
})
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
LANGUAGES.forEach((l) => {
|
|
31
|
+
this.createButton({
|
|
32
|
+
parent: languagesContainer,
|
|
33
|
+
icon: svgFromString(l.flag),
|
|
34
|
+
text: l.name,
|
|
35
|
+
padding: 1,
|
|
36
|
+
modules: {
|
|
37
|
+
base: [new StyleModule({ width: "100%" })]
|
|
38
|
+
},
|
|
39
|
+
onClick: () => {
|
|
40
|
+
this.setSubscreen(new LanguageDetailsSubscreen(l.locale));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
this.createButton({
|
|
45
|
+
x: 200,
|
|
46
|
+
y: 840,
|
|
47
|
+
width: 800,
|
|
48
|
+
height: 70,
|
|
49
|
+
text: "Manage Custom Translations",
|
|
50
|
+
padding: 1,
|
|
51
|
+
onClick: () => {
|
|
52
|
+
this.setSubscreen(new CustomTranslationsSubscreen());
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
const locale = getLocale();
|
|
56
|
+
const language = locale ? LANGUAGES.find((l) => l.locale === locale) ?? null : null;
|
|
57
|
+
if (language) {
|
|
58
|
+
this.createSvg({
|
|
59
|
+
x: 1280,
|
|
60
|
+
y: 180,
|
|
61
|
+
svg: language.flag,
|
|
62
|
+
width: 360,
|
|
63
|
+
recolor: false,
|
|
64
|
+
modules: {
|
|
65
|
+
base: [
|
|
66
|
+
new StyleModule({
|
|
67
|
+
border: "1px solid var(--tmd-accent, black)"
|
|
68
|
+
})
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
this.createText({
|
|
73
|
+
x: 1280,
|
|
74
|
+
y: 450,
|
|
75
|
+
width: 360,
|
|
76
|
+
text: language.name,
|
|
77
|
+
fontSize: 5,
|
|
78
|
+
modules: {
|
|
79
|
+
base: [
|
|
80
|
+
new StyleModule({
|
|
81
|
+
textAlign: "center"
|
|
82
|
+
})
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
} else {
|
|
87
|
+
this.createText({
|
|
88
|
+
x: 1220,
|
|
89
|
+
y: 360,
|
|
90
|
+
width: 400,
|
|
91
|
+
text: "?",
|
|
92
|
+
fontSize: 12
|
|
93
|
+
});
|
|
94
|
+
this.createText({
|
|
95
|
+
x: 1220,
|
|
96
|
+
y: 620,
|
|
97
|
+
width: 400,
|
|
98
|
+
text: "Locale is not defined",
|
|
99
|
+
fontSize: 4
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
this.createText({
|
|
103
|
+
x: 1065,
|
|
104
|
+
y: 550,
|
|
105
|
+
width: 800,
|
|
106
|
+
height: 365,
|
|
107
|
+
padding: 1,
|
|
108
|
+
text: "Here the list of languages supported by the Zoi's mods ecosystem. Translations are expanded and updated over time. Select a language \u2014 if translation file is missing or a string is not found, the mod falls back to its default language. But once a translation into the target language becomes available, the text of the mods will be translated.",
|
|
109
|
+
withBackground: true
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export {
|
|
114
|
+
LocalizationSubscreen
|
|
115
|
+
};
|