feat: removes unecessary allocations
This commit is contained in:
@@ -9,25 +9,19 @@ import {
|
||||
|
||||
class RoomInspector {
|
||||
public static inspectState(room: Room, state: GameState): GameState {
|
||||
if (!this.stateWasInitialized(state)) {
|
||||
state = this.initializeState(room, state);
|
||||
if (!state.sourcesStates) {
|
||||
this.initializeState(room, state);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
private static stateWasInitialized(state: GameState): boolean {
|
||||
return !!state.sourcesStates;
|
||||
}
|
||||
|
||||
private static initializeState(room: Room, state: GameState): GameState {
|
||||
private static initializeState(room: Room, state: GameState): void {
|
||||
state.sourcesStates = {};
|
||||
state.maxHarvesters = 0;
|
||||
|
||||
for (const source of room.find(FIND_SOURCES)) {
|
||||
this.configureSourceState(source, state);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
private static configureSourceState(
|
||||
|
||||
Reference in New Issue
Block a user