Search in sources :

Example 1 with TourneyProto

use of mage.game.result.ResultProtos.TourneyProto in project mage by magefree.

the class TournamentImpl method toProto.

@Override
public TourneyProto toProto() {
    TourneyProto.Builder tourneyBuilder = TourneyProto.newBuilder().setBoosterInfo(this.getBoosterInfo());
    for (TournamentPlayer player : players.values()) {
        TournamentPlayer replacedPlayer = player.getReplacedTournamentPlayer();
        if (replacedPlayer != null) {
            player = replacedPlayer;
        }
        tourneyBuilder.addPlayersBuilder().mergeFrom(player.toProto());
    }
    for (Round round : rounds) {
        TourneyRoundProto.Builder roundBuilder = tourneyBuilder.addRoundsBuilder().setRound(round.getRoundNumber());
        for (TournamentPairing pair : round.getPairs()) {
            Match match = pair.getMatch();
            if (match != null && match.hasEnded()) {
                MatchProto.Builder matchBuilder = roundBuilder.addMatchesBuilder().setName(match.getName()).setGameType(match.getOptions().getGameType()).setDeckType(match.getOptions().getDeckType()).setGames(match.getNumGames()).setDraws(match.getDraws()).addPlayers(matchToProto(match, pair.getPlayer1())).addPlayers(matchToProto(match, pair.getPlayer2())).setMatchOptions(match.getOptions().toProto()).setEndTimeMs((match.getEndTime() != null ? match.getEndTime() : new Date()).getTime());
            }
        }
        for (TournamentPlayer tp : round.getPlayerByes()) {
            roundBuilder.addByes(tp.getPlayer().getName());
        }
    }
    return tourneyBuilder.build();
}
Also used : TourneyProto(mage.game.result.ResultProtos.TourneyProto) MatchProto(mage.game.result.ResultProtos.MatchProto) TourneyRoundProto(mage.game.result.ResultProtos.TourneyRoundProto) Date(java.util.Date) Match(mage.game.match.Match)

Aggregations

Date (java.util.Date)1 Match (mage.game.match.Match)1 MatchProto (mage.game.result.ResultProtos.MatchProto)1 TourneyProto (mage.game.result.ResultProtos.TourneyProto)1 TourneyRoundProto (mage.game.result.ResultProtos.TourneyRoundProto)1