mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 15:30:41 +09:00
Add enabled field for mods in mod packs
Make it possible to disable built in mods like base by providing an enabled field that can be set to false in mod packs.
This commit is contained in:
1 parent
2384c48749
commit
f863aee3c2
6 files changed
+53
-12
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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" },
|
||||
},
|
||||
|
||||
@@ -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"}</Typography.Link>
|
||||
@@ -255,6 +255,30 @@ function ModsTable(props) {
|
||||
</Card>}
|
||||
<Table
|
||||
size="small"
|
||||
rowSelection={{
|
||||
type: "checkbox",
|
||||
selectedRowKeys: [...props.modPack.mods.values()].filter(mod => mod.enabled).map(mod => mod.name),
|
||||
getCheckboxProps(mod) {
|
||||
return { disabled: deletedMods.has(mod.name) };
|
||||
},
|
||||
onChange(selectedRowKeys, selectedRows) {
|
||||
function setEnabled(modNames, enabled) {
|
||||
for (let name of modNames) {
|
||||
props.onChange({
|
||||
type: "mods.set",
|
||||
name,
|
||||
value: { ...props.modPack.mods.get(name), enabled },
|
||||
});
|
||||
}
|
||||
}
|
||||
const added = selectedRowKeys.filter(key => !props.modPack.mods.get(key).enabled);
|
||||
const removed = [...props.modPack.mods.values()].filter(
|
||||
mod => mod.enabled && selectedRowKeys.indexOf(mod.name) === -1
|
||||
).map(mod => mod.name);
|
||||
setEnabled(added, true);
|
||||
setEnabled(removed, false);
|
||||
},
|
||||
}}
|
||||
columns={[
|
||||
{
|
||||
title: "Name",
|
||||
|
||||
@@ -333,13 +333,13 @@ tr.no-expanded-padding > td,
|
||||
.ant-form-item.changed,
|
||||
input.ant-input.changed,
|
||||
textarea.ant-input.changed,
|
||||
tr.ant-table-row.changed {
|
||||
tr.ant-table-row.changed > td {
|
||||
background: #2a1912;
|
||||
}
|
||||
|
||||
.ant-table-tbody > tr.ant-table-row.changed:hover > td,
|
||||
.ant-table-tbody > tr.changed > td.ant-table-cell-row-hover
|
||||
tr.ant-table-row.deleted {
|
||||
tr.ant-table-row.deleted > td {
|
||||
background: #3a2922;
|
||||
}
|
||||
|
||||
|
||||
@@ -845,7 +845,7 @@ describe("Integration of Clusterio", function() {
|
||||
reference.name = "full-pack";
|
||||
reference.description = "Description";
|
||||
reference.factorioVersion = "0.17";
|
||||
reference.mods.set("empty_mod", { name: "empty_mod", version: "1.0.0" });
|
||||
reference.mods.set("empty_mod", { name: "empty_mod", enabled: true, version: "1.0.0" });
|
||||
reference.settings["startup"].set("MyBool", { value: true });
|
||||
reference.settings["runtime-global"].set("MyInt", { value: 1235 });
|
||||
reference.settings["runtime-global"].set("MyDouble", { value: 12.25 });
|
||||
|
||||
@@ -26,8 +26,8 @@ describe("lib/data/ModPack", function() {
|
||||
check(new ModPack({ description: "My Description" }));
|
||||
check(new ModPack({ factorio_version: "2.0" }));
|
||||
check(new ModPack({ mods: [
|
||||
{ name: "subspace_storage", version: "1.99.8" },
|
||||
{ name: "clusterio_lib", version: "0.1.2", sha1: "012345abcd" },
|
||||
{ name: "subspace_storage", enabled: true, version: "1.99.8" },
|
||||
{ name: "clusterio_lib", enabled: true, version: "0.1.2", sha1: "012345abcd" },
|
||||
]}));
|
||||
check(new ModPack({ settings: {
|
||||
"startup": {
|
||||
@@ -46,8 +46,8 @@ describe("lib/data/ModPack", function() {
|
||||
description: "Every option at once.",
|
||||
factorio_version: "2.0",
|
||||
mods: [
|
||||
{ name: "subspace_storage", version: "1.99.8" },
|
||||
{ name: "clusterio_lib", version: "0.1.2", sha1: "012345abcd" },
|
||||
{ name: "subspace_storage", enabled: true, version: "1.99.8" },
|
||||
{ name: "clusterio_lib", enabled: true, version: "0.1.2", sha1: "012345abcd" },
|
||||
],
|
||||
settings: {
|
||||
"startup": {
|
||||
|
||||
Reference in new issue
Block a user