Esempio n. 1
0
  public StageSpec apply(InternalAdminAction action) {
    StageFormat newFormat = action.editStageFormat(stageNum, format);
    int newPlayerLimit = action.editStagePlayerLimit(stageNum, playerLimit);
    Set<TPlayer> newExcludedPlayers = action.editStageExcludedPlayers(stageNum, excludedPlayers);
    List<RoundSpec> newRounds = Lists.newArrayList();
    for (RoundSpec round : rounds) {
      newRounds.add(round.apply(action, stageNum));
    }

    return new StageSpec(
        stageNum,
        newFormat,
        ImmutableList.copyOf(newRounds),
        newPlayerLimit,
        ImmutableSet.copyOf(newExcludedPlayers));
  }
Esempio n. 2
0
 @SuppressWarnings("unchecked")
 public static StageSpec parseYaml(
     Object yamlStage, int stageNum, Map<String, Game> games, AtomicInteger playerLimitSoFar) {
   Map<String, Object> stageMap = (Map<String, Object>) yamlStage;
   YamlUtils.validateKeys(stageMap, "stage", ALLOWED_KEYS);
   String formatName = (String) stageMap.get("format");
   List<RoundSpec> rounds = Lists.newArrayList();
   int roundNum = 0;
   for (Object yamlRound : (List<Object>) stageMap.get("rounds")) {
     rounds.add(RoundSpec.parseYaml(yamlRound, roundNum, games));
     roundNum++;
   }
   int playerLimit = playerLimitSoFar.get();
   if (stageMap.containsKey("playerLimit")) {
     playerLimit = Math.min(playerLimit, (int) stageMap.get("playerLimit"));
     playerLimitSoFar.set(playerLimit);
   }
   if (stageMap.containsKey("playerCutoff")) {
     // This affects the player limit for the next round, not the current round.
     playerLimitSoFar.set((int) stageMap.get("playerCutoff"));
   }
   Set<TPlayer> excludedPlayers = Sets.newHashSet();
   if (stageMap.containsKey("excludedPlayers")) {
     for (Object playerName : (List<Object>) stageMap.get("excludedPlayers")) {
       // Note that playerName could actually be e.g. an Integer instead
       // of a String, so we do need toString() instead of a cast.
       excludedPlayers.add(TPlayer.create(playerName.toString()));
     }
   }
   return new StageSpec(
       stageNum,
       StageFormat.parse(formatName),
       ImmutableList.copyOf(rounds),
       playerLimit,
       ImmutableSet.copyOf(excludedPlayers));
 }