feat: better code formatting

This commit is contained in:
2026-04-23 23:03:00 -03:00
parent a3841bd173
commit e18980938e
37 changed files with 1691 additions and 7930 deletions

View File

@@ -1,14 +1,14 @@
import { CreepRequisition, CreepRole, CreepRoles } from "types/creeps";
import { DEFAULT_GAME_CONFIG } from "types/gameConfig";
import { get_role_cost } from "utils/funcs/getRoleCost";
import { getRoomCreeps } from "utils/funcs/getRoomCreeps";
import { sortCreepRolesByPriority } from "utils/funcs/sortCreepRolesByPriority";
import { CreepRequisition, CreepRole, CreepRoles } from 'types/creeps';
import { DEFAULT_GAME_CONFIG } from 'types/gameConfig';
import { get_role_cost } from 'utils/funcs/getRoleCost';
import { getRoomCreeps } from 'utils/funcs/getRoomCreeps';
import { sortCreepRolesByPriority } from 'utils/funcs/sortCreepRolesByPriority';
class RequisitionsManager {
public static validateState(room: Room, state: GameState): GameState {
const creepRequisition = this.getRoomRequisition(room);
if (Object.values(creepRequisition).every(count => count <= 0)) {
if (Object.values(creepRequisition).every((count) => count <= 0)) {
return state;
}
@@ -24,7 +24,10 @@ class RequisitionsManager {
return state;
}
private static fulfillSpawnRequisition(spawn: StructureSpawn, creepRequisition: CreepRequisition): boolean {
private static fulfillSpawnRequisition(
spawn: StructureSpawn,
creepRequisition: CreepRequisition
): boolean {
if (spawn.spawning) {
return false;
}
@@ -42,14 +45,18 @@ class RequisitionsManager {
role: role.name,
room: spawn.room.name,
spawnId: spawn.id,
working: false
}
working: false,
},
});
if (spawnResult === OK) {
console.log(`Spawn ${spawn.name} successfully spawned a new ${role.name}: ${newName}.`);
console.log(
`Spawn ${spawn.name} successfully spawned a new ${role.name}: ${newName}.`
);
return true; // Exit after spawning one creep
} else {
console.error(`Spawn ${spawn.name} failed to spawn a new ${role.name}: ${spawnResult}`);
console.error(
`Spawn ${spawn.name} failed to spawn a new ${role.name}: ${spawnResult}`
);
}
}
@@ -66,7 +73,7 @@ class RequisitionsManager {
const requisition: CreepRequisition = {
harvester: 0,
upgrader: 0,
builder: 0
builder: 0,
};
for (const role in DEFAULT_GAME_CONFIG.minCreepsPerRole) {
if (!(role in CreepRoles)) {
@@ -74,7 +81,9 @@ class RequisitionsManager {
continue;
}
const roleType = role as CreepRole;
requisition[roleType] = DEFAULT_GAME_CONFIG.minCreepsPerRole[roleType] - (creepCounts[role] || 0);
requisition[roleType] =
DEFAULT_GAME_CONFIG.minCreepsPerRole[roleType] -
(creepCounts[role] || 0);
if (requisition[roleType] < 0) {
requisition[roleType] = 0; // Ensure we don't have negative requisitions