refactor(runtime): expose canonical gameplay state

Move character options and movement skills into the Runtime-owned character graph, expose borrowed inventory, character, and social views, and route retained UI state commands through generation-gated typed Runtime contracts. Preserve the existing synchronous wire path while deleting the App-owned option and skill mirrors and extending normalized parity checkpoints.

Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-26 09:12:30 +02:00
parent 9d0d9b07e0
commit dcb61efb5a
34 changed files with 2076 additions and 103 deletions

View file

@ -12,6 +12,7 @@ namespace AcDream.Core.Items;
public sealed class ItemManaState
{
private readonly ConcurrentDictionary<uint, float> _manaByGuid = new();
private long _revision;
/// <summary>Fires for every valid or invalid query response.</summary>
public event Action<uint /*guid*/, float /*fraction*/, bool /*valid*/>? ItemManaChanged;
@ -20,6 +21,11 @@ public sealed class ItemManaState
_manaByGuid.TryGetValue(guid, out float percent) ? percent : 0f;
public bool HasMana(uint guid) => _manaByGuid.ContainsKey(guid);
public int Count => _manaByGuid.Count;
public long Revision => Interlocked.Read(ref _revision);
public bool TryGetManaPercent(uint guid, out float fraction) =>
_manaByGuid.TryGetValue(guid, out fraction);
public void OnQueryItemManaResponse(uint itemGuid, float manaPercent, bool valid)
{
@ -28,8 +34,13 @@ public sealed class ItemManaState
else
_manaByGuid.TryRemove(itemGuid, out _);
Interlocked.Increment(ref _revision);
ItemManaChanged?.Invoke(itemGuid, manaPercent, valid);
}
public void Clear() => _manaByGuid.Clear();
public void Clear()
{
_manaByGuid.Clear();
Interlocked.Increment(ref _revision);
}
}

View file

@ -5,12 +5,29 @@ public sealed class FriendsState
{
private readonly object _gate = new();
private readonly List<FriendEntry> _entries = new();
private long _revision;
public int Count
{
get { lock (_gate) return _entries.Count; }
}
public long Revision => Interlocked.Read(ref _revision);
public IReadOnlyList<FriendEntry> Snapshot()
{
lock (_gate) return _entries.ToArray();
}
public bool TryGet(uint characterId, out FriendEntry? friend)
{
lock (_gate)
{
friend = _entries.Find(candidate => candidate.Id == characterId);
return friend is not null;
}
}
public void Apply(FriendsUpdate update)
{
ArgumentNullException.ThrowIfNull(update);
@ -43,12 +60,17 @@ public sealed class FriendsState
}
break;
}
Interlocked.Increment(ref _revision);
}
}
public void Clear()
{
lock (_gate) _entries.Clear();
lock (_gate)
{
_entries.Clear();
Interlocked.Increment(ref _revision);
}
}
}

View file

@ -5,6 +5,9 @@ public sealed class SquelchState
{
private readonly object _gate = new();
private SquelchDatabase _database = SquelchDatabase.Empty;
private long _revision;
public long Revision => Interlocked.Read(ref _revision);
public SquelchDatabase Snapshot()
{
@ -14,7 +17,11 @@ public sealed class SquelchState
public void Replace(SquelchDatabase database)
{
ArgumentNullException.ThrowIfNull(database);
lock (_gate) _database = database;
lock (_gate)
{
_database = database;
Interlocked.Increment(ref _revision);
}
}
/// <summary>
@ -25,7 +32,11 @@ public sealed class SquelchState
/// </summary>
public void Clear()
{
lock (_gate) _database = SquelchDatabase.Empty;
lock (_gate)
{
_database = SquelchDatabase.Empty;
Interlocked.Increment(ref _revision);
}
}
}