Room.lua¶
Functions¶
room.new¶
room.new(instance: LibLegelGen.Instance, segment: LibLevelGen.Segment, x: number, y: number, w: number, h: number, flags: number): LibLevelGen.Room
Create a new room within the segment.
Parameters:
| Name | Type | Description |
|---|---|---|
instance |
LibLegelGen.Instance |
The instance. |
segment |
LibLevelGen.Segment |
The segment. |
x |
number |
X coordinate of room's top-left corner. |
y |
number |
Y coordinate of room's top-left corner. |
w |
number |
Room width. |
h |
number |
Room height. |
flags |
number |
Room flags. |
Returns: LibLevelGen.Room
Classes¶
LibLevelGen.TileRequirements¶
Interface used for selecting tiles based on the given requirement.
Fields of the Tribool type can be nil, true or false.
When a Tribool is nil the condition is not checked, and if it's a boolean then
the condition check result must match the value specified.
Properties:
| Name | Type | Description |
|---|---|---|
isFloor |
TriBool |
Whether the tile is a floor. |
isWall |
TriBool |
Whether the tile is a wall. |
levelExit |
TriBool |
Whether the tile is the level exit. |
hasWallTorch |
TriBool |
Whether the tile has a wall torch. |
hasEntity |
TriBool |
Whether the tile has an entity. |
tileType |
string | nil |
Required tile type string name. |
nearFloor |
TriBool |
Whether the tile is near a floor tile, checked within this room only. |
nearWall |
TriBool |
Whether the tile is near a wall tile, checked within this room only. |
nearBorder |
TriBool |
Whether the tile is near the room border. |
filter |
fun(room: LibLevelGen.Room, tile: LibLevelGen.Tile) | nil |
Filter function, if it returns true the condition check passes. |
notCollision |
number | nil |
Collision (from necro.game.tile.Collision) bits which must all NOT be set. |
collision |
number | nil |
Collision (from necro.game.tile.Collision) bits which must all be set. |
rect |
LibLevelGen.Rect | nil |
Rect the tile must be in. |
notRect |
LibLevelGen.Rect | nil |
Rect the tile must NOT be in. |
wire |
TriBool |
Whether the tile has an electric wile. |
info |
table | nil |
Require the tile to have a specific tileInfo (from necro.game.tile.TileTypes) |
entrance |
TriBool |
Whether the tile is the entrance to the room (directly next to the corridor). |
adjacentEntrance |
TriBool |
Whether the tile is adjacent to the entrance. |
directlyAdjacentEntrance |
TriBool |
Whether the tile is adjacent to the entrance, but not diagonally. |
noWallTallSprite |
TriBool |
Whether the tile below the checked tile is a wall. |
LibLevelGen.Tile¶
Object representing a single tile. This will be moved to a separate module in the future.
Properties:
| Name | Type | Description |
|---|---|---|
tileset |
string |
Tileset the tile uses. |
type |
string |
Tile type the tile uses. |
info |
table |
TileInfo of the tile (from necro.game.tile.TileTypes). |
wire |
integer |
The wire connectivity bitmask. |
hasEntity |
boolean |
Whether the tile has an entity. |
entities |
LibLevelGen.Entity[] |
List of entities on this tile. |
hasWallTorch |
boolean |
Whether the tile has a wall torch. |
x |
number |
X coordinate of the tile in the room. |
y |
number |
Y coordinate of the tile in the room. |
rx |
number |
X coordinate of the tile in the segment. |
ry |
number |
Y coordinate of the tile in the segment. |
adjacentEntrance |
boolean |
Whether the tile is adjacent to an entrance. |
directlyAdjacentEntrance |
boolean |
Whether the tile is adjacent to an entrance, but not diagonally. |
isEntrance |
boolean |
Whether the tile is the entrance to the room (directly next to the corridor). |
room |
LibLevelGen.Room |
Room this tile belongs to. |
instance |
LibLegelGen.Instance |
Instance this tile belongs to. |
Methods:
LibLevelGen.Tile.convert¶
Convert the tile to a different type.
Parameters:
Name Type Description selfLibLevelGen.TileThe tile tileTypestringTileType to convert to.
LibLevelGen.Tile.setIsEntrance¶
Set the isEntrance flag on the tile and adjacentEntrance flags on nearby tiles.
Parameters:
Name Type Description selfLibLevelGen.TileThe tile
LibLevelGen.Tile.placeEntity¶
placeEntity(self: LibLevelGen.Tile, entityOrType: string | LibLevelGen.Entity, level?: number): LibLevelGen.EntityPlace entity of given type and level on the tile.
Parameters:
Name Type Description selfLibLevelGen.TileThe tile. entityOrTypestring | LibLevelGen.EntityEntity type or existing entity. level?numberEntity level, ignored if existing entity is passed in the previous argument. Returns:
LibLevelGen.Entity
LibLevelGen.Tile.meetsRequirements¶
Check if the tile meets specified requirements.
Parameters:
Name Type Description selfLibLevelGen.TileThe tile. requirementsLibLevelGen.TileRequirementsRequirements the tile has to meet.
LibLevelGen.Tile.tileBelowIsWall¶
Whether a wall tile or the room border is below this tile.
Parameters:
Name Type Description selfLibLevelGen.TileThe tile.
LibLevelGen.Tile.inRect¶
Check if the tile is within a given rect in the room.
Parameters:
Name Type Description selfLibLevelGen.TileThe tile. rectLibLevelGen.RectRect to check against.
LibLevelGen.RoomLinkData¶
Data which represents where a room connects to other rooms.
Properties:
| Name | Type | Description |
|---|---|---|
x |
number |
Top-left X coordinate of the connection. |
y |
number |
Top-left Y coordinate of the connection. |
centerX |
number |
X center of the connection. |
centerY |
number |
Y center of the connection. |
axis |
number |
LibLevelGen.Axis |
size |
number |
How long the connection is, it's either width or height, depending on the axis. |
room |
LibLevelGen.Room |
The room that the link leads to. |
LibLevelGen.RoomLinks¶
Object containing room links for every side of the room.
Properties:
| Name | Type | Description |
|---|---|---|
top |
LibLevelGen.RoomLinkData[] |
Link data of the top side of the room. |
bottom |
LibLevelGen.RoomLinkData[] |
Link data of the bottom side of the room. |
left |
LibLevelGen.RoomLinkData[] |
Link data of the left side of the room. |
right |
LibLevelGen.RoomLinkData[] |
Link data of the right side of the room. |
LibLevelGen.Point¶
Simple point interface.
Properties:
| Name | Type | Description |
|---|---|---|
x |
number |
x |
y |
number |
y |
LibLevelGen.Room¶
Object representing a room.
Properties:
| Name | Type | Description |
|---|---|---|
x |
number |
X coordinate of the room's top left corner within the segment. |
y |
number |
Y coordinate of the room's top left corner within the segment. |
w |
number |
Width of the room. |
h |
number |
Height of the room. |
flags |
number |
Room flags (from room.Flag). |
links |
LibLevelGen.RoomLinkData[] |
Information about the rooms adjacent to this room and where exactly the entrances are. |
padding |
LibLevelGen.PaddingData | nil |
Padding override to use instead of the segment-defined one. |
tiles |
LibLevelGen.Tile[] |
Array of tiles in this room. |
exit |
LibLevelGen.Point | nil |
Coordinates of exit stairs within this room (if they exist). |
instance |
LibLegelGen.Instance |
Instance this room belongs to. |
segment |
LibLevelGen.Segment |
Segment this table belongs to. |
userData |
table |
Table where you can put whatever you want safely. |
Methods:
LibLevelGen.Room.setFlags¶
Adds new flags on top of existing flags.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. newFlagsnumberThe new flags.
LibLevelGen.Room.clearFlags¶
Removes the given flags.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. flagsToClearnumberFlags to remove.
LibLevelGen.Room.maskFlags¶
Removes all flags apart from the given ones.
Parameters:
Name Type Description selfLibLevelGen.Roomthe room. flagsnumberFlags to use as a mask.
LibLevelGen.Room.checkFlags¶
Checks if the given flags are set.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. flagsnumberFlags to check.
LibLevelGen.Room.setPaddingTileOverride¶
Set the padding that will be used instead of the one specified by the segment.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. dataLibLevelGen.PaddingDataPadding definition object.
LibLevelGen.Room.getBounds¶
Get bounds of the room (in table
{x, y, w, h}).Parameters:
Name Type Description selfLibLevelGen.RoomThe room. Returns:
number[]
LibLevelGen.Room.getRect¶
Get rect of the room.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. Returns:
LibLevelGen.Rect
LibLevelGen.Room.setTile¶
Set tile on the given coordinates. If tileset is not specified, the default one of the segment is used.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. xnumberX coordinates of the tile. ynumberY coordinates of the tile. tileTypestringThe tile type tileset?stringThe tileset, if not specified defaults to the tileset of the segment.
LibLevelGen.Room.getTile¶
Get tile on given coordinates
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. xnumberX coordinates of the tile. ynumberY coordinates of the tile. Returns:
LibLevelGen.Tile
LibLevelGen.Room.deleteTile¶
Delete the given tile (set it to Void pseudotile)
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. xnumberX coordinates of the tile. ynumberY coordinates of the tile.
LibLevelGen.Room.isTileNearWall¶
Checks if the given tile (assumed to be within this room) is near a wall tile.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. tileLibLevelGen.TileThe tile to check. Returns:
boolean
LibLevelGen.Room.isTileNearFloor¶
Checks if the given tile (assumed to be within this room) is near a floor tile.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. tileLibLevelGen.TileThe tile to check. Returns:
boolean
LibLevelGen.Room.isTileNearBorder¶
Checks if the given tile (assumed to be within this room) is near the edge of the room.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. tileLibLevelGen.TileThe tile to check. Returns:
boolean
LibLevelGen.Room.fill¶
Fill the room.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. parametersLibLevelGen.RoomFillParameters | stringEither the RoomFillParameters object or simply the tile type string.
LibLevelGen.Room.border¶
Create a border around the room.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. parametersLibLevelGen.RoomBorderParameters | stringEither a RoomBorderParametersspecifying the border details, or simply a string tile type to create a basic border.
LibLevelGen.Room.selectTiles¶
Returns all tiles that meet the requirements.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. requirementsLibLevelGen.TileRequirementsTile requirements to check against. Returns:
LibLevelGen.Tile[]
LibLevelGen.Room.chooseRandomTile¶
chooseRandomTile(self: LibLevelGen.Room, requirements: LibLevelGen.TileRequirements): LibLevelGen.TileChoose a random tile out of ones that meet requirements
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. requirementsLibLevelGen.TileRequirementsTile requirements to check against. Returns:
LibLevelGen.Tile
LibLevelGen.Room.chooseRandomTiles¶
chooseRandomTiles(self: LibLevelGen.Room, num: number, requirements: LibLevelGen.TileRequirements): LibLevelGen.Tile[]Choose multiple tiles out of ones that meet requirements.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. numnumberAmount of tiles to choose. requirementsLibLevelGen.TileRequirementsTile requirements to check against. Returns:
LibLevelGen.Tile[]
LibLevelGen.Room.placeWallTorch¶
Place a wall torch on the given tile.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. tileLibLevelGen.TileTile to place the torch on. type?stringOptional walltorch entity type override.
LibLevelGen.Room.placeWallTorches¶
Place given amount of wall torches randomly on elligible tiles.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. numnumberAmount of weall torches to place. type?stringOptional walltorch entity type override.
LibLevelGen.Room.placeEntity¶
placeEntity(self: LibLevelGen.Room, tile: LibLevelGen.Tile, entityOrType: string | LibLevelGen.Entity, level?: number): voidPlace entity on the given tile (wrapper around tile:placeEntity that checks if tile is not nil)
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. tileLibLevelGen.TileThe tile to place the entity on. entityOrTypestring | LibLevelGen.EntityExisting entity or an entity type to spawn. level?numberOptional entity level if passing a string entity type.
LibLevelGen.Room.placeEntityAt¶
placeEntityAt(self: LibLevelGen.Room, x: number, y: number, entityOrType: string | LibLevelGen.Entity, level?: number): voidPlace entity on a tile on given coordinates.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. xnumberX coordinate. ynumberY coordinate. entityOrTypestring | LibLevelGen.EntityExisting entity or an entity type to spawn. level?numberOptional entity level if passing a string entity type.
LibLevelGen.Room.placeEntityRand¶
placeEntityRand(self: LibLevelGen.Room, requirements: LibLevelGen.TileRequirements, entityOrType: string | LibLevelGen.Entity, level?: number): voidPlace entity on a random tile that meets requrements.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. requirementsLibLevelGen.TileRequirementsRequirements used to select the tile. entityOrTypestring | LibLevelGen.EntityExisting entity or an entity type to spawn. level?numberOptional entity level if passing a string entity type.
LibLevelGen.Room.placeWire¶
Place wire on the given tile.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room tileLibLevelGen.TileTile to place the wire on. connectivitynumberUnused, reserved.
LibLevelGen.Room.makeExit¶
Turn the room into an exit room - set appropriate flags, place the exit stairs and the miniboss.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. minibossestableList of possible minibosses, in format: { {"type1", level1}, {"type2", level2}, ... }
LibLevelGen.Room.placeExit¶
Place exit somewhere in the room.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room.
LibLevelGen.Room.placeMiniboss¶
Place a miniboss in the room (assumes that the room is an exit room).
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. minibossestableIn format {{"type", level}, ...}.
LibLevelGen.Room.randomlyConvertTiles¶
randomlyConvertTiles(self: LibLevelGen.Room, sourceType: string, targetType: string, ratio: number): voidRandomly convert tiles from sourceType to targetType, chance of conversion happening is ratio.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. sourceTypestringTile type to convert from. targetTypestringTile type to convert to. rationumberChance of the conversion happening, a float between 0.0 and 1.0.
LibLevelGen.Room.convertTiles¶
Convert all tiles from source type to target type, preserving their tileset.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. sourceTypestringTile type to convert from. targetTypestringTile type to convert to.
LibLevelGen.Room.spreadTile¶
spreadTile(self: LibLevelGen.Room, targetType: string, requirements: LibLevelGen.TileRequirements, minConvert: number, maxConvert: number, initialTile?: LibLevelGen.Tile): voidChoose 1 tile that meets requirement and convert it and other nearby tiles to target type.
Parameters:
Name Type Description selfLibLevelGen.RoomThe room. targetTypestringTiletype to convert the tiles to. requirementsLibLevelGen.TileRequirementsThe tile requirements used to pick the initial tile and the subsequent tiles. minConvertnumberMinimum number of tiles to convert. maxConvertnumberMaximum number of tiles to convert. initialTile?LibLevelGen.TileCan be used to specify initial tile, instead of choosing it randomly.
LibLevelGen.Room.makeShop¶
Make the room a shop. TODO: move into a separate module
Parameters:
Name Type Description selfLibLevelGen.RoomThe room locked?booleanWhether the shop should be a locked shop force?booleanWhether to force shopkeeper and items to spawn even if the shopkeeper killed flag is set in runState.
LibLevelGen.RoomFillParameters extends LibLevelGen.TileData¶
no description
Properties:
| Name | Type | Description |
|---|---|---|
tileset |
string |
no description |
type |
string |
no description |
rect |
LibLevelGen.Rect | nil |
no description |
LibLevelGen.RoomBorderSideCount¶
no description
Properties:
| Name | Type | Description |
|---|---|---|
top |
number |
Top tile count. |
bottom |
number |
Bottom tile count. |
left |
number |
Left tile count. |
right |
number |
Right tile count. |
LibLevelGen.RoomBorderParameters extends LibLevelGen.TileData¶
Object used to specify room border details.
Properties:
| Name | Type | Description |
|---|---|---|
tileset |
string |
no description |
type |
string |
no description |
rect |
LibLevelGen.Rect |
The rect around which to place the border. |
sides |
LibLevelGen.RoomBorderSideCount |
Definition of wall count on each side. |
Enums¶
room.Axis¶
Used to determine whether a room was generated vertically or horizontally.
Entries:
VERTICALHORIZONTAL
room.Flag¶
Flags which determine the properties of the room
Entries:
NONEALLOW_ENEMYALLOW_CHESTALLOW_CRATEALLOW_TRAPALLOW_TRAVELRUNEALLOW_SHRINEALLOW_TORCHALLOW_TILE_CONVERSIONALLOW_SECRET_FILLEXITSTARTING
room.Type¶
Helper enum containing common room.Flag bitmasks.
Entries:
REGULARSTARTINGEXITCORRIDORSECRETSHOPSECRET_SHOPOTHER
Other¶
room.Direction¶
room.DirectionVector¶
room.DirectionVector = {
[room.Direction.LEFT] = {-1, 0},
[room.Direction.RIGHT] = {1, 0},
[room.Direction.UP] = {0, -1},
[room.Direction.DOWN] = {0, 1}
}