mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 07:24:53 +09:00
Remove one research queue entry per level a technology sync unlocks
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ed1e4ee3cb
commit
f7c78d9f74
2 files changed
+29
-6
No files matched your search
@@ -86,9 +86,13 @@ export default async function(context: ControllerPluginContext) {
|
||||
return controller.instances.get(src.id)?.config.get("instance.name") ?? String(src.id);
|
||||
}
|
||||
|
||||
function removeFinished(name: string) {
|
||||
let index = queue.indexOf(name);
|
||||
if (index !== -1) {
|
||||
// Removes one entry per level that finished
|
||||
function removeFinished(name: string, levels = 1) {
|
||||
for (let i = 0; i < levels; i++) {
|
||||
let index = queue.indexOf(name);
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
queue.splice(index, 1);
|
||||
queueDirty = true;
|
||||
}
|
||||
@@ -198,7 +202,8 @@ export default async function(context: ControllerPluginContext) {
|
||||
progressToBroadcast.add(name);
|
||||
} else if (researched || baseLevel(name) !== level) {
|
||||
controller.sendTo("allInstances", new FinishedEvent(name, level));
|
||||
removeFinished(name);
|
||||
// One queue entry per level unlocked
|
||||
removeFinished(name, Math.max(level - Number(!researched) - baseLevel(name) + 1, 1));
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -208,9 +213,10 @@ export default async function(context: ControllerPluginContext) {
|
||||
|
||||
if (tech.level < level || researched) {
|
||||
// Send update if the unlocked level is greater
|
||||
if (level - Number(!researched) > tech.level - Number(!tech.researched)) {
|
||||
let unlocked = level - Number(!researched) - (tech.level - Number(!tech.researched));
|
||||
if (unlocked > 0) {
|
||||
controller.sendTo("allInstances", new FinishedEvent(name, level - Number(!researched)));
|
||||
removeFinished(name);
|
||||
removeFinished(name, unlocked);
|
||||
}
|
||||
tech.level = level;
|
||||
tech.progress = progress;
|
||||
|
||||
@@ -119,6 +119,23 @@ describe("research_sync controller", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("technology sync unlocking several levels", function() {
|
||||
const techSync = (name, level, researched) => mock.getHandler(controller, SyncTechnologiesRequest)(
|
||||
new SyncTechnologiesRequest([new TechnologySync(name, level, null, researched)]), src
|
||||
);
|
||||
it("should drop one entry per level unlocked on a known technology", async function() {
|
||||
await techSync("m", 4, true);
|
||||
await update(["m", "m", "m", "x"]);
|
||||
await techSync("m", 7, true);
|
||||
assert.deepEqual(await sync(), ["x"]);
|
||||
});
|
||||
it("should drop one entry per level unlocked on a new technology", async function() {
|
||||
await update(["m", "m", "x"]);
|
||||
await techSync("m", 2, true);
|
||||
assert.deepEqual(await sync(), ["x"]);
|
||||
});
|
||||
});
|
||||
|
||||
it("should persist the queue across loads", async function() {
|
||||
await update(["a", "b"]);
|
||||
await controller.hooks.save.invoke();
|
||||
|
||||
Reference in new issue
Block a user