Skip to content
This repository was archived by the owner on Sep 29, 2018. It is now read-only.

Commit ba11d6c

Browse files
committed
Let generated file be main.js
1 parent 513cfd1 commit ba11d6c

File tree

3 files changed

+98
-96
lines changed

3 files changed

+98
-96
lines changed

Gruntfile.js

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
var path = require("path");
4+
35
module.exports = function(grunt) {
46

57
grunt.loadTasks('tasks');
@@ -88,6 +90,11 @@ module.exports = function(grunt) {
8890
dist: {
8991
src: ['build/deploy/*.js']
9092
}
93+
},
94+
screepsCodeGenerator: {
95+
options: {
96+
output: path.join(__dirname, '/build/deploy/main.js')
97+
}
9198
}
9299
});
93100

extensions/tools/scripts/main.js

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
'use strict';
2+
3+
module.exports = function() {
4+
var timerStart = Game.getUsedCpu();
5+
6+
AI.extensions.scripts.setup();
7+
var timerSetup = Game.getUsedCpu();
8+
9+
if (AI.isFirstTurn()) {
10+
AI.emit("firstTurn");
11+
}
12+
13+
AI.emit("preController");
14+
var timerPreController = Game.getUsedCpu();
15+
16+
var creepTimers = AI.extensions.scripts.creeps();
17+
var timerCreeps = Game.getUsedCpu();
18+
19+
AI.extensions.scripts.spawners();
20+
var timerSpawners = Game.getUsedCpu();
21+
22+
AI.emit("postController");
23+
var timerEnd = Game.getUsedCpu();
24+
25+
if (typeof global.run === "function") {
26+
global.run();
27+
global.run = undefined;
28+
}
29+
30+
if (timerEnd > AI.settings.roundTimeLimit) {
31+
var message = '';
32+
message += "🚀 Round " + Game.time + " * ";
33+
message += AI.getTimeDiff(0, timerEnd).toFixed(2) + " ms used";
34+
35+
if (Number.isFinite(Game.cpuLimit))
36+
message += " (" + Math.round(timerEnd / Game.cpuLimit * 100) + "% of " + Game.cpuLimit + " ms available)";
37+
38+
message += "\n";
39+
40+
// Set up table data
41+
var stageMessages = [
42+
"Main timers",
43+
"Start",
44+
"Setup",
45+
"Pre controller",
46+
"Creeps",
47+
"Spawners",
48+
"Post controller"
49+
];
50+
51+
var stageTimers = [
52+
"⌛",
53+
AI.getTimeDiff(0, timerStart ).toFixed(2) + " ms",
54+
AI.getTimeDiff(timerStart, timerSetup ).toFixed(2) + " ms",
55+
AI.getTimeDiff(timerSetup, timerPreController).toFixed(2) + " ms",
56+
AI.getTimeDiff(timerPreController, timerCreeps ).toFixed(2) + " ms",
57+
AI.getTimeDiff(timerCreeps, timerSpawners ).toFixed(2) + " ms",
58+
AI.getTimeDiff(timerSpawners, timerEnd ).toFixed(2) + " ms"
59+
];
60+
61+
var creepRoleMessages = Object.keys(creepTimers).length > 0 ? ["Creep timers"] : [];
62+
var creepRoleTime = Object.keys(creepTimers).length > 0 ? ["⌛"] : [];
63+
var creepTimeMessages = Object.keys(creepTimers).length > 0 ? [""] : [];
64+
var tmp;
65+
66+
for (var i in creepTimers) {
67+
creepRoleMessages.push(i);
68+
creepRoleTime.push(AI.getTimeDiff(0, creepTimers[i].totalTime).toFixed(2) + " ms");
69+
70+
// Format: <number of creeps> - <creepTimer1> - <creepTimer2> - etc...
71+
tmp = Object.keys(creepTimers[i].timers).length;
72+
for (var creep in creepTimers[i].timers) {
73+
tmp += " - " + creep + " " + creepTimers[i].timers[creep].toFixed(2) + " ms";
74+
}
75+
creepTimeMessages.push(tmp);
76+
}
77+
78+
var displayData = [
79+
stageTimers,
80+
stageMessages,
81+
creepRoleTime,
82+
creepRoleMessages,
83+
creepTimeMessages
84+
];
85+
86+
message += AI.alignColumns(displayData, {glue: " ", align: ["right", "left", "right", "left", "left"]});
87+
message += "Time to print debug message: " + AI.getTimeDiff(timerEnd, Game.getUsedCpu()).toFixed(2) + " ms";
88+
89+
console.log(message);
90+
}
91+
};

scripts/main.js

-96
This file was deleted.

0 commit comments

Comments
 (0)