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

Update RoomVisual.poly to also accept positions #113

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
48 changes: 35 additions & 13 deletions dist/screeps.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1629,14 +1640,10 @@ interface RoomPositionConstructor extends _Constructor<RoomPosition> {
(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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -1725,6 +1732,12 @@ declare class RoomVisual {
*/
getSize(): number;
}
interface GlobalRoomVisual extends RoomVisual {
roomName: undefined;
}
interface RoomSpecificRoomVisual<TRoomName extends string> extends RoomVisual {
roomName: TRoomName;
}
interface LineStyle {
width?: number;
color?: string;
Expand All @@ -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<typeof roomName>;
/** 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.
*/
Expand Down
5 changes: 4 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 27 additions & 13 deletions src/room-visual.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -64,15 +59,15 @@ 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.
Expand All @@ -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.
Expand All @@ -107,6 +102,14 @@ declare class RoomVisual {
getSize(): number;
}

interface GlobalRoomVisual extends RoomVisual {
roomName: undefined;
}

interface RoomSpecificRoomVisual<TRoomName extends string> extends RoomVisual {
roomName: TRoomName;
}

interface LineStyle {
width?: number;
color?: string;
Expand All @@ -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<typeof roomName>;

/** Create a new global RoomVisual instance */
new(): GlobalRoomVisual;
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"noImplicitAny": true,
"strictNullChecks": true,
"outFile": "./dist/screeps.ts",
"newLine": "LF"
"newLine": "lf"
},
"include": ["./src/**/*.ts"],
"exclude": ["node_modules", "dist"]
Expand Down