use of pcgen.cdom.list.ClassSkillList in project pcgen by PCGen.
the class SkilllistToken method unparse.
@Override
public String[] unparse(LoadContext context, PCClass pcc) {
TransitionChoice<ClassSkillList> grantChanges = context.getObjectContext().getObject(pcc, ObjectKey.SKILLLIST_CHOICE);
if (grantChanges == null) {
// Zero indicates no Token
return null;
}
StringBuilder sb = new StringBuilder();
Formula count = grantChanges.getCount();
if (count == null) {
context.addWriteMessage("Unable to find " + getTokenName() + " Count");
return null;
}
sb.append(count);
sb.append(Constants.PIPE);
sb.append(grantChanges.getChoices().getLSTformat().replaceAll(Constants.COMMA, Constants.PIPE));
return new String[] { sb.toString() };
}
use of pcgen.cdom.list.ClassSkillList in project pcgen by PCGen.
the class SkilllistToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
Formula count = FormulaFactory.getFormulaFor(tok.nextToken());
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (!count.isStatic() || count.resolveStatic().intValue() <= 0) {
return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0", context);
}
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail(getTokenName() + " must have a | separating " + "count from the list of possible values: " + value, context);
}
List<CDOMReference<ClassSkillList>> refs = new ArrayList<>();
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
CDOMReference<ClassSkillList> ref;
if (Constants.LST_ALL.equals(token)) {
ref = context.getReferenceContext().getCDOMAllReference(SKILLLIST_CLASS);
} else {
ref = context.getReferenceContext().getCDOMReference(SKILLLIST_CLASS, token);
}
refs.add(ref);
}
ReferenceChoiceSet<ClassSkillList> rcs = new ReferenceChoiceSet<>(refs);
if (!rcs.getGroupingState().isValid()) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value);
}
ChoiceSet<ClassSkillList> cs = new ChoiceSet<>(getTokenName(), rcs);
cs.setTitle("Select class whose class-skills this class will inherit");
TransitionChoice<ClassSkillList> tc = new ConcreteTransitionChoice<>(cs, count);
context.getObjectContext().put(pcc, ObjectKey.SKILLLIST_CHOICE, tc);
tc.setRequired(false);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.list.ClassSkillList in project pcgen by PCGen.
the class SkillListTokenTest method testUnparseNullInList.
@Test
public void testUnparseNullInList() throws PersistenceLayerException {
ClassSkillList wp1 = construct(primaryContext, "TestWP1");
ReferenceChoiceSet<ClassSkillList> rcs = buildRCS(CDOMDirectSingleRef.getRef(wp1), null);
PersistentTransitionChoice<ClassSkillList> tc = buildTC(rcs);
primaryProf.put(ObjectKey.SKILLLIST_CHOICE, tc);
try {
getToken().unparse(primaryContext, primaryProf);
fail();
} catch (NullPointerException e) {
// Yep!
}
}
use of pcgen.cdom.list.ClassSkillList in project pcgen by PCGen.
the class SkillListTokenTest method testUnparseBadCount.
@Test
public void testUnparseBadCount() throws PersistenceLayerException {
ClassSkillList wp1 = construct(primaryContext, "TestWP1");
ReferenceChoiceSet<ClassSkillList> rcs = new ReferenceChoiceSet<>(Collections.singletonList(CDOMDirectSingleRef.getRef(wp1)));
ChoiceSet<ClassSkillList> cs = new ChoiceSet<>(token.getTokenName(), rcs);
cs.setTitle("Pick a ClassSkillList");
PersistentTransitionChoice<ClassSkillList> tc1 = new ConcretePersistentTransitionChoice<>(cs, null);
primaryProf.put(ObjectKey.SKILLLIST_CHOICE, tc1);
assertBadUnparse();
}
use of pcgen.cdom.list.ClassSkillList in project pcgen by PCGen.
the class MonCSkillTokenTest method setUp.
@Override
public void setUp() throws PersistenceLayerException, URISyntaxException {
super.setUp();
ClassSkillList a = primaryContext.getReferenceContext().constructCDOMObject(ClassSkillList.class, "Scary Monster");
a.addType(Type.MONSTER);
ClassSkillList b = secondaryContext.getReferenceContext().constructCDOMObject(ClassSkillList.class, "Scary Monster");
b.addType(Type.MONSTER);
}
Aggregations