Search in sources :

Example 1 with CardSets

use of com.gianlu.pyxreborn.server.Lists.CardSets in project PretendYoureXyzzyReborn by devgianlu.

the class Startup method main.

public static void main(String[] args) throws SQLException {
    Config config = new Config();
    try {
        JCommander.newBuilder().programName("pyx-server").addObject(config).expandAtSign(true).build().parse(args);
    } catch (ParameterException ex) {
        ex.printStackTrace();
        ex.getJCommander().usage();
        System.exit(1);
        return;
    }
    CardsDB db = new CardsDB(config);
    CardSets sets = db.loadCardSets();
    Server server = new Server(config, sets);
    server.start();
}
Also used : ParameterException(com.beust.jcommander.ParameterException) CardsDB(com.gianlu.pyxreborn.server.DB.CardsDB) CardSets(com.gianlu.pyxreborn.server.Lists.CardSets)

Example 2 with CardSets

use of com.gianlu.pyxreborn.server.Lists.CardSets 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

CardSets (com.gianlu.pyxreborn.server.Lists.CardSets)2 ParameterException (com.beust.jcommander.ParameterException)1 BlackCard (com.gianlu.pyxreborn.Models.BlackCard)1 CardSet (com.gianlu.pyxreborn.Models.CardSet)1 WhiteCard (com.gianlu.pyxreborn.Models.WhiteCard)1 CardsDB (com.gianlu.pyxreborn.server.DB.CardsDB)1