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