Fixes for garbage code by Omar

This commit is contained in:
Bas de Jong
2025-10-16 13:59:24 +02:00
parent 975207a6de
commit 3a120803e3
2 changed files with 16 additions and 10 deletions

View File

@@ -29,6 +29,7 @@ public final class Server {
private long clientId = -1;
private List<String> onlinePlayers = new CopyOnWriteArrayList<String>();
private List<String> gameList = new CopyOnWriteArrayList<>();
private ServerView view;
@@ -80,6 +81,9 @@ public final class Server {
ViewStack.push(view);
startPopulateScheduler();
populateGameList();
}).postEvent();
new EventFlow().listen(this::handleReceivedChallenge);
@@ -207,16 +211,18 @@ public final class Server {
scheduler.schedule(() -> populatePlayerList(scheduler, getPlayerlistFlow::postEvent), 0, TimeUnit.MILLISECONDS);
}
public List<String> getGamesList() {
final List<String> list = new ArrayList<String>();
list.add("tic-tac-toe"); // Todo: get games list from server and check if the game is supported
list.add("reversi");
private void gamesListFromServerHandler(NetworkEvents.GamelistResponse event) {
gameList.addAll(List.of(event.gamelist()));
}
public void populateGameList() {
new EventFlow().addPostEvent(new NetworkEvents.SendGetGamelist(clientId))
.listen(NetworkEvents.GamelistResponse.class, e -> {
System.out.println(Arrays.toString(e.gamelist()));
}).postEvent();
.listen(NetworkEvents.GamelistResponse.class,
this::gamesListFromServerHandler, true
).postEvent();
}
return list;
public List<String> getGameList() {
return gameList;
}
}

View File

@@ -46,7 +46,7 @@ public final class SendChallengeView extends View {
gameText.setText(AppContext.getString("to-a-game-of"));
final ComboBox<String> gamesCombobox = combobox();
gamesCombobox.getItems().addAll(server.getGamesList());
gamesCombobox.getItems().addAll(server.getGameList());
gamesCombobox.setValue(gamesCombobox.getItems().getFirst());
final Button sendButton = button();