mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-27 00:37:14 +09:00
Invoke the config changed hook for every field
The fieldChanged handler repeated the hook invoke in each branch, and factorio.shutdown_timeout had no invoke at all, so plugins were never told about a change to it. Do the field specific side effect, then invoke the hook once for every field. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
96362a2835
commit
a76b742294
2 files changed
+32
-9
No files matched your search
@@ -200,24 +200,18 @@ export default class Instance extends lib.Link {
|
|||||||
this.hooks = new InstanceHooks(this.logger);
|
this.hooks = new InstanceHooks(this.logger);
|
||||||
|
|
||||||
this._configFieldChanged = (field: string, curr: unknown, prev: unknown) => {
|
this._configFieldChanged = (field: string, curr: unknown, prev: unknown) => {
|
||||||
let hook = () => this.hooks.instanceConfigFieldChanged.invoke(field, curr, prev);
|
|
||||||
|
|
||||||
if (field === "factorio.shutdown_timeout") {
|
if (field === "factorio.shutdown_timeout") {
|
||||||
this.server.shutdownTimeoutMs = curr as number * 1000;
|
this.server.shutdownTimeoutMs = curr as number * 1000;
|
||||||
|
} else if (field === "factorio.max_concurrent_commands") {
|
||||||
|
this.server.maxConcurrentCommands = curr as number;
|
||||||
} else if (field === "factorio.settings") {
|
} else if (field === "factorio.settings") {
|
||||||
this._applyWhenRunning(
|
this._applyWhenRunning(
|
||||||
"server settings", () => this.updateFactorioSettings(curr as any, prev as any)
|
"server settings", () => this.updateFactorioSettings(curr as any, prev as any)
|
||||||
);
|
);
|
||||||
hook();
|
|
||||||
} else if (field === "factorio.enable_whitelist") {
|
} else if (field === "factorio.enable_whitelist") {
|
||||||
this._applyWhenRunning("whitelist", () => this.updateFactorioWhitelist(curr as any));
|
this._applyWhenRunning("whitelist", () => this.updateFactorioWhitelist(curr as any));
|
||||||
hook();
|
|
||||||
} else {
|
|
||||||
if (field === "factorio.max_concurrent_commands") {
|
|
||||||
this.server.maxConcurrentCommands = curr as number;
|
|
||||||
}
|
|
||||||
hook();
|
|
||||||
}
|
}
|
||||||
|
this.hooks.instanceConfigFieldChanged.invoke(field, curr, prev);
|
||||||
};
|
};
|
||||||
this.config.on("fieldChanged", this._configFieldChanged);
|
this.config.on("fieldChanged", this._configFieldChanged);
|
||||||
|
|
||||||
|
|||||||
@@ -128,6 +128,35 @@ describe("class Instance", function() {
|
|||||||
instance.notifyStatus("stopped");
|
instance.notifyStatus("stopped");
|
||||||
await wait(10);
|
await wait(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should invoke the hook for fields applied to the server directly", async function() {
|
||||||
|
instance.config.set("factorio.shutdown_timeout", 30);
|
||||||
|
assert.equal(await hookInvoked, "factorio.shutdown_timeout");
|
||||||
|
assert.equal(instance.server.shutdownTimeoutMs, 30000);
|
||||||
|
await wait(10);
|
||||||
|
assert.deepEqual(errors, []);
|
||||||
|
assert.deepEqual(rejections, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should invoke the hook exactly once per field changed", async function() {
|
||||||
|
let invoked = [];
|
||||||
|
instance._host.whitelist = new Set();
|
||||||
|
instance.hooks.instanceConfigFieldChanged.attach("count", field => { invoked.push(field); });
|
||||||
|
instance.config.set("factorio.settings", { tags: ["a"] });
|
||||||
|
instance.config.set("factorio.enable_whitelist", true);
|
||||||
|
instance.config.set("factorio.shutdown_timeout", 30);
|
||||||
|
instance.config.set("factorio.max_concurrent_commands", 3);
|
||||||
|
await wait(10);
|
||||||
|
assert.deepEqual(invoked, [
|
||||||
|
"factorio.settings",
|
||||||
|
"factorio.enable_whitelist",
|
||||||
|
"factorio.shutdown_timeout",
|
||||||
|
"factorio.max_concurrent_commands",
|
||||||
|
]);
|
||||||
|
assert.equal(instance.server.maxConcurrentCommands, 3);
|
||||||
|
assert.deepEqual(errors, []);
|
||||||
|
assert.deepEqual(rejections, []);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("list update events", function() {
|
describe("list update events", function() {
|
||||||
|
|||||||
Reference in new issue
Block a user