mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
Fixes for garbage code by Omar
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user