diff --git a/dist/screeps.d.ts b/dist/screeps.d.ts index 4fb0dbf..512e167 100644 --- a/dist/screeps.d.ts +++ b/dist/screeps.d.ts @@ -30,7 +30,8 @@ declare const FIND_HOSTILE_CREEPS: 103; declare const FIND_SOURCES_ACTIVE: 104; declare const FIND_SOURCES: 105; declare const FIND_DROPPED_RESOURCES: 106; -declare const FIND_DROPPED_ENERGY: 106; +/** @deprecated FIND_DROPPED_ENERGY constant is considered deprecated and will be removed soon. Please use FIND_DROPPED_RESOURCES instead. */ +declare const FIND_DROPPED_ENERGY: typeof FIND_DROPPED_RESOURCES; declare const FIND_STRUCTURES: 107; declare const FIND_MY_STRUCTURES: 108; declare const FIND_HOSTILE_STRUCTURES: 109; @@ -853,6 +854,16 @@ interface LookAtResult { interface LookAtResultMatrix { [coord: number]: LookAtResultMatrix | LookAtResult[]; } +interface PointLike { + x: number; + y: number; +} +interface RoomPositionLike extends PointLike { + roomName: string; +} +interface RoomObjectLike { + pos: RoomPositionLike; +} interface FindPathOpts { /** * Treat squares with creeps as walkable. Can be useful with too many moving creeps around or in some other cases. The default @@ -1629,14 +1640,10 @@ interface RoomPositionConstructor extends _Constructor { (x: number, y: number, roomName: string): RoomPosition; } declare const RoomPosition: RoomPositionConstructor; -declare class RoomVisual { +interface RoomVisual { /** The name of the room. */ - roomName: string; - /** - * You can directly create new RoomVisual object in any room, even if it's invisible to your script. - * @param roomName The room name. - */ - constructor(roomName: string); + /** Undefined when this instance is not specific to any one room */ + roomName?: string; /** * Draw a line. * @param x1 The start X coordinate. @@ -1654,7 +1661,7 @@ declare class RoomVisual { * @param style The (optional) style. * @returns The RoomVisual object, for chaining. */ - line(pos1: RoomPosition, pos2: RoomPosition, style?: LineStyle): RoomVisual; + line(pos1: PointLike, pos2: PointLike, style?: LineStyle): RoomVisual; /** * Draw a circle. * @param x The X coordinate of the center. @@ -1669,7 +1676,7 @@ declare class RoomVisual { * @param style The (optional) style. * @returns The RoomVisual object, for chaining. */ - circle(pos: RoomPosition, style?: CircleStyle): RoomVisual; + circle(pos: PointLike, style?: CircleStyle): RoomVisual; /** * Draw a rectangle. * @param x The X coordinate of the top-left corner. @@ -1688,14 +1695,14 @@ declare class RoomVisual { * @param style The (optional) style. * @returns The RoomVisual object, for chaining. */ - rect(topLeftPos: RoomPosition, width: number, height: number, style?: PolyStyle): RoomVisual; + rect(topLeftPos: PointLike, width: number, height: number, style?: PolyStyle): RoomVisual; /** * Draw a polygon. * @param points An array of point coordinate arrays, i.e. [[0,0], [5,5], [5,10]]. * @param style The (optional) style. * @returns The RoomVisual object, for chaining. */ - poly(points: [number, number][], style?: PolyStyle): RoomVisual; + poly(points: Array<[number, number] | PointLike>, style?: PolyStyle): RoomVisual; /** * Draw a text label. * @param text The text message. @@ -1712,7 +1719,7 @@ declare class RoomVisual { * @param style The (optional) text style. * @returns The RoomVisual object, for chaining. */ - text(text: string, pos: RoomPosition, style?: TextStyle): RoomVisual; + text(text: string, pos: PointLike, style?: TextStyle): RoomVisual; /** * Remove all visuals from the room. * @returns The RoomVisual object, for chaining. @@ -1725,6 +1732,12 @@ declare class RoomVisual { */ getSize(): number; } +interface GlobalRoomVisual extends RoomVisual { + roomName: undefined; +} +interface RoomSpecificRoomVisual extends RoomVisual { + roomName: TRoomName; +} interface LineStyle { width?: number; color?: string; @@ -1747,6 +1760,16 @@ interface TextStyle { align?: "center" | "left" | "right"; opacity?: number; } +interface RoomVisualConstructor { + /** + * You can directly create new RoomVisual object in any room, even if it's invisible to your script. + * @param roomName The room name. + */ + new (roomName: string): RoomSpecificRoomVisual; + /** Create a new global RoomVisual instance */ + new (): GlobalRoomVisual; +} +declare const RoomVisual: RoomVisualConstructor; /** * An object representing the room in which your units and structures are in. It can be used to look around, find paths, etc. Every object in the room contains its linked Room instance in the room property. */ diff --git a/src/constants.ts b/src/constants.ts index 29a221f..42bc206 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -32,7 +32,10 @@ declare const FIND_HOSTILE_CREEPS: 103; declare const FIND_SOURCES_ACTIVE: 104; declare const FIND_SOURCES: 105; declare const FIND_DROPPED_RESOURCES: 106; -declare const FIND_DROPPED_ENERGY: 106; // Yup, it's 106. + +/** @deprecated FIND_DROPPED_ENERGY constant is considered deprecated and will be removed soon. Please use FIND_DROPPED_RESOURCES instead. */ +declare const FIND_DROPPED_ENERGY: typeof FIND_DROPPED_RESOURCES; + declare const FIND_STRUCTURES: 107; declare const FIND_MY_STRUCTURES: 108; declare const FIND_HOSTILE_STRUCTURES: 109; diff --git a/src/helpers.ts b/src/helpers.ts index dc7cc53..c5ba91f 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -85,6 +85,19 @@ interface LookAtResultMatrix { [coord: number]: LookAtResultMatrix|LookAtResult[] } +interface PointLike { + x: number; + y: number; +} + +interface RoomPositionLike extends PointLike { + roomName: string; +} + +interface RoomObjectLike { + pos: RoomPositionLike; +} + interface FindPathOpts { /** * Treat squares with creeps as walkable. Can be useful with too many moving creeps around or in some other cases. The default diff --git a/src/room-visual.ts b/src/room-visual.ts index 89dd64c..d52e7e8 100644 --- a/src/room-visual.ts +++ b/src/room-visual.ts @@ -1,12 +1,7 @@ -declare class RoomVisual { +interface RoomVisual { /** The name of the room. */ - roomName: string; - - /** - * You can directly create new RoomVisual object in any room, even if it's invisible to your script. - * @param roomName The room name. - */ - constructor(roomName: string); + /** Undefined when this instance is not specific to any one room */ + roomName?: string; /** * Draw a line. @@ -26,7 +21,7 @@ declare class RoomVisual { * @param style The (optional) style. * @returns The RoomVisual object, for chaining. */ - line(pos1: RoomPosition, pos2: RoomPosition, style?: LineStyle): RoomVisual; + line(pos1: PointLike, pos2: PointLike, style?: LineStyle): RoomVisual; /** * Draw a circle. @@ -43,7 +38,7 @@ declare class RoomVisual { * @param style The (optional) style. * @returns The RoomVisual object, for chaining. */ - circle(pos: RoomPosition, style?: CircleStyle): RoomVisual; + circle(pos: PointLike, style?: CircleStyle): RoomVisual; /** * Draw a rectangle. @@ -64,7 +59,7 @@ declare class RoomVisual { * @param style The (optional) style. * @returns The RoomVisual object, for chaining. */ - rect(topLeftPos: RoomPosition, width: number, height: number, style?: PolyStyle): RoomVisual; + rect(topLeftPos: PointLike, width: number, height: number, style?: PolyStyle): RoomVisual; /** * Draw a polygon. @@ -72,7 +67,7 @@ declare class RoomVisual { * @param style The (optional) style. * @returns The RoomVisual object, for chaining. */ - poly(points: [number, number][], style?: PolyStyle): RoomVisual; + poly(points: Array<[number, number] | PointLike>, style?: PolyStyle): RoomVisual; /** * Draw a text label. @@ -91,7 +86,7 @@ declare class RoomVisual { * @param style The (optional) text style. * @returns The RoomVisual object, for chaining. */ - text(text: string, pos: RoomPosition, style?: TextStyle): RoomVisual; + text(text: string, pos: PointLike, style?: TextStyle): RoomVisual; /** * Remove all visuals from the room. @@ -107,6 +102,14 @@ declare class RoomVisual { getSize(): number; } +interface GlobalRoomVisual extends RoomVisual { + roomName: undefined; +} + +interface RoomSpecificRoomVisual extends RoomVisual { + roomName: TRoomName; +} + interface LineStyle { width?: number; color?: string; @@ -132,3 +135,16 @@ interface TextStyle { align?: "center" | "left" | "right"; opacity?: number; } + +interface RoomVisualConstructor { + /** + * You can directly create new RoomVisual object in any room, even if it's invisible to your script. + * @param roomName The room name. + */ + new(roomName: string): RoomSpecificRoomVisual; + + /** Create a new global RoomVisual instance */ + new(): GlobalRoomVisual; +} + +declare const RoomVisual: RoomVisualConstructor; diff --git a/tsconfig.json b/tsconfig.json index 4291da6..8e437f8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ "noImplicitAny": true, "strictNullChecks": true, "outFile": "./dist/screeps.ts", - "newLine": "LF" + "newLine": "lf" }, "include": ["./src/**/*.ts"], "exclude": ["node_modules", "dist"]