Skip to content

Commit

Permalink
Remove outdated code. Optimise FindTypes and AllLookAtTypes (#264)
Browse files Browse the repository at this point in the history
* Replace hard-coded FIND_ values with their constant
* Replace hard-coded LOOK_ values with their constant
* Remove a couple of leftovers

- Room.mode doesn't look like it exists anymore
- Remove duplicates from StructureSpawn, they're inherited from Structure
- Remove AllLookAtTypes.exit
- Remove SurvivalGameInfo
  • Loading branch information
tiennou authored Feb 1, 2025
1 parent 489e2ba commit 1f73abf
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 176 deletions.
132 changes: 44 additions & 88 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,8 @@ declare const GCL_POW: number;
declare const GCL_MULTIPLY: number;
declare const GCL_NOVICE: number;

declare const MODE_SIMULATION: string;
declare const MODE_SURVIVAL: string;
declare const MODE_WORLD: string;
declare const MODE_ARENA: string;
declare const MODE_SIMULATION: null;
declare const MODE_WORLD: null;

declare const TERRAIN_MASK_WALL: TERRAIN_MASK_WALL;
declare const TERRAIN_MASK_SWAMP: TERRAIN_MASK_SWAMP;
Expand Down Expand Up @@ -1770,11 +1768,6 @@ type StoreDefinition = Store<ResourceConstant, false>;
/** A general purpose Store, which has an unlimited capacity */
type StoreDefinitionUnlimited = Store<ResourceConstant, true>;

// type SD<K extends ResourceConstant> = {
// [P in K]: number;
// energy: number;
// }

/**
* @example
* {
Expand All @@ -1787,21 +1780,20 @@ type StoreDefinitionUnlimited = Store<ResourceConstant, true>;
type ExitsInformation = Partial<Record<ExitKey, string>>;

interface AllLookAtTypes {
constructionSite: ConstructionSite;
creep: Creep;
energy: Resource<RESOURCE_ENERGY>;
exit: any; // TODO what type is this?
flag: Flag;
mineral: Mineral;
deposit: Deposit;
nuke: Nuke;
resource: Resource;
source: Source;
structure: AnyStructure;
terrain: Terrain;
tombstone: Tombstone;
powerCreep: PowerCreep;
ruin: Ruin;
[LOOK_CONSTRUCTION_SITES]: ConstructionSite;
[LOOK_CREEPS]: Creep;
[LOOK_ENERGY]: Resource<RESOURCE_ENERGY>;
[LOOK_FLAGS]: Flag;
[LOOK_MINERALS]: Mineral;
[LOOK_DEPOSITS]: Deposit;
[LOOK_NUKES]: Nuke;
[LOOK_RESOURCES]: Resource;
[LOOK_SOURCES]: Source;
[LOOK_STRUCTURES]: AnyStructure;
[LOOK_TERRAIN]: Terrain;
[LOOK_TOMBSTONES]: Tombstone;
[LOOK_POWER_CREEPS]: PowerCreep;
[LOOK_RUINS]: Ruin;
}

type LookAtTypes = Partial<AllLookAtTypes>;
Expand Down Expand Up @@ -1845,34 +1837,34 @@ interface FindTypes {
| Tombstone
| Deposit
| Ruin;
1: RoomPosition; // FIND_EXIT_TOP
3: RoomPosition; // FIND_EXIT_RIGHT
5: RoomPosition; // FIND_EXIT_BOTTOM
7: RoomPosition; // FIND_EXIT_LEFT
10: RoomPosition; // FIND_EXIT
101: Creep; // FIND_CREEPS
102: Creep; // FIND_MY_CREEPS
103: Creep; // FIND_HOSTILE_CREEPS
104: Source; // FIND_SOURCES_ACTIVE
105: Source; // FIND_SOURCES
106: Resource; // FIND_DROPPED_RESOURCES
107: AnyStructure; // FIND_STRUCTURES
108: AnyOwnedStructure; // FIND_MY_STRUCTURES
109: AnyOwnedStructure; // FIND_HOSTILE_STRUCTURES
110: Flag; // FIND_FLAGS
111: ConstructionSite; // FIND_CONSTRUCTION_SITES
112: StructureSpawn; // FIND_MY_SPAWNS
113: StructureSpawn; // FIND_HOSTILE_SPAWNS
114: ConstructionSite; // FIND_MY_CONSTRUCTION_SITES
115: ConstructionSite; // FIND_HOSTILE_CONSTRUCTION_SITES
116: Mineral; // FIND_MINERALS
117: Nuke; // FIND_NUKES
118: Tombstone; // FIND_TOMBSTONES
119: PowerCreep; // FIND_POWER_CREEPS
120: PowerCreep; // FIND_MY_POWER_CREEPS
121: PowerCreep; // FIND_HOSTILE_POWER_CREEPS
122: Deposit; // FIND_DEPOSITS
123: Ruin; // FIND_RUINS
[FIND_EXIT_TOP]: RoomPosition;
[FIND_EXIT_RIGHT]: RoomPosition;
[FIND_EXIT_BOTTOM]: RoomPosition;
[FIND_EXIT_LEFT]: RoomPosition;
[FIND_EXIT]: RoomPosition;
[FIND_CREEPS]: Creep;
[FIND_MY_CREEPS]: Creep;
[FIND_HOSTILE_CREEPS]: Creep;
[FIND_SOURCES_ACTIVE]: Source;
[FIND_SOURCES]: Source;
[FIND_DROPPED_RESOURCES]: Resource;
[FIND_STRUCTURES]: AnyStructure;
[FIND_MY_STRUCTURES]: AnyOwnedStructure;
[FIND_HOSTILE_STRUCTURES]: AnyOwnedStructure;
[FIND_FLAGS]: Flag;
[FIND_CONSTRUCTION_SITES]: ConstructionSite;
[FIND_MY_SPAWNS]: StructureSpawn;
[FIND_HOSTILE_SPAWNS]: StructureSpawn;
[FIND_MY_CONSTRUCTION_SITES]: ConstructionSite;
[FIND_HOSTILE_CONSTRUCTION_SITES]: ConstructionSite;
[FIND_MINERALS]: Mineral;
[FIND_NUKES]: Nuke;
[FIND_TOMBSTONES]: Tombstone;
[FIND_POWER_CREEPS]: PowerCreep;
[FIND_MY_POWER_CREEPS]: PowerCreep;
[FIND_HOSTILE_POWER_CREEPS]: PowerCreep;
[FIND_DEPOSITS]: Deposit;
[FIND_RUINS]: Ruin;
}

interface FindPathOpts {
Expand Down Expand Up @@ -1991,24 +1983,6 @@ interface PathStep {
direction: DirectionConstant;
}

/**
* An object with survival game info
*/
interface SurvivalGameInfo {
/**
* Current score.
*/
score: number;
/**
* Time to the next wave of invaders.
*/
timeToWave: number;
/**
* The number of the next wave.
*/
wave: number;
}

interface _Constructor<T> {
readonly prototype: T;
}
Expand Down Expand Up @@ -4329,10 +4303,6 @@ interface Room {
* A shorthand to `Memory.rooms[room.name]`. You can use it for quick access the room’s specific memory data object.
*/
memory: RoomMemory;
/**
* One of the `MODE_*` constants.
*/
mode: string;
/**
* The name of the room.
*/
Expand Down Expand Up @@ -4764,20 +4734,6 @@ interface StructureSpawn extends OwnedStructure<STRUCTURE_SPAWN> {
* ```
*/
spawnCreep(body: BodyPartConstant[], name: string, opts?: SpawnOptions): ScreepsReturnCode;

/**
* Destroy this spawn immediately.
*/
destroy(): ScreepsReturnCode;
/**
* Check whether this structure can be used. If the room controller level is not enough, then this method will return false, and the structure will be highlighted with red in the game.
*/
isActive(): boolean;
/**
* Toggle auto notification when the spawn is under attack. The notification will be sent to your account email. Turned on by default.
* @param enabled Whether to enable notification or disable.
*/
notifyWhenAttacked(enabled: boolean): ScreepsReturnCode;
/**
* Increase the remaining time to live of the target creep.
*
Expand Down
6 changes: 2 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,8 @@ declare const GCL_POW: number;
declare const GCL_MULTIPLY: number;
declare const GCL_NOVICE: number;

declare const MODE_SIMULATION: string;
declare const MODE_SURVIVAL: string;
declare const MODE_WORLD: string;
declare const MODE_ARENA: string;
declare const MODE_SIMULATION: null;
declare const MODE_WORLD: null;

declare const TERRAIN_MASK_WALL: TERRAIN_MASK_WALL;
declare const TERRAIN_MASK_SWAMP: TERRAIN_MASK_SWAMP;
Expand Down
108 changes: 42 additions & 66 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ type StoreDefinition = Store<ResourceConstant, false>;
/** A general purpose Store, which has an unlimited capacity */
type StoreDefinitionUnlimited = Store<ResourceConstant, true>;

// type SD<K extends ResourceConstant> = {
// [P in K]: number;
// energy: number;
// }

/**
* @example
* {
Expand All @@ -203,21 +198,20 @@ type StoreDefinitionUnlimited = Store<ResourceConstant, true>;
type ExitsInformation = Partial<Record<ExitKey, string>>;

interface AllLookAtTypes {
constructionSite: ConstructionSite;
creep: Creep;
energy: Resource<RESOURCE_ENERGY>;
exit: any; // TODO what type is this?
flag: Flag;
mineral: Mineral;
deposit: Deposit;
nuke: Nuke;
resource: Resource;
source: Source;
structure: AnyStructure;
terrain: Terrain;
tombstone: Tombstone;
powerCreep: PowerCreep;
ruin: Ruin;
[LOOK_CONSTRUCTION_SITES]: ConstructionSite;
[LOOK_CREEPS]: Creep;
[LOOK_ENERGY]: Resource<RESOURCE_ENERGY>;
[LOOK_FLAGS]: Flag;
[LOOK_MINERALS]: Mineral;
[LOOK_DEPOSITS]: Deposit;
[LOOK_NUKES]: Nuke;
[LOOK_RESOURCES]: Resource;
[LOOK_SOURCES]: Source;
[LOOK_STRUCTURES]: AnyStructure;
[LOOK_TERRAIN]: Terrain;
[LOOK_TOMBSTONES]: Tombstone;
[LOOK_POWER_CREEPS]: PowerCreep;
[LOOK_RUINS]: Ruin;
}

type LookAtTypes = Partial<AllLookAtTypes>;
Expand Down Expand Up @@ -261,34 +255,34 @@ interface FindTypes {
| Tombstone
| Deposit
| Ruin;
1: RoomPosition; // FIND_EXIT_TOP
3: RoomPosition; // FIND_EXIT_RIGHT
5: RoomPosition; // FIND_EXIT_BOTTOM
7: RoomPosition; // FIND_EXIT_LEFT
10: RoomPosition; // FIND_EXIT
101: Creep; // FIND_CREEPS
102: Creep; // FIND_MY_CREEPS
103: Creep; // FIND_HOSTILE_CREEPS
104: Source; // FIND_SOURCES_ACTIVE
105: Source; // FIND_SOURCES
106: Resource; // FIND_DROPPED_RESOURCES
107: AnyStructure; // FIND_STRUCTURES
108: AnyOwnedStructure; // FIND_MY_STRUCTURES
109: AnyOwnedStructure; // FIND_HOSTILE_STRUCTURES
110: Flag; // FIND_FLAGS
111: ConstructionSite; // FIND_CONSTRUCTION_SITES
112: StructureSpawn; // FIND_MY_SPAWNS
113: StructureSpawn; // FIND_HOSTILE_SPAWNS
114: ConstructionSite; // FIND_MY_CONSTRUCTION_SITES
115: ConstructionSite; // FIND_HOSTILE_CONSTRUCTION_SITES
116: Mineral; // FIND_MINERALS
117: Nuke; // FIND_NUKES
118: Tombstone; // FIND_TOMBSTONES
119: PowerCreep; // FIND_POWER_CREEPS
120: PowerCreep; // FIND_MY_POWER_CREEPS
121: PowerCreep; // FIND_HOSTILE_POWER_CREEPS
122: Deposit; // FIND_DEPOSITS
123: Ruin; // FIND_RUINS
[FIND_EXIT_TOP]: RoomPosition;
[FIND_EXIT_RIGHT]: RoomPosition;
[FIND_EXIT_BOTTOM]: RoomPosition;
[FIND_EXIT_LEFT]: RoomPosition;
[FIND_EXIT]: RoomPosition;
[FIND_CREEPS]: Creep;
[FIND_MY_CREEPS]: Creep;
[FIND_HOSTILE_CREEPS]: Creep;
[FIND_SOURCES_ACTIVE]: Source;
[FIND_SOURCES]: Source;
[FIND_DROPPED_RESOURCES]: Resource;
[FIND_STRUCTURES]: AnyStructure;
[FIND_MY_STRUCTURES]: AnyOwnedStructure;
[FIND_HOSTILE_STRUCTURES]: AnyOwnedStructure;
[FIND_FLAGS]: Flag;
[FIND_CONSTRUCTION_SITES]: ConstructionSite;
[FIND_MY_SPAWNS]: StructureSpawn;
[FIND_HOSTILE_SPAWNS]: StructureSpawn;
[FIND_MY_CONSTRUCTION_SITES]: ConstructionSite;
[FIND_HOSTILE_CONSTRUCTION_SITES]: ConstructionSite;
[FIND_MINERALS]: Mineral;
[FIND_NUKES]: Nuke;
[FIND_TOMBSTONES]: Tombstone;
[FIND_POWER_CREEPS]: PowerCreep;
[FIND_MY_POWER_CREEPS]: PowerCreep;
[FIND_HOSTILE_POWER_CREEPS]: PowerCreep;
[FIND_DEPOSITS]: Deposit;
[FIND_RUINS]: Ruin;
}

interface FindPathOpts {
Expand Down Expand Up @@ -407,24 +401,6 @@ interface PathStep {
direction: DirectionConstant;
}

/**
* An object with survival game info
*/
interface SurvivalGameInfo {
/**
* Current score.
*/
score: number;
/**
* Time to the next wave of invaders.
*/
timeToWave: number;
/**
* The number of the next wave.
*/
wave: number;
}

interface _Constructor<T> {
readonly prototype: T;
}
Expand Down
4 changes: 0 additions & 4 deletions src/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ interface Room {
* A shorthand to `Memory.rooms[room.name]`. You can use it for quick access the room’s specific memory data object.
*/
memory: RoomMemory;
/**
* One of the `MODE_*` constants.
*/
mode: string;
/**
* The name of the room.
*/
Expand Down
14 changes: 0 additions & 14 deletions src/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,6 @@ interface StructureSpawn extends OwnedStructure<STRUCTURE_SPAWN> {
* ```
*/
spawnCreep(body: BodyPartConstant[], name: string, opts?: SpawnOptions): ScreepsReturnCode;

/**
* Destroy this spawn immediately.
*/
destroy(): ScreepsReturnCode;
/**
* Check whether this structure can be used. If the room controller level is not enough, then this method will return false, and the structure will be highlighted with red in the game.
*/
isActive(): boolean;
/**
* Toggle auto notification when the spawn is under attack. The notification will be sent to your account email. Turned on by default.
* @param enabled Whether to enable notification or disable.
*/
notifyWhenAttacked(enabled: boolean): ScreepsReturnCode;
/**
* Increase the remaining time to live of the target creep.
*
Expand Down

0 comments on commit 1f73abf

Please sign in to comment.