Adds Routine for Cleaning SpawnHandlers
This commit is contained in:
@@ -4,8 +4,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node esbuild.config.mjs",
|
"build": "node esbuild.config.mjs",
|
||||||
"push:main": "npm run build && screeps-api --server main upload dist/*.js dist/**/*.js",
|
"push:main": "npm run build && screeps-api --server main upload dist/*.js",
|
||||||
"push:sim": "npm run build && screeps-api --server main upload --branch sim dist/*.js dist/**/*.js",
|
"push:sim": "npm run build && screeps-api --server main upload --branch sim dist/*.js",
|
||||||
"format": "prettier --config .prettierrc 'src/**/*.ts' --write && eslint --fix src/"
|
"format": "prettier --config .prettierrc 'src/**/*.ts' --write && eslint --fix src/"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
18
src/main.ts
18
src/main.ts
@@ -48,13 +48,23 @@ export const loop = () => {
|
|||||||
console.log(`Current game tick is ${Game.time}`);
|
console.log(`Current game tick is ${Game.time}`);
|
||||||
|
|
||||||
// Check if spawn still exists
|
// Check if spawn still exists
|
||||||
|
const activeSpawns = Object.keys(Game.spawns);
|
||||||
|
|
||||||
for (const spawn of Object.values(Game.spawns)) {
|
for (const spawnName in Object.keys(Memory.spawnHandlers)) {
|
||||||
|
if (spawnName in Game.spawns) {
|
||||||
|
console.log(`Spawn ${spawnName} exists, continuing to run its handler.`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
console.log(`Spawn ${spawnName} does not exist, deleting its handler.`);
|
||||||
|
delete Memory.spawnHandlers[spawnName];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const spawnName of activeSpawns) {
|
||||||
// Create a handler for each spawn
|
// Create a handler for each spawn
|
||||||
if (spawn.name in Memory.spawnHandlers) {
|
if (spawnName in Memory.spawnHandlers) {
|
||||||
Memory.spawnHandlers[spawn.name] = new SpawnHandler(spawn);
|
Memory.spawnHandlers[spawnName] = new SpawnHandler(Game.spawns[spawnName]);
|
||||||
}
|
}
|
||||||
// Run the handler
|
// Run the handler
|
||||||
Memory.spawnHandlers[spawn.name].run();
|
Memory.spawnHandlers[spawnName].run();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user