Class GameProgressService
Default IGameProgressService implementation. Holds the current progress as an in-memory cache, mutated through immutable GameProgressData replacements, and delegates persistence to an injected IGameProgressStore. Broadcasts completion/unlock/change signals through an optional event dispatcher.
Inherited Members
Namespace: Serenity.GameProgress.Application.Services
Assembly: Serenity.GameProgress.Application.dll
Syntax
public class GameProgressService : IGameProgressService, IService, IFoundationSettings
Constructors
GameProgressService(IGameProgressStore, IEventDispatcherService, ILogService)
Initializes a new instance of the GameProgressService class.
Declaration
public GameProgressService(IGameProgressStore store, IEventDispatcherService eventDispatcherService, ILogService logService)
Parameters
| Type | Name | Description |
|---|---|---|
| IGameProgressStore | store | Backend store used to persist and load game progress. |
| IEventDispatcherService | eventDispatcherService | Dispatcher used to broadcast GameCompletedSignal, ExtraUnlockedSignal
and GameProgressChangedSignal. May be |
| ILogService | logService | Logging service. May be |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
Properties
Guid
Declaration
public string Guid { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Id
Declaration
public string Id { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
LogService
Declaration
public ILogService LogService { get; set; }
Property Value
| Type | Description |
|---|---|
| ILogService |
Methods
GetCustomPayload()
Gets the current custom JSON payload, or null when none is set.
Declaration
public virtual string GetCustomPayload()
Returns
| Type | Description |
|---|---|
| string |
GetProgress()
Gets the current, in-memory game progress.
Declaration
public virtual GameProgressData GetProgress()
Returns
| Type | Description |
|---|---|
| GameProgressData |
GetUnlockedExtras()
Gets every currently unlocked extra id.
Declaration
public virtual IReadOnlyList<string> GetUnlockedExtras()
Returns
| Type | Description |
|---|---|
| IReadOnlyList<string> |
IncrementCompletionCount()
Increments the completion count by one and dispatches the corresponding signals.
Declaration
public virtual void IncrementCompletionCount()
IsExtraUnlocked(string)
Checks whether an extra is unlocked.
Declaration
public virtual bool IsExtraUnlocked(string extraId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | extraId | The extra's identifier. |
Returns
| Type | Description |
|---|---|
| bool | True if the extra is unlocked; otherwise false. |
LoadAsync(CancellationToken)
Loads progress from the configured store into the in-memory cache.
Declaration
public virtual Task LoadAsync(CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | Token used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task |
PersistAsync(CancellationToken)
Persists the current in-memory progress through the configured store.
Declaration
public virtual Task PersistAsync(CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | Token used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task |
SetCustomPayload(string)
Replaces the custom JSON payload escape hatch.
Declaration
public virtual void SetCustomPayload(string json)
Parameters
| Type | Name | Description |
|---|---|---|
| string | json | The new payload. May be null. |
UnlockExtra(string)
Unlocks an extra by id. Idempotent: unlocking an already-unlocked extra is a no-op.
Declaration
public virtual void UnlockExtra(string extraId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | extraId | The extra's identifier. Null or empty is ignored. |