Skip to content

Commit a3563e0

Browse files
authored
Merge pull request #177 from screepers/ptr
MapVisual support
2 parents fa27ebc + 626dd1a commit a3563e0

File tree

5 files changed

+365
-3
lines changed

5 files changed

+365
-3
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## [3.2.0] - 2020-09-06
11+
12+
### Added
13+
14+
- Add new `MapVisual` type for new map visual feature ([#177](https://github.com/screepers/typed-screeps/pull/177))
15+
16+
### Fixed
17+
18+
- Fix decumentation for `PWR_OPERATE_FACTORY` duration ([#174](https://github.com/screepers/typed-screeps/pull/174))
19+
1020
## [3.1.3] - 2020-06-22
1121

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

299309
- Initial public `npm` release.
300310

301-
[unreleased]: https://github.com/screepers/typed-screeps/compare/v3.1.3...HEAD
311+
[unreleased]: https://github.com/screepers/typed-screeps/compare/v3.2.0...HEAD
312+
[3.2.0]: https://github.com/screepers/typed-screeps/compare/v3.1.3...v3.2.0
302313
[3.1.3]: https://github.com/screepers/typed-screeps/compare/v3.1.2...v3.1.3
303314
[3.1.2]: https://github.com/screepers/typed-screeps/compare/v3.1.1...v3.1.2
304315
[3.1.1]: https://github.com/screepers/typed-screeps/compare/v3.1.0...v3.1.1

dist/index.d.ts

Lines changed: 168 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for Screeps 3.1.3
1+
// Type definitions for Screeps 3.2.0
22
// Project: https://github.com/screeps/screeps
33
// Definitions by: Marko Sulamägi <https://github.com/MarkoSulamagi>
44
// Nhan Ho <https://github.com/NhanHo>
@@ -2854,9 +2854,176 @@ interface GameMap {
28542854
* @returns An object with the following properties {status: "normal" | "closed" | "novice" | "respawn", timestamp: number}
28552855
*/
28562856
getRoomStatus(roomName: string): RoomStatus;
2857+
2858+
/**
2859+
* Map visuals provide a way to show various visual debug info on the game map.
2860+
* You can use the `Game.map.visual` object to draw simple shapes that are visible only to you.
2861+
*
2862+
* Map visuals are not stored in the database, their only purpose is to display something in your browser.
2863+
* All drawings will persist for one tick and will disappear if not updated.
2864+
* All `Game.map.visual` calls have no added CPU cost (their cost is natural and mostly related to simple JSON.serialize calls).
2865+
* However, there is a usage limit: you cannot post more than 1000 KB of serialized data.
2866+
*
2867+
* All draw coordinates are measured in global game coordinates (`RoomPosition`).
2868+
*/
2869+
visual: MapVisual;
28572870
}
28582871

28592872
// No static is available
2873+
2874+
interface MapVisual {
2875+
/**
2876+
* Draw a line.
2877+
* @param pos1 The start position object.
2878+
* @param pos2 The finish position object.
2879+
* @param style The optional style
2880+
* @returns The MapVisual object, for chaining.
2881+
*/
2882+
line(pos1: RoomPosition, pos2: RoomPosition, style?: MapLineStyle): MapVisual;
2883+
2884+
/**
2885+
* Draw a circle.
2886+
* @param pos The position object of the center.
2887+
* @param style The optional style
2888+
* @returns The MapVisual object, for chaining.
2889+
*/
2890+
circle(pos: RoomPosition, style?: MapCircleStyle): MapVisual;
2891+
2892+
/**
2893+
* Draw a rectangle.
2894+
* @param topLeftPos The position object of the top-left corner.
2895+
* @param width The width of the rectangle.
2896+
* @param height The height of the rectangle.
2897+
* @param style The optional style
2898+
* @returns The MapVisual object, for chaining.
2899+
*/
2900+
rect(topLeftPos: RoomPosition, width: number, height: number, style?: MapPolyStyle): MapVisual;
2901+
2902+
/**
2903+
* Draw a polyline.
2904+
* @param points An array of points. Every item should be a `RoomPosition` object.
2905+
* @param style The optional style
2906+
* @returns The MapVisual object, for chaining.
2907+
*/
2908+
poly(points: RoomPosition[], style?: MapPolyStyle): MapVisual;
2909+
2910+
/**
2911+
* Draw a text label. You can use any valid Unicode characters, including emoji.
2912+
* @param text The text message.
2913+
* @param pos The position object of the label baseline.
2914+
* @param style The optional style
2915+
* @returns The MapVisual object, for chaining
2916+
*/
2917+
text(text: string, pos: RoomPosition, style?: MapTextStyle): MapVisual;
2918+
2919+
/**
2920+
* Remove all visuals from the map.
2921+
* @returns The MapVisual object, for chaining
2922+
*/
2923+
clear(): MapVisual;
2924+
2925+
/**
2926+
* Get the stored size of all visuals added on the map in the current tick. It must not exceed 1024,000 (1000 KB).
2927+
* @returns The size of the visuals in bytes.
2928+
*/
2929+
getSize(): number;
2930+
}
2931+
2932+
interface MapLineStyle {
2933+
/**
2934+
* Line width, default is 0.1.
2935+
*/
2936+
width?: number;
2937+
/**
2938+
* Line color in the following format: #ffffff (hex triplet). Default is #ffffff.
2939+
*/
2940+
color?: string;
2941+
/**
2942+
* Opacity value, default is 0.5.
2943+
*/
2944+
opacity?: number;
2945+
/**
2946+
* Either undefined (solid line), dashed, or dotted. Default is undefined.
2947+
*/
2948+
lineStyle?: "dashed" | "dotted" | "solid";
2949+
}
2950+
2951+
interface MapPolyStyle {
2952+
/**
2953+
* Fill color in the following format: #ffffff (hex triplet). Default is #ffffff.
2954+
*/
2955+
fill?: string;
2956+
/**
2957+
* Opacity value, default is 0.5.
2958+
*/
2959+
opacity?: number;
2960+
/**
2961+
* Stroke color in the following format: #ffffff (hex triplet). Default is undefined (no stroke).
2962+
*/
2963+
stroke?: string | undefined;
2964+
/**
2965+
* Stroke line width, default is 0.5.
2966+
*/
2967+
strokeWidth?: number;
2968+
/**
2969+
* Either undefined (solid line), dashed, or dotted. Default is undefined.
2970+
*/
2971+
lineStyle?: "dashed" | "dotted" | "solid";
2972+
}
2973+
2974+
interface MapCircleStyle extends MapPolyStyle {
2975+
/**
2976+
* Circle radius, default is 10.
2977+
*/
2978+
radius?: number;
2979+
}
2980+
2981+
interface MapTextStyle {
2982+
/**
2983+
* Font color in the following format: #ffffff (hex triplet). Default is #ffffff.
2984+
*/
2985+
color?: string;
2986+
/**
2987+
* The font family, default is sans-serif
2988+
*/
2989+
fontFamily?: string;
2990+
/**
2991+
* The font size in game coordinates, default is 10
2992+
*/
2993+
fontSize?: number;
2994+
/**
2995+
* The font style ('normal', 'italic' or 'oblique')
2996+
*/
2997+
fontStyle?: string;
2998+
/**
2999+
* The font variant ('normal' or 'small-caps')
3000+
*/
3001+
fontVariant?: string;
3002+
/**
3003+
* Stroke color in the following format: #ffffff (hex triplet). Default is undefined (no stroke).
3004+
*/
3005+
stroke?: string;
3006+
/**
3007+
* Stroke width, default is 0.15.
3008+
*/
3009+
strokeWidth?: number;
3010+
/**
3011+
* 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).
3012+
*/
3013+
backgroundColor?: string;
3014+
/**
3015+
* Background rectangle padding, default is 2.
3016+
*/
3017+
backgroundPadding?: number;
3018+
/**
3019+
* Text align, either center, left, or right. Default is center.
3020+
*/
3021+
align?: "center" | "left" | "right";
3022+
/**
3023+
* Opacity value, default is 0.5.
3024+
*/
3025+
opacity?: number;
3026+
}
28603027
/**
28613028
* A global object representing the in-game market. You can use this object to track resource transactions to/from your
28623029
* terminals, and your buy/sell orders. The object is accessible via the singleton Game.market property.

dist/screeps-tests.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,3 +902,20 @@ function atackPower(creep: Creep) {
902902
{
903903
const ret: OK | ERR_NOT_ENOUGH_RESOURCES | ERR_FULL = Game.cpu.generatePixel();
904904
}
905+
906+
// Game.map.visual
907+
{
908+
const mapVis = Game.map.visual;
909+
const point1 = new RoomPosition(1, 1, "E1N1");
910+
const point2 = new RoomPosition(1, 1, "E1N8");
911+
const point3 = new RoomPosition(1, 1, "E8N8");
912+
const point4 = new RoomPosition(1, 1, "E1N8");
913+
914+
mapVis
915+
.line(point1, point2)
916+
.circle(point3, { fill: "#f2f2f2" })
917+
.poly([point1, point2, point3, point4])
918+
.rect(point3, 50, 50);
919+
920+
const size: number = mapVis.getSize();
921+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typed-screeps",
3-
"version": "3.1.3",
3+
"version": "3.2.0",
44
"description": "Strong TypeScript declarations for the game Screeps.",
55
"repository": "screepers/typed-screeps",
66
"types": "./dist/index.d.ts",

0 commit comments

Comments
 (0)