Exemplo n.º 1
0
  @Override
  protected ParseResult parseTokenWithSeparator(LoadContext context, Race race, String value) {
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    boolean first = true;

    while (tok.hasMoreTokens()) {
      String tokString = tok.nextToken();
      if (Constants.LST_DOT_CLEAR.equals(tokString)) {
        if (!first) {
          return new ParseResult.Fail(
              "  Non-sensical "
                  + getTokenName()
                  + ": .CLEAR was not the first list item: "
                  + value);
        }
        context.obj.removeList(race, ListKey.RACESUBTYPE);
      } else if (tokString.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
        String clearText = tokString.substring(7);
        context
            .getObjectContext()
            .removeFromList(race, ListKey.RACESUBTYPE, RaceSubType.getConstant(clearText));
      } else {
        context
            .getObjectContext()
            .addToList(race, ListKey.RACESUBTYPE, RaceSubType.getConstant(tokString));
      }
      first = false;
    }
    return ParseResult.SUCCESS;
  }
Exemplo n.º 2
0
 public static void clearConstants() {
   AspectName.clearConstants();
   Pantheon.clearConstants();
   RaceSubType.clearConstants();
   RaceType.clearConstants();
   Region.clearConstants();
   SubClassCategory.clearConstants();
   SubRace.clearConstants();
   SubRegion.clearConstants();
   Type.clearConstants();
   VariableKey.clearConstants();
 }
Exemplo n.º 3
0
  @Override
  protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
      return new ParseResult.Fail(
          "Cannot use "
              + getTokenName()
              + " on an Ungranted object type: "
              + obj.getClass().getSimpleName(),
          context);
    }
    StringTokenizer tok = new StringTokenizer(value, LstUtils.PIPE);

    String companionType = tok.nextToken();

    if (!tok.hasMoreTokens()) {
      return new ParseResult.Fail(
          getTokenName() + " requires more than just a Type: " + value, context);
    }

    String list = tok.nextToken();

    ParseResult pr = checkForIllegalSeparator(',', list);
    if (!pr.passed()) {
      return pr;
    }

    StringTokenizer subTok = new StringTokenizer(list, LstUtils.COMMA);

    Set<CDOMReference<Race>> races = new HashSet<>();
    boolean foundAny = false;
    while (subTok.hasMoreTokens()) {
      String tokString = subTok.nextToken();
      if (Constants.LST_ANY.equalsIgnoreCase(tokString)) {
        foundAny = true;
        races.add(context.getReferenceContext().getCDOMAllReference(Race.class));
      } else if (tokString.startsWith("RACETYPE=")) {
        String raceType = tokString.substring(9);
        if (raceType.isEmpty()) {
          return new ParseResult.Fail(
              getTokenName() + " Error: RaceType was not specified.", context);
        }
        races.add(
            new ObjectMatchingReference<>(
                tokString,
                Race.class,
                context.getReferenceContext().getCDOMAllReference(Race.class),
                ObjectKey.RACETYPE,
                RaceType.getConstant(raceType)));
      } else if (tokString.startsWith("RACESUBTYPE=")) {
        String raceSubType = tokString.substring(12);
        if (raceSubType.isEmpty()) {
          return new ParseResult.Fail(
              getTokenName() + " Error: RaceSubType was not specified.", context);
        }
        races.add(
            new ListMatchingReference<>(
                tokString,
                Race.class,
                context.getReferenceContext().getCDOMAllReference(Race.class),
                ListKey.RACESUBTYPE,
                RaceSubType.getConstant(raceSubType)));
      } else if (looksLikeAPrerequisite(tokString)) {
        return new ParseResult.Fail(
            getTokenName() + " Error: " + tokString + " found where companion race expected.",
            context);
      } else {
        races.add(context.getReferenceContext().getCDOMReference(Race.class, tokString));
      }
    }
    if (foundAny && races.size() > 1) {
      return new ParseResult.Fail(
          "Non-sensical Race List includes Any and specific races: " + value, context);
    }

    if (!tok.hasMoreTokens()) {
      // No other args, so we're done
      finish(context, obj, companionType, races, null, null);
      return ParseResult.SUCCESS;
    }

    // The remainder of the elements are optional.
    Integer followerAdjustment = null;
    String optArg = tok.nextToken();
    while (true) {
      if (optArg.startsWith(FOLLOWERADJUSTMENT)) {
        if (followerAdjustment != null) {
          return new ParseResult.Fail(
              getTokenName() + " Error: Multiple " + FOLLOWERADJUSTMENT + " tags specified.",
              context);
        }

        int faStringLength = FOLLOWERADJUSTMENT.length();
        if (optArg.length() <= faStringLength + 1) {
          return new ParseResult.Fail(
              "Empty FOLLOWERADJUSTMENT value in " + getTokenName() + " is prohibited", context);
        }
        String adj = optArg.substring(faStringLength + 1);

        try {
          followerAdjustment = Integer.valueOf(adj);
        } catch (NumberFormatException nfe) {
          ComplexParseResult cpr = new ComplexParseResult();
          cpr.addErrorMessage("Expecting a number for FOLLOWERADJUSTMENT: " + adj);
          cpr.addErrorMessage("  was parsing Token " + getTokenName());
          return cpr;
        }
      } else if (looksLikeAPrerequisite(optArg)) {
        break;
      } else {
        return new ParseResult.Fail(
            getTokenName()
                + ": Unknown argument (was expecting FOLLOWERADJUSTMENT: or PRExxx): "
                + optArg,
            context);
      }
      if (!tok.hasMoreTokens()) {
        // No prereqs, so we're done
        finish(context, obj, companionType, races, followerAdjustment, null);
        return ParseResult.SUCCESS;
      }
      optArg = tok.nextToken();
    }

    List<Prerequisite> prereqs = new ArrayList<>();

    while (true) {
      Prerequisite prereq = getPrerequisite(optArg);
      if (prereq == null) {
        return new ParseResult.Fail(
            "   (Did you put items after the " + "PRExxx tags in " + getTokenName() + ":?)",
            context);
      }
      prereqs.add(prereq);
      if (!tok.hasMoreTokens()) {
        break;
      }
      optArg = tok.nextToken();
    }

    finish(context, obj, companionType, races, followerAdjustment, prereqs);
    return ParseResult.SUCCESS;
  }