Search in sources :

Example 1 with CategorizedChooseInformation

use of pcgen.cdom.base.CategorizedChooseInformation in project pcgen by PCGen.

the class ChooseFeatToken method parseTokenWithSeparator.

protected ParseResult parseTokenWithSeparator(LoadContext context, ReferenceManufacturer<Ability> rm, 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);
            if (title == null || title.isEmpty()) {
                return new ParseResult.Fail(getParentToken() + Constants.COLON + getTokenName() + " had TITLE= but no title: " + value, context);
            }
        } else {
            activeValue = value;
            title = getDefaultTitle();
        }
    }
    PrimitiveCollection<Ability> coll = context.getChoiceSet(rm, activeValue);
    if (coll == null) {
        return ParseResult.INTERNAL_ERROR;
    }
    if (!coll.getGroupingState().isValid()) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage("Invalid combination of objects was used in: " + activeValue);
        cpr.addErrorMessage("  Check that ALL is not combined");
        cpr.addErrorMessage("  Check that a key is not joined with AND (,)");
        return cpr;
    }
    PrimitiveChoiceSet<Ability> pcs = new CollectionToChoiceSet<>(coll);
    //Tricky for compatibility...
    CategorizedChooseInformation<Ability> tc = new CategorizedChooseInformation<>("ABILITY", CDOMDirectSingleRef.getRef(AbilityCategory.FEAT), pcs, Ability.class);
    tc.setTitle(title);
    tc.setChoiceActor(this);
    context.getObjectContext().put(obj, ObjectKey.CHOOSE_INFO, tc);
    return ParseResult.SUCCESS;
}
Also used : Ability(pcgen.core.Ability) CategorizedChooseInformation(pcgen.cdom.base.CategorizedChooseInformation) CollectionToChoiceSet(pcgen.cdom.choiceset.CollectionToChoiceSet) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult)

Example 2 with CategorizedChooseInformation

use of pcgen.cdom.base.CategorizedChooseInformation in project pcgen by PCGen.

the class AbilityToken method parseTokenWithSeparator.

protected ParseResult parseTokenWithSeparator(LoadContext context, ReferenceManufacturer<Ability> rm, CDOMSingleRef<AbilityCategory> acRef, 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);
            if (title == null || title.isEmpty()) {
                return new ParseResult.Fail(getParentToken() + Constants.COLON + getTokenName() + " had TITLE= but no title: " + value, context);
            }
        } else {
            activeValue = value;
            title = getDefaultTitle();
        }
    }
    PrimitiveCollection<Ability> coll = context.getChoiceSet(rm, activeValue);
    if (coll == null) {
        return ParseResult.INTERNAL_ERROR;
    }
    if (!coll.getGroupingState().isValid()) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage("Invalid combination of objects was used in: " + activeValue);
        cpr.addErrorMessage("  Check that ALL is not combined");
        cpr.addErrorMessage("  Check that a key is not joined with AND (,)");
        return cpr;
    }
    PrimitiveChoiceSet<Ability> pcs = new CollectionToChoiceSet<>(coll);
    CategorizedChooseInformation<Ability> tc = new CategorizedChooseInformation<>(getTokenName(), acRef, pcs, Ability.class);
    tc.setTitle(title);
    tc.setChoiceActor(this);
    context.getObjectContext().put(obj, ObjectKey.CHOOSE_INFO, tc);
    return ParseResult.SUCCESS;
}
Also used : Ability(pcgen.core.Ability) CategorizedChooseInformation(pcgen.cdom.base.CategorizedChooseInformation) CollectionToChoiceSet(pcgen.cdom.choiceset.CollectionToChoiceSet) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult)

Aggregations

CategorizedChooseInformation (pcgen.cdom.base.CategorizedChooseInformation)2 CollectionToChoiceSet (pcgen.cdom.choiceset.CollectionToChoiceSet)2 Ability (pcgen.core.Ability)2 ComplexParseResult (pcgen.rules.persistence.token.ComplexParseResult)2