use of com.gianlu.pyxreborn.Exceptions.PyxException in project PretendYoureXyzzyReborn by devgianlu.
the class MainUI method createGame.
@FXML
public void createGame(MouseEvent mouseEvent) {
CGame game;
try {
game = new CGame(client.sendMessageBlocking(client.createRequest(Operations.CREATE_GAME)).getAsJsonObject(Fields.GAME.toString()));
} catch (InterruptedException | PyxException ex) {
UIClient.notifyException(ex);
return;
}
GameUI.show(stage, GameChatUI.show(client, game), client, me, game);
stage.hide();
refreshGamesList();
}
use of com.gianlu.pyxreborn.Exceptions.PyxException in project PretendYoureXyzzyReborn by devgianlu.
the class MainUI method refreshGamesList.
@FXML
public void refreshGamesList() {
JsonObject resp;
try {
resp = client.sendMessageBlocking(client.createRequest(Operations.LIST_GAMES));
} catch (InterruptedException | PyxException ex) {
UIClient.notifyException(ex);
return;
}
JsonArray gamesArray = resp.getAsJsonArray(Fields.GAMES_LIST.toString());
ObservableList<CGame> games = new ObservableListWrapper<>(Utils.toList(gamesArray, CGame.class));
gamesList.setItems(games);
}
use of com.gianlu.pyxreborn.Exceptions.PyxException in project PretendYoureXyzzyReborn by devgianlu.
the class MainUI method refreshUsersList.
@FXML
public void refreshUsersList() {
JsonObject resp;
try {
resp = client.sendMessageBlocking(client.createRequest(Operations.LIST_USERS));
} catch (InterruptedException | PyxException ex) {
UIClient.notifyException(ex);
return;
}
JsonArray usersArray = resp.getAsJsonArray(Fields.USERS_LIST.toString());
ObservableList<CUser> users = new ObservableListWrapper<>(Utils.toList(usersArray, CUser.class));
usersList.setItems(users);
}
use of com.gianlu.pyxreborn.Exceptions.PyxException in project PretendYoureXyzzyReborn by devgianlu.
the class ConsoleClient method mainMenu.
private void mainMenu() throws IOException {
ListChoicePrompt.Builder builder = new ListChoicePrompt.Builder();
builder.text("Request operation:").name("req");
for (Operations op : Operations.values()) builder.newItem().name(op.toString()).text(op.name()).add();
ChoiceAnswer answer = prompt.prompt(builder.build());
Operations op = Operations.parse(answer.getName());
JsonObject req = client.createRequest(op);
Pair<String, String> additionalParams;
do {
additionalParams = askForRequestParam();
if (additionalParams != null)
req.addProperty(additionalParams.getKey(), additionalParams.getValue());
} while (additionalParams != null);
System.out.println("REQUEST: " + req);
JsonObject resp;
try {
resp = client.sendMessageBlocking(req);
} catch (InterruptedException | PyxException ex) {
Logger.severe(ex);
mainMenu();
return;
}
System.out.println("RESPONSE: " + resp);
mainMenu();
}
use of com.gianlu.pyxreborn.Exceptions.PyxException in project PretendYoureXyzzyReborn by devgianlu.
the class PyxClientAdapter method onMessage.
@Override
public void onMessage(String message) {
JsonObject obj = parser.parse(message).getAsJsonObject();
if (obj.has(Fields.EVENT.toString())) {
onEvent(Events.parse(obj.get(Fields.EVENT.toString()).getAsString()), obj);
return;
}
JsonElement id = obj.get(Fields.ID.toString());
if (id == null)
return;
IMessage listener = requests.remove(id.getAsInt());
if (listener instanceof IMessageBlocking) {
if (obj.has(Fields.ERROR_CODE.toString())) {
blockingEx = new PyxException(obj);
blockingResp = null;
synchronized (waitingForResponse) {
waitingForResponse.notifyAll();
}
} else {
blockingEx = null;
blockingResp = obj;
synchronized (waitingForResponse) {
waitingForResponse.notifyAll();
}
}
} else {
if (obj.has(Fields.ERROR_CODE.toString()))
listener.onException(new PyxException(obj));
else
listener.onMessage(obj);
}
}
Aggregations