Implemented ModMetadataReader for Forge mods

This commit is contained in:
Kir_Antipov 2021-12-07 21:57:22 +03:00
parent ddc460484e
commit cb76b6f43f
4 changed files with 29 additions and 1 deletions

5
package-lock.json generated
View file

@ -4828,6 +4828,11 @@
"is-number": "^7.0.0"
}
},
"toml": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz",
"integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w=="
},
"tough-cookie": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.0.0.tgz",

View file

@ -44,6 +44,7 @@
"fast-glob": "^3.2.7",
"formdata-node": "^4.2.4",
"node-fetch": "^3.0.0",
"node-stream-zip": "^1.15.0"
"node-stream-zip": "^1.15.0",
"toml": "^3.0.0"
}
}

View file

@ -0,0 +1,18 @@
import ModMetadata from "../../metadata/mod-metadata";
import toml from "toml";
import ZippedModMetadataReader from "../../metadata/zipped-mod-metadata-reader";
import ForgeModMetadata from "./forge-mod-metadata";
export default class ForgeModMetadataReader extends ZippedModMetadataReader {
constructor() {
super("META-INF/mods.toml");
}
protected loadConfig(buffer: Buffer): Record<string, unknown> {
return toml.parse(buffer.toString("utf8"));
}
protected createMetadataFromConfig(config: Record<string, unknown>): ModMetadata {
return new ForgeModMetadata(config);
}
}

View file

@ -1,4 +1,5 @@
import FabricModMetadataReader from "./fabric/fabric-mod-metadata-reader";
import ForgeModMetadataReader from "./forge/forge-mod-metadata-reader";
import ModLoaderType from "./mod-loader-type";
import ModMetadataReader from "./mod-metadata-reader";
@ -8,6 +9,9 @@ export default class ModMetadataReaderFactory {
case ModLoaderType.Fabric:
return new FabricModMetadataReader();
case ModLoaderType.Forge:
return new ForgeModMetadataReader();
default:
throw new Error(`Unknown mod loader "${ModLoaderType.toString(loaderType)}"`);
}