mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
Add requiredMods to plugin declarations
Plugins can list the Factorio mods they need under requiredMods. When an instance starts, the host warns in the instance log about each loaded plugin whose required mods are missing or disabled in the mod pack. Subspace Storage declares the subspace_storage mod. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eefb4be44b
commit
a845b7ac52
6 files changed
+75
No files matched your search
@@ -151,6 +151,10 @@ The following properties are recognized:
|
||||
Array of features the plugin needs from the instances it is loaded on, any of `"SavePatching"`, `"ScriptCommands"` and `"LuaUdp"`.
|
||||
See [Handling Invalid Configuration](#handling-invalid-configuration)
|
||||
|
||||
**requiredMods**:
|
||||
Array of names of Factorio mods the plugin needs in the mod pack of the instances it is loaded on.
|
||||
See [Handling Invalid Configuration](#handling-invalid-configuration)
|
||||
|
||||
**messages**:
|
||||
Array of request and event classes for this plugin.
|
||||
See guide for [defining link messages](#defining-link-messages) below.
|
||||
@@ -321,6 +325,19 @@ export const plugin = {
|
||||
Enabling the plugin on an instance that has the feature turned off then fails config validation, so the mistake is caught when the config is edited instead of when the instance starts.
|
||||
Instances that have the feature turned off get the plugin disabled by default when it is added.
|
||||
|
||||
If the plugin talks to a Factorio mod, list the mod under `requiredMods`:
|
||||
|
||||
```js
|
||||
export const plugin = {
|
||||
name: "subspace_storage",
|
||||
// ...
|
||||
requiredMods: ["subspace_storage"],
|
||||
};
|
||||
```
|
||||
|
||||
When an instance with the plugin loaded starts with a mod pack that does not have the mod enabled, the host logs a warning to the instance log naming the missing mods.
|
||||
The mods are not added automatically, and the instance still starts.
|
||||
|
||||
Other constraints on config fields are expressed with a `validator` on the field definition, which throws when the value is not acceptable.
|
||||
Use `dependsOn` when the check involves other fields so that the validator runs when those change too.
|
||||
See [Configuration System](config-system.md) for details.
|
||||
|
||||
@@ -1032,6 +1032,24 @@ end`.replace(/\r?\n/g, " ");
|
||||
}
|
||||
|
||||
await this.syncMods();
|
||||
this.checkRequiredMods(this.activeModPack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Warn about mods required by loaded plugins that the mod pack lacks
|
||||
*/
|
||||
checkRequiredMods(modPack: lib.ModPack) {
|
||||
for (const pluginInfo of this.loadedPlugins) {
|
||||
const missing = (pluginInfo.requiredMods ?? []).filter(name => !modPack.mods.get(name)?.enabled);
|
||||
if (missing.length) {
|
||||
this.logger.warn(
|
||||
`Plugin ${pluginInfo.name} requires ${missing.join(", ")} which ` +
|
||||
`${missing.length === 1 ? "is" : "are"} not enabled in mod pack ${modPack.name}. ` +
|
||||
`Add ${missing.length === 1 ? "it" : "them"} to the mod pack or set ` +
|
||||
`${pluginInfo.name}.load_plugin to false for this instance.`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,6 +41,8 @@ export type PluginDeclaration = {
|
||||
migrationEntrypoint?: string;
|
||||
|
||||
features?: (typeof PluginFeatureFlags)[number][];
|
||||
/** Names of Factorio mods the plugin needs in the instance's mod pack */
|
||||
requiredMods?: string[];
|
||||
|
||||
messages?: any[];
|
||||
errors?: ErrorClass[];
|
||||
|
||||
@@ -12,6 +12,10 @@ Run the following commands in the folder Clusterio is installed to:
|
||||
|
||||
Substitute clusteriocontroller with clusteriohost or clusterioctl if this a dedicate host or ctl installation respectively.
|
||||
|
||||
The plugin needs the [Subspace Storage mod](https://mods.factorio.com/mod/subspace_storage) in the mod pack of every instance it is loaded on.
|
||||
Instances started without it log a warning, and the plugin's commands fail in game.
|
||||
Set `subspace_storage.load_plugin` to false on instances that should not use it.
|
||||
|
||||
|
||||
## Controller Configuration
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ export const plugin: lib.PluginDeclaration = {
|
||||
title: "Subspace Storage",
|
||||
description: "Provides shared storage across instances for the Subspace Storage mod",
|
||||
instanceEntrypoint: "dist/node/instance.js",
|
||||
requiredMods: ["subspace_storage"],
|
||||
instanceConfigFields: {
|
||||
"subspace_storage.log_item_transfers": {
|
||||
title: "Log Item Transfers",
|
||||
|
||||
@@ -336,6 +336,39 @@ describe("class Instance", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe(".checkRequiredMods()", function() {
|
||||
let warnings;
|
||||
beforeEach(function() {
|
||||
warnings = [];
|
||||
instance.logger = { warn(message) { warnings.push(message); } };
|
||||
instance.loadedPlugins = new Set([
|
||||
{ name: "foo", requiredMods: ["foo_mod", "bar_mod"] },
|
||||
{ name: "bar" },
|
||||
]);
|
||||
});
|
||||
function modPack(mods) {
|
||||
return lib.ModPack.fromJSON({ name: "pack", mods });
|
||||
}
|
||||
|
||||
it("should not warn when the required mods are enabled", function() {
|
||||
instance.checkRequiredMods(modPack([
|
||||
{ name: "foo_mod", enabled: true, version: "1.0.0" },
|
||||
{ name: "bar_mod", enabled: true, version: "1.0.0" },
|
||||
]));
|
||||
assert.deepEqual(warnings, []);
|
||||
});
|
||||
|
||||
it("should warn about missing and disabled required mods", function() {
|
||||
instance.checkRequiredMods(modPack([
|
||||
{ name: "foo_mod", enabled: false, version: "1.0.0" },
|
||||
]));
|
||||
assert.deepEqual(warnings, [
|
||||
"Plugin foo requires foo_mod, bar_mod which are not enabled in mod pack pack. " +
|
||||
"Add them to the mod pack or set foo.load_plugin to false for this instance.",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("save name checks", function() {
|
||||
it("should reject a start save outside the saves directory", async function() {
|
||||
await assert.rejects(
|
||||
|
||||
Reference in new issue
Block a user