Search in sources :

Example 6 with SubClassCategory

use of pcgen.cdom.enumeration.SubClassCategory in project pcgen by PCGen.

the class FavoredClassTokenTest method testCategorizationFail.

@Test
public void testCategorizationFail() throws PersistenceLayerException {
    construct(primaryContext, "TestWP1");
    assertTrue(parse("TestWP1.Two"));
    SubClass obj = primaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Two");
    SubClassCategory cat = SubClassCategory.getConstant("TestWP2");
    primaryContext.getReferenceContext().reassociateCategory(cat, obj);
    assertConstructionError();
}
Also used : SubClass(pcgen.core.SubClass) SubClassCategory(pcgen.cdom.enumeration.SubClassCategory) Test(org.junit.Test)

Example 7 with SubClassCategory

use of pcgen.cdom.enumeration.SubClassCategory in project pcgen by PCGen.

the class FavclassToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Race race, String value) {
    context.getObjectContext().remove(race, ObjectKey.ANY_FAVORED_CLASS);
    context.getObjectContext().removeList(race, ListKey.FAVORED_CLASS);
    context.getObjectContext().removeFromList(race, ListKey.NEW_CHOOSE_ACTOR, this);
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        if (Constants.HIGHEST_LEVEL_CLASS.equalsIgnoreCase(token)) {
            foundAny = true;
            context.getObjectContext().put(race, ObjectKey.ANY_FAVORED_CLASS, true);
        } else if (Constants.LST_PERCENT_LIST.equalsIgnoreCase(token)) {
            foundOther = true;
            context.getObjectContext().addToList(race, ListKey.NEW_CHOOSE_ACTOR, this);
        } else {
            CDOMReference<? extends PCClass> ref;
            foundOther = true;
            int dotLoc = token.indexOf('.');
            if (dotLoc == -1) {
                // Primitive
                ref = context.getReferenceContext().getCDOMReference(PCCLASS_CLASS, token);
            } else {
                ParseResult pr = checkForIllegalSeparator('.', value);
                if (!pr.passed()) {
                    return pr;
                }
                // 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);
            }
            context.getObjectContext().addToList(race, ListKey.FAVORED_CLASS, ref);
        }
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains " + Constants.HIGHEST_LEVEL_CLASS + " and a specific reference: " + value);
    }
    return ParseResult.SUCCESS;
}
Also used : SubClassCategory(pcgen.cdom.enumeration.SubClassCategory) StringTokenizer(java.util.StringTokenizer) ParseResult(pcgen.rules.persistence.token.ParseResult) PCClass(pcgen.core.PCClass) CDOMReference(pcgen.cdom.base.CDOMReference) CategorizedCDOMReference(pcgen.cdom.reference.CategorizedCDOMReference)

Example 8 with SubClassCategory

use of pcgen.cdom.enumeration.SubClassCategory in project pcgen by PCGen.

the class ClassToken method decodeChoice.

@Override
public PCClass decodeChoice(LoadContext context, String s) {
    int dotLoc = s.indexOf('.');
    if (dotLoc == -1) {
        // Primitive
        return context.getReferenceContext().silentlyGetConstructedCDOMObject(PCCLASS_CLASS, s);
    }
    // SubClass
    String parent = s.substring(0, dotLoc);
    String subclass = s.substring(dotLoc + 1);
    SubClassCategory scc = SubClassCategory.getConstant(parent);
    return context.getReferenceContext().silentlyGetConstructedCDOMObject(SUBCLASS_CLASS, scc, subclass);
}
Also used : SubClassCategory(pcgen.cdom.enumeration.SubClassCategory)

Example 9 with SubClassCategory

use of pcgen.cdom.enumeration.SubClassCategory in project pcgen by PCGen.

the class FavoredclassToken method parseFavoredClass.

public ParseResult parseFavoredClass(LoadContext context, CDOMObject cdo, String value) {
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        if (Constants.HIGHEST_LEVEL_CLASS.equalsIgnoreCase(token)) {
            foundAny = true;
            context.getObjectContext().put(cdo, ObjectKey.ANY_FAVORED_CLASS, true);
        } else if (Constants.LST_PERCENT_LIST.equalsIgnoreCase(token)) {
            context.getObjectContext().addToList(cdo, ListKey.NEW_CHOOSE_ACTOR, this);
        } else {
            CDOMReference<? extends PCClass> ref;
            foundOther = true;
            int dotLoc = token.indexOf('.');
            if (dotLoc == -1) {
                // Primitive
                ref = context.getReferenceContext().getCDOMReference(PCCLASS_CLASS, token);
            } else {
                ParseResult pr = checkForIllegalSeparator('.', token);
                if (!pr.passed()) {
                    return pr;
                }
                // 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);
            }
            context.getObjectContext().addToList(cdo, ListKey.FAVORED_CLASS, ref);
        }
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains " + Constants.HIGHEST_LEVEL_CLASS + " and a specific reference: " + value, context);
    }
    return ParseResult.SUCCESS;
}
Also used : SubClassCategory(pcgen.cdom.enumeration.SubClassCategory) StringTokenizer(java.util.StringTokenizer) ParseResult(pcgen.rules.persistence.token.ParseResult) PCClass(pcgen.core.PCClass) CDOMReference(pcgen.cdom.base.CDOMReference) CategorizedCDOMReference(pcgen.cdom.reference.CategorizedCDOMReference)

Example 10 with SubClassCategory

use of pcgen.cdom.enumeration.SubClassCategory in project pcgen by PCGen.

the class FavoredClassIntegrationTest method testRoundRobinSimpleCategorized.

@Test
public void testRoundRobinSimpleCategorized() throws PersistenceLayerException {
    verifyCleanStart();
    construct(primaryContext, "TestWP1");
    construct(primaryContext, "TestWP2");
    construct(secondaryContext, "TestWP1");
    construct(secondaryContext, "TestWP2");
    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);
    TestContext tc = new TestContext();
    commit(testCampaign, tc, "TestWP1");
    commit(modCampaign, tc, "TestWP2.Sub");
    completeRoundRobin(tc);
}
Also used : SubClass(pcgen.core.SubClass) SubClassCategory(pcgen.cdom.enumeration.SubClassCategory) TestContext(plugin.lsttokens.editcontext.testsupport.TestContext) 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