Skip to content

Commit 1f73abf

Browse files
authored
Remove outdated code. Optimise FindTypes and AllLookAtTypes (#264)
* 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
1 parent 489e2ba commit 1f73abf

File tree

5 files changed

+88
-176
lines changed

5 files changed

+88
-176
lines changed

dist/index.d.ts

Lines changed: 44 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,8 @@ declare const GCL_POW: number;
370370
declare const GCL_MULTIPLY: number;
371371
declare const GCL_NOVICE: number;
372372

373-
declare const MODE_SIMULATION: string;
374-
declare const MODE_SURVIVAL: string;
375-
declare const MODE_WORLD: string;
376-
declare const MODE_ARENA: string;
373+
declare const MODE_SIMULATION: null;
374+
declare const MODE_WORLD: null;
377375

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

1773-
// type SD<K extends ResourceConstant> = {
1774-
// [P in K]: number;
1775-
// energy: number;
1776-
// }
1777-
17781771
/**
17791772
* @example
17801773
* {
@@ -1787,21 +1780,20 @@ type StoreDefinitionUnlimited = Store<ResourceConstant, true>;
17871780
type ExitsInformation = Partial<Record<ExitKey, string>>;
17881781

17891782
interface AllLookAtTypes {
1790-
constructionSite: ConstructionSite;
1791-
creep: Creep;
1792-
energy: Resource<RESOURCE_ENERGY>;
1793-
exit: any; // TODO what type is this?
1794-
flag: Flag;
1795-
mineral: Mineral;
1796-
deposit: Deposit;
1797-
nuke: Nuke;
1798-
resource: Resource;
1799-
source: Source;
1800-
structure: AnyStructure;
1801-
terrain: Terrain;
1802-
tombstone: Tombstone;
1803-
powerCreep: PowerCreep;
1804-
ruin: Ruin;
1783+
[LOOK_CONSTRUCTION_SITES]: ConstructionSite;
1784+
[LOOK_CREEPS]: Creep;
1785+
[LOOK_ENERGY]: Resource<RESOURCE_ENERGY>;
1786+
[LOOK_FLAGS]: Flag;
1787+
[LOOK_MINERALS]: Mineral;
1788+
[LOOK_DEPOSITS]: Deposit;
1789+
[LOOK_NUKES]: Nuke;
1790+
[LOOK_RESOURCES]: Resource;
1791+
[LOOK_SOURCES]: Source;
1792+
[LOOK_STRUCTURES]: AnyStructure;
1793+
[LOOK_TERRAIN]: Terrain;
1794+
[LOOK_TOMBSTONES]: Tombstone;
1795+
[LOOK_POWER_CREEPS]: PowerCreep;
1796+
[LOOK_RUINS]: Ruin;
18051797
}
18061798

18071799
type LookAtTypes = Partial<AllLookAtTypes>;
@@ -1845,34 +1837,34 @@ interface FindTypes {
18451837
| Tombstone
18461838
| Deposit
18471839
| Ruin;
1848-
1: RoomPosition; // FIND_EXIT_TOP
1849-
3: RoomPosition; // FIND_EXIT_RIGHT
1850-
5: RoomPosition; // FIND_EXIT_BOTTOM
1851-
7: RoomPosition; // FIND_EXIT_LEFT
1852-
10: RoomPosition; // FIND_EXIT
1853-
101: Creep; // FIND_CREEPS
1854-
102: Creep; // FIND_MY_CREEPS
1855-
103: Creep; // FIND_HOSTILE_CREEPS
1856-
104: Source; // FIND_SOURCES_ACTIVE
1857-
105: Source; // FIND_SOURCES
1858-
106: Resource; // FIND_DROPPED_RESOURCES
1859-
107: AnyStructure; // FIND_STRUCTURES
1860-
108: AnyOwnedStructure; // FIND_MY_STRUCTURES
1861-
109: AnyOwnedStructure; // FIND_HOSTILE_STRUCTURES
1862-
110: Flag; // FIND_FLAGS
1863-
111: ConstructionSite; // FIND_CONSTRUCTION_SITES
1864-
112: StructureSpawn; // FIND_MY_SPAWNS
1865-
113: StructureSpawn; // FIND_HOSTILE_SPAWNS
1866-
114: ConstructionSite; // FIND_MY_CONSTRUCTION_SITES
1867-
115: ConstructionSite; // FIND_HOSTILE_CONSTRUCTION_SITES
1868-
116: Mineral; // FIND_MINERALS
1869-
117: Nuke; // FIND_NUKES
1870-
118: Tombstone; // FIND_TOMBSTONES
1871-
119: PowerCreep; // FIND_POWER_CREEPS
1872-
120: PowerCreep; // FIND_MY_POWER_CREEPS
1873-
121: PowerCreep; // FIND_HOSTILE_POWER_CREEPS
1874-
122: Deposit; // FIND_DEPOSITS
1875-
123: Ruin; // FIND_RUINS
1840+
[FIND_EXIT_TOP]: RoomPosition;
1841+
[FIND_EXIT_RIGHT]: RoomPosition;
1842+
[FIND_EXIT_BOTTOM]: RoomPosition;
1843+
[FIND_EXIT_LEFT]: RoomPosition;
1844+
[FIND_EXIT]: RoomPosition;
1845+
[FIND_CREEPS]: Creep;
1846+
[FIND_MY_CREEPS]: Creep;
1847+
[FIND_HOSTILE_CREEPS]: Creep;
1848+
[FIND_SOURCES_ACTIVE]: Source;
1849+
[FIND_SOURCES]: Source;
1850+
[FIND_DROPPED_RESOURCES]: Resource;
1851+
[FIND_STRUCTURES]: AnyStructure;
1852+
[FIND_MY_STRUCTURES]: AnyOwnedStructure;
1853+
[FIND_HOSTILE_STRUCTURES]: AnyOwnedStructure;
1854+
[FIND_FLAGS]: Flag;
1855+
[FIND_CONSTRUCTION_SITES]: ConstructionSite;
1856+
[FIND_MY_SPAWNS]: StructureSpawn;
1857+
[FIND_HOSTILE_SPAWNS]: StructureSpawn;
1858+
[FIND_MY_CONSTRUCTION_SITES]: ConstructionSite;
1859+
[FIND_HOSTILE_CONSTRUCTION_SITES]: ConstructionSite;
1860+
[FIND_MINERALS]: Mineral;
1861+
[FIND_NUKES]: Nuke;
1862+
[FIND_TOMBSTONES]: Tombstone;
1863+
[FIND_POWER_CREEPS]: PowerCreep;
1864+
[FIND_MY_POWER_CREEPS]: PowerCreep;
1865+
[FIND_HOSTILE_POWER_CREEPS]: PowerCreep;
1866+
[FIND_DEPOSITS]: Deposit;
1867+
[FIND_RUINS]: Ruin;
18761868
}
18771869

18781870
interface FindPathOpts {
@@ -1991,24 +1983,6 @@ interface PathStep {
19911983
direction: DirectionConstant;
19921984
}
19931985

1994-
/**
1995-
* An object with survival game info
1996-
*/
1997-
interface SurvivalGameInfo {
1998-
/**
1999-
* Current score.
2000-
*/
2001-
score: number;
2002-
/**
2003-
* Time to the next wave of invaders.
2004-
*/
2005-
timeToWave: number;
2006-
/**
2007-
* The number of the next wave.
2008-
*/
2009-
wave: number;
2010-
}
2011-
20121986
interface _Constructor<T> {
20131987
readonly prototype: T;
20141988
}
@@ -4329,10 +4303,6 @@ interface Room {
43294303
* A shorthand to `Memory.rooms[room.name]`. You can use it for quick access the room’s specific memory data object.
43304304
*/
43314305
memory: RoomMemory;
4332-
/**
4333-
* One of the `MODE_*` constants.
4334-
*/
4335-
mode: string;
43364306
/**
43374307
* The name of the room.
43384308
*/
@@ -4764,20 +4734,6 @@ interface StructureSpawn extends OwnedStructure<STRUCTURE_SPAWN> {
47644734
* ```
47654735
*/
47664736
spawnCreep(body: BodyPartConstant[], name: string, opts?: SpawnOptions): ScreepsReturnCode;
4767-
4768-
/**
4769-
* Destroy this spawn immediately.
4770-
*/
4771-
destroy(): ScreepsReturnCode;
4772-
/**
4773-
* 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.
4774-
*/
4775-
isActive(): boolean;
4776-
/**
4777-
* Toggle auto notification when the spawn is under attack. The notification will be sent to your account email. Turned on by default.
4778-
* @param enabled Whether to enable notification or disable.
4779-
*/
4780-
notifyWhenAttacked(enabled: boolean): ScreepsReturnCode;
47814737
/**
47824738
* Increase the remaining time to live of the target creep.
47834739
*

src/constants.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,8 @@ declare const GCL_POW: number;
370370
declare const GCL_MULTIPLY: number;
371371
declare const GCL_NOVICE: number;
372372

373-
declare const MODE_SIMULATION: string;
374-
declare const MODE_SURVIVAL: string;
375-
declare const MODE_WORLD: string;
376-
declare const MODE_ARENA: string;
373+
declare const MODE_SIMULATION: null;
374+
declare const MODE_WORLD: null;
377375

378376
declare const TERRAIN_MASK_WALL: TERRAIN_MASK_WALL;
379377
declare const TERRAIN_MASK_SWAMP: TERRAIN_MASK_SWAMP;

src/helpers.ts

Lines changed: 42 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,6 @@ type StoreDefinition = Store<ResourceConstant, false>;
186186
/** A general purpose Store, which has an unlimited capacity */
187187
type StoreDefinitionUnlimited = Store<ResourceConstant, true>;
188188

189-
// type SD<K extends ResourceConstant> = {
190-
// [P in K]: number;
191-
// energy: number;
192-
// }
193-
194189
/**
195190
* @example
196191
* {
@@ -203,21 +198,20 @@ type StoreDefinitionUnlimited = Store<ResourceConstant, true>;
203198
type ExitsInformation = Partial<Record<ExitKey, string>>;
204199

205200
interface AllLookAtTypes {
206-
constructionSite: ConstructionSite;
207-
creep: Creep;
208-
energy: Resource<RESOURCE_ENERGY>;
209-
exit: any; // TODO what type is this?
210-
flag: Flag;
211-
mineral: Mineral;
212-
deposit: Deposit;
213-
nuke: Nuke;
214-
resource: Resource;
215-
source: Source;
216-
structure: AnyStructure;
217-
terrain: Terrain;
218-
tombstone: Tombstone;
219-
powerCreep: PowerCreep;
220-
ruin: Ruin;
201+
[LOOK_CONSTRUCTION_SITES]: ConstructionSite;
202+
[LOOK_CREEPS]: Creep;
203+
[LOOK_ENERGY]: Resource<RESOURCE_ENERGY>;
204+
[LOOK_FLAGS]: Flag;
205+
[LOOK_MINERALS]: Mineral;
206+
[LOOK_DEPOSITS]: Deposit;
207+
[LOOK_NUKES]: Nuke;
208+
[LOOK_RESOURCES]: Resource;
209+
[LOOK_SOURCES]: Source;
210+
[LOOK_STRUCTURES]: AnyStructure;
211+
[LOOK_TERRAIN]: Terrain;
212+
[LOOK_TOMBSTONES]: Tombstone;
213+
[LOOK_POWER_CREEPS]: PowerCreep;
214+
[LOOK_RUINS]: Ruin;
221215
}
222216

223217
type LookAtTypes = Partial<AllLookAtTypes>;
@@ -261,34 +255,34 @@ interface FindTypes {
261255
| Tombstone
262256
| Deposit
263257
| Ruin;
264-
1: RoomPosition; // FIND_EXIT_TOP
265-
3: RoomPosition; // FIND_EXIT_RIGHT
266-
5: RoomPosition; // FIND_EXIT_BOTTOM
267-
7: RoomPosition; // FIND_EXIT_LEFT
268-
10: RoomPosition; // FIND_EXIT
269-
101: Creep; // FIND_CREEPS
270-
102: Creep; // FIND_MY_CREEPS
271-
103: Creep; // FIND_HOSTILE_CREEPS
272-
104: Source; // FIND_SOURCES_ACTIVE
273-
105: Source; // FIND_SOURCES
274-
106: Resource; // FIND_DROPPED_RESOURCES
275-
107: AnyStructure; // FIND_STRUCTURES
276-
108: AnyOwnedStructure; // FIND_MY_STRUCTURES
277-
109: AnyOwnedStructure; // FIND_HOSTILE_STRUCTURES
278-
110: Flag; // FIND_FLAGS
279-
111: ConstructionSite; // FIND_CONSTRUCTION_SITES
280-
112: StructureSpawn; // FIND_MY_SPAWNS
281-
113: StructureSpawn; // FIND_HOSTILE_SPAWNS
282-
114: ConstructionSite; // FIND_MY_CONSTRUCTION_SITES
283-
115: ConstructionSite; // FIND_HOSTILE_CONSTRUCTION_SITES
284-
116: Mineral; // FIND_MINERALS
285-
117: Nuke; // FIND_NUKES
286-
118: Tombstone; // FIND_TOMBSTONES
287-
119: PowerCreep; // FIND_POWER_CREEPS
288-
120: PowerCreep; // FIND_MY_POWER_CREEPS
289-
121: PowerCreep; // FIND_HOSTILE_POWER_CREEPS
290-
122: Deposit; // FIND_DEPOSITS
291-
123: Ruin; // FIND_RUINS
258+
[FIND_EXIT_TOP]: RoomPosition;
259+
[FIND_EXIT_RIGHT]: RoomPosition;
260+
[FIND_EXIT_BOTTOM]: RoomPosition;
261+
[FIND_EXIT_LEFT]: RoomPosition;
262+
[FIND_EXIT]: RoomPosition;
263+
[FIND_CREEPS]: Creep;
264+
[FIND_MY_CREEPS]: Creep;
265+
[FIND_HOSTILE_CREEPS]: Creep;
266+
[FIND_SOURCES_ACTIVE]: Source;
267+
[FIND_SOURCES]: Source;
268+
[FIND_DROPPED_RESOURCES]: Resource;
269+
[FIND_STRUCTURES]: AnyStructure;
270+
[FIND_MY_STRUCTURES]: AnyOwnedStructure;
271+
[FIND_HOSTILE_STRUCTURES]: AnyOwnedStructure;
272+
[FIND_FLAGS]: Flag;
273+
[FIND_CONSTRUCTION_SITES]: ConstructionSite;
274+
[FIND_MY_SPAWNS]: StructureSpawn;
275+
[FIND_HOSTILE_SPAWNS]: StructureSpawn;
276+
[FIND_MY_CONSTRUCTION_SITES]: ConstructionSite;
277+
[FIND_HOSTILE_CONSTRUCTION_SITES]: ConstructionSite;
278+
[FIND_MINERALS]: Mineral;
279+
[FIND_NUKES]: Nuke;
280+
[FIND_TOMBSTONES]: Tombstone;
281+
[FIND_POWER_CREEPS]: PowerCreep;
282+
[FIND_MY_POWER_CREEPS]: PowerCreep;
283+
[FIND_HOSTILE_POWER_CREEPS]: PowerCreep;
284+
[FIND_DEPOSITS]: Deposit;
285+
[FIND_RUINS]: Ruin;
292286
}
293287

294288
interface FindPathOpts {
@@ -407,24 +401,6 @@ interface PathStep {
407401
direction: DirectionConstant;
408402
}
409403

410-
/**
411-
* An object with survival game info
412-
*/
413-
interface SurvivalGameInfo {
414-
/**
415-
* Current score.
416-
*/
417-
score: number;
418-
/**
419-
* Time to the next wave of invaders.
420-
*/
421-
timeToWave: number;
422-
/**
423-
* The number of the next wave.
424-
*/
425-
wave: number;
426-
}
427-
428404
interface _Constructor<T> {
429405
readonly prototype: T;
430406
}

src/room.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ interface Room {
3232
* A shorthand to `Memory.rooms[room.name]`. You can use it for quick access the room’s specific memory data object.
3333
*/
3434
memory: RoomMemory;
35-
/**
36-
* One of the `MODE_*` constants.
37-
*/
38-
mode: string;
3935
/**
4036
* The name of the room.
4137
*/

src/spawn.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,6 @@ interface StructureSpawn extends OwnedStructure<STRUCTURE_SPAWN> {
9898
* ```
9999
*/
100100
spawnCreep(body: BodyPartConstant[], name: string, opts?: SpawnOptions): ScreepsReturnCode;
101-
102-
/**
103-
* Destroy this spawn immediately.
104-
*/
105-
destroy(): ScreepsReturnCode;
106-
/**
107-
* 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.
108-
*/
109-
isActive(): boolean;
110-
/**
111-
* Toggle auto notification when the spawn is under attack. The notification will be sent to your account email. Turned on by default.
112-
* @param enabled Whether to enable notification or disable.
113-
*/
114-
notifyWhenAttacked(enabled: boolean): ScreepsReturnCode;
115101
/**
116102
* Increase the remaining time to live of the target creep.
117103
*

0 commit comments

Comments
 (0)