Search in sources :

Example 46 with PCTemplate

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

the class TemplateFacetTest method getObject.

@Override
protected PCTemplate getObject() {
    PCTemplate t = new PCTemplate();
    t.setName("Template" + n++);
    return t;
}
Also used : PCTemplate(pcgen.core.PCTemplate)

Example 47 with PCTemplate

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

the class RaceTypeFacetTest method testGetFromTemplateOverridesRaceandCMod.

@Test
public void testGetFromTemplateOverridesRaceandCMod() {
    Race r = new Race();
    r.put(ObjectKey.RACETYPE, TEST_RACE_TYPE);
    rfacet.set(id, r);
    assertSame(TEST_RACE_TYPE, facet.getRaceType(id));
    CompanionMod c = new CompanionMod();
    c.put(ObjectKey.RACETYPE, RACE_TYPE_TOO);
    cfacet.add(id, c);
    assertSame(RACE_TYPE_TOO, facet.getRaceType(id));
    PCTemplate t = new PCTemplate();
    t.put(ObjectKey.RACETYPE, LAST_RACE_TYPE);
    tfacet.add(id, t, this);
    assertSame(LAST_RACE_TYPE, facet.getRaceType(id));
    tfacet.remove(id, t, this);
    assertSame(RACE_TYPE_TOO, facet.getRaceType(id));
    cfacet.remove(id, c);
    assertSame(TEST_RACE_TYPE, facet.getRaceType(id));
}
Also used : Race(pcgen.core.Race) PCTemplate(pcgen.core.PCTemplate) CompanionMod(pcgen.core.character.CompanionMod) Test(org.junit.Test)

Example 48 with PCTemplate

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

the class RaceTypeFacetTest method testGetFromTemplateSecondOverrides.

@Test
public void testGetFromTemplateSecondOverrides() {
    Race r = new Race();
    r.put(ObjectKey.RACETYPE, TEST_RACE_TYPE);
    rfacet.set(id, r);
    assertSame(TEST_RACE_TYPE, facet.getRaceType(id));
    PCTemplate t = new PCTemplate();
    t.setName("PCT");
    t.put(ObjectKey.RACETYPE, RACE_TYPE_TOO);
    tfacet.add(id, t, this);
    assertSame(RACE_TYPE_TOO, facet.getRaceType(id));
    PCTemplate t2 = new PCTemplate();
    t2.setName("Other");
    t2.put(ObjectKey.RACETYPE, LAST_RACE_TYPE);
    tfacet.add(id, t2, this);
    assertSame(LAST_RACE_TYPE, facet.getRaceType(id));
    tfacet.remove(id, t, this);
    assertSame(LAST_RACE_TYPE, facet.getRaceType(id));
    tfacet.add(id, t, this);
    assertSame(RACE_TYPE_TOO, facet.getRaceType(id));
    tfacet.remove(id, t, this);
    assertSame(LAST_RACE_TYPE, facet.getRaceType(id));
    tfacet.remove(id, t2, this);
    assertSame(TEST_RACE_TYPE, facet.getRaceType(id));
}
Also used : Race(pcgen.core.Race) PCTemplate(pcgen.core.PCTemplate) Test(org.junit.Test)

Example 49 with PCTemplate

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

the class HdToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCTemplate template, String value) {
    StringTokenizer tok = new StringTokenizer(value, Constants.COLON);
    String hdString = tok.nextToken();
    int minhd;
    int maxhd;
    try {
        int minusLoc = hdString.indexOf('-');
        if (minusLoc == -1) {
            int plusLoc = hdString.indexOf('+');
            if (plusLoc == 0) {
                return new ParseResult.Fail("Malformed " + getTokenName() + " Cannot start with +: " + hdString, context);
            } else if (plusLoc == hdString.length() - 1) {
                minhd = Integer.parseInt(hdString.substring(0, hdString.length() - 1));
                maxhd = Integer.MAX_VALUE;
            } else {
                minhd = Integer.parseInt(hdString);
                maxhd = minhd;
            }
        } else {
            minhd = Integer.parseInt(hdString.substring(0, minusLoc));
            maxhd = Integer.parseInt(hdString.substring(minusLoc + 1));
        }
        if (maxhd < minhd) {
            return new ParseResult.Fail("Malformed " + getTokenName() + " Token (Max < Min): " + hdString, context);
        }
    } catch (NumberFormatException ex) {
        return new ParseResult.Fail("Malformed " + getTokenName() + " Token (HD syntax invalid): " + hdString, context);
    }
    if (!tok.hasMoreTokens()) {
        return new ParseResult.Fail("Invalid " + getTokenName() + ": requires 3 colon separated elements (has one): " + value, context);
    }
    String typeStr = tok.nextToken();
    if (!tok.hasMoreTokens()) {
        return new ParseResult.Fail("Invalid " + getTokenName() + ": requires 3 colon separated elements (has two): " + value, context);
    }
    String argument = tok.nextToken();
    PCTemplate derivative = new PCTemplate();
    derivative.put(ObjectKey.VISIBILITY, Visibility.HIDDEN);
    derivative.put(IntegerKey.HD_MIN, minhd);
    derivative.put(IntegerKey.HD_MAX, maxhd);
    context.getReferenceContext().getManufacturer(PCTemplate.class).addDerivativeObject(derivative);
    context.getObjectContext().addToList(template, ListKey.HD_TEMPLATES, derivative);
    try {
        if (context.processToken(derivative, typeStr, argument)) {
            return ParseResult.SUCCESS;
        }
    } catch (PersistenceLayerException e) {
        return new ParseResult.Fail(e.getMessage(), context);
    }
    return ParseResult.INTERNAL_ERROR;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) StringTokenizer(java.util.StringTokenizer) ParseResult(pcgen.rules.persistence.token.ParseResult) PCTemplate(pcgen.core.PCTemplate)

Example 50 with PCTemplate

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

the class LevelToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCTemplate template, String value) {
    StringTokenizer tok = new StringTokenizer(value, Constants.COLON);
    String levelStr = tok.nextToken();
    int plusLoc = levelStr.indexOf('+');
    if (plusLoc == 0) {
        return new ParseResult.Fail("Malformed " + getTokenName() + " Level cannot start with +: " + value, context);
    }
    int lvl;
    try {
        /*
			 * Note this test of integer (even if it doesn't get used outside
			 * this try) is necessary for catching errors.
			 */
        lvl = Integer.parseInt(levelStr);
        if (lvl <= 0) {
            ComplexParseResult cpr = new ComplexParseResult();
            cpr.addErrorMessage("Malformed " + getTokenName() + " Token (Level was <= 0): " + lvl);
            cpr.addErrorMessage("  Line was: " + value);
            return cpr;
        }
    } catch (NumberFormatException ex) {
        return new ParseResult.Fail("Misunderstood Level value: " + levelStr + " in " + getTokenName(), context);
    }
    if (!tok.hasMoreTokens()) {
        return new ParseResult.Fail("Invalid " + getTokenName() + ": requires 3 colon separated elements (has one): " + value, context);
    }
    String typeStr = tok.nextToken();
    if (!tok.hasMoreTokens()) {
        return new ParseResult.Fail("Invalid " + getTokenName() + ": requires 3 colon separated elements (has two): " + value, context);
    }
    String argument = tok.nextToken();
    PCTemplate derivative = new PCTemplate();
    derivative.put(ObjectKey.VISIBILITY, Visibility.HIDDEN);
    derivative.put(IntegerKey.LEVEL, lvl);
    context.getReferenceContext().getManufacturer(PCTemplate.class).addDerivativeObject(derivative);
    context.getObjectContext().addToList(template, ListKey.LEVEL_TEMPLATES, derivative);
    try {
        if (context.processToken(derivative, typeStr, argument)) {
            return ParseResult.SUCCESS;
        }
    } catch (PersistenceLayerException e) {
        return new ParseResult.Fail(e.getMessage(), context);
    }
    return ParseResult.INTERNAL_ERROR;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) StringTokenizer(java.util.StringTokenizer) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) ParseResult(pcgen.rules.persistence.token.ParseResult) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) PCTemplate(pcgen.core.PCTemplate)

Aggregations

PCTemplate (pcgen.core.PCTemplate)215 Test (org.junit.Test)105 Race (pcgen.core.Race)66 PlayerCharacter (pcgen.core.PlayerCharacter)38 CDOMObject (pcgen.cdom.base.CDOMObject)31 ArrayList (java.util.ArrayList)19 CharID (pcgen.cdom.enumeration.CharID)18 ParseResult (pcgen.rules.persistence.token.ParseResult)14 SimpleAssociatedObject (pcgen.cdom.base.SimpleAssociatedObject)13 Vision (pcgen.core.Vision)12 LoadContext (pcgen.rules.context.LoadContext)12 PCClass (pcgen.core.PCClass)11 StringTokenizer (java.util.StringTokenizer)10 VariableKey (pcgen.cdom.enumeration.VariableKey)8 DataFacetChangeEvent (pcgen.cdom.facet.event.DataFacetChangeEvent)8 Ability (pcgen.core.Ability)8 Formula (pcgen.base.formula.Formula)6 Equipment (pcgen.core.Equipment)6 PCStat (pcgen.core.PCStat)6 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)6