Search in sources :

Example 11 with SubClassCategory

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();
}
Also used : SubClassCategory(pcgen.cdom.enumeration.SubClassCategory) SubClass(pcgen.core.SubClass) Test(org.junit.Test)

Example 12 with SubClassCategory

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");
}
Also used : SubClassCategory(pcgen.cdom.enumeration.SubClassCategory) SubClass(pcgen.core.SubClass) Test(org.junit.Test)

Example 13 with SubClassCategory

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;
}
Also used : SubClassCategory(pcgen.cdom.enumeration.SubClassCategory) SubClass(pcgen.core.SubClass) ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) CategorizedCDOMReference(pcgen.cdom.reference.CategorizedCDOMReference) StringTokenizer(java.util.StringTokenizer) LoadContext(pcgen.rules.context.LoadContext) PCTemplate(pcgen.core.PCTemplate) CDOMReference(pcgen.cdom.base.CDOMReference) CategorizedCDOMReference(pcgen.cdom.reference.CategorizedCDOMReference)

Example 14 with SubClassCategory

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");
}
Also used : SubClass(pcgen.core.SubClass) SubClassCategory(pcgen.cdom.enumeration.SubClassCategory) Test(org.junit.Test)

Aggregations

SubClassCategory (pcgen.cdom.enumeration.SubClassCategory)14 SubClass (pcgen.core.SubClass)11 Test (org.junit.Test)9 PCClass (pcgen.core.PCClass)4 StringTokenizer (java.util.StringTokenizer)3 CDOMReference (pcgen.cdom.base.CDOMReference)3 CategorizedCDOMReference (pcgen.cdom.reference.CategorizedCDOMReference)3 ParseResult (pcgen.rules.persistence.token.ParseResult)2 ArrayList (java.util.ArrayList)1 ClassSkillList (pcgen.cdom.list.ClassSkillList)1 ClassSpellList (pcgen.cdom.list.ClassSpellList)1 DomainSpellList (pcgen.cdom.list.DomainSpellList)1 Domain (pcgen.core.Domain)1 PCTemplate (pcgen.core.PCTemplate)1 LoadContext (pcgen.rules.context.LoadContext)1 TestContext (plugin.lsttokens.editcontext.testsupport.TestContext)1