From 05a29057caccf2b29a26cc4899f2eca5841486b5 Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Tue, 7 Dec 2021 21:53:08 +0300 Subject: [PATCH] Implemented ModMetadataReader for Fabric mods --- .../fabric/fabric-mod-metadata-reader.ts | 17 +++++++++++++++++ src/metadata/mod-metadata-reader-factory.ts | 4 ++++ 2 files changed, 21 insertions(+) create mode 100644 src/metadata/fabric/fabric-mod-metadata-reader.ts diff --git a/src/metadata/fabric/fabric-mod-metadata-reader.ts b/src/metadata/fabric/fabric-mod-metadata-reader.ts new file mode 100644 index 0000000..fbe4a6a --- /dev/null +++ b/src/metadata/fabric/fabric-mod-metadata-reader.ts @@ -0,0 +1,17 @@ +import ModMetadata from "../../metadata/mod-metadata"; +import ZippedModMetadataReader from "../../metadata/zipped-mod-metadata-reader"; +import FabricModMetadata from "./fabric-mod-metadata"; + +export default class FabricModMetadataReader extends ZippedModMetadataReader { + constructor() { + super("fabric.mod.json"); + } + + protected loadConfig(buffer: Buffer): Record { + return JSON.parse(buffer.toString("utf8")); + } + + protected createMetadataFromConfig(config: Record): ModMetadata { + return new FabricModMetadata(config); + } +} diff --git a/src/metadata/mod-metadata-reader-factory.ts b/src/metadata/mod-metadata-reader-factory.ts index 3abf394..0c8dfe8 100644 --- a/src/metadata/mod-metadata-reader-factory.ts +++ b/src/metadata/mod-metadata-reader-factory.ts @@ -1,9 +1,13 @@ +import FabricModMetadataReader from "./fabric/fabric-mod-metadata-reader"; import ModLoaderType from "./mod-loader-type"; import ModMetadataReader from "./mod-metadata-reader"; export default class ModMetadataReaderFactory { public create(loaderType: ModLoaderType): ModMetadataReader { switch (loaderType) { + case ModLoaderType.Fabric: + return new FabricModMetadataReader(); + default: throw new Error(`Unknown mod loader "${ModLoaderType.toString(loaderType)}"`); }