Class GameStateBase
An abstract base class used to implement IGameState from a method to retrieve game objects.
Implements
Inherited Members
Namespace: Microsoft.XboxStudios.GameStateTracker
Assembly: GameStateTracker.Core.dll
Syntax
public abstract class GameStateBase : StateBase<ObjectInfo, IGameObject>, IDisposable, IGameState, IState<ObjectInfo, IGameObject>, IReadOnlyCollection<IGameObject>, IEnumerable<IGameObject>, IEnumerable, IEventAggregator<IGameEventArgs>, IEventPublisher<IGameEventArgs>, IHasUpdateTime
Constructors
View SourceGameStateBase(ILogger<GameStateBase>?, IGameObjectCache?)
Initializes a new instance of the GameStateBase class.
Declaration
protected GameStateBase(ILogger<GameStateBase>? logger = null, IGameObjectCache? cache = null)
Parameters
Type | Name | Description |
---|---|---|
ILogger<GameStateBase> | logger | The logger to use. |
IGameObjectCache | cache | The cache to use to store game objects. |
Properties
View SourceEventAggregator
Gets or sets the game event aggregator.
Declaration
protected IEventAggregator<IGameEventArgs>? EventAggregator { get; set; }
Property Value
Type | Description |
---|---|
IEventAggregator<IGameEventArgs> |
GameCache
Gets the cache of game objects.
Declaration
protected IGameObjectCache GameCache { get; }
Property Value
Type | Description |
---|---|
IGameObjectCache |
RecentEvents
Gets a read-only list of recent game events.
Declaration
public IReadOnlyList<IGameEventArgs> RecentEvents { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<IGameEventArgs> |
Methods
View SourceClear(ObjectInfo?)
Removes an object from the cache.
Declaration
public bool Clear(ObjectInfo? info)
Parameters
Type | Name | Description |
---|---|---|
ObjectInfo? | info | The object info. |
Returns
Type | Description |
---|---|
bool | True if the object was removed. |
ClearAll<T>(params string?[])
Removes all cached objects derived from the given class names.
Declaration
public virtual void ClearAll<T>(params string?[] classNames) where T : IGameObject
Parameters
Type | Name | Description |
---|---|---|
string[] | classNames | The class names. |
Type Parameters
Name | Description |
---|---|
T | The game object type. |
ClearEvents()
Clears the list of game events.
Declaration
public virtual void ClearEvents()
ExistingAll<T>(string?)
Gets all cached game objects derived from the given type and class name.
Declaration
public virtual IEnumerable<T> ExistingAll<T>(string? className = null) where T : IGameObject
Parameters
Type | Name | Description |
---|---|---|
string | className | The class name. If null, no class filter is applied. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An enumerable of game objects. |
Type Parameters
Name | Description |
---|---|
T | The game object type. |
Existing<T>(ObjectInfo?)
Gets a cached game object with the given info.
Declaration
public T? Existing<T>(ObjectInfo? info = null) where T : class, IGameObject
Parameters
Type | Name | Description |
---|---|---|
ObjectInfo? | info | The object info. |
Returns
Type | Description |
---|---|
T | A game object. |
Type Parameters
Name | Description |
---|---|
T | The game object type. |
GetAll<T>(ObjectInfo, TimeSpan, CancellationToken)
Retrieves all objects matching the given query.
Declaration
public Task<IEnumerable<T>> GetAll<T>(ObjectInfo query, TimeSpan maxAge, CancellationToken token = default) where T : IGameObject
Parameters
Type | Name | Description |
---|---|---|
ObjectInfo | query | The objects to look for. |
TimeSpan | maxAge | The maximum age of the objects, if they exist in the cache. |
CancellationToken | token | The cancellation token. |
Returns
Type | Description |
---|---|
Task<IEnumerable<T>> | An enumerable of objects. |
Type Parameters
Name | Description |
---|---|
T | The object type. |
GetAll<T>(string, TimeSpan, CancellationToken)
Retrieves all game objects derived from the given class name.
Declaration
public virtual Task<IEnumerable<T>> GetAll<T>(string className, TimeSpan maxAge, CancellationToken token = default) where T : IGameObject
Parameters
Type | Name | Description |
---|---|---|
string | className | The class name. |
TimeSpan | maxAge | The maximum age of the objects, if they exist in the cache. |
CancellationToken | token | The cancellation token. |
Returns
Type | Description |
---|---|
Task<IEnumerable<T>> | An enumerable of game objects. |
Type Parameters
Name | Description |
---|---|
T | The game object type. |
GetAll<T>(TimeSpan, CancellationToken)
Retrieves all game objects derived from the given object type.
Declaration
public virtual Task<IEnumerable<T>> GetAll<T>(TimeSpan maxAge, CancellationToken token = default) where T : IGameObject
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | maxAge | The maximum age of the object, if it exists in the cache. |
CancellationToken | token | The cancellation token. |
Returns
Type | Description |
---|---|
Task<IEnumerable<T>> | An enumerable of game objects. |
Type Parameters
Name | Description |
---|---|
T | The game object type. |
GetObject(ObjectInfo, CancellationToken)
Retrieves an object matching the given query.
Declaration
protected override Task<IGameObject?> GetObject(ObjectInfo query, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
ObjectInfo | query | The objects to look for. |
CancellationToken | token | The cancellation token. |
Returns
Type | Description |
---|---|
Task<IGameObject> | An object. |
Overrides
View SourceGetObjects(ObjectInfo, CancellationToken)
Retrieves all objects matching the given query.
Declaration
protected abstract Task<IEnumerable<IGameObject>> GetObjects(ObjectInfo query, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
ObjectInfo | query | The objects to look for. |
CancellationToken | token | The cancellation token. |
Returns
Type | Description |
---|---|
Task<IEnumerable<IGameObject>> | An enumeration of objects. |
Get<T>(ObjectInfo, TimeSpan, CancellationToken)
Retrieves an object.
Declaration
public virtual Task<T?> Get<T>(ObjectInfo query, TimeSpan maxAge, CancellationToken token = default) where T : class, IGameObject
Parameters
Type | Name | Description |
---|---|---|
ObjectInfo | query | The object to look for. |
TimeSpan | maxAge | The maximum age of the object, if it exists in the cache. |
CancellationToken | token | The cancellation token. |
Returns
Type | Description |
---|---|
Task<T> | The object. |
Type Parameters
Name | Description |
---|---|
T | The object type. |
Match(IGameObject, in ObjectInfo)
Determines if the game object matches the given query.
Declaration
protected virtual bool Match(IGameObject input, in ObjectInfo query)
Parameters
Type | Name | Description |
---|---|---|
IGameObject | input | The game object. |
ObjectInfo | query | The query. |
Returns
Type | Description |
---|---|
bool | True if the game object matches the given query. |
Match(IGameObject, string)
Determines if the game object has the given class name.
Declaration
protected virtual bool Match(IGameObject input, string className)
Parameters
Type | Name | Description |
---|---|---|
IGameObject | input | The game object. |
string | className | The class name. |
Returns
Type | Description |
---|---|
bool | True if the game object's class name matches the given name. |
PublishEvent(object?, IGameEventArgs)
Publishes a game event.
Declaration
protected void PublishEvent(object? sender, IGameEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
object | sender | The event source. |
IGameEventArgs | e | The game event. |
Set(in ObjectInfo, IGameObject?)
Stores or removes an object.
Declaration
protected override void Set(in ObjectInfo info, IGameObject? value)
Parameters
Type | Name | Description |
---|---|---|
ObjectInfo | info | The object information. |
IGameObject | value | The object to store. If null, the object is removed. |
Overrides
Events
View SourceEventReceived
Occurs when a game event is published.
Declaration
public event EventHandler<IGameEventArgs>? EventReceived
Event Type
Type | Description |
---|---|
EventHandler<IGameEventArgs> |