Basic setup new system.
This commit is contained in:
29
main.js
29
main.js
@@ -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; });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user