Search in sources :

Example 11 with SubClass

use of pcgen.core.SubClass in project pcgen by PCGen.

the class FavoredClassTokenTest method testCategorizationPass.

@Test
public void testCategorizationPass() 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);
    obj = primaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Two");
    cat = SubClassCategory.getConstant("TestWP1");
    primaryContext.getReferenceContext().reassociateCategory(cat, obj);
    assertCleanConstruction();
}
Also used : SubClass(pcgen.core.SubClass) SubClassCategory(pcgen.cdom.enumeration.SubClassCategory) Test(org.junit.Test)

Example 12 with SubClass

use of pcgen.core.SubClass 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 13 with SubClass

use of pcgen.core.SubClass in project pcgen by PCGen.

the class ClassLoader method process.

@Override
public List<CDOMObject> process(StringBuilder sb, int line, String lineString, ConversionDecider decider) throws PersistenceLayerException, InterruptedException {
    List<CDOMObject> list = new ArrayList<>();
    String[] tokens = lineString.split(FIELD_SEPARATOR);
    if (tokens.length == 0) {
        return list;
    }
    String firstToken = tokens[0];
    sb.append(firstToken);
    Class<? extends CDOMObject> buildClass;
    Class<? extends CDOMObject> buildParent = null;
    if (firstToken.startsWith("SUBCLASS:")) {
        buildClass = SubClass.class;
    } else if (firstToken.startsWith("SUBCLASSLEVEL:")) {
        buildClass = PCClassLevel.class;
        buildParent = SubClass.class;
    } else if (firstToken.startsWith("SUBSTITUTIONCLASS:")) {
        buildClass = SubstitutionClass.class;
    } else if (firstToken.startsWith("SUBSTITUTIONLEVEL:")) {
        buildClass = PCClassLevel.class;
        buildParent = SubstitutionClass.class;
    } else if (firstToken.startsWith("CLASS:")) {
        buildClass = PCClass.class;
    } else {
        buildClass = PCClassLevel.class;
        buildParent = PCClass.class;
    }
    for (int tok = 1; tok < tokens.length; tok++) {
        String token = tokens[tok];
        sb.append(FIELD_SEPARATOR);
        if (token.isEmpty()) {
            continue;
        }
        CDOMObject obj = context.getReferenceContext().constructCDOMObject(buildClass, line + "Test" + tok);
        CDOMObject parent = null;
        if (obj instanceof PCClassLevel) {
            obj.put(IntegerKey.LEVEL, 1);
            parent = context.getReferenceContext().constructCDOMObject(buildParent, line + "Test" + tok);
            try {
                // Ensure processing against the PCClassLevel cannot cause side effects on the parent class
                obj.put(ObjectKey.TOKEN_PARENT, parent.clone());
            } catch (CloneNotSupportedException e) {
                Logging.errorPrint("Unable to preare a copy of " + parent);
            }
        }
        List<CDOMObject> injected = processToken(sb, firstToken, obj, parent, token, decider, line);
        if (injected != null) {
            list.addAll(injected);
        }
        context.purge(obj);
        if (parent != null) {
            context.purge(parent);
        }
        TokenConverter.clearConstants();
    }
    return list;
}
Also used : SubClass(pcgen.core.SubClass) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) PCClassLevel(pcgen.cdom.inst.PCClassLevel) SubstitutionClass(pcgen.core.SubstitutionClass)

Example 14 with SubClass

use of pcgen.core.SubClass in project pcgen by PCGen.

the class PCClassLoader method loadSubLines.

public void loadSubLines(LoadContext context) {
    Collection<PCClass> allClasses = context.getReferenceContext().getConstructedCDOMObjects(PCClass.class);
    for (PCClass cl : allClasses) {
        List<SubClass> subClasses = cl.getListFor(ListKey.SUB_CLASS);
        if (subClasses != null) {
            for (SubClass sc : subClasses) {
                sc.copyLevelsFrom(cl);
                processSubLevelLines(context, cl, sc);
            }
        }
        List<SubstitutionClass> substClasses = cl.getListFor(ListKey.SUBSTITUTION_CLASS);
        if (substClasses != null) {
            for (SubstitutionClass sc : substClasses) {
                processSubLevelLines(context, cl, sc);
            }
        }
    }
}
Also used : SubClass(pcgen.core.SubClass) PCClass(pcgen.core.PCClass) SubstitutionClass(pcgen.core.SubstitutionClass)

Example 15 with SubClass

use of pcgen.core.SubClass 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

SubClass (pcgen.core.SubClass)21 SubClassCategory (pcgen.cdom.enumeration.SubClassCategory)11 Test (org.junit.Test)9 PCClass (pcgen.core.PCClass)8 ArrayList (java.util.ArrayList)3 ClassSkillList (pcgen.cdom.list.ClassSkillList)3 SubstitutionClass (pcgen.core.SubstitutionClass)3 StringTokenizer (java.util.StringTokenizer)2 SpellProhibitor (pcgen.core.SpellProhibitor)2 CDOMObject (pcgen.cdom.base.CDOMObject)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 HitDie (pcgen.cdom.content.HitDie)1 PCClassLevel (pcgen.cdom.inst.PCClassLevel)1 ClassSpellList (pcgen.cdom.list.ClassSpellList)1 DomainSpellList (pcgen.cdom.list.DomainSpellList)1 CategorizedCDOMReference (pcgen.cdom.reference.CategorizedCDOMReference)1 Domain (pcgen.core.Domain)1 PCTemplate (pcgen.core.PCTemplate)1 CDOMChooserFacadeImpl (pcgen.core.chooser.CDOMChooserFacadeImpl)1 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)1