Search in sources :

Example 1 with CardSet

use of com.gianlu.pyxreborn.Models.CardSet in project PretendYoureXyzzyReborn by devgianlu.

the class ListCardSetsHandler method handleRequest.

@Override
public JsonObject handleRequest(Server server, JsonObject request, JsonObject response) throws GeneralException {
    JsonArray array = new JsonArray();
    for (CardSet set : server.cardSets) array.add(set.toCompactJson());
    response.add(Fields.CARD_SET.toString(), array);
    return response;
}
Also used : JsonArray(com.google.gson.JsonArray) CardSet(com.gianlu.pyxreborn.Models.CardSet)

Example 2 with CardSet

use of com.gianlu.pyxreborn.Models.CardSet in project PretendYoureXyzzyReborn by devgianlu.

the class ListCardsHandler method handleRequest.

@Override
public JsonObject handleRequest(Server server, JsonObject request, JsonObject response) throws GeneralException {
    JsonElement cardSetId = request.get(Fields.CARD_SET_ID.toString());
    if (cardSetId == null)
        throw new GeneralException(ErrorCodes.INVALID_REQUEST);
    CardSet set = server.cardSets.findCardSetById(cardSetId.getAsInt());
    if (set == null)
        throw new GeneralException(ErrorCodes.INVALID_CARD_SET_ID);
    response.add(Fields.CARD_SET.toString(), set.toJson());
    return response;
}
Also used : GeneralException(com.gianlu.pyxreborn.Exceptions.GeneralException) JsonElement(com.google.gson.JsonElement) CardSet(com.gianlu.pyxreborn.Models.CardSet)

Example 3 with CardSet

use of com.gianlu.pyxreborn.Models.CardSet in project PretendYoureXyzzyReborn by devgianlu.

the class CardsDB method loadCardSets.

/**
 * Loads all the card sets in the database.
 */
public CardSets loadCardSets() throws SQLException {
    CardSets sets = new CardSets();
    try (Statement statement = db.createStatement()) {
        try (ResultSet result = statement.executeQuery("SELECT * FROM card_set")) {
            while (result.next()) {
                sets.add(new CardSet(result.getInt("id"), result.getInt("active") == 1, result.getString("name"), result.getInt("base_deck") == 1, result.getString("description"), result.getInt("weight")));
            }
        }
        Map<Integer, WhiteCard> whiteCards = loadWhiteCards(statement);
        for (CardSet set : sets) {
            try (ResultSet result = statement.executeQuery("SELECT white_card_id FROM card_set_white_card WHERE card_set_id=" + set.id)) {
                while (result.next()) {
                    set.whiteCards.add(whiteCards.get(result.getInt("white_card_id")));
                }
            }
        }
        Map<Integer, BlackCard> blackCards = loadBlackCards(statement);
        for (CardSet set : sets) {
            try (ResultSet result = statement.executeQuery("SELECT black_card_id FROM card_set_black_card WHERE card_set_id=" + set.id)) {
                while (result.next()) {
                    set.blackCards.add(blackCards.get(result.getInt("black_card_id")));
                }
            }
        }
    }
    sets.sort(new CardSets.WeightComparator());
    return sets;
}
Also used : WhiteCard(com.gianlu.pyxreborn.Models.WhiteCard) BlackCard(com.gianlu.pyxreborn.Models.BlackCard) CardSets(com.gianlu.pyxreborn.server.Lists.CardSets) CardSet(com.gianlu.pyxreborn.Models.CardSet)

Aggregations

CardSet (com.gianlu.pyxreborn.Models.CardSet)3 GeneralException (com.gianlu.pyxreborn.Exceptions.GeneralException)1 BlackCard (com.gianlu.pyxreborn.Models.BlackCard)1 WhiteCard (com.gianlu.pyxreborn.Models.WhiteCard)1 CardSets (com.gianlu.pyxreborn.server.Lists.CardSets)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1