Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict return types #265

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,448 changes: 1,778 additions & 670 deletions dist/index.d.ts

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,10 @@ declare const MINERAL_DENSITY_PROBABILITY: {

declare const MINERAL_DENSITY_CHANGE: number;

declare const DENSITY_LOW: number;
declare const DENSITY_MODERATE: number;
declare const DENSITY_HIGH: number;
declare const DENSITY_ULTRA: number;
declare const DENSITY_LOW: DENSITY_LOW;
declare const DENSITY_MODERATE: DENSITY_MODERATE;
declare const DENSITY_HIGH: DENSITY_HIGH;
declare const DENSITY_ULTRA: DENSITY_ULTRA;

declare const DEPOSIT_EXHAUST_MULTIPLY: number;
declare const DEPOSIT_EXHAUST_POW: number;
Expand Down
12 changes: 10 additions & 2 deletions src/construction-site.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
/**
* A site of a structure which is currently under construction.
*
* A construction site can be created using the 'Construct' button at the left of the game field or the {@link Room.createConstructionSite} method.
*
* To build a structure on the construction site, give a worker creep some amount of energy and perform {@link Creep.build} action.
*
* You can remove enemy construction sites by moving a creep on it.
*/
interface ConstructionSite<T extends BuildableStructureConstant = BuildableStructureConstant> extends RoomObject {
readonly prototype: ConstructionSite;
/**
* A unique object identifier. You can use `Game.getObjectById` method to retrieve an object instance by its `id`.
* A unique object identifier.
*
* You can use {@link Game.getObjectById} to retrieve an object instance by its `id`.
*/
id: Id<this>;
/**
Expand All @@ -24,7 +32,7 @@ interface ConstructionSite<T extends BuildableStructureConstant = BuildableStruc
*/
progressTotal: number;
/**
* One of the `STRUCTURE_*` constants.
* One of the {@link StructureConstant} constants.
*/
structureType: T;
/**
Expand Down
399 changes: 319 additions & 80 deletions src/creep.ts

Large diffs are not rendered by default.

28 changes: 19 additions & 9 deletions src/deposit.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
/**
* A rare resource deposit needed for producing commodities.
* Can be harvested by creeps with a WORK body part.
* Each harvest operation triggers a cooldown period, which becomes longer and longer over time.
*
* Can be harvested by creeps with a WORK body part. Each harvest operation triggers a cooldown period, which becomes longer and longer over time.
*
* Learn more about deposits from [this article](https://docs.screeps.com/resources.html).
*
* | | |
* | ------------ | ----------- |
* | **Cooldown** | 0.001 * totalHarvested ^ 1.2
* | **Decay** | 50,000 ticks after appearing or last harvest operation
*/
interface Deposit extends RoomObject {
/**
* A unique object identificator.
* You can use {@link Game.getObjectById} method to retrieve an object instance by its id.
* The prototype is stored in the {@link Deposit.prototype} global object.
*
* You can use it to extend game objects behaviour globally.
*/
readonly prototype: Deposit;
/**
* A unique object identifier.
*
* You can use {@link Game.getObjectById} to retrieve an object instance by its id.
*/
id: Id<this>;
/**
* The deposit type, one of the following constants:
* * `RESOURCE_MIST`
* * `RESOURCE_BIOMASS`
* * `RESOURCE_METAL`
* * `RESOURCE_SILICON`
* The deposit type, one of the {@link DepositConstant}.
*/
depositType: DepositConstant;
/**
Expand Down
37 changes: 26 additions & 11 deletions src/flag.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
/**
* A flag. Flags can be used to mark particular spots in a room. Flags are visible to their owners only.
* A flag.
*
* 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.
*/
interface Flag extends RoomObject {
/**
* The prototype is stored in the {@link Flag.prototype} global object.
*
* You can use it to extend game objects behaviour globally.
*/
readonly prototype: Flag;

/**
* Flag color. One of the `COLOR_*` constants.
* Flag color. One of the {@link ColorConstant} constants.
*/
color: ColorConstant;
/**
* The flag's memory.
*
* A shorthand to Memory.flags[flag.name]. You can use it for quick access the flag's specific memory data object.
*/
memory: FlagMemory;
/**
* Flag’s name.
* The flag’s name.
*
* You can choose the name while creating a new flag, and it cannot be changed later.
*
* This name is a hash key to access the flag via the `Game.flags` object. The maximum name length is 60 characters.
* This name is a hash key to access the flag via the {@link Game.flags} object. The maximum name length is 60 characters.
*/
name: string;
/**
* Flag secondary color. One of the `COLOR_*` constants.
* Flag secondary color. One of the {@link ColorConstant} constants.
*/
secondaryColor: ColorConstant;
/**
Expand All @@ -31,22 +40,28 @@ interface Flag extends RoomObject {
remove(): OK;
/**
* Set new color of the flag.
* @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
* @parma secondaryColor Secondary color of the flag. One of the COLOR_* constants.
* @returns Result Code: OK, ERR_INVALID_ARGS
* @param color One of the {@link ColorConstant} constants.
* @param secondaryColor Secondary color of the flag. One of the {@link ColorConstant} constants.
* @returns One of the following codes:
* - OK: The operation has been scheduled successfully.
* - ERR_INVALID_ARGS: color or secondaryColor is not a valid color constant.
*/
setColor(color: ColorConstant, secondaryColor?: ColorConstant): OK | ERR_INVALID_ARGS;
/**
* Set new position of the flag.
* @param x The X position in the room.
* @param y The Y position in the room.
* @returns Result Code: OK, ERR_INVALID_TARGET
* @returns One of the following codes:
* - OK: The operation has been scheduled successfully.
* - ERR_INVALID_TARGET: The target provided is invalid.
*/
setPosition(x: number, y: number): OK | ERR_INVALID_ARGS;
/**
* Set new position of the flag.
* @param pos Can be a RoomPosition object or any object containing RoomPosition.
* @returns Result Code: OK, ERR_INVALID_TARGET
* @param pos Can be a {@link RoomPosition} object or any object containing RoomPosition.
* @returns One of the following codes:
* - OK: The operation has been scheduled successfully.
* - ERR_INVALID_TARGET: The target provided is invalid.
*/
setPosition(pos: RoomPosition | { pos: RoomPosition }): OK | ERR_INVALID_ARGS;
}
Expand Down
24 changes: 18 additions & 6 deletions src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@ interface Game {
*/
market: Market;
/**
* 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.
* 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.
*/
powerCreeps: { [creepName: string]: PowerCreep };
/**
* 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.
* 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.
*/
resources: { [key: string]: any };
/**
* A hash containing all the rooms available to you with room names as hash keys.
*
* A room is visible if you have a creep or an owned structure in it.
*/
rooms: { [roomName: string]: Room };
Expand All @@ -63,12 +68,16 @@ interface Game {
shard: Shard;

/**
* System game tick counter. It is automatically incremented on every tick.
* System game tick counter.
*
* It is automatically incremented on every tick.
*/
time: number;

/**
* 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.
* 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.
* @param id The unique identifier.
* @returns an object instance or null if it cannot be found.
*/
Expand All @@ -80,12 +89,15 @@ interface Game {
*
* This way, you can set up notifications to yourself on any occasion within the game.
*
* You can schedule up to 20 notifications during one game tick. Not available in the Simulation Room.
* You can schedule up to 20 notifications during one game tick. Not available in the Simulator.
* @param message Custom text which will be sent in the message. Maximum length is 1000 characters.
* @param groupInterval If set to 0 (default), the notification will be scheduled immediately.
* Otherwise, it will be grouped with other notifications and mailed out later using the specified time in minutes.
* @returns One of the following codes:
* - OK: The message has been sent successfully.
* - ERR_FULL: More than 20 notifications sent this tick.
*/
notify(message: string, groupInterval?: number): undefined;
notify(message: string, groupInterval?: number): OK | ERR_FULL;
}

declare var Game: Game;
Loading
Loading