cyclops-infobook-html 5.1.0 → 5.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -12
- package/bin/compress-icons.js +42 -7
- package/bin/convert-pom-to-modpack.d.ts +2 -0
- package/bin/convert-pom-to-modpack.js +96 -0
- package/bin/generate-icons.js +50 -15
- package/bin/generate-infobook-html.js +46 -10
- package/bin/generate-mod-metadata.js +52 -14
- package/index.d.ts +25 -25
- package/lib/icon/IconsCompressor.js +43 -12
- package/lib/icon/IconsGenerator.d.ts +42 -20
- package/lib/icon/IconsGenerator.js +156 -70
- package/lib/infobook/FileWriter.d.ts +3 -3
- package/lib/infobook/FileWriter.js +5 -5
- package/lib/infobook/IFileWriter.d.ts +2 -2
- package/lib/infobook/IInfoAppendix.d.ts +3 -3
- package/lib/infobook/IInfoBook.d.ts +2 -4
- package/lib/infobook/IInfoSection.d.ts +1 -1
- package/lib/infobook/IInfobookPlugin.d.ts +5 -5
- package/lib/infobook/InfoBookInitializer.d.ts +7 -9
- package/lib/infobook/InfoBookInitializer.js +1 -1
- package/lib/infobook/appendix/IInfoBookAppendixHandler.d.ts +2 -2
- package/lib/infobook/appendix/InfoBookAppendixAd.d.ts +3 -3
- package/lib/infobook/appendix/InfoBookAppendixAd.js +7 -2
- package/lib/infobook/appendix/InfoBookAppendixHandlerAbstractRecipe.d.ts +12 -14
- package/lib/infobook/appendix/InfoBookAppendixHandlerAbstractRecipe.js +41 -8
- package/lib/infobook/appendix/InfoBookAppendixHandlerAdvancementRewards.d.ts +3 -3
- package/lib/infobook/appendix/InfoBookAppendixHandlerAdvancementRewards.js +5 -4
- package/lib/infobook/appendix/InfoBookAppendixHandlerCraftingRecipe.d.ts +6 -5
- package/lib/infobook/appendix/InfoBookAppendixHandlerCraftingRecipe.js +4 -3
- package/lib/infobook/appendix/InfoBookAppendixHandlerImage.d.ts +3 -3
- package/lib/infobook/appendix/InfoBookAppendixHandlerImage.js +4 -4
- package/lib/infobook/appendix/InfoBookAppendixHandlerKeybinding.d.ts +3 -3
- package/lib/infobook/appendix/InfoBookAppendixHandlerKeybinding.js +3 -2
- package/lib/infobook/appendix/InfoBookAppendixHandlerSmeltingRecipe.d.ts +6 -5
- package/lib/infobook/appendix/InfoBookAppendixHandlerSmeltingRecipe.js +3 -2
- package/lib/infobook/appendix/InfoBookAppendixHandlerTextfield.d.ts +3 -3
- package/lib/infobook/appendix/InfoBookAppendixHandlerTextfield.js +4 -5
- package/lib/infobook/appendix/InfoBookAppendixTagIndex.d.ts +4 -4
- package/lib/infobook/appendix/InfoBookAppendixTagIndex.js +2 -1
- package/lib/modloader/ModLoader.d.ts +13 -2
- package/lib/modloader/ModLoader.js +164 -69
- package/lib/modloader/PomConverter.d.ts +28 -0
- package/lib/modloader/PomConverter.js +194 -0
- package/lib/parse/XmlInfoBookParser.d.ts +5 -7
- package/lib/parse/XmlInfoBookParser.js +42 -9
- package/lib/resource/ResourceHandler.d.ts +7 -13
- package/lib/resource/ResourceHandler.js +16 -11
- package/lib/resource/ResourceLoader.d.ts +4 -5
- package/lib/resource/ResourceLoader.js +35 -33
- package/lib/serialize/HtmlInfoBookSerializer.d.ts +10 -16
- package/lib/serialize/HtmlInfoBookSerializer.js +83 -80
- package/package.json +33 -27
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IInfoBookAppendixHandler } from
|
|
2
|
-
import { IInfoAppendix } from
|
|
3
|
-
import { IInfoBook } from
|
|
4
|
-
import { IInfoSection } from
|
|
1
|
+
import type { IInfoBookAppendixHandler } from '../infobook/appendix/IInfoBookAppendixHandler';
|
|
2
|
+
import type { IInfoAppendix } from '../infobook/IInfoAppendix';
|
|
3
|
+
import type { IInfoBook } from '../infobook/IInfoBook';
|
|
4
|
+
import type { IInfoSection } from '../infobook/IInfoSection';
|
|
5
5
|
/**
|
|
6
6
|
* Parses an XML file into an {@link IInfoBook}.
|
|
7
7
|
*/
|
|
@@ -34,9 +34,7 @@ export declare class XmlInfoBookParser {
|
|
|
34
34
|
* @param {string} modId The owning mod.
|
|
35
35
|
* @returns {IInfoSection} A section.
|
|
36
36
|
*/
|
|
37
|
-
jsonToSection(data: any, sections:
|
|
38
|
-
[id: string]: IInfoSection;
|
|
39
|
-
}, modId: string): IInfoSection;
|
|
37
|
+
jsonToSection(data: any, sections: Record<string, IInfoSection>, modId: string): IInfoSection;
|
|
40
38
|
/**
|
|
41
39
|
* Convert a data object to a paragraph.
|
|
42
40
|
* @param data A data object.
|
|
@@ -1,7 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.XmlInfoBookParser = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
37
|
+
const fs = __importStar(require("node:fs"));
|
|
5
38
|
const xml2js_1 = require("xml2js");
|
|
6
39
|
/**
|
|
7
40
|
* Parses an XML file into an {@link IInfoBook}.
|
|
@@ -29,7 +62,7 @@ class XmlInfoBookParser {
|
|
|
29
62
|
*/
|
|
30
63
|
parse(path, modId) {
|
|
31
64
|
return new Promise((resolve, reject) => {
|
|
32
|
-
(0, xml2js_1.parseString)(fs.readFileSync(path), (error, data) => {
|
|
65
|
+
(0, xml2js_1.parseString)(fs.readFileSync(path, 'utf8'), (error, data) => {
|
|
33
66
|
if (error) {
|
|
34
67
|
return reject(error);
|
|
35
68
|
}
|
|
@@ -58,14 +91,15 @@ class XmlInfoBookParser {
|
|
|
58
91
|
* @returns {IInfoSection} A section.
|
|
59
92
|
*/
|
|
60
93
|
jsonToSection(data, sections, modId) {
|
|
61
|
-
// tslint:disable:object-literal-sort-keys
|
|
62
94
|
const section = {
|
|
63
95
|
nameTranslationKey: data.$.name,
|
|
64
96
|
subSections: (data.section || []).map((subData) => this.jsonToSection(subData, sections, modId)),
|
|
65
97
|
paragraphTranslationKeys: (data.paragraph || []).map((subData) => this.jsonToParagraph(subData)),
|
|
66
|
-
appendix:
|
|
67
|
-
.
|
|
68
|
-
|
|
98
|
+
appendix: [
|
|
99
|
+
...(data.appendix || []),
|
|
100
|
+
...(data.appendix_list || []),
|
|
101
|
+
].map((subData) => this.jsonToAppendix(subData, modId)),
|
|
102
|
+
tags: (data.tag ? data.tag.filter((entry) => typeof entry === 'string') : []),
|
|
69
103
|
modId,
|
|
70
104
|
};
|
|
71
105
|
sections[section.nameTranslationKey] = section;
|
|
@@ -89,13 +123,12 @@ class XmlInfoBookParser {
|
|
|
89
123
|
if (!data.$ || (!data.$.type && !data.$.factory)) {
|
|
90
124
|
throw new Error(`No type or factory was found for the appendix ${JSON.stringify(data)}.`);
|
|
91
125
|
}
|
|
92
|
-
const type = data.$.type || data.$.factory;
|
|
126
|
+
const type = (data.$.type || data.$.factory);
|
|
93
127
|
const handler = this.appendixHandlers[type];
|
|
94
128
|
if (handler) {
|
|
95
129
|
return handler.createAppendix(data, modId);
|
|
96
130
|
}
|
|
97
|
-
|
|
98
|
-
console.error(`Could not find an appendix handler for type '${type}'`);
|
|
131
|
+
process.stderr.write(`Could not find an appendix handler for type '${type}'\n`);
|
|
99
132
|
return null;
|
|
100
133
|
}
|
|
101
134
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { IFluid } from
|
|
2
|
-
import { IItem } from
|
|
1
|
+
import type { IFluid } from '../infobook/IFluid';
|
|
2
|
+
import type { IItem } from '../infobook/IItem';
|
|
3
3
|
/**
|
|
4
4
|
* Allows Minecraft resources to be used.
|
|
5
5
|
*/
|
|
6
6
|
export declare class ResourceHandler {
|
|
7
|
-
private static readonly
|
|
7
|
+
private static readonly translationDefaults;
|
|
8
8
|
private readonly translations;
|
|
9
9
|
private readonly languages;
|
|
10
10
|
private readonly resourcePackBasePaths;
|
|
@@ -25,6 +25,7 @@ export declare class ResourceHandler {
|
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
27
|
* Add an entry to a {@llink IItemKeyedRegistry}.
|
|
28
|
+
* @param {IItemKeyedRegistry} registry The registry.
|
|
28
29
|
* @param {string} namespace The namespace.
|
|
29
30
|
* @param {string} path The path.
|
|
30
31
|
* @param {string} nbt The NBT. (empty string represents no NBT)
|
|
@@ -33,6 +34,7 @@ export declare class ResourceHandler {
|
|
|
33
34
|
protected static addItemKeyedRegistryEntry(registry: IItemKeyedRegistry, namespace: string, path: string, nbt: string, value: string): void;
|
|
34
35
|
/**
|
|
35
36
|
* Get an value from a {@llink IItemKeyedRegistry}.
|
|
37
|
+
* @param {IItemKeyedRegistry} registry The registry.
|
|
36
38
|
* @param {string} namespace The namespace.
|
|
37
39
|
* @param {string} path The path.
|
|
38
40
|
* @param {string} nbt The NBT. (empty string represents no NBT)
|
|
@@ -48,9 +50,7 @@ export declare class ResourceHandler {
|
|
|
48
50
|
* @param {string} language A language key.
|
|
49
51
|
* @param {{[p: string]: string}} translations A mapping from translation key to translated value.
|
|
50
52
|
*/
|
|
51
|
-
addTranslations(language: string, translations:
|
|
52
|
-
[key: string]: string;
|
|
53
|
-
}, excludedModLanguage: boolean): void;
|
|
53
|
+
addTranslations(language: string, translations: Record<string, string>, excludedModLanguage: boolean): void;
|
|
54
54
|
/**
|
|
55
55
|
* Get the translation for the given key.
|
|
56
56
|
* @param {string} translationKey A translation key.
|
|
@@ -146,13 +146,7 @@ export declare class ResourceHandler {
|
|
|
146
146
|
*/
|
|
147
147
|
getKeybinding(id: string): string;
|
|
148
148
|
}
|
|
149
|
-
export
|
|
150
|
-
[namespace: string]: {
|
|
151
|
-
[path: string]: {
|
|
152
|
-
[nbt: string]: string;
|
|
153
|
-
};
|
|
154
|
-
};
|
|
155
|
-
}
|
|
149
|
+
export type IItemKeyedRegistry = Record<string, Record<string, Record<string, string>>>;
|
|
156
150
|
export interface IAdvancement {
|
|
157
151
|
itemIcon: IItem;
|
|
158
152
|
title: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ResourceHandler = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
5
|
/**
|
|
6
6
|
* Allows Minecraft resources to be used.
|
|
7
7
|
*/
|
|
@@ -30,6 +30,7 @@ class ResourceHandler {
|
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Add an entry to a {@llink IItemKeyedRegistry}.
|
|
33
|
+
* @param {IItemKeyedRegistry} registry The registry.
|
|
33
34
|
* @param {string} namespace The namespace.
|
|
34
35
|
* @param {string} path The path.
|
|
35
36
|
* @param {string} nbt The NBT. (empty string represents no NBT)
|
|
@@ -48,6 +49,7 @@ class ResourceHandler {
|
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
50
51
|
* Get an value from a {@llink IItemKeyedRegistry}.
|
|
52
|
+
* @param {IItemKeyedRegistry} registry The registry.
|
|
51
53
|
* @param {string} namespace The namespace.
|
|
52
54
|
* @param {string} path The path.
|
|
53
55
|
* @param {string} nbt The NBT. (empty string represents no NBT)
|
|
@@ -64,7 +66,8 @@ class ResourceHandler {
|
|
|
64
66
|
}
|
|
65
67
|
let file = nbts[nbt];
|
|
66
68
|
if (!file) {
|
|
67
|
-
|
|
69
|
+
// Take the first NBT-tagged item if none without NBT could be found
|
|
70
|
+
file = nbts[Object.keys(nbts)[0]];
|
|
68
71
|
}
|
|
69
72
|
return file;
|
|
70
73
|
}
|
|
@@ -82,14 +85,14 @@ class ResourceHandler {
|
|
|
82
85
|
addTranslations(language, translations, excludedModLanguage) {
|
|
83
86
|
language = language.toLowerCase();
|
|
84
87
|
const existingTranslations = this.translations[language];
|
|
85
|
-
if (
|
|
86
|
-
this.translations[language] = translations;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
88
|
+
if (existingTranslations) {
|
|
89
89
|
for (const key in translations) {
|
|
90
90
|
existingTranslations[key] = translations[key];
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
+
else {
|
|
94
|
+
this.translations[language] = translations;
|
|
95
|
+
}
|
|
93
96
|
if (!excludedModLanguage && Object.keys(translations).length > 0) {
|
|
94
97
|
this.languages[language] = true;
|
|
95
98
|
}
|
|
@@ -104,7 +107,7 @@ class ResourceHandler {
|
|
|
104
107
|
const entries = this.translations[languageKey] || this.translations.en_us;
|
|
105
108
|
let value = entries[translationKey];
|
|
106
109
|
if (!value) {
|
|
107
|
-
value = this.translations.en_us[translationKey] || ResourceHandler.
|
|
110
|
+
value = this.translations.en_us[translationKey] || ResourceHandler.translationDefaults[translationKey];
|
|
108
111
|
if (!value) {
|
|
109
112
|
throw new Error(`Could not find translation key ${translationKey} in ${languageKey}`);
|
|
110
113
|
}
|
|
@@ -132,13 +135,13 @@ class ResourceHandler {
|
|
|
132
135
|
if (separator < 0) {
|
|
133
136
|
throw new Error(`Invalid resource key for expansion: ${resourceKey}`);
|
|
134
137
|
}
|
|
135
|
-
const resourcePackId = resourceKey.
|
|
138
|
+
const resourcePackId = resourceKey.slice(0, Math.max(0, separator));
|
|
136
139
|
const basePath = this.resourcePackBasePaths[resourcePackId];
|
|
137
140
|
if (!basePath) {
|
|
138
141
|
throw new Error(`Failed to expand unknown resource pack id for resource path: ${resourceKey}`);
|
|
139
142
|
}
|
|
140
|
-
const suffix = resourceKey.
|
|
141
|
-
return (0,
|
|
143
|
+
const suffix = resourceKey.slice(separator + 1);
|
|
144
|
+
return (0, node_path_1.join)(basePath, suffix);
|
|
142
145
|
}
|
|
143
146
|
/**
|
|
144
147
|
* Add an item icon file.
|
|
@@ -258,8 +261,10 @@ class ResourceHandler {
|
|
|
258
261
|
}
|
|
259
262
|
}
|
|
260
263
|
exports.ResourceHandler = ResourceHandler;
|
|
261
|
-
ResourceHandler.
|
|
264
|
+
ResourceHandler.translationDefaults = {
|
|
265
|
+
// eslint-disable-next-line ts/naming-convention
|
|
262
266
|
'fluid.tile.lava': 'Lava',
|
|
267
|
+
// eslint-disable-next-line ts/naming-convention
|
|
263
268
|
'fluid.tile.water': 'Water',
|
|
264
269
|
};
|
|
265
270
|
//# sourceMappingURL=ResourceHandler.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResourceHandler } from
|
|
1
|
+
import { ResourceHandler } from './ResourceHandler';
|
|
2
2
|
/**
|
|
3
3
|
* Loads Minecraft resources in-memory.
|
|
4
4
|
*/
|
|
@@ -30,7 +30,8 @@ export declare class ResourceLoader {
|
|
|
30
30
|
/**
|
|
31
31
|
* Load all resources within the given paths.
|
|
32
32
|
* @param {string} baseDir A base directory.
|
|
33
|
-
* @param {string
|
|
33
|
+
* @param {string} path A path.
|
|
34
|
+
* @param {string[]} excludedModLanguages Excluded mod languages.
|
|
34
35
|
* @returns {Promise<void>} A promise resolving when loading is done.
|
|
35
36
|
*/
|
|
36
37
|
loadAll(baseDir: string, path: string, excludedModLanguages: string[]): Promise<void>;
|
|
@@ -83,7 +84,5 @@ export declare class ResourceLoader {
|
|
|
83
84
|
* Load the given keybindings.
|
|
84
85
|
* @param {{[p: string]: string}} keybindings Keybindings.
|
|
85
86
|
*/
|
|
86
|
-
loadKeybindings(keybindings:
|
|
87
|
-
[key: string]: string;
|
|
88
|
-
}): void;
|
|
87
|
+
loadKeybindings(keybindings: Record<string, string>): void;
|
|
89
88
|
}
|
|
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ResourceLoader = void 0;
|
|
13
|
-
const
|
|
14
|
-
const
|
|
13
|
+
const node_fs_1 = require("node:fs");
|
|
14
|
+
const node_path_1 = require("node:path");
|
|
15
15
|
const ResourceHandler_1 = require("./ResourceHandler");
|
|
16
16
|
/**
|
|
17
17
|
* Loads Minecraft resources in-memory.
|
|
@@ -33,23 +33,23 @@ class ResourceLoader {
|
|
|
33
33
|
*/
|
|
34
34
|
loadIcons(iconsPath) {
|
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
const iconNames = yield
|
|
36
|
+
const iconNames = yield node_fs_1.promises.readdir(iconsPath);
|
|
37
37
|
for (const iconName of iconNames) {
|
|
38
|
-
const iconFile = (0,
|
|
38
|
+
const iconFile = (0, node_path_1.join)(iconsPath, iconName);
|
|
39
39
|
if (iconName.startsWith('fluid__')) {
|
|
40
|
-
this.resourceHandler.addFluidIcon(iconName.
|
|
40
|
+
this.resourceHandler.addFluidIcon(iconName.slice(7, -4), iconFile);
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
|
-
const split = iconName.split(
|
|
43
|
+
const split = iconName.split('__');
|
|
44
44
|
const namespace = split[0];
|
|
45
45
|
let path = split[1];
|
|
46
46
|
let nbt = '';
|
|
47
47
|
if (split.length > 2) {
|
|
48
|
-
nbt = split.slice(2, split.length).join(
|
|
49
|
-
nbt = nbt.
|
|
48
|
+
nbt = split.slice(2, split.length).join(':');
|
|
49
|
+
nbt = nbt.slice(0, Math.max(0, nbt.length - 4));
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
52
|
-
path = path.
|
|
52
|
+
path = path.slice(0, Math.max(0, path.length - 4));
|
|
53
53
|
}
|
|
54
54
|
this.resourceHandler.addItemIcon(namespace, path, nbt, iconFile);
|
|
55
55
|
}
|
|
@@ -63,7 +63,7 @@ class ResourceLoader {
|
|
|
63
63
|
*/
|
|
64
64
|
loadItemTranslationKeys(registriesPath) {
|
|
65
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
const registry = JSON.parse((0,
|
|
66
|
+
const registry = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(registriesPath, 'item_translation_keys.json'), 'utf8'));
|
|
67
67
|
for (const entry of registry.items) {
|
|
68
68
|
this.resourceHandler.addItemTranslationKey(entry.item, entry.translationKey);
|
|
69
69
|
}
|
|
@@ -76,7 +76,7 @@ class ResourceLoader {
|
|
|
76
76
|
*/
|
|
77
77
|
loadFluidTranslationKeys(registriesPath) {
|
|
78
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
const registry = JSON.parse((0,
|
|
79
|
+
const registry = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(registriesPath, 'fluid_translation_keys.json'), 'utf8'));
|
|
80
80
|
for (const entry of registry.fluids) {
|
|
81
81
|
this.resourceHandler.addFluidTranslationKey(entry.fluid, entry.translationKey);
|
|
82
82
|
}
|
|
@@ -85,12 +85,13 @@ class ResourceLoader {
|
|
|
85
85
|
/**
|
|
86
86
|
* Load all resources within the given paths.
|
|
87
87
|
* @param {string} baseDir A base directory.
|
|
88
|
-
* @param {string
|
|
88
|
+
* @param {string} path A path.
|
|
89
|
+
* @param {string[]} excludedModLanguages Excluded mod languages.
|
|
89
90
|
* @returns {Promise<void>} A promise resolving when loading is done.
|
|
90
91
|
*/
|
|
91
92
|
loadAll(baseDir, path, excludedModLanguages) {
|
|
92
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
yield this.load((0,
|
|
94
|
+
yield this.load((0, node_path_1.join)(baseDir, path), excludedModLanguages);
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
97
|
/**
|
|
@@ -103,12 +104,12 @@ class ResourceLoader {
|
|
|
103
104
|
*/
|
|
104
105
|
load(fullPath, excludedModLanguages) {
|
|
105
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
const entries = yield
|
|
107
|
+
const entries = yield node_fs_1.promises.readdir(fullPath);
|
|
107
108
|
// Look for a valid pack
|
|
108
109
|
for (const modid of entries) {
|
|
109
110
|
const excludedModLanguage = excludedModLanguages.includes(modid);
|
|
110
|
-
const modPath = (0,
|
|
111
|
-
if ((yield
|
|
111
|
+
const modPath = (0, node_path_1.join)(fullPath, modid);
|
|
112
|
+
if ((yield node_fs_1.promises.stat(modPath)).isDirectory()) {
|
|
112
113
|
yield this.loadAssets(modid, modPath, excludedModLanguage);
|
|
113
114
|
}
|
|
114
115
|
}
|
|
@@ -125,23 +126,23 @@ class ResourceLoader {
|
|
|
125
126
|
// Set base path
|
|
126
127
|
this.resourceHandler.setResourcePackBasePath(modid, fullPath);
|
|
127
128
|
// Handle languages
|
|
128
|
-
const langDir = (0,
|
|
129
|
+
const langDir = (0, node_path_1.join)(fullPath, 'lang');
|
|
129
130
|
try {
|
|
130
|
-
if ((yield
|
|
131
|
+
if ((yield node_fs_1.promises.stat(langDir)).isDirectory()) {
|
|
131
132
|
yield this.loadAssetsLang(modid, langDir, excludedModLanguage);
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
|
-
catch (
|
|
135
|
+
catch (_a) {
|
|
135
136
|
// Ignore mods without language files
|
|
136
137
|
}
|
|
137
138
|
// Handle advancements
|
|
138
|
-
const advancementsDir = (0,
|
|
139
|
+
const advancementsDir = (0, node_path_1.join)(fullPath, 'advancement');
|
|
139
140
|
try {
|
|
140
|
-
if ((yield
|
|
141
|
+
if ((yield node_fs_1.promises.stat(langDir)).isDirectory()) {
|
|
141
142
|
yield this.loadAssetsAdvancements(modid, advancementsDir, '');
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
|
-
catch (
|
|
145
|
+
catch (_b) {
|
|
145
146
|
// Ignore mods without advancements
|
|
146
147
|
}
|
|
147
148
|
});
|
|
@@ -154,10 +155,10 @@ class ResourceLoader {
|
|
|
154
155
|
*/
|
|
155
156
|
loadAssetsLang(modid, langDir, excludedModLanguage) {
|
|
156
157
|
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
-
const entries = yield
|
|
158
|
+
const entries = yield node_fs_1.promises.readdir(langDir);
|
|
158
159
|
for (const entry of entries) {
|
|
159
|
-
const language = entry.
|
|
160
|
-
yield this.loadAssetsLangFile(modid, language, (0,
|
|
160
|
+
const language = entry.slice(0, Math.max(0, entry.indexOf('.')));
|
|
161
|
+
yield this.loadAssetsLangFile(modid, language, (0, node_path_1.join)(langDir, entry), excludedModLanguage);
|
|
161
162
|
}
|
|
162
163
|
});
|
|
163
164
|
}
|
|
@@ -170,7 +171,7 @@ class ResourceLoader {
|
|
|
170
171
|
*/
|
|
171
172
|
loadAssetsLangFile(modid, language, fullFilePath, excludedModLanguage) {
|
|
172
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
-
const translations = JSON.parse((yield
|
|
174
|
+
const translations = JSON.parse((yield node_fs_1.promises.readFile(fullFilePath)).toString('utf8'));
|
|
174
175
|
this.resourceHandler.addTranslations(language, translations, excludedModLanguage);
|
|
175
176
|
});
|
|
176
177
|
}
|
|
@@ -182,11 +183,11 @@ class ResourceLoader {
|
|
|
182
183
|
*/
|
|
183
184
|
loadAssetsAdvancements(modid, advancementsDir, idPrefix) {
|
|
184
185
|
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
-
const entries = yield
|
|
186
|
+
const entries = yield node_fs_1.promises.readdir(advancementsDir);
|
|
186
187
|
for (const entry of entries) {
|
|
187
|
-
const entryFullPath = (0,
|
|
188
|
-
const entryId = idPrefix
|
|
189
|
-
if ((yield
|
|
188
|
+
const entryFullPath = (0, node_path_1.join)(advancementsDir, entry);
|
|
189
|
+
const entryId = `${idPrefix}/${entry}`;
|
|
190
|
+
if ((yield node_fs_1.promises.stat(entryFullPath)).isDirectory()) {
|
|
190
191
|
yield this.loadAssetsAdvancements(modid, entryFullPath, entryId);
|
|
191
192
|
}
|
|
192
193
|
else {
|
|
@@ -203,13 +204,14 @@ class ResourceLoader {
|
|
|
203
204
|
*/
|
|
204
205
|
loadAssetsAdvancement(modid, advancementsFile, id) {
|
|
205
206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
-
const
|
|
207
|
+
const contentsData = (yield node_fs_1.promises.readFile(advancementsFile)).toString('utf8');
|
|
208
|
+
const contents = JSON.parse(contentsData);
|
|
207
209
|
const itemIcon = contents.display.icon;
|
|
208
210
|
const title = contents.display.title.translate;
|
|
209
211
|
const description = contents.display.description.translate;
|
|
210
212
|
// Remove first slash and '.json' suffix.
|
|
211
|
-
id = id.
|
|
212
|
-
this.resourceHandler.addAdvancement({ itemIcon, title, description }, modid
|
|
213
|
+
id = id.slice(1, 1 + id.length - 6);
|
|
214
|
+
this.resourceHandler.addAdvancement({ itemIcon, title, description }, `${modid}:${id}`);
|
|
213
215
|
});
|
|
214
216
|
}
|
|
215
217
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { compileTemplate } from
|
|
2
|
-
import { IFileWriter } from
|
|
3
|
-
import { IFluid } from
|
|
4
|
-
import { IInfoBook } from
|
|
5
|
-
import { IInfoSection } from
|
|
6
|
-
import { IItem } from
|
|
7
|
-
import { ResourceHandler } from
|
|
1
|
+
import type { compileTemplate } from 'pug';
|
|
2
|
+
import type { IFileWriter } from '../infobook/IFileWriter';
|
|
3
|
+
import type { IFluid } from '../infobook/IFluid';
|
|
4
|
+
import type { IInfoBook } from '../infobook/IInfoBook';
|
|
5
|
+
import type { IInfoSection } from '../infobook/IInfoSection';
|
|
6
|
+
import type { IItem } from '../infobook/IItem';
|
|
7
|
+
import type { ResourceHandler } from '../resource/ResourceHandler';
|
|
8
8
|
/**
|
|
9
9
|
* Serializes an infobook to a collection of HTML files.
|
|
10
10
|
*/
|
|
@@ -53,9 +53,7 @@ export interface ISerializeContext {
|
|
|
53
53
|
path: string;
|
|
54
54
|
modId: string;
|
|
55
55
|
resourceHandler: ResourceHandler;
|
|
56
|
-
colors:
|
|
57
|
-
[key: string]: string;
|
|
58
|
-
};
|
|
56
|
+
colors: Record<string, string>;
|
|
59
57
|
headSuffixGetters: ((context: ISerializeContext) => string)[];
|
|
60
58
|
sectionIndex?: ISectionIndex;
|
|
61
59
|
root: boolean;
|
|
@@ -98,13 +96,9 @@ export interface ISectionIndex {
|
|
|
98
96
|
/**
|
|
99
97
|
* Mapping from url to page index within linkedPagesList.
|
|
100
98
|
*/
|
|
101
|
-
urlIndex:
|
|
102
|
-
[url: string]: number;
|
|
103
|
-
};
|
|
99
|
+
urlIndex: Record<string, number>;
|
|
104
100
|
/**
|
|
105
101
|
* Mapping from tag to page URL.
|
|
106
102
|
*/
|
|
107
|
-
tags:
|
|
108
|
-
[tag: string]: string;
|
|
109
|
-
};
|
|
103
|
+
tags: Record<string, string>;
|
|
110
104
|
}
|