Skip to content

Commit a68662a

Browse files
committed
formatting
1 parent ec879c4 commit a68662a

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

Diff for: js/screepsstats.js

+36-29
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
var ScreepsStats = function () {
2-
if(!Memory.___screeps_stats) {
2+
if (!Memory.___screeps_stats) {
33
Memory.___screeps_stats = {}
44
}
55
this.username = _.get(
6-
_.find(Game.structures,(s) => true),'owner.username',
7-
_.get(_.find(Game.creeps,(s) => true),'owner.username')
6+
_.find(Game.structures, (s) => true), 'owner.username',
7+
_.get(_.find(Game.creeps, (s) => true), 'owner.username')
88
) || false
99
this.clean()
1010
}
@@ -58,19 +58,21 @@ ScreepsStats.prototype.runBuiltinStats = function () {
5858
}
5959
})
6060

61-
_.forEach(Game.rooms,(room) => {
61+
_.forEach(Game.rooms, (room) => {
6262

63-
if(!stats[room.name]) {
63+
if (!stats[room.name]) {
6464
stats.rooms[room.name] = {}
6565
}
6666

67-
if (_.isEmpty(room.controller)) { return }
67+
if (_.isEmpty(room.controller)) {
68+
return
69+
}
6870
var controller = room.controller
6971

7072
// Is hostile room? Continue
71-
if(!controller.my) {
72-
if(!!controller.owner) { // Owner is set but is not this user.
73-
if(controller.owner.username != this.username) {
73+
if (!controller.my) {
74+
if (!!controller.owner) { // Owner is set but is not this user.
75+
if (controller.owner.username != this.username) {
7476
return
7577
}
7678
} else {
@@ -83,20 +85,20 @@ ScreepsStats.prototype.runBuiltinStats = function () {
8385
level: controller.level,
8486
progress: controller.progress,
8587
upgradeBlocked: controller.upgradeBlocked,
86-
reservation: _.get(controller,'reservation.ticksToEnd'),
88+
reservation: _.get(controller, 'reservation.ticksToEnd'),
8789
ticksToDowngrade: controller.ticksToDowngrade
8890
})
8991

90-
if(controller.level > 0) {
92+
if (controller.level > 0) {
9193

9294
// Room
93-
_.merge(stats.rooms[room.name],{
95+
_.merge(stats.rooms[room.name], {
9496
energyAvailable: room.energyAvailable,
9597
energyCapacityAvailable: room.energyCapacityAvailable,
9698
})
9799

98100
// Storage
99-
if(room.storage) {
101+
if (room.storage) {
100102
_.defaults(stats, {
101103
storage: {
102104
subgroups: true
@@ -107,14 +109,14 @@ ScreepsStats.prototype.runBuiltinStats = function () {
107109
store: _.sum(room.storage.store),
108110
resources: {}
109111
}
110-
for(var resourceType in room.storage.store) {
112+
for (var resourceType in room.storage.store) {
111113
stats.storage[room.storage.id].resources[resourceType] = room.storage.store[resourceType]
112114
stats.storage[room.storage.id][resourceType] = room.storage.store[resourceType]
113115
}
114116
}
115117

116118
// Terminals
117-
if(room.terminal) {
119+
if (room.terminal) {
118120
_.defaults(stats, {
119121
terminal: {
120122
subgroups: true
@@ -125,7 +127,7 @@ ScreepsStats.prototype.runBuiltinStats = function () {
125127
store: _.sum(room.terminal.store),
126128
resources: {}
127129
}
128-
for(var resourceType in room.terminal.store) {
130+
for (var resourceType in room.terminal.store) {
129131
stats.terminal[room.terminal.id].resources[resourceType] = room.terminal.store[resourceType]
130132
stats.terminal[room.terminal.id][resourceType] = room.terminal.store[resourceType]
131133
}
@@ -144,11 +146,11 @@ ScreepsStats.prototype.runBuiltinStats = function () {
144146
subgroups: true
145147
}
146148
})
147-
_.forEach(Game.spawns, function(spawn) {
149+
_.forEach(Game.spawns, function (spawn) {
148150
stats.spawns[spawn.name] = {
149151
room: spawn.room.name,
150152
busy: !!spawn.spawning,
151-
remainingTime: _.get(spawn,'spawning.remainingTime',0)
153+
remainingTime: _.get(spawn, 'spawning.remainingTime', 0)
152154
}
153155
})
154156

@@ -174,16 +176,16 @@ ScreepsStats.prototype.roomExpensive = function (stats, room) {
174176
stats.rooms[room.name].sources = {}
175177
var sources = room.find(FIND_SOURCES)
176178

177-
_.forEach(sources,(source) => {
179+
_.forEach(sources, (source) => {
178180
stats.sources[source.id] = {
179181
room: room.name,
180182
energy: source.energy,
181183
energyCapacity: source.energyCapacity,
182184
ticksToRegeneration: source.ticksToRegeneration
183185
}
184-
if(source.energy < source.energyCapacity && source.ticksToRegeneration) {
186+
if (source.energy < source.energyCapacity && source.ticksToRegeneration) {
185187
var energyHarvested = source.energyCapacity - source.energy
186-
if(source.ticksToRegeneration < ENERGY_REGEN_TIME) {
188+
if (source.ticksToRegeneration < ENERGY_REGEN_TIME) {
187189
var ticksHarvested = ENERGY_REGEN_TIME - source.ticksToRegeneration
188190
stats.sources[source.id].averageHarvest = energyHarvested / ticksHarvested
189191
}
@@ -198,7 +200,7 @@ ScreepsStats.prototype.roomExpensive = function (stats, room) {
198200
// Mineral Mining
199201
var minerals = room.find(FIND_MINERALS)
200202
stats.rooms[room.name].minerals = {}
201-
_.forEach(minerals,(mineral) => {
203+
_.forEach(minerals, (mineral) => {
202204
stats.minerals[mineral.id] = {
203205
room: room.name,
204206
mineralType: mineral.mineralType,
@@ -212,8 +214,8 @@ ScreepsStats.prototype.roomExpensive = function (stats, room) {
212214
// Hostiles in Room
213215
var hostiles = room.find(FIND_HOSTILE_CREEPS)
214216
stats.rooms[room.name].hostiles = {}
215-
_.forEach(hostiles,(hostile) => {
216-
if(!stats.rooms[room.name].hostiles[hostile.owner.username]) {
217+
_.forEach(hostiles, (hostile) => {
218+
if (!stats.rooms[room.name].hostiles[hostile.owner.username]) {
217219
stats.rooms[room.name].hostiles[hostile.owner.username] = 1
218220
} else {
219221
stats.rooms[room.name].hostiles[hostile.owner.username]++
@@ -226,14 +228,14 @@ ScreepsStats.prototype.roomExpensive = function (stats, room) {
226228

227229
ScreepsStats.prototype.removeTick = function (tick) {
228230

229-
if(Array.isArray(tick)) {
230-
for(var index in tick) {
231+
if (Array.isArray(tick)) {
232+
for (var index in tick) {
231233
this.removeTick(tick[index])
232234
}
233235
return 'ScreepStats: Processed ' + tick.length + ' ticks'
234236
}
235237

236-
if(!!Memory.___screeps_stats[tick]) {
238+
if (!!Memory.___screeps_stats[tick]) {
237239
delete Memory.___screeps_stats[tick]
238240
return 'ScreepStats: Removed tick ' + tick
239241
} else {
@@ -242,19 +244,24 @@ ScreepsStats.prototype.removeTick = function (tick) {
242244
}
243245

244246
ScreepsStats.prototype.getStats = function (json) {
245-
if(json) {
247+
if (json) {
246248
return JSON.stringify(Memory.___screeps_stats)
247249
} else {
248250
return Memory.__screeps_stats
249251
}
250252
}
251253

252254
ScreepsStats.prototype.getStatsForTick = function (tick) {
253-
if(!Memory.__screeps_stats[tick]) {
255+
if (!Memory.__screeps_stats[tick]) {
254256
return false
255257
} else {
256258
return Memory.__screeps_stats[tick]
257259
}
258260
}
259261

262+
if (ENABLE_PROFILER && !!Profiler) {
263+
ScreepsStats.prototype = Profiler.registerObject(ScreepsStats, 'ScreepsStats')
264+
}
265+
266+
260267
module.exports = ScreepsStats

0 commit comments

Comments
 (0)