Basic setup new system.

This commit is contained in:
Douwe Ravers
2023-08-24 01:48:31 +02:00
parent ae3812aa83
commit ccd0557339
12 changed files with 147 additions and 242 deletions

29
main.js
View File

@@ -3,25 +3,40 @@
// ########################################
const system = require("System");
const Class = require("Class");
const Job = require("Job");
const Room = require("Room");
const Structure = require("Structure");
module.exports.loop = function () {
if(!global.compiled) onRecompile();
else if (!global.started) onRestart();
else onTick();
}
function onRecompile(){
system.setup();
function onRecompile(){
Class.setup();
Job.setup();
console.log("Script recompiled...");
global.compiled = true;
}
function onRestart(){
system.begin();
Object.values(Game.rooms).forEach(room => Room.begin(room));
Object.values(Game.spawns).forEach(spawn => Structure.begin(spawn));
Object.values(Game.creeps).forEach(creep => Job.begin(creep));
global.started = true;
}
function onTick(){
system.tick();
}
Object.values(Game.rooms).forEach(room => Room.tick(room));
Object.values(Game.spawns).forEach(spawn => Structure.tick(spawn));
Object.values(Game.creeps).forEach(creep => Job.tick(creep));
if(!(Game.time % 100)) cleanUp();
}
function cleanUp(){
Object.keys(Memory.rooms).forEach(roomName => { if(!Game.rooms[roomName]) Memory.rooms[roomName] = undefined; });
Object.keys(Memory.creeps).forEach(creepName => { if(!Game.creeps[creepName]) Memory.creeps[creepName] = undefined; });
}