Class EntityManagerZoned
Manages a set of entities. Adds a render step and only renders the entities that are in the parent IScreenSurface visible area.
Inherited Members
Namespace: SadConsole.Entities
Assembly: SadConsole.Extended.dll
Syntax
[DataContract]
public class EntityManagerZoned : EntityManager, IList<Entity>, ICollection<Entity>, IEnumerable<Entity>, IEnumerable, IComponent
Constructors
EntityManagerZoned()
Creates a new manager to handle entity movement within zones.
Declaration
public EntityManagerZoned()
Fields
_zones
The zones in this manager.
Declaration
[DataMember(Name = "Zones")]
protected List<Zone> _zones
Field Value
Properties
Zones
The zones associated with this manager.
Declaration
public IReadOnlyList<Zone> Zones { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<Zone> |
Methods
Add(Zone)
Adds a zone to this manager.
Declaration
public void Add(Zone zone)
Parameters
Type | Name | Description |
---|---|---|
Zone | zone | The zone to add. |
Contains(Zone)
Checks if the manager contains the specified zone.
Declaration
public bool Contains(Zone zone)
Parameters
Type | Name | Description |
---|---|---|
Zone | zone | The zone to check for. |
Returns
Type | Description |
---|---|
bool |
DisableEntity(Entity)
Prevents an entity from being processed with the Zones.
Declaration
public void DisableEntity(Entity entity)
Parameters
Type | Name | Description |
---|---|---|
Entity | entity | The entity to disable. |
EnableEntity(Entity)
Enables the entity to be processed with with the Zones.
Declaration
public void EnableEntity(Entity entity)
Parameters
Type | Name | Description |
---|---|---|
Entity | entity | The entity to disable. |
GetEntitiesAtPosition(Point)
Returns an enumerator containing the entities, if any, at the specified position.
Declaration
public ListEnumerator<Entity> GetEntitiesAtPosition(Point position)
Parameters
Type | Name | Description |
---|---|---|
Point | position | The position to get an entity at. |
Returns
Type | Description |
---|---|
ListEnumerator<Entity> | An array of entities if they exist; otherwise null. |
GetEntitiesInZone(Zone)
Returns a list of entities that are located in the specified zone.
Declaration
public IReadOnlyList<Entity> GetEntitiesInZone(Zone zone)
Parameters
Type | Name | Description |
---|---|---|
Zone | zone | The zone to filter entities by. |
Returns
Type | Description |
---|---|
IReadOnlyList<Entity> | A list of entities. |
GetEntityAtPosition(Point)
Returns an entity at the specified position or null if there is no entity. If there are multiple entities at the specified position, only one of them is returned.
Declaration
public Entity? GetEntityAtPosition(Point position)
Parameters
Type | Name | Description |
---|---|---|
Point | position | The position to get an entity at. |
Returns
GetZonesAtPosition(Point)
Returns a collection of zones at the specified position.
Declaration
public Zone[] GetZonesAtPosition(Point position)
Parameters
Type | Name | Description |
---|---|---|
Point | position | The position to check for zones. |
Returns
Type | Description |
---|---|
Zone[] | Every zone that contains the position. |
GetZonesAtPosition(in Point, out HashSet<Zone>)
Gets the zones that contain the specified position.
Declaration
public bool GetZonesAtPosition(in Point point, out HashSet<Zone> zones)
Parameters
Type | Name | Description |
---|---|---|
Point | point | The position to check. |
HashSet<Zone> | zones | The zones that contain this position. |
Returns
HasEntityAt(Point)
Declaration
public bool HasEntityAt(Point position)
Parameters
Type | Name | Description |
---|---|---|
Point | position | The position to check. |
Returns
Type | Description |
---|---|
bool | A value indicating if an entity exists. |
IsEntityDisabled(Entity)
Returns true when the entity has been disabled by DisableEntity(Entity); otherwise false.
Declaration
public bool IsEntityDisabled(Entity entity)
Parameters
Type | Name | Description |
---|---|---|
Entity | entity | The entity to check. |
Returns
OnEntityAdded(Entity)
Adds entity state information to an entity when it's added.
Declaration
protected override void OnEntityAdded(Entity entity)
Parameters
Type | Name | Description |
---|---|---|
Entity | entity | The entity that was added. |
Overrides
OnEntityChangedPosition(Entity, ValueChangedEventArgs<Point>)
Called when an entity changes position.
Declaration
protected override void OnEntityChangedPosition(Entity entity, ValueChangedEventArgs<Point> e)
Parameters
Type | Name | Description |
---|---|---|
Entity | entity | The entity that moved. |
ValueChangedEventArgs<Point> | e | The previous and new values of the position. |
Overrides
OnEntityEnterZone(IScreenSurface, Zone, Entity, Point)
Called when an entity enters a zone and raises the EnterZone event.
Declaration
protected virtual void OnEntityEnterZone(IScreenSurface host, Zone zone, Entity entity, Point triggeredPosition)
Parameters
Type | Name | Description |
---|---|---|
IScreenSurface | host | The host that the zone and entity share. |
Zone | zone | The zone the entity entered. |
Entity | entity | The entity that entered the zone. |
Point | triggeredPosition | The position the entity entered. |
OnEntityExitZone(IScreenSurface, Zone, Entity, Point)
Called when an entity enters a zone and raises the ExitZone event.
Declaration
protected virtual void OnEntityExitZone(IScreenSurface host, Zone zone, Entity entity, Point triggeredPosition)
Parameters
Type | Name | Description |
---|---|---|
IScreenSurface | host | The host that the zone and entity share. |
Zone | zone | The zone the entity exited. |
Entity | entity | The entity that exited the zone. |
Point | triggeredPosition | The new position the entity left. |
OnEntityMoveZone(IScreenSurface, Zone, Entity, Point, Point)
Called when an entity moves within a zone.
Declaration
protected virtual void OnEntityMoveZone(IScreenSurface host, Zone zone, Entity entity, Point newPosition, Point oldPosition)
Parameters
Type | Name | Description |
---|---|---|
IScreenSurface | host | The host that the zone and entity share. |
Zone | zone | The zone the entity moved in. |
Entity | entity | The entity that moved in the zone. |
Point | newPosition | The position the entity moved to. |
Point | oldPosition | The position the entity moved from. |
OnEntityRemoved(Entity)
Removes the entity state information of an entity being removed.
Declaration
protected override void OnEntityRemoved(Entity entity)
Parameters
Type | Name | Description |
---|---|---|
Entity | entity | The entity that was removed. |
Overrides
Remove(Zone)
Removes a zone from this manager.
Declaration
public void Remove(Zone zone)
Parameters
Type | Name | Description |
---|---|---|
Zone | zone | The hotspot to remove. |
Events
EnterZone
An event to indicate that an entity entered a zone.
Declaration
public event EventHandler<EntityManagerZoned.ZoneEventArgs>? EnterZone
Event Type
Type | Description |
---|---|
EventHandler<EntityManagerZoned.ZoneEventArgs> |
ExitZone
An event to indicate that an entity exited a zone.
Declaration
public event EventHandler<EntityManagerZoned.ZoneEventArgs>? ExitZone
Event Type
Type | Description |
---|---|
EventHandler<EntityManagerZoned.ZoneEventArgs> |