From 8b8e965d310bb0f447d608bdc8169ce9cf57143b Mon Sep 17 00:00:00 2001 From: Zoey Date: Sat, 22 Jul 2017 15:11:57 -0700 Subject: [PATCH 1/5] Update RoomVisual.poly to also accept positions --- src/room-visual.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/room-visual.ts b/src/room-visual.ts index 89dd64c..65804fb 100644 --- a/src/room-visual.ts +++ b/src/room-visual.ts @@ -72,7 +72,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] | RoomPosition>, style?: PolyStyle): RoomVisual; /** * Draw a text label. From 0f63a6f0bfc4be151bb30e76b26657652c7e1450 Mon Sep 17 00:00:00 2001 From: Zoey Date: Sat, 22 Jul 2017 15:14:31 -0700 Subject: [PATCH 2/5] Update dist manually for RoomVisual.poly --- dist/screeps.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/screeps.d.ts b/dist/screeps.d.ts index 4fb0dbf..2d430b1 100644 --- a/dist/screeps.d.ts +++ b/dist/screeps.d.ts @@ -1695,7 +1695,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] | RoomPosition>, style?: PolyStyle): RoomVisual; /** * Draw a text label. * @param text The text message. From 8c053c24d6548028d92bdc3b8d6e76af5cdd23e4 Mon Sep 17 00:00:00 2001 From: Dessix Date: Sat, 22 Jul 2017 19:24:19 -0700 Subject: [PATCH 3/5] Updated to use PointLike descriptors where the RoomVisual API accepts them --- src/constants.ts | 5 ++++- src/helpers.ts | 13 +++++++++++++ src/room-visual.ts | 40 +++++++++++++++++++++++++++------------- 3 files changed, 44 insertions(+), 14 deletions(-) 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 65804fb..d26694a 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: Array<[number, number] | RoomPosition>, 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,14 @@ 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; +} From 99b16a3f8627860d3e12eb50acbe6a9255b1a87d Mon Sep 17 00:00:00 2001 From: Dessix Date: Sat, 22 Jul 2017 19:44:59 -0700 Subject: [PATCH 4/5] Rebuilt dist files. Updated tsconfig.json newLine to meet new Typescript compiler casing requirements --- dist/screeps.d.ts | 48 ++++++++++++++++++++++++++++++++++------------- tsconfig.json | 2 +- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/dist/screeps.d.ts b/dist/screeps.d.ts index 2d430b1..d6d2fb0 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: Array<[number, number] | RoomPosition>, 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,15 @@ 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; +} /** * 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/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"] From 2483cd35bbc8f20aace84a0d2a4356741265fa6a Mon Sep 17 00:00:00 2001 From: Dessix Date: Tue, 3 Oct 2017 22:53:16 -0700 Subject: [PATCH 5/5] Added RoomVisual static object. --- dist/screeps.d.ts | 1 + src/room-visual.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/dist/screeps.d.ts b/dist/screeps.d.ts index d6d2fb0..512e167 100644 --- a/dist/screeps.d.ts +++ b/dist/screeps.d.ts @@ -1769,6 +1769,7 @@ interface RoomVisualConstructor { /** 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/room-visual.ts b/src/room-visual.ts index d26694a..d52e7e8 100644 --- a/src/room-visual.ts +++ b/src/room-visual.ts @@ -146,3 +146,5 @@ interface RoomVisualConstructor { /** Create a new global RoomVisual instance */ new(): GlobalRoomVisual; } + +declare const RoomVisual: RoomVisualConstructor;