Delta state system: replace full-push with game.state_delta

After any game action, push a structured GameStateDelta instead of
the full GameStateDto to both players and spectators. Full state is
preserved for: initial connect (game.ready), reconnect/get_state,
spectate ACK, and turn-timer expiry.

Server:
- GameMessages.cs: add GameStateDeltaPush, GameStateDelta, TileDelta,
  UnitDelta, PlayerStatsDelta, GameMetaDelta record types
- GameEngine.cs: make ToCardDto internal (used by differ)
- GameStateDiffer.cs: new file — ComputeDelta (viewer-specific) and
  ComputeSpectatorDelta; diffs tiles, field units, hands, discards,
  archs, player stats, and game meta
- GameHandlerBase.cs: PushStateToPlayersAsync gains optional prevState
  param; when provided pushes delta, else falls back to full push
- All 10 action handlers: pass prev state to PushStateToPlayersAsync

Client:
- Game.gd: _state_version tracking, _apply_delta, _merge_unit_delta,
  request_sync, game.state_delta push handler with auto-resync on gap
- in_game_settings.gd + InGameSettings.tscn: Request Sync button

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-21 06:54:33 -04:00
co-authored by Claude Happy
parent c93aaf64c0
commit cf5089ae50
17 changed files with 735 additions and 43 deletions
+72
View File
@@ -389,6 +389,78 @@ public sealed record LobbyRuleSuggestionPush(
/// <summary>Pushed to the guest when the host rejects their rule suggestion.</summary>
public sealed record LobbyRuleSuggestionRejectedPush(Guid LobbyId);
/// <summary>
/// Pushed to each viewer after any game action that changes state.
/// Replaces the full <see cref="GameStateUpdatePush"/> for incremental updates.
/// </summary>
public sealed record GameStateDeltaPush(GameStateDelta Delta);
/// <summary>
/// Viewer-specific state delta. Null collections mean no change for that category.
/// Own hand is shown in full; opponent hand = count only.
/// </summary>
public sealed record GameStateDelta(
int StateVersion,
IReadOnlyList<TileDelta>? ChangedTiles,
IReadOnlyList<CardInstanceDto>? AddedUnits,
IReadOnlyList<string>? RemovedUnitIds,
IReadOnlyList<UnitDelta>? ChangedUnits,
IReadOnlyList<CardInstanceDto>? HandAdded,
IReadOnlyList<string>? HandRemovedIds,
IReadOnlyList<CardInstanceDto>? DiscardAdded,
int? OpponentHandCount,
int? OpponentDeckCount,
UnitDelta? OwnArchSpiritDelta,
UnitDelta? OpponentArchSpiritDelta,
PlayerStatsDelta? OwnStatsDelta,
PlayerStatsDelta? OpponentStatsDelta,
GameMetaDelta? MetaDelta);
public sealed record TileDelta(
int X,
int Y,
string? Base1,
string? Base2,
string? ResolvedAffinity,
string? OccupantId,
bool OccupantCleared,
string? OccupantOwner,
string? RuinId,
bool RuinCleared,
string? RuinOwner);
public sealed record UnitDelta(
string InstanceId,
int? CurrentHealth,
int? MaxHealth,
int? CurrentDefense,
int? MaxDefense,
int? Damage,
bool? IsExhausted,
bool? CanMove,
bool? CanAttack,
bool? CanBeAttacked,
bool? CanUseAbility,
int? CurrentMp,
int? MaxMp,
int? ExtraAttacksRemaining,
CoordDto? Position,
string? EffectsJson,
string? AbilitiesJson,
string? AbilityUsesJson);
public sealed record PlayerStatsDelta(
int? CurrentSp,
int? CurrentSt,
int? DeckCount,
int? HandCount,
int? DiscardCount);
public sealed record GameMetaDelta(
string? Phase,
string? ActivePlayerAccountId,
int? TurnNumber);
// ── DTOs ─────────────────────────────────────────────────────────────────────
/// <summary>