Class AchievementStateCache
The in-memory answer to "what has this player unlocked, and how far along is everything else". Every read on the achievement service is served from here, because the backend may be a network call and a HUD cannot await one.
Inherited Members
Namespace: Serenity.Achievements.Application.Services
Assembly: Serenity.Achievements.Application.dll
Syntax
public class AchievementStateCache
Remarks
Rows for achievements the project no longer declares are dropped on hydrate rather than kept: a stored row from an older build has no definition to render, score or unlock, and carrying it would put a phantom into every listing and into the point total. Not thread-safe on its own — AchievementService owns the mutation gate that serializes access to it.
Constructors
AchievementStateCache(AchievementRegistry)
Initializes a new instance of the AchievementStateCache class.
Declaration
public AchievementStateCache(AchievementRegistry registry)
Parameters
| Type | Name | Description |
|---|---|---|
| AchievementRegistry | registry | The achievements this project declares. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
Properties
TotalPoints
The points the recorded unlocks add up to.
Declaration
public int TotalPoints { get; }
Property Value
| Type | Description |
|---|---|
| int |
UnlockedIds
The achievements currently recorded as unlocked.
Declaration
public IEnumerable<AchievementId> UnlockedIds { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<AchievementId> |
Methods
Clear()
Forgets every unlock and every progress row.
Declaration
public void Clear()
CollectPendingPlatformSync()
The unlocks the platform has not accepted yet, paired with the definition each belongs to — the offline queue the next sync pass drains.
Declaration
public IReadOnlyList<KeyValuePair<AchievementDefinition, AchievementUnlockRecord>> CollectPendingPlatformSync()
Returns
| Type | Description |
|---|---|
| IReadOnlyList<KeyValuePair<AchievementDefinition, AchievementUnlockRecord>> |
HydrateFrom(IReadOnlyList<AchievementUnlockRecord>, IReadOnlyList<AchievementProgress>)
Replaces the whole cache with what the store returned, dropping undeclared rows.
Declaration
public void HydrateFrom(IReadOnlyList<AchievementUnlockRecord> records, IReadOnlyList<AchievementProgress> progressRows)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<AchievementUnlockRecord> | records | The stored unlock records. |
| IReadOnlyList<AchievementProgress> | progressRows | The stored progress rows. |
IsUnlocked(AchievementId)
Whether an achievement is recorded as unlocked.
Declaration
public bool IsUnlocked(AchievementId achievement)
Parameters
| Type | Name | Description |
|---|---|---|
| AchievementId | achievement | The achievement to test. |
Returns
| Type | Description |
|---|---|
| bool |
ReadProgressOrEmpty(AchievementId, long)
Reads the tracked progress, restated against the definition's current target. A stored row carries the target that was authored when it was written, so a designer who retunes the target would otherwise keep measuring old runs against the old denominator.
Declaration
public AchievementProgress ReadProgressOrEmpty(AchievementId achievement, long target)
Parameters
| Type | Name | Description |
|---|---|---|
| AchievementId | achievement | The achievement to read. |
| long | target | The target the definition declares today. |
Returns
| Type | Description |
|---|---|
| AchievementProgress |
SetProgress(AchievementProgress)
Records progress, replacing whatever was held for that achievement.
Declaration
public void SetProgress(AchievementProgress progress)
Parameters
| Type | Name | Description |
|---|---|---|
| AchievementProgress | progress | The progress to hold. |
SetUnlock(AchievementUnlockRecord)
Records an unlock, replacing whatever was held for that achievement.
Declaration
public void SetUnlock(AchievementUnlockRecord record)
Parameters
| Type | Name | Description |
|---|---|---|
| AchievementUnlockRecord | record | The record to hold. |
TryGetProgress(AchievementId, out AchievementProgress)
Reads the tracked progress of an achievement.
Declaration
public bool TryGetProgress(AchievementId achievement, out AchievementProgress progress)
Parameters
| Type | Name | Description |
|---|---|---|
| AchievementId | achievement | The achievement to look up. |
| AchievementProgress | progress | The tracked progress, when one exists. |
Returns
| Type | Description |
|---|---|
| bool |
TryGetUnlock(AchievementId, out AchievementUnlockRecord)
Reads the unlock record of an achievement.
Declaration
public bool TryGetUnlock(AchievementId achievement, out AchievementUnlockRecord record)
Parameters
| Type | Name | Description |
|---|---|---|
| AchievementId | achievement | The achievement to look up. |
| AchievementUnlockRecord | record | The unlock record, when the achievement is unlocked. |
Returns
| Type | Description |
|---|---|
| bool |