use of pcgen.cdom.base.SpellLevelChooseInformation in project pcgen by PCGen.
the class SpellLevelToken method parseTokenWithSeparator.
@Override
public ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
int pipeLoc = value.lastIndexOf('|');
String activeValue;
String title;
if (pipeLoc == -1) {
activeValue = value;
title = getDefaultTitle();
} else {
String titleString = value.substring(pipeLoc + 1);
if (titleString.startsWith("TITLE=")) {
title = titleString.substring(6);
if (title.startsWith("\"")) {
title = title.substring(1, title.length() - 1);
}
activeValue = value.substring(0, pipeLoc);
} else {
activeValue = value;
title = getDefaultTitle();
}
}
pipeLoc = value.indexOf('|');
ParsingSeparator sep = new ParsingSeparator(activeValue, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
if (!sep.hasNext()) {
return new ParseResult.Fail("Found no arguments in " + getFullName() + ": " + value, context);
}
List<SpellLevelInfo> sliList = new ArrayList<>();
while (sep.hasNext()) {
String token = sep.next();
PrimitiveCollection<PCClass> pcf = context.getPrimitiveChoiceFilter(context.getReferenceContext().getManufacturer(PCClass.class), token);
if (!sep.hasNext()) {
return new ParseResult.Fail("Expected minimum level argument after " + token + " in " + getFullName() + ": " + value, context);
}
String minLevelString = sep.next();
Formula minLevel = FormulaFactory.getFormulaFor(minLevelString);
if (!sep.hasNext()) {
return new ParseResult.Fail("Expected maximum level argument after " + minLevelString + " in " + getFullName() + ": " + value, context);
}
String maxLevelString = sep.next();
Formula maxLevel = FormulaFactory.getFormulaFor(maxLevelString);
if (!maxLevel.isValid()) {
return new ParseResult.Fail("Max Level Formula in " + getTokenName() + " was not valid: " + maxLevel.toString(), context);
}
SpellLevelInfo sli = new SpellLevelInfo(pcf, minLevel, maxLevel);
sliList.add(sli);
}
SpellLevelChooseInformation tc = new SpellLevelChooseInformation(getTokenName(), sliList);
tc.setTitle(title);
tc.setChoiceActor(this);
context.getObjectContext().put(obj, ObjectKey.CHOOSE_INFO, tc);
return ParseResult.SUCCESS;
}
Aggregations