diff --git a/packages/ctl/src/commands.js b/packages/ctl/src/commands.js index f4a31510..6173e808 100644 --- a/packages/ctl/src/commands.js +++ b/packages/ctl/src/commands.js @@ -875,7 +875,8 @@ modPackCommands.add(new libCommand.Command({ if (field === "mods") { print(`${field}:`); for (let entry of value) { - print(` ${entry.name} ${entry.version}${entry.sha1 ? ` (${entry.sha1})` : ""}`); + const enabled = entry.enabled ? "" : "(disabled) "; + print(` ${enabled}${entry.name} ${entry.version}${entry.sha1 ? ` (${entry.sha1})` : ""}`); } } else if (field === "settings") { print(`${field}:`); @@ -958,7 +959,16 @@ function setModPackMods(modPack, mods) { if (sha1 && !/^[0-9a-f]{40}$/.test(sha1)) { throw new libErrors.CommandError("sha1 must be a 40 digit lower case hex string"); } - modPack.mods.set(name, { name, version, sha1 }); + modPack.mods.set(name, { name, enabled: true, version, sha1 }); + } +} + +function setModPackModsEnabled(modPack, mods, enabled) { + for (let mod of mods || []) { + if (!modPack.mods.has(mod)) { + throw new libErrors.CommandError(`Mod named ${mod} does not exist in the mod pack`); + } + modPack.mods.get(mod).enabled = enabled; } } @@ -969,6 +979,7 @@ modPackCommands.add(new libCommand.Command({ yargs.options({ "description": { describe: "Description for mod pack", type: "string" }, "mods": { describe: "Mods in the form of name:version[:sha1]", array: true, type: "string" }, + "disabled-mods": { describe: "Mods that are in the pack but not enabled", array: true, type: "string" }, "bool-setting": { describe: "Set boolean setting", array: true, nargs: 3, type: "string" }, "int-setting": { describe: "Set int setting", array: true, nargs: 3, type: "string" }, "double-setting": { describe: "Set double setting", array: true, nargs: 3, type: "string" }, @@ -986,6 +997,7 @@ modPackCommands.add(new libCommand.Command({ modPack.factorioVersion = args.factorioVersion; } setModPackMods(modPack, args.mods); + setModPackModsEnabled(modPack, args.disabledMods, false); setModPackSettings(modPack, args); await libLink.messages.createModPack.send(control, { mod_pack: modPack.toJSON() }); print(`Created mod pack ${modPack.name} (${modPack.id})`); @@ -1000,6 +1012,8 @@ modPackCommands.add(new libCommand.Command({ "description": { describe: "New description for mod pack", type: "string" }, "factorio-version": { describe: "Set version of factorio the mod pack is for", type: "string" }, "add-mods": { describe: "Mods in the form of name:version[:sha1] to add", array: true, type: "string" }, + "enable-mods": { describe: "Mods to set as enabled", array: true, type: "string" }, + "disable-mods": { describe: "Mods to set as disabled", array: true, type: "string" }, "remove-mods": { describe: "Name of mods to remove", array: true, type: "string" }, "bool-setting": { describe: "Set boolean setting", array: true, nargs: 3, type: "string" }, "int-setting": { describe: "Set int setting", array: true, nargs: 3, type: "string" }, @@ -1031,6 +1045,8 @@ modPackCommands.add(new libCommand.Command({ logger.warn(`Mod ${name} did not exist on ${modPack.name}`); } } + setModPackModsEnabled(modPack, args.disableMods, false); + setModPackModsEnabled(modPack, args.enableMods, true); setModPackSettings(modPack, args); if (args.removeSetting) { diff --git a/packages/lib/data/ModPack.js b/packages/lib/data/ModPack.js index 50f21db1..60d3c53c 100644 --- a/packages/lib/data/ModPack.js +++ b/packages/lib/data/ModPack.js @@ -29,15 +29,16 @@ const ModSettingsJsonSchema = { * A mod in a mod pack * @typedef {object} module:lib/data.ModPack~ModRecord * @property {string} name - name of the mod. + * @property {boolean} enabled - if mod is to be loaded. * @property {string} version - version of the mod. * @property {string=} sha1 - SHA1 hash of the zip file. */ const ModRecordJsonSchema = { type: "object", - additionalProperties: false, - required: ["name", "version"], + required: ["name", "enabled", "version"], properties: { "name": { type: "string" }, + "enabled": { type: "boolean" }, "version": { type: "string" }, "sha1": { type: "string" }, }, diff --git a/packages/web_ui/src/components/ModPackViewPage.jsx b/packages/web_ui/src/components/ModPackViewPage.jsx index 17042616..39264fe1 100644 --- a/packages/web_ui/src/components/ModPackViewPage.jsx +++ b/packages/web_ui/src/components/ModPackViewPage.jsx @@ -95,7 +95,7 @@ function SearchModsTable(props) { props.onChange({ type: "mods.set", name: mod.name, - value: { name: mod.name, version: mod.version, sha1: mod.sha1 }, + value: { name: mod.name, enabled: true, version: mod.version, sha1: mod.sha1 }, }); }} >{props.modPack.mods.has(mod.name) ? "change" : "add"} @@ -255,6 +255,30 @@ function ModsTable(props) { }