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;
}
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));
}
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));
}
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;
}
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;
}
Aggregations