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;
}
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;
}
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;
}
Aggregations