Search in sources :

Example 1 with SpellLevelInfo

use of pcgen.cdom.helper.SpellLevelInfo 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;
}
Also used : Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) SpellLevelInfo(pcgen.cdom.helper.SpellLevelInfo) ArrayList(java.util.ArrayList) SpellLevelChooseInformation(pcgen.cdom.base.SpellLevelChooseInformation) PCClass(pcgen.core.PCClass)

Aggregations

ArrayList (java.util.ArrayList)1 Formula (pcgen.base.formula.Formula)1 ParsingSeparator (pcgen.base.text.ParsingSeparator)1 SpellLevelChooseInformation (pcgen.cdom.base.SpellLevelChooseInformation)1 SpellLevelInfo (pcgen.cdom.helper.SpellLevelInfo)1 PCClass (pcgen.core.PCClass)1