ManiaMap.Godot
Procedural generation of metroidvania style maps for Godot .NET.
RoomNode2D Class Reference

A node serving as the top level of a 2D room. More...

Inheritance diagram for RoomNode2D:
IRoomNode

Public Member Functions

override void _Ready ()
 
override void _ValidateProperty (Godot.Collections.Dictionary property)
 
Vector2 CellCenterGlobalPosition (int row, int column)
 Returns the cell center global position for the specified cell index. More...
 
Vector2 CellCenterLocalPosition (int row, int column)
 Returns the cell center local position for the specified cell index. More...
 
Error EmitOnCellAreaEntered (CellArea2D cell, Node collision)
 
Error EmitOnCellAreaExited (CellArea2D cell, Node collection)
 
Error EmitOnCellGridChanged ()
 
Vector2I FindClosestActiveCellIndex (Vector2 position)
 Returns the closest active cell index to the specified global position. More...
 
DoorDirection FindClosestDoorDirection (int row, int column, Vector2 position)
 Returns the closest door direction based on the cell index and specified global position. The nearest direction is determined based on the change between the specified position and cell center. More...
 
Vector2I GlobalPositionToCellIndex (Vector2 position)
 Returns the row (x) and column (y) index corresponding to the specified global position. If the position is outside the room bounds, returns Vector2I(-1, -1). More...
 
bool Initialize (LayoutPack layoutPack, Room roomLayout, RoomState roomState, uint cellCollisionMask, bool assignLayoutPosition)
 Initializes the room. The room should be initialized before adding it to the scene tree since cell children often require this information on ready. More...
 
Vector2I LocalPositionToCellIndex (Vector2 position)
 Returns the row (x) and column (y) index corresponding to the specified local position. If the position is outside the room bounds, returns Vector2I(-1, -1). More...
 
void MoveToLayoutPosition ()
 Moves the room to its position in the Layout. More...
 
delegate void OnCellAreaEnteredEventHandler (CellArea2D cell, Node collision)
 Signal emitted when a cell area is entered by a tracked area or body. More...
 
delegate void OnCellAreaExitedEventHandler (CellArea2D cell, Node collision)
 Signal emitted when a cell area is exited by a tracked area or body. More...
 
delegate void OnCellGridChangedEventHandler ()
 Signal emitted when the cell grid size or cell sizes are set.
 

Static Public Member Functions

static RoomNode2D CreateInstance (PackedScene scene, Node parent, LayoutPack layoutPack, Room roomLayout, RoomState roomState, uint cellCollisionMask, bool assignLayoutPosition)
 Creates and initializes an instance of a room. More...
 
static RoomNode2D CreateInstance (Uid id, LayoutPack layoutPack, PackedScene scene, Node parent, bool assignLayoutPosition=false)
 Creates and initializes an instance of a room. The layout and layout state are assigned to the room based on the current ManiaMapManager. More...
 

Properties

Godot.Collections.Array< Godot.Collections.Array< bool > > ActiveCells = new Godot.Collections.Array<Godot.Collections.Array<bool>>() [getset]
 
Vector2 CellSize [getset]
 The width and height of the room cells. More...
 
int Columns [getset]
 
bool IsInitialized [getprivate set]
 
LayoutPack LayoutPack [getprivate set]
 
Room RoomLayout [getprivate set]
 
RoomState RoomState [getprivate set]
 
RoomTemplateResource RoomTemplate [getset]
 
int Rows [getset]
 
- Properties inherited from IRoomNode
Godot.Collections.Array< Godot.Collections.Array< bool > > ActiveCells [getset]
 A nested array of room cell activities. More...
 
int Columns [getset]
 The number of cell columns in the room. More...
 
bool IsInitialized [get]
 True if the room has been initialized. More...
 
LayoutPack LayoutPack [get]
 The current layout pack. More...
 
Room RoomLayout [get]
 This room's layout. More...
 
RoomState RoomState [get]
 This room's layout state. More...
 
RoomTemplateResource RoomTemplate [getset]
 The room template used by the procedural generator. More...
 
int Rows [getset]
 The number or cell rows in the room. More...
 

Private Member Functions

void CreateCellAreas (uint cellCollisionMask)
 Creates CellArea2D for all active cells. More...
 
void SetCellSizeField (ref Vector2 field, Vector2 value)
 
void SetSizeField (ref int field, int value)
 

Private Attributes

Vector2 _cellSize = new Vector2(96, 96)
 
int _columns = 1
 
int _rows = 1
 

Detailed Description

A node serving as the top level of a 2D room.

See IRoomNodeExtensions for additional methods usable by this class.

Definition at line 16 of file RoomNode2D.cs.

Member Function Documentation

◆ _Ready()

override void _Ready ( )

Definition at line 90 of file RoomNode2D.cs.

◆ _ValidateProperty()

override void _ValidateProperty ( Godot.Collections.Dictionary  property)

Definition at line 107 of file RoomNode2D.cs.

◆ CellCenterGlobalPosition()

Vector2 CellCenterGlobalPosition ( int  row,
int  column 
)

Returns the cell center global position for the specified cell index.

Parameters
rowThe cell row.
columnThe cell column.

Definition at line 351 of file RoomNode2D.cs.

◆ CellCenterLocalPosition()

Vector2 CellCenterLocalPosition ( int  row,
int  column 
)

Returns the cell center local position for the specified cell index.

Parameters
rowThe cell row.
columnThe cell column.

Definition at line 361 of file RoomNode2D.cs.

◆ CreateCellAreas()

void CreateCellAreas ( uint  cellCollisionMask)
private

Creates CellArea2D for all active cells.

Parameters
cellCollisionMaskThe cell collision mask.

Definition at line 323 of file RoomNode2D.cs.

◆ CreateInstance() [1/2]

static RoomNode2D CreateInstance ( PackedScene  scene,
Node  parent,
LayoutPack  layoutPack,
Room  roomLayout,
RoomState  roomState,
uint  cellCollisionMask,
bool  assignLayoutPosition 
)
static

Creates and initializes an instance of a room.

Parameters
sceneThe room scene.
parentThe node to which the room will be added as a child.
layoutPackThe layout pack..
roomLayoutThe room's layout.
roomStateThe room's state.
cellCollisionMaskThe cell collision mask.
assignLayoutPositionIf true, the position of the room will be set to that of the room layout. Otherwise, it will be initialized at its original position.

Definition at line 200 of file RoomNode2D.cs.

◆ CreateInstance() [2/2]

static RoomNode2D CreateInstance ( Uid  id,
LayoutPack  layoutPack,
PackedScene  scene,
Node  parent,
bool  assignLayoutPosition = false 
)
static

Creates and initializes an instance of a room. The layout and layout state are assigned to the room based on the current ManiaMapManager.

Parameters
idThe room ID.
layoutPackThe layout pack.
sceneThe room scene.
parentThe node to which the room will be added as a child.
assignLayoutPositionIf true, the position of the room will be set to that of the room layout. Otherwise, it will be initialized at its original position.

Definition at line 182 of file RoomNode2D.cs.

◆ FindClosestActiveCellIndex()

Vector2I FindClosestActiveCellIndex ( Vector2  position)

Returns the closest active cell index to the specified global position.

Parameters
positionThe global position.

Definition at line 243 of file RoomNode2D.cs.

◆ FindClosestDoorDirection()

DoorDirection FindClosestDoorDirection ( int  row,
int  column,
Vector2  position 
)

Returns the closest door direction based on the cell index and specified global position. The nearest direction is determined based on the change between the specified position and cell center.

Parameters
rowThe cell row.
columnThe cell column.
positionThe global position.

Definition at line 283 of file RoomNode2D.cs.

◆ GlobalPositionToCellIndex()

Vector2I GlobalPositionToCellIndex ( Vector2  position)

Returns the row (x) and column (y) index corresponding to the specified global position. If the position is outside the room bounds, returns Vector2I(-1, -1).

Parameters
positionThe global position.

Definition at line 371 of file RoomNode2D.cs.

◆ Initialize()

bool Initialize ( LayoutPack  layoutPack,
Room  roomLayout,
RoomState  roomState,
uint  cellCollisionMask,
bool  assignLayoutPosition 
)

Initializes the room. The room should be initialized before adding it to the scene tree since cell children often require this information on ready.

If the room has already been initialized, no action is taken, and this method returns false. Othwerwise, it returns true.

Parameters
layoutPackThe layout pack.
roomLayoutThe room's layout.
roomStateThe room's state.
cellCollisionMaskThe cell collision mask.
assignLayoutPositionIf true, the position of the room will be set to that of the room layout. Otherwise, it will be initialized at its original position.

Definition at line 221 of file RoomNode2D.cs.

◆ LocalPositionToCellIndex()

Vector2I LocalPositionToCellIndex ( Vector2  position)

Returns the row (x) and column (y) index corresponding to the specified local position. If the position is outside the room bounds, returns Vector2I(-1, -1).

Parameters
positionThe local position.

Definition at line 381 of file RoomNode2D.cs.

◆ MoveToLayoutPosition()

void MoveToLayoutPosition ( )

Moves the room to its position in the Layout.

Definition at line 340 of file RoomNode2D.cs.

◆ OnCellAreaEnteredEventHandler()

delegate void OnCellAreaEnteredEventHandler ( CellArea2D  cell,
Node  collision 
)

Signal emitted when a cell area is entered by a tracked area or body.

Parameters
cellThe entered cell.
collisionThe entering object.

◆ OnCellAreaExitedEventHandler()

delegate void OnCellAreaExitedEventHandler ( CellArea2D  cell,
Node  collision 
)

Signal emitted when a cell area is exited by a tracked area or body.

Parameters
cellThe exited cell.
collisionThe exiting object.

◆ SetCellSizeField()

void SetCellSizeField ( ref Vector2  field,
Vector2  value 
)
private

Definition at line 84 of file RoomNode2D.cs.

◆ SetSizeField()

void SetSizeField ( ref int  field,
int  value 
)
private

Definition at line 77 of file RoomNode2D.cs.

Member Data Documentation

◆ _cellSize

Vector2 _cellSize = new Vector2(96, 96)
private

Definition at line 51 of file RoomNode2D.cs.

◆ _columns

int _columns = 1
private

Definition at line 47 of file RoomNode2D.cs.

◆ _rows

int _rows = 1
private

Definition at line 43 of file RoomNode2D.cs.

Property Documentation

◆ ActiveCells

Godot.Collections.Array<Godot.Collections.Array<bool> > ActiveCells = new Godot.Collections.Array<Godot.Collections.Array<bool>>()
getset

Definition at line 58 of file RoomNode2D.cs.

◆ CellSize

Vector2 CellSize
getset

The width and height of the room cells.

Definition at line 55 of file RoomNode2D.cs.

◆ Columns

int Columns
getset

Definition at line 49 of file RoomNode2D.cs.

◆ IsInitialized

bool IsInitialized
getprivate set

Definition at line 70 of file RoomNode2D.cs.

◆ LayoutPack

LayoutPack LayoutPack
getprivate set

Definition at line 61 of file RoomNode2D.cs.

◆ RoomLayout

Room RoomLayout
getprivate set

Definition at line 64 of file RoomNode2D.cs.

◆ RoomState

RoomState RoomState
getprivate set

Definition at line 67 of file RoomNode2D.cs.

◆ RoomTemplate

RoomTemplateResource RoomTemplate
getset

Definition at line 41 of file RoomNode2D.cs.

◆ Rows

int Rows
getset

Definition at line 45 of file RoomNode2D.cs.


The documentation for this class was generated from the following file: