use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.
the class DomainTokenTest method testUnparseSinglePre.
@Test
public void testUnparseSinglePre() throws PersistenceLayerException {
Domain wp1 = construct(primaryContext, "TestWP1");
CDOMDirectSingleRef<Domain> ref = CDOMDirectSingleRef.getRef(wp1);
PreParserFactory prereqParser = PreParserFactory.getInstance();
Prerequisite prereq = prereqParser.parse("PRERACE:1,Dwarf");
assertNotNull(prereq);
QualifiedObject<CDOMSingleRef<Domain>> qo = new QualifiedObject<>(ref, prereq);
primaryProf.addToListFor(ListKey.DOMAIN, qo);
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getLegalValue() + "|PRERACE:1,Dwarf");
}
use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.
the class TemplateToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, KitTemplate kitTemplate, String value) {
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
while (tok.hasMoreTokens()) {
String tokText = tok.nextToken();
int openLoc = tokText.indexOf('[');
String name;
List<CDOMSingleRef<PCTemplate>> subList;
if (openLoc == -1) {
name = tokText;
subList = null;
} else {
name = tokText.substring(0, openLoc);
subList = new ArrayList<>();
String rest = tokText.substring(openLoc + 1);
StringTokenizer subTok = new StringTokenizer(rest, "[]");
while (subTok.hasMoreTokens()) {
String subStr = subTok.nextToken();
if (subStr.startsWith("TEMPLATE:")) {
String ownedTemplateName = subStr.substring(9);
CDOMSingleRef<PCTemplate> ref = context.getReferenceContext().getCDOMReference(TEMPLATE_CLASS, ownedTemplateName);
subList.add(ref);
} else {
return new ParseResult.Fail("Did not understand " + getTokenName() + " option: " + subStr + " in line: " + value, context);
}
}
}
CDOMSingleRef<PCTemplate> ref = context.getReferenceContext().getCDOMReference(TEMPLATE_CLASS, name);
kitTemplate.addTemplate(ref, subList);
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.
the class ClassLevelDomainBracketToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClassLevel level, String value) {
Logging.deprecationPrint(getMessage(level, value));
StringTokenizer pipeTok = new StringTokenizer(value, Constants.PIPE);
boolean first = true;
while (pipeTok.hasMoreTokens()) {
String tok = pipeTok.nextToken();
if (Constants.LST_DOT_CLEAR.equals(tok)) {
if (!first) {
return new ParseResult.Fail(" Non-sensical " + getTokenName() + ": .CLEAR was not the first list item", context);
}
context.getObjectContext().removeList(level, ListKey.DOMAIN);
continue;
}
// Note: May contain PRExxx
String domainKey;
Prerequisite prereq = null;
int openBracketLoc = tok.indexOf('[');
if (openBracketLoc == -1) {
if (tok.indexOf(']') != -1) {
return new ParseResult.Fail("Invalid " + getTokenName() + " must have '[' if it contains a PREREQ tag", context);
}
domainKey = tok;
} else {
if (tok.lastIndexOf(']') != tok.length() - 1) {
return new ParseResult.Fail("Invalid " + getTokenName() + " must end with ']' if it contains a PREREQ tag", context);
}
domainKey = tok.substring(0, openBracketLoc);
String prereqString = tok.substring(openBracketLoc + 1, tok.length() - 1);
if (prereqString.isEmpty()) {
return new ParseResult.Fail(getTokenName() + " cannot have empty prerequisite : " + value, context);
}
prereq = getPrerequisite(prereqString);
if (prereq == null) {
return new ParseResult.Fail(getTokenName() + " had invalid prerequisite : " + prereqString, context);
}
}
CDOMSingleRef<Domain> domain = context.getReferenceContext().getCDOMReference(DOMAIN_CLASS, domainKey);
QualifiedObject<CDOMSingleRef<Domain>> qo = new QualifiedObject<>(domain);
if (prereq != null) {
qo.addPrerequisite(prereq);
}
context.getObjectContext().addToList(level, ListKey.DOMAIN, qo);
first = false;
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.
the class ProficiencyToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Equipment eq, String value) {
int pipeLoc = value.indexOf(Constants.PIPE);
if (pipeLoc == -1) {
return new ParseResult.Fail("Equipment Token PROFICIENCY syntax " + "without a Subtoken is invalid: PROFICIENCY:" + value, context);
}
if (pipeLoc != value.lastIndexOf(Constants.PIPE)) {
return new ParseResult.Fail(getTokenName() + " expecting only one '|', " + "format is: SubToken|ProfName value was: " + value, context);
}
String subtoken = value.substring(0, pipeLoc);
String prof = value.substring(pipeLoc + 1);
if (prof == null || prof.isEmpty()) {
return new ParseResult.Fail("PROFICIENCY cannot have " + "empty second argument: " + value, context);
}
if (subtoken.equals("WEAPON")) {
// This can be reactivated if .CLEAR is implemented, to allow .MOD to override the proficiency
// if (context.getObjectContext().getObject(eq, ObjectKey.WEAPON_PROF) != null)
// {
// return new ParseResult.Fail(
// "Only one PROFICIENCY:WEAPON is allowed per item. Token was PROFICIENCY:"
// + value, context);
// }
CDOMSingleRef<WeaponProf> wp = context.getReferenceContext().getCDOMReference(WeaponProf.class, prof);
context.getObjectContext().put(eq, ObjectKey.WEAPON_PROF, wp);
} else if (subtoken.equals("ARMOR")) {
// if (context.getObjectContext().getObject(eq, ObjectKey.ARMOR_PROF) != null)
// {
// return new ParseResult.Fail(
// "Only one PROFICIENCY:ARMOR is allowed per item. Token was PROFICIENCY:"
// + value, context);
// }
CDOMSingleRef<ArmorProf> wp = context.getReferenceContext().getCDOMReference(ArmorProf.class, prof);
context.getObjectContext().put(eq, ObjectKey.ARMOR_PROF, wp);
} else if (subtoken.equals("SHIELD")) {
// if (context.getObjectContext().getObject(eq, ObjectKey.SHIELD_PROF) != null)
// {
// return new ParseResult.Fail(
// "Only one PROFICIENCY:SHIELD is allowed per item. Token was PROFICIENCY:"
// + value, context);
// }
CDOMSingleRef<ShieldProf> wp = context.getReferenceContext().getCDOMReference(ShieldProf.class, prof);
context.getObjectContext().put(eq, ObjectKey.SHIELD_PROF, wp);
} else {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Unknown Subtoken for PROFICIENCY: " + subtoken);
cpr.addErrorMessage(" Subtoken must be " + "WEAPON, ARMOR or SHIELD");
return cpr;
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.
the class ObjectKeyActorTest method testWrappedObjectKeyActor.
public void testWrappedObjectKeyActor() {
Deity d = new Deity();
d.setName("Bob");
PCStat str = new PCStat();
str.setName("Strength");
BigDecimal expectedResult = new BigDecimal("4.063");
str.put(ObjectKey.COST, expectedResult);
df.set(id, d);
d.put(ObjectKey.SPELL_STAT, CDOMDirectSingleRef.getRef(str));
ObjectKeyActor<BigDecimal> oka_cost = new ObjectKeyActor<>(ObjectKey.COST);
CDOMObjectWrapper.load(dsid, str.getClass(), "cost", oka_cost);
ObjectKeyActor<CDOMSingleRef<PCStat>> oka_stat = new ObjectKeyActor<>(ObjectKey.SPELL_STAT);
CDOMObjectWrapper.load(dsid, d.getClass(), "stat", oka_stat);
processThroughFreeMarker("${deity.stat}", str.getDisplayName());
processThroughFreeMarker("${deity.stat.cost}", expectedResult.toString());
}
Aggregations