Search in sources :

Example 1 with CollectionToAbilitySelection

use of pcgen.cdom.choiceset.CollectionToAbilitySelection in project pcgen by PCGen.

the class AbilitySelectionToken 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);
            }
            if (title == null || title.isEmpty()) {
                return new ParseResult.Fail(getParentToken() + Constants.COLON + getTokenName() + " had TITLE= but no title: " + value, context);
            }
            activeValue = value.substring(0, pipeLoc);
        } else {
            activeValue = value;
            title = getDefaultTitle();
        }
    }
    PrimitiveCollection<Ability> prim = context.getChoiceSet(rm, activeValue);
    if (prim == null) {
        return ParseResult.INTERNAL_ERROR;
    }
    if (!prim.getGroupingState().isValid()) {
        return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
    }
    CollectionToAbilitySelection pcs = new CollectionToAbilitySelection(acRef, prim);
    CategorizedAbilitySelectionChooseInformation tc = new CategorizedAbilitySelectionChooseInformation(getTokenName(), pcs);
    tc.setTitle(title);
    tc.setChoiceActor(this);
    context.getObjectContext().put(obj, ObjectKey.CHOOSE_INFO, tc);
    return ParseResult.SUCCESS;
}
Also used : Ability(pcgen.core.Ability) CollectionToAbilitySelection(pcgen.cdom.choiceset.CollectionToAbilitySelection) CategorizedAbilitySelectionChooseInformation(pcgen.cdom.base.CategorizedAbilitySelectionChooseInformation)

Aggregations

CategorizedAbilitySelectionChooseInformation (pcgen.cdom.base.CategorizedAbilitySelectionChooseInformation)1 CollectionToAbilitySelection (pcgen.cdom.choiceset.CollectionToAbilitySelection)1 Ability (pcgen.core.Ability)1