KernelAPI reference
Class AchievementTracker
Namespace: MicroEngine.Core
Assembly: MicroEngine.Achievements.dll
Guide: Game lifecycle and time
Owns a game’s achievements: the catalog, progress, unlocking and persistence. Games decide when something happened and report it with Unlock, AddProgress or SetProgress; the tracker guarantees that an achievement unlocks (and raises Unlocked) exactly once, across sessions.
public sealed class AchievementTrackerInheritance
Remarks
State lives in the SaveSlot slot of the game’s SaveStore, so each game keeps its own file. Missing or corrupt data starts from scratch (the store keeps the corrupt file aside); a file that exists but cannot be read is never overwritten during that session. Entries for ids that are no longer in the catalog are kept untouched, and new catalog entries start locked. Unlocks are written at once; plain progress is written by Flush (the game loop calls it about once a second and on exit).
Constructors
AchievementTracker(IEnumerable<Achievement>, SaveStore?)
public AchievementTracker(IEnumerable<Achievement> catalog, SaveStore? store = null)Parameters
catalog IEnumerable<Achievement>
The game’s achievements, in display order.
store SaveStore?
Where progress persists; null keeps it in memory only.
Fields
SaveSlot
The SaveStore slot that holds achievement state: “achievements”.
public const string SaveSlot = "achievements"Field Value
Properties
All
Every achievement in catalog order.
public IReadOnlyList<AchievementStatus> All { get; }Property Value
IReadOnlyList<AchievementStatus>
Catalog
The achievements in display order.
public IReadOnlyList<Achievement> Catalog { get; }Property Value
Count
Number of achievements in the catalog.
public int Count { get; }Property Value
HasUnsavedChanges
True when progress changed since the last successful save.
public bool HasUnsavedChanges { get; }Property Value
UnlockedCount
Number of unlocked achievements in the catalog.
public int UnlockedCount { get; }Property Value
Methods
AddProgress(string, int)
Adds to an achievement’s progress; unlocks it when the goal is reached. Returns true only on that unlock.
public bool AddProgress(string id, int amount = 1)Parameters
id string
amount int
Returns
Flush()
Writes pending progress. Failures (read-only disk, unreadable existing file) keep it in memory and return false; the next call tries again.
public bool Flush()Returns
Get(string)
The current state of one achievement; progress is capped at its goal.
public AchievementStatus Get(string id)Parameters
id string
Returns
Exceptions
id is not in the catalog.
IsUnlocked(string)
Whether the achievement is unlocked.
public bool IsUnlocked(string id)Parameters
id string
Returns
Exceptions
id is not in the catalog.
Progress(string)
The achievement’s progress, from 0 to its goal.
public int Progress(string id)Parameters
id string
Returns
Exceptions
id is not in the catalog.
SetProgress(string, int)
Reports an absolute count (“rooms visited: 7”). Progress never goes down, so recounting after a new game cannot erase what was achieved before. Returns true only when this call unlocks it.
public bool SetProgress(string id, int value)Parameters
id string
value int
Returns
Unlock(string)
Unlocks an achievement now. Returns true only the first time.
public bool Unlock(string id)Parameters
id string
Returns
Unlocked
Raised once when an achievement becomes unlocked (never for ones loaded already unlocked).
public event Action<Achievement>? Unlocked