Search in sources :

Example 6 with PyxException

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();
}
Also used : CGame(com.gianlu.pyxreborn.Models.Client.CGame) PyxException(com.gianlu.pyxreborn.Exceptions.PyxException) FXML(javafx.fxml.FXML)

Example 7 with PyxException

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);
}
Also used : JsonArray(com.google.gson.JsonArray) CGame(com.gianlu.pyxreborn.Models.Client.CGame) ObservableListWrapper(com.sun.javafx.collections.ObservableListWrapper) JsonObject(com.google.gson.JsonObject) PyxException(com.gianlu.pyxreborn.Exceptions.PyxException) FXML(javafx.fxml.FXML)

Example 8 with PyxException

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);
}
Also used : JsonArray(com.google.gson.JsonArray) CUser(com.gianlu.pyxreborn.Models.Client.CUser) ObservableListWrapper(com.sun.javafx.collections.ObservableListWrapper) JsonObject(com.google.gson.JsonObject) PyxException(com.gianlu.pyxreborn.Exceptions.PyxException) FXML(javafx.fxml.FXML)

Example 9 with PyxException

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();
}
Also used : ListChoicePrompt(com.gianlu.consoleui.Choice.List.ListChoicePrompt) ChoiceAnswer(com.gianlu.consoleui.Choice.ChoiceAnswer) JsonObject(com.google.gson.JsonObject) PyxException(com.gianlu.pyxreborn.Exceptions.PyxException) Operations(com.gianlu.pyxreborn.Operations)

Example 10 with PyxException

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);
    }
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) PyxException(com.gianlu.pyxreborn.Exceptions.PyxException)

Aggregations

PyxException (com.gianlu.pyxreborn.Exceptions.PyxException)15 JsonObject (com.google.gson.JsonObject)12 FXML (javafx.fxml.FXML)10 CGame (com.gianlu.pyxreborn.Models.Client.CGame)3 CUser (com.gianlu.pyxreborn.Models.Client.CUser)2 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)2 ObservableListWrapper (com.sun.javafx.collections.ObservableListWrapper)2 ChoiceAnswer (com.gianlu.consoleui.Choice.ChoiceAnswer)1 ListChoicePrompt (com.gianlu.consoleui.Choice.List.ListChoicePrompt)1 CCompactCardSet (com.gianlu.pyxreborn.Models.Client.CCompactCardSet)1 Operations (com.gianlu.pyxreborn.Operations)1 Client (com.gianlu.pyxreborn.client.Client)1 PyxCardGroup (com.gianlu.pyxreborn.client.UI.Card.PyxCardGroup)1 CheckboxCardSetCell (com.gianlu.pyxreborn.client.UI.ListCells.CheckboxCardSetCell)1 PlayerCell (com.gianlu.pyxreborn.client.UI.ListCells.PlayerCell)1 UserCell (com.gianlu.pyxreborn.client.UI.ListCells.UserCell)1 NumberStringFilteredConverter (com.gianlu.pyxreborn.client.UI.NumberStringFilteredConverter)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1