229c43beb5
Replaces the manual Submit button with an auto-sync pipeline driven by `OrderDraftStore`: every successful add / remove / move coalesces a `submitOrder` call so the engine always mirrors the local draft. Removing the last command sends an empty cmd[] PUT — the engine, repo, and rest model now accept that as a valid "player cleared their draft" state. `hydrateFromServer` is now invoked unconditionally on game boot so a fresh device picks up the player's stored order, and the local cache is overwritten by the server's view (server is the source of truth). Header replaces the static "race ?" + turn counter with a single headline string `<race> @ <game>, turn <n>`, sourced from the engine's Report.race + the lobby's GameSummary.gameName + the live turn number, with a `?` fallback while any piece is loading. Tests: - engine: empty PUT round-trips, repo round-trips empty Commands - order-draft: auto-sync sends full draft on every mutation, rejected response surfaces error sync status, rapid mutations coalesce, server hydration overwrites cache - order-tab: per-row status flips through the auto-sync lifecycle, remove → empty cmd[] PUT, rejected → retry button - inspector overlay: applied + valid + submitting all participate in the optimistic projection - header: live race / game / turn rendering with fall-back Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
24 lines
740 B
Go
24 lines
740 B
Go
package rest
|
|
|
|
import "encoding/json"
|
|
|
|
type Command struct {
|
|
Actor string `json:"actor" binding:"notblank"`
|
|
// Commands carries the engine-bound payload for either the
|
|
// command (`PUT /api/v1/command`, immediate) or the order
|
|
// (`PUT /api/v1/order`, validate-and-store) path. The order
|
|
// path treats an empty array as "the player has no orders for
|
|
// this turn" and stores it. The command handler still rejects
|
|
// an empty array by hand because immediate execution of a
|
|
// no-op makes no sense.
|
|
Commands []json.RawMessage `json:"cmd"`
|
|
}
|
|
|
|
func (o Command) MarshalBinary() (data []byte, err error) {
|
|
return json.Marshal(&o)
|
|
}
|
|
|
|
func (o *Command) UnmarshalBinary(data []byte) error {
|
|
return json.Unmarshal(data, o)
|
|
}
|