diff --git a/src/main/client/src/feature/game/state.js b/src/main/client/src/feature/game/state.js index 385bf44..64345a3 100644 --- a/src/main/client/src/feature/game/state.js +++ b/src/main/client/src/feature/game/state.js @@ -35,6 +35,7 @@ export function initialState() { viewPos: Number.NaN, winnerByTime: 0, dim: 0, + timesetting: 0, handicap: 0, queueStatus: "behind", black: "", @@ -272,6 +273,7 @@ export function createGameState(game, auth) { black: game.black, white: game.white, dim: game.dim, + timesetting: game.timesetting, handicap: game.handicap, counting: counting, baseBoard: baseBoard, diff --git a/src/main/client/src/feature/lobby/Lobby.jsx b/src/main/client/src/feature/lobby/Lobby.jsx index f723bb0..1e63297 100644 --- a/src/main/client/src/feature/lobby/Lobby.jsx +++ b/src/main/client/src/feature/lobby/Lobby.jsx @@ -49,6 +49,20 @@ export function Lobby() { let stompClient = useContext(StompContext) let navigate = useNavigate() let auth = useAuthStore(state => state.auth) + let newGameRef = useRef() + let onClickOutside = useCallback((event) => { + if (!isNewGameOpen) { + return + } + let el = newGameRef.current + if (!el) { + return + } + let rect = el.getBoundingClientRect() + if (event.clientX > rect.right || event.clientX < rect.left || event.clientY > rect.bottom || event.clientY < rect.top) { + setNewGameOpen(false) + } + }, [isNewGameOpen] ) let onNewGame = useCallback((d) => doTry(async () => { let response = await tfetch("/api/create", { method: "POST", @@ -77,28 +91,31 @@ export function Lobby() { navigate(base + "/game/" + response.id) }), [auth, navigate]) return ( -
+
{isNewGameOpen ? ( newGameRef.current = ref} onNewGame={onNewGame} onStartEdit={onStartEdit} setNewGameOpen={setNewGameOpen} /> - ) : ( - - )} +
@@ -114,33 +131,70 @@ export function Lobby() { ) } -function NewGameDialog({onNewGame, onStartEdit, setNewGameOpen}) { +function NewGameDialog({onNewGame, onStartEdit, setNewGameOpen, onRef}) { let dimRef = useRef(9) + let timeRef = useRef(0) let [edit, setEdit] = useState(false) return (
{ e.preventDefault() - let game = {dim: dimRef.current} + let game = {dim: dimRef.current, timesetting: timeRef.current} if (edit) { onStartEdit(game) } else { onNewGame(game) } }}> - - dimRef.current = 9} /> - - dimRef.current = 13} /> - - dimRef.current = 19} /> - - setEdit(!edit)} /> - - +
+
+
+ +
+
+
+ +
+
+ dimRef.current = 9} /> + +
+
+ dimRef.current = 13} /> + +
+
+ dimRef.current = 19} /> + +
+
+ +
+
+ timeRef.current = 0} /> + +
+
+ timeRef.current = 10} /> + +
+
+ timeRef.current = 30} /> + +
+
+
+ setEdit(!edit)} /> + +
+ +
+
+
+ ) } diff --git a/src/main/java/com/bernd/LobbyController.java b/src/main/java/com/bernd/LobbyController.java index af95c37..c9158e6 100644 --- a/src/main/java/com/bernd/LobbyController.java +++ b/src/main/java/com/bernd/LobbyController.java @@ -72,6 +72,7 @@ public ViewGame startEdit(@RequestBody MatchRequest request) { false, createEmptyBoard(request.dim()), request.dim(), + request.timesetting(), request.handicap(), new int[]{-1, -1}, MoveList.create(request.dim()))); diff --git a/src/main/java/com/bernd/model/Game.java b/src/main/java/com/bernd/model/Game.java index ee87b70..5c74baa 100644 --- a/src/main/java/com/bernd/model/Game.java +++ b/src/main/java/com/bernd/model/Game.java @@ -20,6 +20,7 @@ public record Game( boolean counting, int[][] board, int dim, + int timesetting, int handicap, int[] forbidden, MoveList moves diff --git a/src/main/java/com/bernd/model/GameBuilder.java b/src/main/java/com/bernd/model/GameBuilder.java index d925832..716e87d 100644 --- a/src/main/java/com/bernd/model/GameBuilder.java +++ b/src/main/java/com/bernd/model/GameBuilder.java @@ -46,6 +46,7 @@ public Game build() { counting, board, game.dim(), + game.timesetting(), game.handicap(), forbidden, game.moves() diff --git a/src/main/java/com/bernd/model/MatchRequest.java b/src/main/java/com/bernd/model/MatchRequest.java index 3956c0f..c80d0f1 100644 --- a/src/main/java/com/bernd/model/MatchRequest.java +++ b/src/main/java/com/bernd/model/MatchRequest.java @@ -2,6 +2,7 @@ public record MatchRequest( int dim, + int timesetting, boolean editMode, int handicap) { } diff --git a/src/main/java/com/bernd/model/OpenGame.java b/src/main/java/com/bernd/model/OpenGame.java index 595e16d..ee38e1a 100644 --- a/src/main/java/com/bernd/model/OpenGame.java +++ b/src/main/java/com/bernd/model/OpenGame.java @@ -8,14 +8,15 @@ public record OpenGame( String id, String user, int dim, + int timesetting, int handicap) { public OpenGame withId(String id) { - return new OpenGame(id, user, dim, handicap); + return new OpenGame(id, user, dim, timesetting, handicap); } public OpenGame withUser(String name) { - return new OpenGame(id, name, dim, handicap); + return new OpenGame(id, name, dim, timesetting, handicap); } public Game accept(String opponent, AcceptRequest acceptRequest) { @@ -28,6 +29,7 @@ public Game accept(String opponent, AcceptRequest acceptRequest) { false, createEmptyBoard(dim), dim, + timesetting, acceptRequest.handicap(), new int[]{-1, -1}, MoveList.create(dim)); diff --git a/src/main/java/com/bernd/model/ViewGame.java b/src/main/java/com/bernd/model/ViewGame.java index a943d16..6afa84c 100644 --- a/src/main/java/com/bernd/model/ViewGame.java +++ b/src/main/java/com/bernd/model/ViewGame.java @@ -7,6 +7,7 @@ public record ViewGame( String black, String white, int dim, + int timesetting, int handicap, List moves ) { @@ -17,6 +18,7 @@ static ViewGame fromGame(Game game) { game.black(), game.white(), game.dim(), + game.timesetting(), game.handicap(), game.moves().moves()); } diff --git a/src/test/java/com/bernd/model/GameBuilderTest.java b/src/test/java/com/bernd/model/GameBuilderTest.java index 2e032ef..4343b80 100644 --- a/src/test/java/com/bernd/model/GameBuilderTest.java +++ b/src/test/java/com/bernd/model/GameBuilderTest.java @@ -18,6 +18,7 @@ void unchanged() { createEmptyBoard(9), 9, 2, + 0, new int[]{-1, -1}, MoveList.create(2)); Game game2 = GameBuilder.builder(game).build(); diff --git a/src/test/java/com/bernd/util/SgfCreatorTest.java b/src/test/java/com/bernd/util/SgfCreatorTest.java index 576ae12..3acc33c 100644 --- a/src/test/java/com/bernd/util/SgfCreatorTest.java +++ b/src/test/java/com/bernd/util/SgfCreatorTest.java @@ -17,7 +17,7 @@ void testCreate() { MoveList moveList = MoveList.create(20); moveList.add(new Move(Board.B, 0, null, 3, 4)); moveList.add(new Move(Board.W, 0, null, 6, 4)); - Game game = new Game("1234", "B", "W", false, new int[9][], 9, 0, null, moveList); + Game game = new Game("1234", "B", "W", false, new int[9][], 9, 0, 0, new int[]{-1, -1}, moveList); String sgf = SgfCreator.createSgf(game, LocalDate.of(2024, Month.AUGUST, 30)); assertEquals("(;FF[4]CA[UTF-8]GM[1]DT[2024-08-30]GN[1234]PB[B]PW[W]RE[?]SZ[9];B[de];W[ge])", sgf.replace("\n", ""));