Add lobby and pack concept.

This commit is contained in:
Greyson Parrelli
2026-07-23 22:01:54 -04:00
parent 9d9acc4577
commit e74f983470
18 changed files with 665 additions and 111 deletions
+17 -3
View File
@@ -33,7 +33,7 @@ func TestE2EBotGame(t *testing.T) {
defer cancel()
resp, err := http.Post(ts.URL+"/api/games", "application/json",
bytes.NewBufferString(`{"name":"Human","bot":"easy"}`))
bytes.NewBufferString(`{"name":"Human"}`))
if err != nil {
t.Fatal(err)
}
@@ -51,9 +51,23 @@ func TestE2EBotGame(t *testing.T) {
}
defer ws.Close(websocket.StatusNormalClosure, "")
v := readState(t, ctx, ws)
// The host opens in the lobby, adds a bot, then starts the game — the
// unified lobby flow a real client drives.
if p := readState(t, ctx, ws).Phase; p != game.PhaseLobby {
t.Fatalf("phase = %s, want lobby on create", p)
}
send(t, ctx, ws, map[string]any{"type": "addBot", "difficulty": "easy"})
send(t, ctx, ws, map[string]any{"type": "start"})
var v *game.View
startDeadline := time.Now().Add(5 * time.Second)
for (v == nil || v.Phase != game.PhaseShop) && time.Now().Before(startDeadline) {
rctx, rcancel := context.WithTimeout(ctx, 3*time.Second)
v = readState(t, rctx, ws)
rcancel()
}
if v.Phase != game.PhaseShop {
t.Fatalf("phase = %s, want shop (bot fills the lobby instantly)", v.Phase)
t.Fatalf("phase = %s, want shop after host starts", v.Phase)
}
var bot *game.PlayerView
for i := range v.Players {