Skip to content

Commit

Permalink
Merge pull request #177 from screepers/ptr
Browse files Browse the repository at this point in the history
MapVisual support
  • Loading branch information
pyrodogg authored Sep 6, 2020
2 parents fa27ebc + 626dd1a commit a3563e0
Show file tree
Hide file tree
Showing 5 changed files with 365 additions and 3 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [3.2.0] - 2020-09-06

### Added

- Add new `MapVisual` type for new map visual feature ([#177](https://github.com/screepers/typed-screeps/pull/177))

### Fixed

- Fix decumentation for `PWR_OPERATE_FACTORY` duration ([#174](https://github.com/screepers/typed-screeps/pull/174))

## [3.1.3] - 2020-06-22

### Added
Expand Down Expand Up @@ -298,7 +308,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Initial public `npm` release.

[unreleased]: https://github.com/screepers/typed-screeps/compare/v3.1.3...HEAD
[unreleased]: https://github.com/screepers/typed-screeps/compare/v3.2.0...HEAD
[3.2.0]: https://github.com/screepers/typed-screeps/compare/v3.1.3...v3.2.0
[3.1.3]: https://github.com/screepers/typed-screeps/compare/v3.1.2...v3.1.3
[3.1.2]: https://github.com/screepers/typed-screeps/compare/v3.1.1...v3.1.2
[3.1.1]: https://github.com/screepers/typed-screeps/compare/v3.1.0...v3.1.1
Expand Down
169 changes: 168 additions & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for Screeps 3.1.3
// Type definitions for Screeps 3.2.0
// Project: https://github.com/screeps/screeps
// Definitions by: Marko Sulamägi <https://github.com/MarkoSulamagi>
// Nhan Ho <https://github.com/NhanHo>
Expand Down Expand Up @@ -2854,9 +2854,176 @@ interface GameMap {
* @returns An object with the following properties {status: "normal" | "closed" | "novice" | "respawn", timestamp: number}
*/
getRoomStatus(roomName: string): RoomStatus;

/**
* Map visuals provide a way to show various visual debug info on the game map.
* You can use the `Game.map.visual` object to draw simple shapes that are visible only to you.
*
* Map visuals are not stored in the database, their only purpose is to display something in your browser.
* All drawings will persist for one tick and will disappear if not updated.
* All `Game.map.visual` calls have no added CPU cost (their cost is natural and mostly related to simple JSON.serialize calls).
* However, there is a usage limit: you cannot post more than 1000 KB of serialized data.
*
* All draw coordinates are measured in global game coordinates (`RoomPosition`).
*/
visual: MapVisual;
}

// No static is available

interface MapVisual {
/**
* Draw a line.
* @param pos1 The start position object.
* @param pos2 The finish position object.
* @param style The optional style
* @returns The MapVisual object, for chaining.
*/
line(pos1: RoomPosition, pos2: RoomPosition, style?: MapLineStyle): MapVisual;

/**
* Draw a circle.
* @param pos The position object of the center.
* @param style The optional style
* @returns The MapVisual object, for chaining.
*/
circle(pos: RoomPosition, style?: MapCircleStyle): MapVisual;

/**
* Draw a rectangle.
* @param topLeftPos The position object of the top-left corner.
* @param width The width of the rectangle.
* @param height The height of the rectangle.
* @param style The optional style
* @returns The MapVisual object, for chaining.
*/
rect(topLeftPos: RoomPosition, width: number, height: number, style?: MapPolyStyle): MapVisual;

/**
* Draw a polyline.
* @param points An array of points. Every item should be a `RoomPosition` object.
* @param style The optional style
* @returns The MapVisual object, for chaining.
*/
poly(points: RoomPosition[], style?: MapPolyStyle): MapVisual;

/**
* Draw a text label. You can use any valid Unicode characters, including emoji.
* @param text The text message.
* @param pos The position object of the label baseline.
* @param style The optional style
* @returns The MapVisual object, for chaining
*/
text(text: string, pos: RoomPosition, style?: MapTextStyle): MapVisual;

/**
* Remove all visuals from the map.
* @returns The MapVisual object, for chaining
*/
clear(): MapVisual;

/**
* Get the stored size of all visuals added on the map in the current tick. It must not exceed 1024,000 (1000 KB).
* @returns The size of the visuals in bytes.
*/
getSize(): number;
}

interface MapLineStyle {
/**
* Line width, default is 0.1.
*/
width?: number;
/**
* Line color in the following format: #ffffff (hex triplet). Default is #ffffff.
*/
color?: string;
/**
* Opacity value, default is 0.5.
*/
opacity?: number;
/**
* Either undefined (solid line), dashed, or dotted. Default is undefined.
*/
lineStyle?: "dashed" | "dotted" | "solid";
}

interface MapPolyStyle {
/**
* Fill color in the following format: #ffffff (hex triplet). Default is #ffffff.
*/
fill?: string;
/**
* Opacity value, default is 0.5.
*/
opacity?: number;
/**
* Stroke color in the following format: #ffffff (hex triplet). Default is undefined (no stroke).
*/
stroke?: string | undefined;
/**
* Stroke line width, default is 0.5.
*/
strokeWidth?: number;
/**
* Either undefined (solid line), dashed, or dotted. Default is undefined.
*/
lineStyle?: "dashed" | "dotted" | "solid";
}

interface MapCircleStyle extends MapPolyStyle {
/**
* Circle radius, default is 10.
*/
radius?: number;
}

interface MapTextStyle {
/**
* Font color in the following format: #ffffff (hex triplet). Default is #ffffff.
*/
color?: string;
/**
* The font family, default is sans-serif
*/
fontFamily?: string;
/**
* The font size in game coordinates, default is 10
*/
fontSize?: number;
/**
* The font style ('normal', 'italic' or 'oblique')
*/
fontStyle?: string;
/**
* The font variant ('normal' or 'small-caps')
*/
fontVariant?: string;
/**
* Stroke color in the following format: #ffffff (hex triplet). Default is undefined (no stroke).
*/
stroke?: string;
/**
* Stroke width, default is 0.15.
*/
strokeWidth?: number;
/**
* Background color in the following format: #ffffff (hex triplet). Default is undefined (no background). When background is enabled, text vertical align is set to middle (default is baseline).
*/
backgroundColor?: string;
/**
* Background rectangle padding, default is 2.
*/
backgroundPadding?: number;
/**
* Text align, either center, left, or right. Default is center.
*/
align?: "center" | "left" | "right";
/**
* Opacity value, default is 0.5.
*/
opacity?: number;
}
/**
* A global object representing the in-game market. You can use this object to track resource transactions to/from your
* terminals, and your buy/sell orders. The object is accessible via the singleton Game.market property.
Expand Down
17 changes: 17 additions & 0 deletions dist/screeps-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,3 +902,20 @@ function atackPower(creep: Creep) {
{
const ret: OK | ERR_NOT_ENOUGH_RESOURCES | ERR_FULL = Game.cpu.generatePixel();
}

// Game.map.visual
{
const mapVis = Game.map.visual;
const point1 = new RoomPosition(1, 1, "E1N1");
const point2 = new RoomPosition(1, 1, "E1N8");
const point3 = new RoomPosition(1, 1, "E8N8");
const point4 = new RoomPosition(1, 1, "E1N8");

mapVis
.line(point1, point2)
.circle(point3, { fill: "#f2f2f2" })
.poly([point1, point2, point3, point4])
.rect(point3, 50, 50);

const size: number = mapVis.getSize();
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typed-screeps",
"version": "3.1.3",
"version": "3.2.0",
"description": "Strong TypeScript declarations for the game Screeps.",
"repository": "screepers/typed-screeps",
"types": "./dist/index.d.ts",
Expand Down
Loading

0 comments on commit a3563e0

Please sign in to comment.