Search in sources :

Example 1 with ModifyChoiceDecorator

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

the class ModifyfeatchoiceToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Ability ability, String value) {
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    List<CDOMReference<Ability>> refs = new ArrayList<>();
    ReferenceManufacturer<Ability> rm = context.getReferenceContext().getManufacturer(ABILITY_CLASS, AbilityCategory.FEAT);
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        CDOMReference<Ability> ref = TokenUtilities.getTypeOrPrimitive(rm, token);
        if (ref == null) {
            return ParseResult.INTERNAL_ERROR;
        }
        refs.add(ref);
    }
    ReferenceChoiceSet<Ability> rcs = new ReferenceChoiceSet<>(refs);
    ModifyChoiceDecorator gfd = new ModifyChoiceDecorator(rcs);
    ChoiceSet<CNAbility> cs = new ChoiceSet<>(getTokenName(), gfd);
    TabInfo ti = context.getReferenceContext().silentlyGetConstructedCDOMObject(TabInfo.class, Tab.ABILITIES.toString());
    String singularName = ti.getResolvedName();
    if (singularName.endsWith("s")) {
        singularName = singularName.substring(0, singularName.length() - 1);
    }
    cs.setTitle("Select a " + singularName + " to modify");
    TransitionChoice<CNAbility> tc = new ConcreteTransitionChoice<>(cs, FormulaFactory.ONE);
    tc.setRequired(false);
    context.getObjectContext().put(ability, ObjectKey.MODIFY_CHOICE, tc);
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) ConcreteTransitionChoice(pcgen.cdom.base.ConcreteTransitionChoice) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) CNAbility(pcgen.cdom.content.CNAbility) StringTokenizer(java.util.StringTokenizer) TabInfo(pcgen.cdom.content.TabInfo) ModifyChoiceDecorator(pcgen.cdom.choiceset.ModifyChoiceDecorator) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet)

Aggregations

ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 ChoiceSet (pcgen.cdom.base.ChoiceSet)1 ConcreteTransitionChoice (pcgen.cdom.base.ConcreteTransitionChoice)1 ModifyChoiceDecorator (pcgen.cdom.choiceset.ModifyChoiceDecorator)1 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)1 CNAbility (pcgen.cdom.content.CNAbility)1 TabInfo (pcgen.cdom.content.TabInfo)1 Ability (pcgen.core.Ability)1