From fafdac21fbf9189f15d895d3a627d8154975b1df Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sun, 9 Oct 2022 16:26:43 +0200 Subject: [PATCH] Follow mod pack string proposal Make all properties on the mod pack object except sha1 required and add the base mod if it does not exist in order to align the JSON representation with the proposed Mod Pack String format I published on the Factorio Forums (https://forums.factorio.com/103578) --- packages/lib/data/ModPack.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/lib/data/ModPack.js b/packages/lib/data/ModPack.js index 60d3c53c..52c99d6a 100644 --- a/packages/lib/data/ModPack.js +++ b/packages/lib/data/ModPack.js @@ -108,6 +108,7 @@ class ModPack { static jsonSchema = { type: "object", additionalProperties: false, + required: ["name", "description", "factorio_version", "mods", "settings"], properties: { "id": { type: "integer" }, "name": { type: "string" }, @@ -151,23 +152,25 @@ class ModPack { }; } if (json.is_deleted) { this.isDeleted = json.is_deleted; } + + if (!this.mods.has("base")) { + this.mods.set("base", { name: "base", enabled: true, version: this.factorioVersion }); + } } toJSON() { let json = { id: this.id, - }; - if (this.name) { json.name = this.name; } - if (this.description) { json.description = this.description; } - json.factorio_version = this.factorioVersion; - if (this.mods.size) { json.mods = [...this.mods.values()]; } - if (this.settings) { - json.settings = { + name: this.name, + description: this.description, + factorio_version: this.factorioVersion, + mods: [...this.mods.values()], + settings: { "startup": Object.fromEntries(this.settings["startup"]), "runtime-global": Object.fromEntries(this.settings["runtime-global"]), "runtime-per-user": Object.fromEntries(this.settings["runtime-per-user"]), - }; - } + }, + }; if (this.isDeleted) { json.is_deleted = this.isDeleted; } return json; }