diff options
author | jbion <joffrey.bion@amadeus.com> | 2017-01-12 22:12:42 +0100 |
---|---|---|
committer | jbion <joffrey.bion@amadeus.com> | 2017-01-12 22:26:32 +0100 |
commit | a9ecd7b80d21cd65679eb764e46fd97a8fe226f0 (patch) | |
tree | 2cb996a566cc655901067102247bceec9cf2b34c /src/main/java/org/luxons | |
parent | Add PLAY_LAST_CARD special ability handling (diff) | |
download | seven-wonders-a9ecd7b80d21cd65679eb764e46fd97a8fe226f0.tar.gz seven-wonders-a9ecd7b80d21cd65679eb764e46fd97a8fe226f0.tar.bz2 seven-wonders-a9ecd7b80d21cd65679eb764e46fd97a8fe226f0.zip |
Fix LobbyController to match the documentation
Diffstat (limited to 'src/main/java/org/luxons')
3 files changed, 12 insertions, 29 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/actions/StartGameAction.java b/src/main/java/org/luxons/sevenwonders/actions/StartGameAction.java deleted file mode 100644 index 632b80ef..00000000 --- a/src/main/java/org/luxons/sevenwonders/actions/StartGameAction.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.luxons.sevenwonders.actions; - -import javax.validation.constraints.NotNull; - -import org.luxons.sevenwonders.game.Settings; - -public class StartGameAction { - - @NotNull - private Settings settings; - - public Settings getSettings() { - return settings; - } - - public void setSettings(Settings settings) { - this.settings = settings; - } -} diff --git a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java index cfc540bb..1664d05e 100644 --- a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java +++ b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java @@ -8,7 +8,6 @@ import org.luxons.sevenwonders.actions.ChooseNameAction; import org.luxons.sevenwonders.actions.CreateGameAction; import org.luxons.sevenwonders.actions.JoinGameAction; import org.luxons.sevenwonders.actions.ReorderPlayersAction; -import org.luxons.sevenwonders.actions.StartGameAction; import org.luxons.sevenwonders.actions.UpdateSettingsAction; import org.luxons.sevenwonders.errors.ApiMisuseException; import org.luxons.sevenwonders.game.Game; @@ -51,11 +50,13 @@ public class LobbyController { } @MessageMapping("/chooseName") - public void chooseName(@Validated ChooseNameAction action, Principal principal) { + @SendToUser("/queue/nameChoice") + public Player chooseName(@Validated ChooseNameAction action, Principal principal) { String userName = principal.getName(); Player player = playerRepository.updateOrCreatePlayer(userName, action.getPlayerName()); logger.info("Player '{}' chose the name '{}'", userName, player.getDisplayName()); + return player; } @SubscribeMapping("/games") // prefix /topic not shown @@ -79,8 +80,8 @@ public class LobbyController { } @MessageMapping("/lobby/join") - @SendToUser("/queue/lobby") - public Collection<Lobby> joinGame(@Validated JoinGameAction action, Principal principal) { + @SendToUser("/queue/lobby/joined") + public Lobby joinGame(@Validated JoinGameAction action, Principal principal) { checkThatUserIsNotInAGame(principal, "cannot join another game"); Lobby lobby = lobbyRepository.find(action.getGameId()); @@ -90,7 +91,8 @@ public class LobbyController { logger.info("Player '{}' ({}) joined game {}", newPlayer.getDisplayName(), newPlayer.getUserName(), lobby.getName()); - return Collections.singletonList(lobby); + sendLobbyUpdateToPlayers(lobby); + return lobby; } private void checkThatUserIsNotInAGame(Principal principal, String impossibleActionDescription) { @@ -123,7 +125,7 @@ public class LobbyController { } @MessageMapping("/lobby/start") - public void startGame(@Validated StartGameAction action, Principal principal) { + public void startGame(Principal principal) { Lobby lobby = getOwnedLobby(principal); Game game = lobby.startGame(); gameRepository.add(game); diff --git a/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java b/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java index cd63c440..76df13b4 100644 --- a/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java +++ b/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java @@ -20,26 +20,26 @@ public class PlayerRepository { } } - private Player createPlayer(String userName, String displayName) { + private Player createPlayer(String userName, String displayName) throws PlayerAlreadyExistsException { Player player = new Player(userName, displayName); add(player); return player; } - private void add(Player player) { + private void add(Player player) throws PlayerAlreadyExistsException { if (players.containsKey(player.getUserName())) { throw new PlayerAlreadyExistsException(player.getUserName()); } players.put(player.getUserName(), player); } - private Player updatePlayerName(String userName, String displayName) { + private Player updatePlayerName(String userName, String displayName) throws PlayerNotFoundException { Player player = find(userName); player.setDisplayName(displayName); return player; } - public Player find(String userName) { + public Player find(String userName) throws PlayerNotFoundException { Player player = players.get(userName); if (player == null) { throw new PlayerNotFoundException(userName); |