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