From cb76b6f43fef542f9b5b3a0d8b4bc46d05b3ccd9 Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Tue, 7 Dec 2021 21:57:22 +0300 Subject: [PATCH] Implemented ModMetadataReader for Forge mods --- package-lock.json | 5 +++++ package.json | 3 ++- .../forge/forge-mod-metadata-reader.ts | 18 ++++++++++++++++++ src/metadata/mod-metadata-reader-factory.ts | 4 ++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/metadata/forge/forge-mod-metadata-reader.ts diff --git a/package-lock.json b/package-lock.json index 50f2115..93b8002 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index e2da1f4..e773351 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/metadata/forge/forge-mod-metadata-reader.ts b/src/metadata/forge/forge-mod-metadata-reader.ts new file mode 100644 index 0000000..d4af1c7 --- /dev/null +++ b/src/metadata/forge/forge-mod-metadata-reader.ts @@ -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 { + return toml.parse(buffer.toString("utf8")); + } + + protected createMetadataFromConfig(config: Record): ModMetadata { + return new ForgeModMetadata(config); + } +} diff --git a/src/metadata/mod-metadata-reader-factory.ts b/src/metadata/mod-metadata-reader-factory.ts index 0c8dfe8..f8b2921 100644 --- a/src/metadata/mod-metadata-reader-factory.ts +++ b/src/metadata/mod-metadata-reader-factory.ts @@ -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)}"`); }