QueryKeyNames
Public static class of string constants that build the param key names. The constants are used to create ParamKey instances in QueryKeys.
public static class QueryKeyNames
{
public const string QuerySubject; // "core.query.query.subject"
public const string TimeInLevel; // "core.query.time.level"
public const string CurrentLevel; // "core.query.current.level"
public const string GameSpeed; // "core.query.game.speed"
public const string CurrentPlatformType; // "core.query.current.platformType"
}QueryKeys
Public static class of typed parameter keys used in query params.
public static class QueryKeys
{
/// Result key for the current runtime platform. Filled by the owning domain handler.
public static readonly ParamKey<RuntimePlatform> CurrentPlatformType;
/// Result key for how long the player has been in the level. Filled by the Level domain handler.
public static readonly ParamKey<float> TimeInLevel;
/// Result key for the level the player is on.
public static readonly ParamKey<int> CurrentLevel;
/// Key for the current game speed value. Read as a result by QueryFactory.GetGameSpeed.
public static readonly ParamKey<float> GameSpeed;
/// Input key for the subject a query pertains to.
public static readonly ParamKey<QuerySubjects> QuerySubject;
}Query
Public class. A read-only message addressed to a domain. Implements IQuery.
public class Query : IQuery
{
public Domain TargetDomain { get; }
public QueryVerb Verb { get; }
public Params Params { get; }
public Params Result { get; }
public QueryStatus Status { set; get; }
public Query(Domain targetDomain, QueryVerb verb);
}| Member | Description |
|---|---|
TargetDomain | The domain of the system the query is addressed to. Used by the query bus for routing. |
Verb | What the query asks for. |
Params | Input data, set by the caller before sending. Created empty. |
Result | Answer data, set by the handling system. Empty until answered. Created empty. |
Status | Starts as QueryStatus.Pending. The handling system may set it. |
Query(Domain, QueryVerb) | Creates a query for the given domain and verb. |
IQuery
Public interface that defines the query contract. Handlers that receive a query use this interface.
public interface IQuery
{
Domain TargetDomain { get; }
QueryVerb Verb { get; }
Params Params { get; }
Params Result { get; }
QueryStatus Status { set; get; }
}| Member | Description |
|---|---|
TargetDomain | The domain the query is addressed to. The query bus routes by this value. |
Verb | What the query asks for. Its meaning is decided by the handling system. |
Params | Input data describing the request. |
Result | Answer data filled in by the handling system. |
Status | Query status. Settable by the handling system. |
QueryFactory
Public static class. Builds and sends the shared queries and returns their typed answers.
public static class QueryFactory
{
/// Queries Domain.Release for the current runtime platform.
public static RuntimePlatform GetCurrentPlatform();
/// Queries Domain.Level for how long the player has been in the current level.
public static float GetTimeInLevel();
/// Queries Domain.Game for the level the player is currently on.
public static int GetCurrentLevel();
/// Queries Domain.Game for the current game speed.
public static float GetGameSpeed();
}| Method | Target domain | Subject | Returns |
|---|---|---|---|
GetCurrentPlatform | Domain.Release | QuerySubjects.Platform | RuntimePlatform |
GetTimeInLevel | Domain.Level | QuerySubjects.Time | float |
GetCurrentLevel | Domain.Game | QuerySubjects.Level | int |
GetGameSpeed | Domain.Game | QuerySubjects.Speed | float |
QueryVerb
Public enum. What a query asks for. The handling system decides the exact meaning within its domain.
public enum QueryVerb
{
Get = 0, // Asks for data from the target domain.
Own = 1, // Asks whether the player owns something, such as a purchased item.
Has = 2 // Asks whether something exists in the target domain.
}Note:
QueryFactoryuses onlyGet. No code in these blocks sendsOwnorHas.
QueryStatus
Public enum. The status of a query, set by the handling system. Yes-or-no queries answer through it, with Success meaning yes and Failure meaning no.
public enum QueryStatus
{
Pending = 0, // Not yet answered.
Success = 1, // Answered positively.
Failure = 2 // Answered negatively, or could not be answered.
}QuerySubjects
Public enum. What a query asks about within its target domain. Stored in the input params under QueryKeys.QuerySubject.
public enum QuerySubjects
{
Platform, // The platform the application is running on.
Time, // Time-related data, such as how long something has been running.
Level, // Level-related data, such as which level is active.
Speed // Speed-related data, such as how fast the game is running.
}