Skip to content

WallRooms

namespace Griff.Scenes;
public sealed class WallRooms : Component, IDrawable

The rooms walls make on a tilemap’s grid, for heat, air, occupancy or anything else that goes by room: every patch of floor cells joined side by side (four ways; six on a hex map) without crossing a wall. Walls are the map’s solid tiles on any of its layers (as grid movers see them), its WallTiles even where they can be walked through (a door counts as shut), and solid colliders on WallLayers. A room that reaches past the map’s edge (or, with EmptyIsOutside, an empty cell) is open to the outside. Put it on the tilemap whose cells make the rooms.

Not a camera’s Room: these are found from the walls, not placed. They’re worked out again only when the walls change (a tile painted, a wall collider added, moved or taken away), and Changed says when they have, at the end of that step. A script that changes walls and wants the new rooms in the same step calls Refresh. Each room keeps its Id as walls go up and come down: split in two, the bigger part keeps it; joined, the room takes the id of the one it has most of. A new room gets a new id.

This is a component: its saved properties are on its component page.

public int Closed { get; }

How many rooms the walls close off: those not open to the outside.

public bool EmptyIsOutside { get; set; }

Cells with no tile on the map or any of its layers are outside, like the cells past its edge, so a room next to one is open: a floor painted in the shape of a building, or a ship’s hull with a hole in it.

public Tilemap? Map { get; }

The tilemap whose cells make the rooms: the one on its entity (the map it’s a layer of, for a layer).

public string? Message { get; set; }

A message sent with Game.Send whenever the rooms change, with this entity as its data.

public IReadOnlyList<WallRoom> Rooms { get; }

The rooms, open and closed, by Id.

public bool Show { get; set; }

Tints each closed room a color of its own (open ones aren’t tinted), to see where the walls close rooms off.

public bool SolidTiles { get; set; }

The map’s solid tiles (on it and its layers) are walls, as they are to grid movers. Untick it to count only WallTiles and WallLayers.

public string? WallLayers { get; set; }

Collision layers whose solid colliders are walls too, over a cell’s middle, e.g. “Walls, Doors”: walls built as entities rather than painted. Grid movers (workers walking about) never are. Empty for none.

public string? WallTiles { get; set; }

Tiles that are walls to rooms even where they can be walked through, on the map or any of its layers: a door’s tiles, so a door counts as shut. Tile numbers and ranges, e.g. “300-301”. Empty for none.

public ValueTuple<int, int> CellAt(Vector2 world)

The cell of the map a world position is in.

public Vector2 CellCenter(ValueTuple<int, int> cell)

The world position of the middle of a cell of the map.

public List<Entity> EntitiesIn(WallRoom room)

Every active entity standing in room, in hierarchy order: the map and its layers aside.

public List<T> EntitiesIn<T>(WallRoom room)

The T components on active entities standing in room: its machines, heaters or workers.

public void Refresh()

Works the rooms out again now if the walls have changed, rather than at the end of the step: for a script that changes walls and asks about rooms straight after. Changed is still raised at the end of the step.

public WallRoom? Room(int id)

The room with id id, or null if there’s none now.

public int RoomArea(string entity)

The area, in cells, of the room the entity called this stands in; 0 when it’s in none (on a wall, or off the map).

public WallRoom? RoomAt(ValueTuple<int, int> cell)

The room a cell of the map is in, or null for a wall, an outside cell or one off the map.

public WallRoom? RoomAt(Vector2 world)

The room a point in the world is in, or null for none.

public int RoomId(string entity)

The Id of the room the entity called this stands in; 0 when it’s in none.

public WallRoom? RoomOf(Entity entity)

The room an entity stands in (the cell its position is in), or null for none.

public event Action<IReadOnlyList<WallRoom>>? Changed

Raised at the end of a step in which the rooms changed (or were first found), with the rooms now.