Room visuals provide a way to show various visual debug info in game rooms.
You can use the
RoomVisual
object to draw simple shapes that are visible only to you.
Every existing
Room
object already contains the
visual
property,
but you also can create new
RoomVisual
objects for any room (even without visibility)
using the
constructor
.
Room 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
RoomVisual
API 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 500 KB
of serialized data per one room (see
getSize
method).
All draw coordinates are measured in game coordinates and centered to tile centers, i.e. (10,10)
will point to the center of the creep at
x:10; y:10
position. Fractional coordinates are allowed.
Game.rooms['W10N10'].visual.circle(10,20).line(0,0,10,20);
// the same as:
new RoomVisual('W10N10').circle(10,20).line(0,0,10,20);
// this text will be displayed in all rooms
new RoomVisual().text('Some text', 1, 1, {align: 'left'});
You can directly create new
RoomVisual
object in any room, even if it's invisible to your script.
parameter | type | description |
---|---|---|
roomName
optional |
string |
The room name. If undefined, visuals will be posted to all rooms simultaneously. |
The name of the room.
new RoomVisual('W1N1').line(10,15, 20,20);
creep.room.visual.line(creep.pos, target.pos,
{color: 'red', lineStyle: 'dashed'});
Draw a line.
parameter | type | description |
---|---|---|
x1
|
number |
The start X coordinate. |
y1
|
number |
The start Y coordinate. |
x2
|
number |
The finish X coordinate. |
y2
|
number |
The finish Y coordinate. |
pos1
|
RoomPosition |
The start position object. |
pos2
|
RoomPosition |
The finish position object. |
style
optional |
object |
An object with the following properties:
|
The
RoomVisual
object itself, so that you can chain calls.
new RoomVisual('W1N1').circle(10,15);
creep.room.visual.circle(creep.pos,
{fill: 'transparent', radius: 0.55, stroke: 'red'});
Draw a circle.
parameter | type | description |
---|---|---|
x
|
number |
The X coordinate of the center. |
y
|
number |
The Y coordinate of the center. |
pos
|
RoomPosition |
The position object of the center. |
style
optional |
object |
An object with the following properties:
|
The
RoomVisual
object itself, so that you can chain calls.
// 9x9 area from (2,2) to (10,10)
new RoomVisual('W1N1').rect(1.5, 1.5, 9, 9);
// a rectangle border on creep
creep.room.visual.rect(creep.pos.x - 0.6, creep.pos.y - 0.6,
1.2, 1.2,
{fill: 'transparent', stroke: '#f00'});
Draw a rectangle.
parameter | type | description |
---|---|---|
x
|
number |
The X coordinate of the top-left corner. |
y
|
number |
The Y coordinate of the top-left corner. |
topLeftPos
|
RoomPosition |
The position object of the top-left corner. |
width
|
number |
The width of the rectangle. |
height
|
number |
The height of the rectangle. |
style
optional |
object |
An object with the following properties:
|
The
RoomVisual
object itself, so that you can chain calls.
const points = [];
points.push(creep1.pos);
points.push([10,15]);
points.push(new RoomPosition(20,21,'W1N1'));
new RoomVisual('W1N1').poly(points, {fill: 'aqua'});
// visualize the path
const path = Game.rooms['W1N1'].findPath(from, to);
new RoomVisual('W1N1').poly(path, {stroke: '#fff', strokeWidth: .15,
opacity: .2, lineStyle: 'dashed'});
Draw a polyline.
parameter | type | description |
---|---|---|
points
|
array |
An array of points. Every item should be either an array with 2 numbers (i.e.
|
style
optional |
object |
An object with the following properties:
|
The
RoomVisual
object itself, so that you can chain calls.
new RoomVisual('W1N1').text("Targetš„", 10, 15, {color: 'green', font: 0.8});
Draw a text label. You can use any valid Unicode characters, including emoji .
parameter | type | description |
---|---|---|
text
|
string |
The text message. |
x
|
number |
The X coordinate of the label baseline point. |
y
|
number |
The Y coordinate of the label baseline point. |
pos
|
RoomPosition |
The position object of the label baseline. |
style
optional |
object |
An object with the following properties:
|
The
RoomVisual
object itself, so that you can chain calls.
new RoomVisual('W1N1').clear();
Remove all visuals from the room.
The
RoomVisual
object itself, so that you can chain calls.
if(creep.room.visual.getSize() >= 512000) {
// cannot add more visuals in this tick
}
Get the stored size of all visuals added in the room in the current tick. It must not exceed 512,000 (500 KB).
The size of the visuals in bytes.
Memory.RoomVisualData['E2S7'] = Game.rooms.E2S7.visual.export();
Returns a compact representation of all visuals added in the room in the current tick.
A string with visuals data. There's not much you can do with the string besides store them for later.
if(Memory.RoomVisualData['E2S7']) {
Game.rooms.E2S7.visual.import(Memory.RoomVisualData['E2S7']);
}
Add previously exported (with RoomVisual.export ) room visuals to the room visual data of the current tick.
parameter | type | description |
---|---|---|
val
|
string |
The string returned from RoomVisual.export. |
The
RoomVisual
object itself, so that you can chain calls.