Class GenericGameState
A class used to implement IGameState from a generic object repository and class manager.
Inheritance
Implements
Inherited Members
Namespace: Microsoft.XboxStudios.GameStateTracker.Generic
Assembly: GameStateTracker.Generic.dll
Syntax
public class GenericGameState : GameStateBase, IDisposable, IGenericGameState, IGameState, IState<ObjectInfo, IGameObject>, IReadOnlyCollection<IGameObject>, IEnumerable<IGameObject>, IEnumerable, IEventAggregator<IGameEventArgs>, IEventPublisher<IGameEventArgs>, IHasUpdateTime, IQueryResultConsumer<IGameObject>, IEventProcessor
Constructors
View SourceGenericGameState(IGenericGameObjectRepository, IClassManager?, ILogger<GenericGameState>?, IGameObjectCache?)
Initializes a new instance of the GenericGameState class.
Declaration
public GenericGameState(IGenericGameObjectRepository repository, IClassManager? classManager = null, ILogger<GenericGameState>? logger = null, IGameObjectCache? cache = null)
Parameters
Type | Name | Description |
---|---|---|
IGenericGameObjectRepository | repository | The generic object repository. |
IClassManager | classManager | The class manager. |
ILogger<GenericGameState> | logger | The logger to use. |
IGameObjectCache | cache | The cache to use to store game objects. |
Fields
View SourceGameStateChangedEventName
The event name for the repository to indicate that game objects have changed.
Declaration
public const string GameStateChangedEventName = "GameStateChanged"
Field Value
Type | Description |
---|---|
string |
Properties
View SourceClassManager
Gets the class manager.
Declaration
public IClassManager ClassManager { get; }
Property Value
Type | Description |
---|---|
IClassManager |
Repository
Gets the generic game object repository.
Declaration
protected IGenericGameObjectRepository Repository { get; }
Property Value
Type | Description |
---|---|
IGenericGameObjectRepository |
Methods
View SourceCheckQueryResultChangesGameClass(in QueryResult)
Checks whether the query result changes the class to convert a game object to.
Declaration
protected virtual bool CheckQueryResultChangesGameClass(in QueryResult result)
Parameters
Type | Name | Description |
---|---|---|
QueryResult | result | The query result. |
Returns
Type | Description |
---|---|
bool | True if the class is affected. |
ClearAll<T>(params string?[])
Removes all cached objects derived from the given class names.
Declaration
public override 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. |
Overrides
View SourceClear<T>(ObjectInfo?)
Removes an object from the cache.
Declaration
public virtual bool Clear<T>(ObjectInfo? info)
Parameters
Type | Name | Description |
---|---|---|
ObjectInfo? | info | The object info. |
Returns
Type | Description |
---|---|
bool | True if the object was removed. |
Type Parameters
Name | Description |
---|---|
T | The game object type. |
Existing(ObjectInfo)
Gets a cached object with the given info.
Declaration
public override IGameObject? Existing(ObjectInfo info)
Parameters
Type | Name | Description |
---|---|---|
ObjectInfo | info | The object info. |
Returns
Type | Description |
---|---|
IGameObject | The object. |
Overrides
View SourceExisting<T>(string?)
Gets a cached game object with the given type and object name.
Declaration
public virtual T? Existing<T>(string? objectName = null) where T : class, IGameObject
Parameters
Type | Name | Description |
---|---|---|
string | objectName | The object name. If null, there must be only one object with the given type. |
Returns
Type | Description |
---|---|
T | A game object. |
Type Parameters
Name | Description |
---|---|
T | The game object type. |
GetAll<T>(string, TimeSpan, CancellationToken)
Retrieves all game objects derived from the given class name.
Declaration
public override 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 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. |
Overrides
View SourceGetAll<T>(TimeSpan, CancellationToken)
Retrieves all game objects derived from the given class name.
Declaration
public override 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. |
Overrides
View SourceGetObjects(ObjectInfo, CancellationToken)
Retrieves all objects matching the given query.
Declaration
protected override 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. |
Overrides
View SourceGet<T>(ObjectInfo, TimeSpan, CancellationToken)
Retrieves an object.
Declaration
public override 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. |
Overrides
View SourceGet<T>(string?, TimeSpan, CancellationToken)
Retrieves an object.
Declaration
public Task<T?> Get<T>(string? objectName, TimeSpan maxAge, CancellationToken token = default) where T : class, IGameObject
Parameters
Type | Name | Description |
---|---|---|
string | objectName | 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. |
Get<T>(TimeSpan, CancellationToken)
Retrieves an object of the given type.
Declaration
public Task<T?> Get<T>(TimeSpan maxAge, CancellationToken token = default) where T : class, 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<T> | The object. |
Type Parameters
Name | Description |
---|---|
T | The object type. |
HandleGameStateChangedEvent(object?, IGameEventArgs)
Used to update the game state when the repository publishes an event with query results.
Declaration
protected virtual void HandleGameStateChangedEvent(object? sender, IGameEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
object | sender | The event sender. |
IGameEventArgs | e | The event. |
Match(IGameObject, string)
Determines if the game object has the given class name.
Declaration
protected override 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. |
Overrides
View SourceMergeResult(in QueryResult)
Transforms the query result into an object, and then adds the object to the cache.
Declaration
public virtual IGameObject MergeResult(in QueryResult item)
Parameters
Type | Name | Description |
---|---|---|
QueryResult | item | The query result. |
Returns
Type | Description |
---|---|
IGameObject | The object. |
ProcessEvents()
Processes the buffer of game events, clearing objects from the game state as needed.
Declaration
public virtual void ProcessEvents()