From 91f5ab45c5fdedc991f0bacdaabde72b7e2ab3d2 Mon Sep 17 00:00:00 2001 From: jbock Date: Mon, 7 Oct 2024 13:27:15 +0200 Subject: [PATCH] add field requests to OpenGame --- .../client/src/feature/lobby/LobbyPanel.jsx | 4 ++-- .../java/com/bernd/model/AcceptRequest.java | 5 +++++ src/main/java/com/bernd/model/OpenGame.java | 18 +++++++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/client/src/feature/lobby/LobbyPanel.jsx b/src/main/client/src/feature/lobby/LobbyPanel.jsx index 1ca9823..b1fdacb 100644 --- a/src/main/client/src/feature/lobby/LobbyPanel.jsx +++ b/src/main/client/src/feature/lobby/LobbyPanel.jsx @@ -37,7 +37,7 @@ function Panel() { }) return undefined }, [auth]) - return <> + return ( - + ) } diff --git a/src/main/java/com/bernd/model/AcceptRequest.java b/src/main/java/com/bernd/model/AcceptRequest.java index b394bca..db7aad1 100644 --- a/src/main/java/com/bernd/model/AcceptRequest.java +++ b/src/main/java/com/bernd/model/AcceptRequest.java @@ -1,7 +1,12 @@ package com.bernd.model; public record AcceptRequest( + String opponent, OpenGame game, boolean flip, int handicap) { + + public AcceptRequest withOpponent(String opponent) { + return new AcceptRequest(opponent, game, flip, handicap); + } } diff --git a/src/main/java/com/bernd/model/OpenGame.java b/src/main/java/com/bernd/model/OpenGame.java index e826361..ae111ba 100644 --- a/src/main/java/com/bernd/model/OpenGame.java +++ b/src/main/java/com/bernd/model/OpenGame.java @@ -1,22 +1,30 @@ package com.bernd.model; import com.bernd.game.MoveList; +import java.util.List; import static com.bernd.LobbyController.createEmptyBoard; public record OpenGame( String id, String user, + List requests, int dim, - int timesetting, - int handicap) { + int timesetting) { public OpenGame withId(String id) { - return new OpenGame(id, user, dim, timesetting, handicap); + return new OpenGame(id, user, requests, dim, timesetting).sanitize(); } - public OpenGame withUser(String name) { - return new OpenGame(id, name, dim, timesetting, handicap); + public OpenGame withUser(String user) { + return new OpenGame(id, user, requests, dim, timesetting).sanitize(); + } + + private OpenGame sanitize() { + if (requests == null) { + return new OpenGame(id, user, List.of(), dim, timesetting); + } + return this; } public Game accept(String opponent, AcceptRequest acceptRequest) {