use of pcgen.cdom.enumeration.SubClassCategory in project pcgen by PCGen.
the class SubClassTokenTest method testInvalidInputOnlyOne.
@Test
public void testInvalidInputOnlyOne() throws PersistenceLayerException {
SubClassCategory cat = SubClassCategory.getConstant("Wizard");
SubClass sc = primaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Fireball");
primaryContext.getReferenceContext().reassociateCategory(cat, sc);
sc = secondaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Fireball");
secondaryContext.getReferenceContext().reassociateCategory(cat, sc);
sc = primaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "English");
primaryContext.getReferenceContext().reassociateCategory(cat, sc);
sc = secondaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "English");
secondaryContext.getReferenceContext().reassociateCategory(cat, sc);
assertTrue(parse("Fireball,English"));
assertConstructionError();
}
use of pcgen.cdom.enumeration.SubClassCategory in project pcgen by PCGen.
the class SubClassTokenTest method testRoundRobinSimple.
@Test
public void testRoundRobinSimple() throws PersistenceLayerException {
SubClassCategory cat = SubClassCategory.getConstant("Wizard");
SubClass sc = primaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Fireball");
primaryContext.getReferenceContext().reassociateCategory(cat, sc);
sc = secondaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Fireball");
secondaryContext.getReferenceContext().reassociateCategory(cat, sc);
runRoundRobin("Fireball");
}
use of pcgen.cdom.enumeration.SubClassCategory in project pcgen by PCGen.
the class FavClassConvertPlugin method process.
@Override
public String process(TokenProcessEvent tpe) {
String value = tpe.getValue();
if (!value.startsWith(Constants.LST_CHOOSE_COLON)) {
// Don't consume, force the default processor to do the work...
return null;
}
String choices = value.substring(7);
if (isEmpty(choices) || hasIllegalSeparator('|', choices)) {
return "Empty Token";
}
boolean foundAny = false;
boolean foundOther = false;
StringTokenizer tok = new StringTokenizer(choices, Constants.PIPE);
List<CDOMReference<? extends PCClass>> refList = new ArrayList<>();
LoadContext context = tpe.getContext();
while (tok.hasMoreTokens()) {
CDOMReference<? extends PCClass> ref;
String token = tok.nextToken();
if (Constants.LST_ALL.equalsIgnoreCase(token) || Constants.LST_ANY.equalsIgnoreCase(token)) {
foundAny = true;
ref = context.getReferenceContext().getCDOMAllReference(PCCLASS_CLASS);
} else {
foundOther = true;
int dotLoc = token.indexOf('.');
if (dotLoc == -1) {
// Primitive
ref = context.getReferenceContext().getCDOMReference(PCCLASS_CLASS, token);
} else {
// SubClass
String parent = token.substring(0, dotLoc);
String subclass = token.substring(dotLoc + 1);
SubClassCategory scc = SubClassCategory.getConstant(parent);
ref = context.getReferenceContext().getCDOMReference(SUBCLASS_CLASS, scc, subclass);
}
}
refList.add(ref);
}
if (foundAny && foundOther) {
return "Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value;
}
String name = tpe.getPrimary().get(StringKey.CONVERT_NAME);
// TODO Need a method of guaranteeing this name is unique?
String templName = "Race " + name + " Favored Class";
tpe.append("TEMPLATE:");
tpe.append(templName);
PCTemplate templ = new PCTemplate();
context.unconditionallyProcess(templ, "FAVOREDCLASS", "%LIST");
StringBuilder chooseValue = new StringBuilder();
chooseValue.append("CLASS|");
boolean first = true;
for (CDOMReference<? extends PCClass> ref : refList) {
if (!first) {
chooseValue.append(Constants.COMMA);
}
first = false;
Class<? extends PCClass> refClass = ref.getReferenceClass();
if (SUBCLASS_CLASS.equals(refClass)) {
Category<SubClass> parent = ((CategorizedCDOMReference<SubClass>) ref).getCDOMCategory();
chooseValue.append(parent);
chooseValue.append('.');
}
chooseValue.append(ref.getLSTformat(false));
}
context.unconditionallyProcess(templ, "CHOOSE", chooseValue.toString());
templ.setName(templName);
tpe.inject(templ);
tpe.consume();
return null;
}
use of pcgen.cdom.enumeration.SubClassCategory in project pcgen by PCGen.
the class FavoredClassTokenTest method testRoundRobinThreeSub.
@Test
public void testRoundRobinThreeSub() throws PersistenceLayerException {
construct(primaryContext, "TestWP1");
construct(primaryContext, "TestWP2");
construct(primaryContext, "TestWP3");
construct(secondaryContext, "TestWP1");
construct(secondaryContext, "TestWP2");
construct(secondaryContext, "TestWP3");
SubClass obj = primaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Sub");
SubClassCategory cat = SubClassCategory.getConstant("TestWP2");
primaryContext.getReferenceContext().reassociateCategory(cat, obj);
obj = secondaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Sub");
secondaryContext.getReferenceContext().reassociateCategory(cat, obj);
runRoundRobin("TestWP1" + getJoinCharacter() + "TestWP2.Sub" + getJoinCharacter() + "TestWP3");
}
Aggregations