Search in sources :

Example 16 with ChoiceSet

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

the class SkillToken method parseToken.

@Override
public ParseResult parseToken(LoadContext context, CDOMObject obj, String value) {
    if (isEmpty(value)) {
        return new ParseResult.Fail("Value in " + getFullName() + " may not be empty", context);
    }
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String activeValue = sep.next();
    Formula count;
    if (!sep.hasNext()) {
        count = FormulaFactory.ONE;
    } else {
        count = FormulaFactory.getFormulaFor(activeValue);
        if (!count.isValid()) {
            return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
        }
        if (count.isStatic() && count.resolveStatic().doubleValue() <= 0) {
            return new ParseResult.Fail("Count in " + getFullName() + " must be > 0", context);
        }
        activeValue = sep.next();
    }
    if (sep.hasNext()) {
        return new ParseResult.Fail(getFullName() + " had too many pipe separated items: " + value, context);
    }
    ParseResult pr = checkSeparatorsAndNonEmpty(',', activeValue);
    if (!pr.passed()) {
        return pr;
    }
    StringTokenizer tok = new StringTokenizer(activeValue, Constants.COMMA);
    List<CDOMReference<Skill>> refs = new ArrayList<>();
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        CDOMReference<Skill> ref;
        if (Constants.LST_ANY.equalsIgnoreCase(token)) {
            ref = context.getReferenceContext().getCDOMAllReference(SKILL_CLASS);
        } else {
            ref = TokenUtilities.getTypeOrPrimitive(context, SKILL_CLASS, token);
            if (ref == null) {
                return new ParseResult.Fail("  Error was encountered while parsing " + getFullName() + ": " + token + " is not a valid reference: " + value, context);
            }
        }
        refs.add(ref);
    }
    ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
    if (!rcs.getGroupingState().isValid()) {
        return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
    }
    ChoiceSet<Skill> cs = new ChoiceSet<>("SKILL", rcs, true);
    PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, count);
    context.getObjectContext().addToList(obj, ListKey.ADD, tc);
    tc.setChoiceActor(this);
    tc.allowStack(true);
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) Skill(pcgen.core.Skill) ParsingSeparator(pcgen.base.text.ParsingSeparator) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet)

Example 17 with ChoiceSet

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

the class ClassSkillsLevelTokenTest method testUnparseTrained.

@Test
public void testUnparseTrained() throws PersistenceLayerException {
    List<CDOMReference<Skill>> refs = new ArrayList<>();
    ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("TRAINED", Skill.class, getAllRef(), ObjectKey.USE_UNTRAINED, Boolean.FALSE);
    omr.returnIncludesNulls(true);
    refs.add(omr);
    ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
    ChoiceSet<Skill> cs = new ChoiceSet<>(getSubToken().getTokenName(), rcs);
    PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
    primaryProf.addToListFor(ListKey.ADD, tc);
    tc.setChoiceActor(new ClassSkillChoiceActor(fighter, null));
    String[] unparsed = getToken().unparse(primaryContext, primaryProf);
    expectSingle(unparsed, getSubTokenName() + '|' + "TRAINED");
}
Also used : ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Skill(pcgen.core.Skill) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor) CDOMReference(pcgen.cdom.base.CDOMReference) ObjectMatchingReference(pcgen.cdom.reference.ObjectMatchingReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) Test(org.junit.Test)

Example 18 with ChoiceSet

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

the class ClassSkillsLevelTokenTest method testUnparseNonExclusive.

@Test
public void testUnparseNonExclusive() throws PersistenceLayerException {
    List<CDOMReference<Skill>> refs = new ArrayList<>();
    ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("NONEXCLUSIVE", Skill.class, getAllRef(), ObjectKey.EXCLUSIVE, Boolean.FALSE);
    omr.returnIncludesNulls(true);
    refs.add(omr);
    ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
    ChoiceSet<Skill> cs = new ChoiceSet<>(getSubToken().getTokenName(), rcs);
    PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
    primaryProf.addToListFor(ListKey.ADD, tc);
    tc.setChoiceActor(new ClassSkillChoiceActor(fighter, null));
    String[] unparsed = getToken().unparse(primaryContext, primaryProf);
    expectSingle(unparsed, getSubTokenName() + '|' + "NONEXCLUSIVE");
}
Also used : ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Skill(pcgen.core.Skill) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor) CDOMReference(pcgen.cdom.base.CDOMReference) ObjectMatchingReference(pcgen.cdom.reference.ObjectMatchingReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) Test(org.junit.Test)

Example 19 with ChoiceSet

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

the class ClassSkillsTokenTest method testUnparseExclusive.

@Test
public void testUnparseExclusive() throws PersistenceLayerException {
    List<CDOMReference<Skill>> refs = new ArrayList<>();
    ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("EXCLUSIVE", Skill.class, getAllRef(), ObjectKey.EXCLUSIVE, Boolean.TRUE);
    omr.returnIncludesNulls(true);
    refs.add(omr);
    ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
    ChoiceSet<Skill> cs = new ChoiceSet<>(getSubToken().getTokenName(), rcs);
    PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
    primaryProf.addToListFor(ListKey.ADD, tc);
    tc.setChoiceActor(new ClassSkillChoiceActor(fighter, null));
    String[] unparsed = getToken().unparse(primaryContext, primaryProf);
    expectSingle(unparsed, getSubTokenName() + '|' + "EXCLUSIVE");
}
Also used : ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Skill(pcgen.core.Skill) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor) CDOMReference(pcgen.cdom.base.CDOMReference) ObjectMatchingReference(pcgen.cdom.reference.ObjectMatchingReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) Test(org.junit.Test)

Example 20 with ChoiceSet

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

the class ClassSkillsTokenTest method testUnparseNonExclusive.

@Test
public void testUnparseNonExclusive() throws PersistenceLayerException {
    List<CDOMReference<Skill>> refs = new ArrayList<>();
    ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("NONEXCLUSIVE", Skill.class, getAllRef(), ObjectKey.EXCLUSIVE, Boolean.FALSE);
    omr.returnIncludesNulls(true);
    refs.add(omr);
    ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
    ChoiceSet<Skill> cs = new ChoiceSet<>(getSubToken().getTokenName(), rcs);
    PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
    primaryProf.addToListFor(ListKey.ADD, tc);
    tc.setChoiceActor(new ClassSkillChoiceActor(fighter, null));
    String[] unparsed = getToken().unparse(primaryContext, primaryProf);
    expectSingle(unparsed, getSubTokenName() + '|' + "NONEXCLUSIVE");
}
Also used : ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Skill(pcgen.core.Skill) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor) CDOMReference(pcgen.cdom.base.CDOMReference) ObjectMatchingReference(pcgen.cdom.reference.ObjectMatchingReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) Test(org.junit.Test)

Aggregations

ChoiceSet (pcgen.cdom.base.ChoiceSet)25 ArrayList (java.util.ArrayList)22 CDOMReference (pcgen.cdom.base.CDOMReference)22 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)21 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)20 Skill (pcgen.core.Skill)13 Test (org.junit.Test)12 ClassSkillChoiceActor (pcgen.cdom.helper.ClassSkillChoiceActor)12 StringTokenizer (java.util.StringTokenizer)11 Formula (pcgen.base.formula.Formula)11 ObjectMatchingReference (pcgen.cdom.reference.ObjectMatchingReference)10 ParsingSeparator (pcgen.base.text.ParsingSeparator)7 ParseResult (pcgen.rules.persistence.token.ParseResult)7 ConcreteTransitionChoice (pcgen.cdom.base.ConcreteTransitionChoice)5 CDOMListObject (pcgen.cdom.base.CDOMListObject)2 NonInteractive (pcgen.cdom.base.NonInteractive)2 PrimitiveChoiceSet (pcgen.cdom.base.PrimitiveChoiceSet)2 Ungranted (pcgen.cdom.base.Ungranted)2 AbilityRefChoiceSet (pcgen.cdom.choiceset.AbilityRefChoiceSet)2 CNAbility (pcgen.cdom.content.CNAbility)2