use of pcgen.cdom.base.ChoiceSet in project pcgen by PCGen.
the class ClassSkillsLevelTokenTest method testUnparseSingleRanked.
@Test
public void testUnparseSingleRanked() throws PersistenceLayerException {
List<CDOMReference<Skill>> refs = new ArrayList<>();
addSingleRef(refs, "TestWP1");
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, 3));
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getSubTokenName() + '|' + "TestWP1,AUTORANK=3");
}
use of pcgen.cdom.base.ChoiceSet in project pcgen by PCGen.
the class ClassSkillsLevelTokenTest 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");
}
use of pcgen.cdom.base.ChoiceSet in project pcgen by PCGen.
the class ClassSkillsLevelTokenTest method testUnparseUntrained.
@Test
public void testUnparseUntrained() throws PersistenceLayerException {
List<CDOMReference<Skill>> refs = new ArrayList<>();
ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("UNTRAINED", Skill.class, getAllRef(), ObjectKey.USE_UNTRAINED, 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() + '|' + "UNTRAINED");
}
use of pcgen.cdom.base.ChoiceSet in project pcgen by PCGen.
the class ClassSkillsTokenTest method testUnparseUntrained.
@Test
public void testUnparseUntrained() throws PersistenceLayerException {
List<CDOMReference<Skill>> refs = new ArrayList<>();
ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("UNTRAINED", Skill.class, getAllRef(), ObjectKey.USE_UNTRAINED, 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() + '|' + "UNTRAINED");
}
use of pcgen.cdom.base.ChoiceSet in project pcgen by PCGen.
the class RegionLst method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
if (obj instanceof NonInteractive) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: " + obj.getClass().getSimpleName(), context);
}
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
String item = tok.nextToken();
Formula count = FormulaFactory.getFormulaFor(item);
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (count.isStatic()) {
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail(getTokenName() + " cannot have only a count: " + value, context);
}
item = tok.nextToken();
if (count.resolveStatic().intValue() <= 0) {
return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0: " + value, context);
}
} else {
count = FormulaFactory.ONE;
}
List<Region> regions = new ArrayList<>();
while (true) {
regions.add(Region.getConstant(item));
if (!tok.hasMoreTokens()) {
break;
}
item = tok.nextToken();
}
SimpleChoiceSet<Region> rcs = new SimpleChoiceSet<>(regions);
ChoiceSet<Region> cs = new ChoiceSet<>(getTokenName(), rcs);
cs.setTitle("Region Selection");
TransitionChoice<Region> tc = new ConcreteTransitionChoice<>(cs, count);
context.getObjectContext().put(obj, ObjectKey.REGION_CHOICE, tc);
tc.setRequired(false);
tc.setChoiceActor(this);
return ParseResult.SUCCESS;
}
Aggregations