cyclops-infobook-html 4.0.1 → 5.1.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.
Files changed (42) hide show
  1. package/README.md +23 -2
  2. package/bin/compress-icons.d.ts +2 -0
  3. package/bin/compress-icons.js +47 -0
  4. package/bin/generate-icons.d.ts +2 -0
  5. package/bin/generate-icons.js +68 -0
  6. package/bin/generate-infobook-html.js +16 -8
  7. package/bin/generate-mod-metadata.js +15 -7
  8. package/index.d.ts +2 -0
  9. package/index.js +39 -24
  10. package/lib/icon/IconsCompressor.d.ts +18 -0
  11. package/lib/icon/IconsCompressor.js +81 -0
  12. package/lib/icon/IconsGenerator.d.ts +128 -0
  13. package/lib/icon/IconsGenerator.js +597 -0
  14. package/lib/infobook/FileWriter.d.ts +1 -2
  15. package/lib/infobook/FileWriter.js +21 -6
  16. package/lib/infobook/IFileWriter.d.ts +1 -2
  17. package/lib/infobook/IInfoAppendix.d.ts +1 -1
  18. package/lib/infobook/InfoBookInitializer.js +10 -2
  19. package/lib/infobook/appendix/InfoBookAppendixAd.d.ts +1 -1
  20. package/lib/infobook/appendix/InfoBookAppendixAd.js +13 -2
  21. package/lib/infobook/appendix/InfoBookAppendixHandlerAbstractRecipe.d.ts +1 -1
  22. package/lib/infobook/appendix/InfoBookAppendixHandlerAbstractRecipe.js +13 -4
  23. package/lib/infobook/appendix/InfoBookAppendixHandlerAdvancementRewards.js +14 -5
  24. package/lib/infobook/appendix/InfoBookAppendixHandlerCraftingRecipe.d.ts +1 -1
  25. package/lib/infobook/appendix/InfoBookAppendixHandlerCraftingRecipe.js +39 -28
  26. package/lib/infobook/appendix/InfoBookAppendixHandlerImage.js +13 -4
  27. package/lib/infobook/appendix/InfoBookAppendixHandlerKeybinding.js +12 -3
  28. package/lib/infobook/appendix/InfoBookAppendixHandlerSmeltingRecipe.d.ts +1 -1
  29. package/lib/infobook/appendix/InfoBookAppendixHandlerSmeltingRecipe.js +16 -5
  30. package/lib/infobook/appendix/InfoBookAppendixHandlerTextfield.js +11 -2
  31. package/lib/infobook/appendix/InfoBookAppendixTagIndex.d.ts +1 -1
  32. package/lib/infobook/appendix/InfoBookAppendixTagIndex.js +31 -20
  33. package/lib/modloader/ModLoader.d.ts +2 -3
  34. package/lib/modloader/ModLoader.js +56 -48
  35. package/lib/parse/XmlInfoBookParser.js +2 -2
  36. package/lib/resource/ResourceHandler.d.ts +2 -1
  37. package/lib/resource/ResourceHandler.js +7 -3
  38. package/lib/resource/ResourceLoader.d.ts +5 -5
  39. package/lib/resource/ResourceLoader.js +37 -28
  40. package/lib/serialize/HtmlInfoBookSerializer.d.ts +2 -2
  41. package/lib/serialize/HtmlInfoBookSerializer.js +80 -65
  42. package/package.json +10 -6
@@ -1,7 +1,15 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.ModLoader = void 0;
4
- const tslib_1 = require("tslib");
5
13
  const child_process_1 = require("child_process");
6
14
  const fs_1 = require("fs");
7
15
  const fs = require("fs");
@@ -33,7 +41,7 @@ class ModLoader {
33
41
  * Download and install Forge.
34
42
  */
35
43
  installForge() {
36
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
44
+ return __awaiter(this, void 0, void 0, function* () {
37
45
  if (!fs.existsSync(this.path)) {
38
46
  yield fs.promises.mkdir(this.path);
39
47
  }
@@ -42,33 +50,33 @@ class ModLoader {
42
50
  // Download Forge installer
43
51
  process.stdout.write('Downloading Forge...\n');
44
52
  const forgeInstaller = `https://files.minecraftforge.net/maven/net/minecraftforge/forge/${this.versionMinecraft}-${this.loader.versionForge}/forge-${this.versionMinecraft}-${this.loader.versionForge}-installer.jar`;
45
- const res = yield node_fetch_1.default(forgeInstaller);
53
+ const res = yield (0, node_fetch_1.default)(forgeInstaller);
46
54
  if (!res.ok) {
47
55
  throw new Error(`Failed to fetch (${res.statusText}): ${forgeInstaller}`);
48
56
  }
49
- installerFile = path_1.join(this.path, 'forge-installer.jar');
50
- yield new Promise((resolve, reject) => tslib_1.__awaiter(this, void 0, void 0, function* () {
57
+ installerFile = (0, path_1.join)(this.path, 'forge-installer.jar');
58
+ yield new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
51
59
  return fs.writeFile(installerFile, yield res.buffer(), (err) => err ? reject(err) : resolve());
52
60
  }));
53
61
  // Install Forge
54
62
  process.stdout.write('Installing Forge...\n');
55
- yield new Promise((resolve, reject) => child_process_1.exec(`cd ${this.path} && java -jar forge-installer.jar --installServer`).on('exit', resolve));
63
+ yield new Promise((resolve, reject) => (0, child_process_1.exec)(`cd ${this.path} && java -jar forge-installer.jar --installServer`).on('exit', resolve));
56
64
  }
57
65
  else {
58
66
  // Download NeoForge installer
59
67
  process.stdout.write('Downloading NeoForge...\n');
60
68
  const installer = `https://maven.neoforged.net/releases/net/neoforged/neoforge/${this.loader.versionNeoForge}/neoforge-${this.loader.versionNeoForge}-installer.jar`;
61
- const res = yield node_fetch_1.default(installer);
69
+ const res = yield (0, node_fetch_1.default)(installer);
62
70
  if (!res.ok) {
63
71
  throw new Error(`Failed to fetch (${res.statusText}): ${installer}`);
64
72
  }
65
- installerFile = path_1.join(this.path, 'neoforge-installer.jar');
66
- yield new Promise((resolve, reject) => tslib_1.__awaiter(this, void 0, void 0, function* () {
73
+ installerFile = (0, path_1.join)(this.path, 'neoforge-installer.jar');
74
+ yield new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
67
75
  return fs.writeFile(installerFile, yield res.buffer(), (err) => err ? reject(err) : resolve());
68
76
  }));
69
77
  // Install Forge
70
78
  process.stdout.write('Installing NeoForge...\n');
71
- yield new Promise((resolve, reject) => child_process_1.exec(`cd ${this.path} && java -jar neoforge-installer.jar --installServer`).on('exit', resolve));
79
+ yield new Promise((resolve, reject) => (0, child_process_1.exec)(`cd ${this.path} && java -jar neoforge-installer.jar --installServer`).on('exit', resolve));
72
80
  }
73
81
  // Wait a bit, because otherwise some files don't exist yet (while they should...)
74
82
  process.stdout.write('Wait a bit after mod loader installation...\n');
@@ -83,24 +91,24 @@ class ModLoader {
83
91
  * Accept the Minecraft EULA
84
92
  */
85
93
  acceptEula() {
86
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
94
+ return __awaiter(this, void 0, void 0, function* () {
87
95
  process.stdout.write('Accepting EULA...\n');
88
- yield fs.promises.writeFile(path_1.join(this.path, 'eula.txt'), 'eula=true');
96
+ yield fs.promises.writeFile((0, path_1.join)(this.path, 'eula.txt'), 'eula=true');
89
97
  });
90
98
  }
91
99
  /**
92
100
  * @returns {boolean} If mods are installed.
93
101
  */
94
102
  areModsInstalled() {
95
- return fs.existsSync(path_1.join(this.path, 'mods'));
103
+ return fs.existsSync((0, path_1.join)(this.path, 'mods'));
96
104
  }
97
105
  /**
98
106
  * Download and install mods.
99
107
  */
100
108
  installMods() {
101
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
109
+ return __awaiter(this, void 0, void 0, function* () {
102
110
  process.stdout.write('Downloading mods...\n');
103
- const modsDir = path_1.join(this.path, 'mods');
111
+ const modsDir = (0, path_1.join)(this.path, 'mods');
104
112
  if (!fs.existsSync(modsDir)) {
105
113
  yield fs.promises.mkdir(modsDir);
106
114
  }
@@ -114,10 +122,10 @@ class ModLoader {
114
122
  }
115
123
  else if (mod.type === 'maven') {
116
124
  process.stdout.write(` - ${mod.artifact} from ${mod.repo}...\n`);
117
- const name = yield mvn_artifact_download_1.default(mod.artifact, modsDir, mod.repo);
125
+ const name = yield (0, mvn_artifact_download_1.default)(mod.artifact, modsDir, mod.repo);
118
126
  // Rename file if needed
119
127
  if ('name' in mod) {
120
- fs.renameSync(name, path_1.join(modsDir, mod.name));
128
+ fs.renameSync(name, (0, path_1.join)(modsDir, mod.name));
121
129
  }
122
130
  }
123
131
  else if (mod.type === 'raw') {
@@ -131,8 +139,8 @@ class ModLoader {
131
139
  });
132
140
  }
133
141
  downloadFile(url, fileName, modsDir) {
134
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
135
- const response = yield node_fetch_1.default(url);
142
+ return __awaiter(this, void 0, void 0, function* () {
143
+ const response = yield (0, node_fetch_1.default)(url);
136
144
  if (response.status !== 200) {
137
145
  throw new Error(response.statusText + ' on ' + url);
138
146
  }
@@ -140,7 +148,7 @@ class ModLoader {
140
148
  response.body
141
149
  .on('error', reject)
142
150
  .on('end', resolve)
143
- .pipe(fs.createWriteStream(path_1.join(modsDir, fileName)));
151
+ .pipe(fs.createWriteStream((0, path_1.join)(modsDir, fileName)));
144
152
  });
145
153
  });
146
154
  }
@@ -148,10 +156,10 @@ class ModLoader {
148
156
  * Start the server and execute a command to dump all registries
149
157
  */
150
158
  startServer() {
151
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
159
+ return __awaiter(this, void 0, void 0, function* () {
152
160
  // Start the Forge server
153
161
  process.stdout.write('Starting server...\n');
154
- const proc = child_process_1.exec(`cd ${this.path} && ./run.sh nogui`);
162
+ const proc = (0, child_process_1.exec)(`cd ${this.path} && ./run.sh nogui`);
155
163
  // Ignore stdout: proc.stdout.pipe(process.stdout);
156
164
  proc.stderr.pipe(process.stderr);
157
165
  const onDone = new Promise((resolve, reject) => {
@@ -189,22 +197,22 @@ class ModLoader {
189
197
  * @param {string} target A target path.
190
198
  */
191
199
  copyRegistries(target) {
192
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
200
+ return __awaiter(this, void 0, void 0, function* () {
193
201
  process.stdout.write('Copying registries...\n');
194
- if (!fs.existsSync(path_1.join(this.path, 'cyclops_registries'))) {
195
- yield fs.promises.mkdir(path_1.join(this.path, 'cyclops_registries'));
202
+ if (!fs.existsSync((0, path_1.join)(this.path, 'cyclops_registries'))) {
203
+ yield fs.promises.mkdir((0, path_1.join)(this.path, 'cyclops_registries'));
196
204
  }
197
- yield util_1.promisify(ncp_1.ncp)(path_1.join(this.path, 'cyclops_registries'), target);
205
+ yield (0, util_1.promisify)(ncp_1.ncp)((0, path_1.join)(this.path, 'cyclops_registries'), target);
198
206
  });
199
207
  }
200
208
  /**
201
209
  * Extract the Minecraft assets from the server jar
202
210
  */
203
211
  extractMinecraftAssets() {
204
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
212
+ return __awaiter(this, void 0, void 0, function* () {
205
213
  process.stdout.write('Extracting minecraft assets...\n');
206
- if (!fs.existsSync(path_1.join(this.path, 'mc_assets'))) {
207
- yield fs.promises.mkdir(path_1.join(this.path, 'mc_assets'));
214
+ if (!fs.existsSync((0, path_1.join)(this.path, 'mc_assets'))) {
215
+ yield fs.promises.mkdir((0, path_1.join)(this.path, 'mc_assets'));
208
216
  }
209
217
  // Find Minecraft jar
210
218
  let jar = null;
@@ -213,7 +221,7 @@ class ModLoader {
213
221
  if (dir.indexOf('-') > 0) {
214
222
  for (const file of yield fs.promises.readdir(Path.join(subPath, dir))) {
215
223
  if (file.startsWith('server') && file.endsWith('extra.jar')) {
216
- jar = path_1.join(subPath, dir, file);
224
+ jar = (0, path_1.join)(subPath, dir, file);
217
225
  }
218
226
  }
219
227
  }
@@ -231,16 +239,16 @@ class ModLoader {
231
239
  * Extract assets from all mod jars
232
240
  */
233
241
  extractModsAssets() {
234
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
242
+ return __awaiter(this, void 0, void 0, function* () {
235
243
  process.stdout.write('Extracting mod assets...\n');
236
- if (!fs.existsSync(path_1.join(this.path, 'mod_assets'))) {
237
- yield fs.promises.mkdir(path_1.join(this.path, 'mod_assets'));
244
+ if (!fs.existsSync((0, path_1.join)(this.path, 'mod_assets'))) {
245
+ yield fs.promises.mkdir((0, path_1.join)(this.path, 'mod_assets'));
238
246
  }
239
247
  // Loop over all mods
240
- const modsDir = path_1.join(this.path, 'mods');
248
+ const modsDir = (0, path_1.join)(this.path, 'mods');
241
249
  for (const mod of yield fs.promises.readdir(modsDir)) {
242
250
  if (mod.endsWith('.jar')) {
243
- const modFile = path_1.join(modsDir, mod);
251
+ const modFile = (0, path_1.join)(modsDir, mod);
244
252
  process.stdout.write(` - ${mod}...\n`);
245
253
  yield this.extractModAssets(modFile);
246
254
  }
@@ -252,9 +260,9 @@ class ModLoader {
252
260
  * @param {string} modFile A mod file path.
253
261
  */
254
262
  extractModAssets(modFile) {
255
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
263
+ return __awaiter(this, void 0, void 0, function* () {
256
264
  const zipFile = yield new Promise((resolve, reject) => {
257
- yauzl_1.open(modFile, { lazyEntries: true, autoClose: true }, (e, f) => {
265
+ (0, yauzl_1.open)(modFile, { lazyEntries: true, autoClose: true }, (e, f) => {
258
266
  if (e) {
259
267
  reject(e);
260
268
  }
@@ -271,14 +279,14 @@ class ModLoader {
271
279
  else {
272
280
  // File
273
281
  if (entry.fileName.startsWith('assets/') || entry.fileName.startsWith('data/')) {
274
- const targetFile = path_1.join(this.path, 'mod_assets', entry.fileName.substring(entry.fileName.startsWith('assets/') ? 7 : 5, entry.fileName.length));
275
- const targetDir = path_1.dirname(targetFile);
282
+ const targetFile = (0, path_1.join)(this.path, 'mod_assets', entry.fileName.substring(entry.fileName.startsWith('assets/') ? 7 : 5, entry.fileName.length));
283
+ const targetDir = (0, path_1.dirname)(targetFile);
276
284
  this.ensureDirExists(targetDir).then(() => {
277
285
  zipFile.openReadStream(entry, (e, readStream) => {
278
286
  if (e) {
279
287
  throw e;
280
288
  }
281
- readStream.pipe(fs_1.createWriteStream(targetFile));
289
+ readStream.pipe((0, fs_1.createWriteStream)(targetFile));
282
290
  readStream.on('end', () => zipFile.readEntry());
283
291
  });
284
292
  });
@@ -296,32 +304,32 @@ class ModLoader {
296
304
  * @param {string} target A target path.
297
305
  */
298
306
  copyModAssets(target) {
299
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
307
+ return __awaiter(this, void 0, void 0, function* () {
300
308
  process.stdout.write('Copying mod assets...\n');
301
- yield util_1.promisify(ncp_1.ncp)(path_1.join(this.path, 'mod_assets'), target);
309
+ yield (0, util_1.promisify)(ncp_1.ncp)((0, path_1.join)(this.path, 'mod_assets'), target);
302
310
  });
303
311
  }
304
312
  /**
305
313
  * Remove the server files.
306
314
  */
307
315
  removeServer() {
308
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
309
- yield util_1.promisify(rimraf)(this.path);
316
+ return __awaiter(this, void 0, void 0, function* () {
317
+ yield (0, util_1.promisify)(rimraf)(this.path);
310
318
  });
311
319
  }
312
320
  /**
313
321
  * Remove the mod directory.
314
322
  */
315
323
  removeMods() {
316
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
317
- yield util_1.promisify(rimraf)(path_1.join(this.path, 'mods'));
324
+ return __awaiter(this, void 0, void 0, function* () {
325
+ yield (0, util_1.promisify)(rimraf)((0, path_1.join)(this.path, 'mods'));
318
326
  });
319
327
  }
320
328
  ensureDirExists(path) {
321
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
329
+ return __awaiter(this, void 0, void 0, function* () {
322
330
  const segments = path.substr(this.path.length, path.length).split(path_1.sep);
323
331
  for (let i = 1; i <= segments.length; i++) {
324
- const subPath = path_1.join(this.path, segments.slice(0, i).join(path_1.sep));
332
+ const subPath = (0, path_1.join)(this.path, segments.slice(0, i).join(path_1.sep));
325
333
  try {
326
334
  yield fs.promises.stat(subPath);
327
335
  }
@@ -29,7 +29,7 @@ class XmlInfoBookParser {
29
29
  */
30
30
  parse(path, modId) {
31
31
  return new Promise((resolve, reject) => {
32
- xml2js_1.parseString(fs.readFileSync(path), (error, data) => {
32
+ (0, xml2js_1.parseString)(fs.readFileSync(path), (error, data) => {
33
33
  if (error) {
34
34
  return reject(error);
35
35
  }
@@ -65,7 +65,7 @@ class XmlInfoBookParser {
65
65
  paragraphTranslationKeys: (data.paragraph || []).map((subData) => this.jsonToParagraph(subData)),
66
66
  appendix: ((data.appendix || []).concat(data.appendix_list || []))
67
67
  .map((subData) => this.jsonToAppendix(subData, modId)),
68
- tags: data.tag || [],
68
+ tags: (data.tag ? data.tag.filter((entry) => typeof entry === 'string') : undefined) || [],
69
69
  modId,
70
70
  };
71
71
  sections[section.nameTranslationKey] = section;
@@ -6,6 +6,7 @@ import { IItem } from "../infobook/IItem";
6
6
  export declare class ResourceHandler {
7
7
  private static readonly TRANSLATION_DEFAULTS;
8
8
  private readonly translations;
9
+ private readonly languages;
9
10
  private readonly resourcePackBasePaths;
10
11
  private readonly iconsItem;
11
12
  private readonly itemTranslationKeys;
@@ -49,7 +50,7 @@ export declare class ResourceHandler {
49
50
  */
50
51
  addTranslations(language: string, translations: {
51
52
  [key: string]: string;
52
- }): void;
53
+ }, excludedModLanguage: boolean): void;
53
54
  /**
54
55
  * Get the translation for the given key.
55
56
  * @param {string} translationKey A translation key.
@@ -8,6 +8,7 @@ const path_1 = require("path");
8
8
  class ResourceHandler {
9
9
  constructor() {
10
10
  this.translations = {};
11
+ this.languages = {};
11
12
  this.resourcePackBasePaths = {};
12
13
  this.iconsItem = {};
13
14
  this.itemTranslationKeys = {};
@@ -71,14 +72,14 @@ class ResourceHandler {
71
72
  * @returns {string[]} All available language keys.
72
73
  */
73
74
  getLanguages() {
74
- return Object.keys(this.translations);
75
+ return Object.keys(this.languages);
75
76
  }
76
77
  /**
77
78
  * Add translations for the given language.
78
79
  * @param {string} language A language key.
79
80
  * @param {{[p: string]: string}} translations A mapping from translation key to translated value.
80
81
  */
81
- addTranslations(language, translations) {
82
+ addTranslations(language, translations, excludedModLanguage) {
82
83
  language = language.toLowerCase();
83
84
  const existingTranslations = this.translations[language];
84
85
  if (!existingTranslations) {
@@ -89,6 +90,9 @@ class ResourceHandler {
89
90
  existingTranslations[key] = translations[key];
90
91
  }
91
92
  }
93
+ if (!excludedModLanguage && Object.keys(translations).length > 0) {
94
+ this.languages[language] = true;
95
+ }
92
96
  }
93
97
  /**
94
98
  * Get the translation for the given key.
@@ -134,7 +138,7 @@ class ResourceHandler {
134
138
  throw new Error(`Failed to expand unknown resource pack id for resource path: ${resourceKey}`);
135
139
  }
136
140
  const suffix = resourceKey.substr(separator + 1);
137
- return path_1.join(basePath, suffix);
141
+ return (0, path_1.join)(basePath, suffix);
138
142
  }
139
143
  /**
140
144
  * Add an item icon file.
@@ -33,7 +33,7 @@ export declare class ResourceLoader {
33
33
  * @param {string[]} paths An array of paths to traverse to look for resources.
34
34
  * @returns {Promise<void>} A promise resolving when loading is done.
35
35
  */
36
- loadAll(baseDir: string, path: string): Promise<void>;
36
+ loadAll(baseDir: string, path: string, excludedModLanguages: string[]): Promise<void>;
37
37
  /**
38
38
  * Load a resource somewhere within the given path.
39
39
  *
@@ -42,21 +42,21 @@ export declare class ResourceLoader {
42
42
  * @param {string} fullPath A full path to look in.
43
43
  * @returns {Promise<void>} A promise resolving when loading is done.
44
44
  */
45
- load(fullPath: string): Promise<void>;
45
+ load(fullPath: string, excludedModLanguages: string[]): Promise<void>;
46
46
  /**
47
47
  * Load the assets of the given pack.
48
48
  * @param {string} modid A mod id.
49
49
  * @param {string} fullPath The full path of the pack.
50
50
  * @returns {Promise<void>} A promise resolving when loading is done.
51
51
  */
52
- loadAssets(modid: string, fullPath: string): Promise<void>;
52
+ loadAssets(modid: string, fullPath: string, excludedModLanguage: boolean): Promise<void>;
53
53
  /**
54
54
  * Load the language file within the given language folder.
55
55
  * @param {string} modid A mod id.
56
56
  * @param {string} langDir The full language directory path.
57
57
  * @returns {Promise<void>} A promise resolving when loading is done.
58
58
  */
59
- loadAssetsLang(modid: string, langDir: string): Promise<void>;
59
+ loadAssetsLang(modid: string, langDir: string, excludedModLanguage: boolean): Promise<void>;
60
60
  /**
61
61
  * Load a single language file.
62
62
  * @param {string} modid A mod id.
@@ -64,7 +64,7 @@ export declare class ResourceLoader {
64
64
  * @param {string} fullFilePath The full language file path.
65
65
  * @returns {Promise<void>} A promise resolving when loading is done.
66
66
  */
67
- loadAssetsLangFile(modid: string, language: string, fullFilePath: string): Promise<void>;
67
+ loadAssetsLangFile(modid: string, language: string, fullFilePath: string, excludedModLanguage: boolean): Promise<void>;
68
68
  /**
69
69
  * Load the advancements within the given folder, recursively.
70
70
  * @param {string} modid A mod id.
@@ -1,7 +1,15 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.ResourceLoader = void 0;
4
- const tslib_1 = require("tslib");
5
13
  const fs_1 = require("fs");
6
14
  const path_1 = require("path");
7
15
  const ResourceHandler_1 = require("./ResourceHandler");
@@ -24,10 +32,10 @@ class ResourceLoader {
24
32
  * @returns {Promise<void>} A promise resolving when loading is done.
25
33
  */
26
34
  loadIcons(iconsPath) {
27
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
35
+ return __awaiter(this, void 0, void 0, function* () {
28
36
  const iconNames = yield fs_1.promises.readdir(iconsPath);
29
37
  for (const iconName of iconNames) {
30
- const iconFile = path_1.join(iconsPath, iconName);
38
+ const iconFile = (0, path_1.join)(iconsPath, iconName);
31
39
  if (iconName.startsWith('fluid__')) {
32
40
  this.resourceHandler.addFluidIcon(iconName.substring(7, iconName.length - 4), iconFile);
33
41
  }
@@ -54,8 +62,8 @@ class ResourceLoader {
54
62
  * @returns {Promise<void>} A promise resolving when loading is done.
55
63
  */
56
64
  loadItemTranslationKeys(registriesPath) {
57
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
58
- const registry = JSON.parse(fs_1.readFileSync(path_1.join(registriesPath, 'item_translation_keys.json'), "utf8"));
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ const registry = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(registriesPath, 'item_translation_keys.json'), "utf8"));
59
67
  for (const entry of registry.items) {
60
68
  this.resourceHandler.addItemTranslationKey(entry.item, entry.translationKey);
61
69
  }
@@ -67,8 +75,8 @@ class ResourceLoader {
67
75
  * @returns {Promise<void>} A promise resolving when loading is done.
68
76
  */
69
77
  loadFluidTranslationKeys(registriesPath) {
70
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
71
- const registry = JSON.parse(fs_1.readFileSync(path_1.join(registriesPath, 'fluid_translation_keys.json'), "utf8"));
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const registry = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(registriesPath, 'fluid_translation_keys.json'), "utf8"));
72
80
  for (const entry of registry.fluids) {
73
81
  this.resourceHandler.addFluidTranslationKey(entry.fluid, entry.translationKey);
74
82
  }
@@ -80,9 +88,9 @@ class ResourceLoader {
80
88
  * @param {string[]} paths An array of paths to traverse to look for resources.
81
89
  * @returns {Promise<void>} A promise resolving when loading is done.
82
90
  */
83
- loadAll(baseDir, path) {
84
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
85
- yield this.load(path_1.join(baseDir, path));
91
+ loadAll(baseDir, path, excludedModLanguages) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ yield this.load((0, path_1.join)(baseDir, path), excludedModLanguages);
86
94
  });
87
95
  }
88
96
  /**
@@ -93,14 +101,15 @@ class ResourceLoader {
93
101
  * @param {string} fullPath A full path to look in.
94
102
  * @returns {Promise<void>} A promise resolving when loading is done.
95
103
  */
96
- load(fullPath) {
97
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
104
+ load(fullPath, excludedModLanguages) {
105
+ return __awaiter(this, void 0, void 0, function* () {
98
106
  const entries = yield fs_1.promises.readdir(fullPath);
99
107
  // Look for a valid pack
100
108
  for (const modid of entries) {
101
- const modPath = path_1.join(fullPath, modid);
109
+ const excludedModLanguage = excludedModLanguages.includes(modid);
110
+ const modPath = (0, path_1.join)(fullPath, modid);
102
111
  if ((yield fs_1.promises.stat(modPath)).isDirectory()) {
103
- yield this.loadAssets(modid, modPath);
112
+ yield this.loadAssets(modid, modPath, excludedModLanguage);
104
113
  }
105
114
  }
106
115
  });
@@ -111,22 +120,22 @@ class ResourceLoader {
111
120
  * @param {string} fullPath The full path of the pack.
112
121
  * @returns {Promise<void>} A promise resolving when loading is done.
113
122
  */
114
- loadAssets(modid, fullPath) {
115
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
123
+ loadAssets(modid, fullPath, excludedModLanguage) {
124
+ return __awaiter(this, void 0, void 0, function* () {
116
125
  // Set base path
117
126
  this.resourceHandler.setResourcePackBasePath(modid, fullPath);
118
127
  // Handle languages
119
- const langDir = path_1.join(fullPath, 'lang');
128
+ const langDir = (0, path_1.join)(fullPath, 'lang');
120
129
  try {
121
130
  if ((yield fs_1.promises.stat(langDir)).isDirectory()) {
122
- yield this.loadAssetsLang(modid, langDir);
131
+ yield this.loadAssetsLang(modid, langDir, excludedModLanguage);
123
132
  }
124
133
  }
125
134
  catch (e) {
126
135
  // Ignore mods without language files
127
136
  }
128
137
  // Handle advancements
129
- const advancementsDir = path_1.join(fullPath, 'advancement');
138
+ const advancementsDir = (0, path_1.join)(fullPath, 'advancement');
130
139
  try {
131
140
  if ((yield fs_1.promises.stat(langDir)).isDirectory()) {
132
141
  yield this.loadAssetsAdvancements(modid, advancementsDir, '');
@@ -143,12 +152,12 @@ class ResourceLoader {
143
152
  * @param {string} langDir The full language directory path.
144
153
  * @returns {Promise<void>} A promise resolving when loading is done.
145
154
  */
146
- loadAssetsLang(modid, langDir) {
147
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
155
+ loadAssetsLang(modid, langDir, excludedModLanguage) {
156
+ return __awaiter(this, void 0, void 0, function* () {
148
157
  const entries = yield fs_1.promises.readdir(langDir);
149
158
  for (const entry of entries) {
150
159
  const language = entry.substring(0, entry.indexOf('.'));
151
- yield this.loadAssetsLangFile(modid, language, path_1.join(langDir, entry));
160
+ yield this.loadAssetsLangFile(modid, language, (0, path_1.join)(langDir, entry), excludedModLanguage);
152
161
  }
153
162
  });
154
163
  }
@@ -159,10 +168,10 @@ class ResourceLoader {
159
168
  * @param {string} fullFilePath The full language file path.
160
169
  * @returns {Promise<void>} A promise resolving when loading is done.
161
170
  */
162
- loadAssetsLangFile(modid, language, fullFilePath) {
163
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
171
+ loadAssetsLangFile(modid, language, fullFilePath, excludedModLanguage) {
172
+ return __awaiter(this, void 0, void 0, function* () {
164
173
  const translations = JSON.parse((yield fs_1.promises.readFile(fullFilePath)).toString('utf8'));
165
- this.resourceHandler.addTranslations(language, translations);
174
+ this.resourceHandler.addTranslations(language, translations, excludedModLanguage);
166
175
  });
167
176
  }
168
177
  /**
@@ -172,10 +181,10 @@ class ResourceLoader {
172
181
  * @param {string} idPrefix The prefix to use for advancement id.
173
182
  */
174
183
  loadAssetsAdvancements(modid, advancementsDir, idPrefix) {
175
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
184
+ return __awaiter(this, void 0, void 0, function* () {
176
185
  const entries = yield fs_1.promises.readdir(advancementsDir);
177
186
  for (const entry of entries) {
178
- const entryFullPath = path_1.join(advancementsDir, entry);
187
+ const entryFullPath = (0, path_1.join)(advancementsDir, entry);
179
188
  const entryId = idPrefix + '/' + entry;
180
189
  if ((yield fs_1.promises.stat(entryFullPath)).isDirectory()) {
181
190
  yield this.loadAssetsAdvancements(modid, entryFullPath, entryId);
@@ -193,7 +202,7 @@ class ResourceLoader {
193
202
  * @param {string} id The id of the advancement.
194
203
  */
195
204
  loadAssetsAdvancement(modid, advancementsFile, id) {
196
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
205
+ return __awaiter(this, void 0, void 0, function* () {
197
206
  const contents = JSON.parse((yield fs_1.promises.readFile(advancementsFile)).toString('utf8'));
198
207
  const itemIcon = contents.display.icon;
199
208
  const title = contents.display.title.translate;
@@ -26,8 +26,8 @@ export declare class HtmlInfoBookSerializer {
26
26
  link: string;
27
27
  linkTarget: string;
28
28
  };
29
- createItemDisplay(resourceHandler: ResourceHandler, context: ISerializeContext, fileWriter: IFileWriter, item: IItem, slot: boolean, annotation?: string): string;
30
- createFluidDisplay(resourceHandler: ResourceHandler, context: ISerializeContext, fileWriter: IFileWriter, fluid: IFluid, slot: boolean): string;
29
+ createItemDisplay(resourceHandler: ResourceHandler, context: ISerializeContext, fileWriter: IFileWriter, item: IItem, slot: boolean, annotation?: string): Promise<string>;
30
+ createFluidDisplay(resourceHandler: ResourceHandler, context: ISerializeContext, fileWriter: IFileWriter, fluid: IFluid, slot: boolean): Promise<string>;
31
31
  tagFluid(context: ISerializeContext, fluidName: string): string;
32
32
  getLanguagePath(language: string, path?: string): string;
33
33
  /**