From 1c75030ef45abfa044e39645bf9922e173b7d323 Mon Sep 17 00:00:00 2001 From: Vitor Hideyoshi Date: Thu, 23 Apr 2026 23:56:52 -0300 Subject: [PATCH] chore: fixes module pathing --- src/CreepRunner.ts | 4 +- src/RequisitionsManager.ts | 10 ++-- src/RoomInspector.ts | 4 +- src/RoomRunner.ts | 6 +-- src/global.d.ts | 48 ++++++++++++++++++++ src/main.ts | 48 +------------------- src/roleHandlers/harvester.handler.ts | 6 +-- src/roleHandlers/upgrader.handler.ts | 8 ++-- src/types/creeps.ts | 4 +- src/utils/funcs/getRoleCost.ts | 2 +- src/utils/funcs/sortCreepRolesByPriority.ts | 2 +- src/utils/positions/positionMatrix.ts | 0 tests/roleHandlers/harvester.handler.test.ts | 4 +- tests/roleHandlers/upgrader.handler.test.ts | 6 +-- tsconfig.json | 5 +- 15 files changed, 80 insertions(+), 77 deletions(-) create mode 100644 src/global.d.ts delete mode 100644 src/utils/positions/positionMatrix.ts diff --git a/src/CreepRunner.ts b/src/CreepRunner.ts index 26626d1..9bb7963 100644 --- a/src/CreepRunner.ts +++ b/src/CreepRunner.ts @@ -1,5 +1,5 @@ -import { CreepRole, CreepRoles } from 'types/creeps'; -import { getRoomCreeps } from 'utils/funcs/getRoomCreeps'; +import { CreepRole, CreepRoles } from '@/types/creeps'; +import { getRoomCreeps } from '@/utils/funcs/getRoomCreeps'; class CreepRunner { public static run(room: Room, state: GameState): GameState { diff --git a/src/RequisitionsManager.ts b/src/RequisitionsManager.ts index fdf43cc..34864ca 100644 --- a/src/RequisitionsManager.ts +++ b/src/RequisitionsManager.ts @@ -1,8 +1,8 @@ -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 { diff --git a/src/RoomInspector.ts b/src/RoomInspector.ts index c7180f9..5d652a2 100644 --- a/src/RoomInspector.ts +++ b/src/RoomInspector.ts @@ -1,11 +1,11 @@ -import { checkPositionWalkable } from 'utils/funcs/checkPosition'; +import { checkPositionWalkable } from '@/utils/funcs/checkPosition'; import { createSourcePositionMatrix, forEachMatrixSpot, getPositionWithDelta, PositionSpotStatus, setSpotStatus, -} from 'utils/positions'; +} from '@/utils/positions'; class RoomInspector { public static inspectState(room: Room, state: GameState): GameState { diff --git a/src/RoomRunner.ts b/src/RoomRunner.ts index 7d100d2..153976d 100644 --- a/src/RoomRunner.ts +++ b/src/RoomRunner.ts @@ -1,6 +1,6 @@ -import CreepRunner from 'CreepRunner'; -import RequisitionsManager from 'RequisitionsManager'; -import RoomInspector from 'RoomInspector'; +import CreepRunner from '@/CreepRunner'; +import RequisitionsManager from '@/RequisitionsManager'; +import RoomInspector from '@/RoomInspector'; class RoomRunner { public static run(room: Room, state: GameState): GameState { diff --git a/src/global.d.ts b/src/global.d.ts new file mode 100644 index 0000000..98bb4c8 --- /dev/null +++ b/src/global.d.ts @@ -0,0 +1,48 @@ +import { CreepDestination } from '@/types/creeps'; +import { PositionMatrix } from '@/utils/positions'; + +declare global { + /* + Example types, expand on these or remove them and add your own. + Note: Values, properties defined here do no fully *exist* by this type definiton alone. + You must also give them an implemention if you would like to use them. (ex. actually setting a `role` property in a Creeps memory) + + Types added in this `global` block are in an ambient, global context. This is needed because `main.ts` is a module file (uses import or export). + Interfaces matching on name from @types/screeps will be merged. This is how you can extend the 'built-in' interfaces from @types/screeps. + */ + interface SourceState { + id: string; + spots: PositionMatrix; + pos: RoomPosition; + } + + interface GameState { + sourcesStates: { [sourceId: string]: SourceState }; + maxHarvesters: number; // Maximum number of harvesters allowed in the game + } + + // Memory extension samples + interface Memory { + uuid: number; + log: any; + roomStateRegistry: { [name: string]: GameState }; + } + + interface CreepMemory { + role: string; + room: string; + spawnId: string; + working: boolean; + destination?: CreepDestination; + previousDestination?: CreepDestination; + } + + // Syntax for adding proprties to `global` (ex "global.log") + namespace NodeJS { + interface Global { + log: any; + } + } +} + +export {}; diff --git a/src/main.ts b/src/main.ts index c64c04a..ca33224 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,50 +1,4 @@ -import RoomRunner from 'RoomRunner'; -import { CreepDestination } from 'types/creeps'; -import { PositionMatrix } from 'utils/positions'; - -declare global { - /* - Example types, expand on these or remove them and add your own. - Note: Values, properties defined here do no fully *exist* by this type definiton alone. - You must also give them an implemention if you would like to use them. (ex. actually setting a `role` property in a Creeps memory) - - Types added in this `global` block are in an ambient, global context. This is needed because `main.ts` is a module file (uses import or export). - Interfaces matching on name from @types/screeps will be merged. This is how you can extend the 'built-in' interfaces from @types/screeps. - */ - interface SourceState { - id: string; - spots: PositionMatrix; - pos: RoomPosition; - } - - interface GameState { - sourcesStates: { [sourceId: string]: SourceState }; - maxHarvesters: number; // Maximum number of harvesters allowed in the game - } - - // Memory extension samples - interface Memory { - uuid: number; - log: any; - roomStateRegistry: { [name: string]: GameState }; - } - - interface CreepMemory { - role: string; - room: string; - spawnId: string; - working: boolean; - destination?: CreepDestination; - previousDestination?: CreepDestination; - } - - // Syntax for adding proprties to `global` (ex "global.log") - namespace NodeJS { - interface Global { - log: any; - } - } -} +import RoomRunner from '@/RoomRunner'; export const loop = () => { Memory.roomStateRegistry = Memory.roomStateRegistry || {}; diff --git a/src/roleHandlers/harvester.handler.ts b/src/roleHandlers/harvester.handler.ts index 68e05df..2a60b68 100644 --- a/src/roleHandlers/harvester.handler.ts +++ b/src/roleHandlers/harvester.handler.ts @@ -1,12 +1,12 @@ import { RoleHandler } from './BaseHandler.interface'; -import { SourceDestination } from 'types/creeps'; -import { getSourceById, getSpawnById } from 'utils/funcs/getById'; +import { SourceDestination } from '@/types/creeps'; +import { getSourceById, getSpawnById } from '@/utils/funcs/getById'; import { getNextEmptySpot, getPositionWithDelta, PositionSpotStatus, setSpotStatus, -} from 'utils/positions'; +} from '@/utils/positions'; class HarvesterHandler extends RoleHandler { public static destroy(creepMemory: CreepMemory, state: GameState): void { diff --git a/src/roleHandlers/upgrader.handler.ts b/src/roleHandlers/upgrader.handler.ts index d3c6645..2c97533 100644 --- a/src/roleHandlers/upgrader.handler.ts +++ b/src/roleHandlers/upgrader.handler.ts @@ -1,12 +1,12 @@ import { RoleHandler } from './BaseHandler.interface'; -import { SourceDestination } from 'types/creeps'; -import { getControllerById, getSourceById } from 'utils/funcs/getById'; +import { SourceDestination } from '@/types/creeps'; +import { getControllerById, getSourceById } from '@/utils/funcs/getById'; import { getNextEmptySpot, + getPositionWithDelta, PositionSpotStatus, setSpotStatus, - getPositionWithDelta, -} from 'utils/positions'; +} from '@/utils/positions'; class UpgraderHandler extends RoleHandler { public static destroy(creepMemory: CreepMemory, state: GameState): void { diff --git a/src/types/creeps.ts b/src/types/creeps.ts index ee45140..e3ffbd1 100644 --- a/src/types/creeps.ts +++ b/src/types/creeps.ts @@ -1,5 +1,5 @@ -import { HarvesterHandler, RoleHandler, UpgraderHandler } from 'roleHandlers'; -import { PositionDelta } from 'utils/positions'; +import { HarvesterHandler, RoleHandler, UpgraderHandler } from '@/roleHandlers'; +import { PositionDelta } from '@/utils/positions'; export type RoleDefinition = { name: string; diff --git a/src/utils/funcs/getRoleCost.ts b/src/utils/funcs/getRoleCost.ts index 6594117..f03fa6c 100644 --- a/src/utils/funcs/getRoleCost.ts +++ b/src/utils/funcs/getRoleCost.ts @@ -1,4 +1,4 @@ -import { RoleDefinition } from 'types/creeps'; +import { RoleDefinition } from '@/types/creeps'; export const get_role_cost = (role: RoleDefinition) => { return role.body.reduce((cost, part) => { diff --git a/src/utils/funcs/sortCreepRolesByPriority.ts b/src/utils/funcs/sortCreepRolesByPriority.ts index aff7f5a..82b3f13 100644 --- a/src/utils/funcs/sortCreepRolesByPriority.ts +++ b/src/utils/funcs/sortCreepRolesByPriority.ts @@ -3,7 +3,7 @@ import { CreepRole, CreepRoles, RoleDefinition, -} from 'types/creeps'; +} from '@/types/creeps'; export const sortCreepRolesByPriority = ( requisition: CreepRequisition diff --git a/src/utils/positions/positionMatrix.ts b/src/utils/positions/positionMatrix.ts deleted file mode 100644 index e69de29..0000000 diff --git a/tests/roleHandlers/harvester.handler.test.ts b/tests/roleHandlers/harvester.handler.test.ts index 535ac71..4c6081b 100644 --- a/tests/roleHandlers/harvester.handler.test.ts +++ b/tests/roleHandlers/harvester.handler.test.ts @@ -133,7 +133,7 @@ describe('HarvesterHandler', () => { // None of the source spots should have changed expect( state.sourcesStates['src1'].spots.every( - (s) => + (s: PositionSpotStatus) => s === PositionSpotStatus.EMPTY || s === PositionSpotStatus.CENTER ) @@ -232,7 +232,7 @@ describe('HarvesterHandler', () => { // Fill all non-center spots with OCCUPIED state.sourcesStates['src1'].spots = state.sourcesStates[ 'src1' - ].spots.map((s) => + ].spots.map((s: PositionSpotStatus) => s === PositionSpotStatus.CENTER ? s : PositionSpotStatus.OCCUPIED diff --git a/tests/roleHandlers/upgrader.handler.test.ts b/tests/roleHandlers/upgrader.handler.test.ts index f3ef8e0..e74fd14 100644 --- a/tests/roleHandlers/upgrader.handler.test.ts +++ b/tests/roleHandlers/upgrader.handler.test.ts @@ -131,7 +131,7 @@ describe('UpgraderHandler', () => { expect( state.sourcesStates['src1'].spots.every( - (s) => + (s: PositionSpotStatus) => s === PositionSpotStatus.EMPTY || s === PositionSpotStatus.CENTER ) @@ -220,7 +220,7 @@ describe('UpgraderHandler', () => { // Occupy all spots so onFindNewSource cannot reassign a source state.sourcesStates['src1'].spots = state.sourcesStates[ 'src1' - ].spots.map((s) => + ].spots.map((s: PositionSpotStatus) => s === PositionSpotStatus.CENTER ? s : PositionSpotStatus.OCCUPIED @@ -260,7 +260,7 @@ describe('UpgraderHandler', () => { const state = makeState(); state.sourcesStates['src1'].spots = state.sourcesStates[ 'src1' - ].spots.map((s) => + ].spots.map((s: PositionSpotStatus) => s === PositionSpotStatus.CENTER ? s : PositionSpotStatus.OCCUPIED diff --git a/tsconfig.json b/tsconfig.json index a822af4..7b609b7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,8 +19,9 @@ "paths": { "@/*": ["./src/*"], "~/*": ["./*"] - } + }, + "typeRoots": ["node_modules/@types", "src"] }, - "include": ["src/*.ts", "src/**/*.ts"], + "include": ["src/global.d.ts", "src/*.ts", "src/**/*.ts"], "exclude": ["node_modules", "dist"] }