Skip to content

Commit cb2e5e8

Browse files
Greatly improve documentation for methods and their return types (#270)
* Copy over all the return type info * Add comment for @link constants * Revert listing bodypart constants * Revert changes of return type to keep this pr pure * Revert listing `DepositConstant` --------- Co-authored-by: Mofeng <52260316+DiamondMofeng@users.noreply.github.com>
1 parent 95b4cc4 commit cb2e5e8

27 files changed

+3091
-1105
lines changed

dist/index.d.ts

Lines changed: 1545 additions & 552 deletions
Large diffs are not rendered by default.

src/construction-site.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
/**
22
* A site of a structure which is currently under construction.
3+
*
4+
* A construction site can be created using the 'Construct' button at the left of the game field or the {@link Room.createConstructionSite} method.
5+
*
6+
* To build a structure on the construction site, give a worker creep some amount of energy and perform {@link Creep.build} action.
7+
*
8+
* You can remove enemy construction sites by moving a creep on it.
39
*/
410
interface ConstructionSite<T extends BuildableStructureConstant = BuildableStructureConstant> extends RoomObject {
511
readonly prototype: ConstructionSite;
612
/**
7-
* A unique object identifier. You can use `Game.getObjectById` method to retrieve an object instance by its `id`.
13+
* A unique object identifier.
14+
*
15+
* You can use {@link Game.getObjectById} to retrieve an object instance by its `id`.
816
*/
917
id: Id<this>;
1018
/**
@@ -24,7 +32,7 @@ interface ConstructionSite<T extends BuildableStructureConstant = BuildableStruc
2432
*/
2533
progressTotal: number;
2634
/**
27-
* One of the `STRUCTURE_*` constants.
35+
* One of the {@link StructureConstant STRUCTURE_*} constants.
2836
*/
2937
structureType: T;
3038
/**

src/creep.ts

Lines changed: 281 additions & 54 deletions
Large diffs are not rendered by default.

src/deposit.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
/**
22
* A rare resource deposit needed for producing commodities.
3-
* Can be harvested by creeps with a WORK body part.
4-
* Each harvest operation triggers a cooldown period, which becomes longer and longer over time.
3+
*
4+
* Can be harvested by creeps with a WORK body part. Each harvest operation triggers a cooldown period, which becomes longer and longer over time.
5+
*
6+
* Learn more about deposits from [this article](https://docs.screeps.com/resources.html).
7+
*
8+
* | | |
9+
* | ------------ | ----------- |
10+
* | **Cooldown** | 0.001 * totalHarvested ^ 1.2
11+
* | **Decay** | 50,000 ticks after appearing or last harvest operation
512
*/
613
interface Deposit extends RoomObject {
714
/**
8-
* A unique object identificator.
9-
* You can use {@link Game.getObjectById} method to retrieve an object instance by its id.
15+
* A unique object identifier.
16+
*
17+
* You can use {@link Game.getObjectById} to retrieve an object instance by its id.
1018
*/
1119
id: Id<this>;
1220
/**
13-
* The deposit type, one of the following constants:
14-
* * `RESOURCE_MIST`
15-
* * `RESOURCE_BIOMASS`
16-
* * `RESOURCE_METAL`
17-
* * `RESOURCE_SILICON`
21+
* The deposit type, one of the {@link DepositConstant}:
22+
* - `RESOURCE_MIST`
23+
* - `RESOURCE_BIOMASS`
24+
* - `RESOURCE_METAL`
25+
* - `RESOURCE_SILICON`
1826
*/
1927
depositType: DepositConstant;
2028
/**

src/flag.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
/**
2-
* A flag. Flags can be used to mark particular spots in a room. Flags are visible to their owners only.
2+
* A flag.
3+
*
4+
* Flags can be used to mark particular spots in a room. Flags are visible to their owners only. You cannot have more than 10,000 flags.
35
*/
46
interface Flag extends RoomObject {
57
readonly prototype: Flag;
68

79
/**
8-
* Flag color. One of the `COLOR_*` constants.
10+
* Flag color. One of the {@link ColorConstant COLOR_*} constants.
911
*/
1012
color: ColorConstant;
1113
/**
14+
* The flag's memory.
15+
*
1216
* A shorthand to Memory.flags[flag.name]. You can use it for quick access the flag's specific memory data object.
1317
*/
1418
memory: FlagMemory;
1519
/**
16-
* Flag’s name.
20+
* The flag’s name.
1721
*
1822
* You can choose the name while creating a new flag, and it cannot be changed later.
1923
*
20-
* This name is a hash key to access the flag via the `Game.flags` object. The maximum name length is 60 characters.
24+
* This name is a hash key to access the flag via the {@link Game.flags} object. The maximum name length is 60 characters.
2125
*/
2226
name: string;
2327
/**
24-
* Flag secondary color. One of the `COLOR_*` constants.
28+
* Flag secondary color. One of the {@link ColorConstant COLOR_*} constants.
2529
*/
2630
secondaryColor: ColorConstant;
2731
/**
@@ -31,22 +35,28 @@ interface Flag extends RoomObject {
3135
remove(): OK;
3236
/**
3337
* Set new color of the flag.
34-
* @param color One of the following constants: COLOR_WHITE, COLOR_GREY, COLOR_RED, COLOR_PURPLE, COLOR_BLUE, COLOR_CYAN, COLOR_GREEN, COLOR_YELLOW, COLOR_ORANGE, COLOR_BROWN
35-
* @parma secondaryColor Secondary color of the flag. One of the COLOR_* constants.
36-
* @returns Result Code: OK, ERR_INVALID_ARGS
38+
* @param color One of the {@link ColorConstant COLOR_*} constants.
39+
* @param secondaryColor Secondary color of the flag. One of the {@link ColorConstant COLOR_*} constants.
40+
* @returns One of the following codes:
41+
* - OK: The operation has been scheduled successfully.
42+
* - ERR_INVALID_ARGS: color or secondaryColor is not a valid color constant.
3743
*/
3844
setColor(color: ColorConstant, secondaryColor?: ColorConstant): OK | ERR_INVALID_ARGS;
3945
/**
4046
* Set new position of the flag.
4147
* @param x The X position in the room.
4248
* @param y The Y position in the room.
43-
* @returns Result Code: OK, ERR_INVALID_TARGET
49+
* @returns One of the following codes:
50+
* - OK: The operation has been scheduled successfully.
51+
* - ERR_INVALID_TARGET: The target provided is invalid.
4452
*/
4553
setPosition(x: number, y: number): OK | ERR_INVALID_ARGS;
4654
/**
4755
* Set new position of the flag.
48-
* @param pos Can be a RoomPosition object or any object containing RoomPosition.
49-
* @returns Result Code: OK, ERR_INVALID_TARGET
56+
* @param pos Can be a {@link RoomPosition} object or any object containing RoomPosition.
57+
* @returns One of the following codes:
58+
* - OK: The operation has been scheduled successfully.
59+
* - ERR_INVALID_TARGET: The target provided is invalid.
5060
*/
5161
setPosition(pos: RoomPosition | { pos: RoomPosition }): OK | ERR_INVALID_ARGS;
5262
}

src/game.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,20 @@ interface Game {
3131
*/
3232
market: Market;
3333
/**
34-
* A hash containing all your power creeps with their names as hash keys. Even power creeps not spawned in the world can be accessed here.
34+
* A hash containing all your power creeps with their names as hash keys.
35+
*
36+
* Even power creeps not spawned in the world can be accessed here.
3537
*/
3638
powerCreeps: { [creepName: string]: PowerCreep };
3739
/**
38-
* An object with your global resources that are bound to the account, like pixels or cpu unlocks. Each object key is a resource constant, values are resources amounts.
40+
* An object with your global resources that are bound to the account, like pixels or cpu unlocks.
41+
*
42+
* Each object key is a resource constant, values are resources amounts.
3943
*/
4044
resources: { [key: string]: any };
4145
/**
4246
* A hash containing all the rooms available to you with room names as hash keys.
47+
*
4348
* A room is visible if you have a creep or an owned structure in it.
4449
*/
4550
rooms: { [roomName: string]: Room };
@@ -63,12 +68,16 @@ interface Game {
6368
shard: Shard;
6469

6570
/**
66-
* System game tick counter. It is automatically incremented on every tick.
71+
* System game tick counter.
72+
*
73+
* It is automatically incremented on every tick.
6774
*/
6875
time: number;
6976

7077
/**
71-
* Get an object with the specified unique ID. It may be a game object of any type. Only objects from the rooms which are visible to you can be accessed.
78+
* Get an object with the specified unique ID.
79+
*
80+
* It may be a game object of any type. Only objects from the rooms which are visible to you can be accessed.
7281
* @param id The unique identifier.
7382
* @returns an object instance or null if it cannot be found.
7483
*/
@@ -80,12 +89,15 @@ interface Game {
8089
*
8190
* This way, you can set up notifications to yourself on any occasion within the game.
8291
*
83-
* You can schedule up to 20 notifications during one game tick. Not available in the Simulation Room.
92+
* You can schedule up to 20 notifications during one game tick. Not available in the Simulator.
8493
* @param message Custom text which will be sent in the message. Maximum length is 1000 characters.
8594
* @param groupInterval If set to 0 (default), the notification will be scheduled immediately.
8695
* Otherwise, it will be grouped with other notifications and mailed out later using the specified time in minutes.
96+
* @returns One of the following codes:
97+
* - OK: The message has been sent successfully.
98+
* - ERR_FULL: More than 20 notifications sent this tick.
8799
*/
88-
notify(message: string, groupInterval?: number): undefined;
100+
notify(message: string, groupInterval?: number): OK | ERR_FULL;
89101
}
90102

91103
declare var Game: Game;

0 commit comments

Comments
 (0)