use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.
the class DomainToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClassLevel pcl, String value) {
StringTokenizer pipeTok = new StringTokenizer(value, Constants.PIPE);
boolean first = true;
String tok = pipeTok.nextToken();
if (looksLikeAPrerequisite(tok)) {
return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName() + ": " + value, context);
}
List<QualifiedObject<CDOMSingleRef<Domain>>> toAdd = new ArrayList<>();
boolean foundClear = false;
while (true) {
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(pcl, ListKey.DOMAIN);
foundClear = true;
} else {
CDOMSingleRef<Domain> domain = context.getReferenceContext().getCDOMReference(DOMAIN_CLASS, tok);
QualifiedObject<CDOMSingleRef<Domain>> qo = new QualifiedObject<>(domain);
toAdd.add(qo);
context.getObjectContext().addToList(pcl, ListKey.DOMAIN, qo);
}
first = false;
if (!pipeTok.hasMoreTokens()) {
// No prereqs, so we're done
return ParseResult.SUCCESS;
}
tok = pipeTok.nextToken();
if (looksLikeAPrerequisite(tok)) {
break;
}
}
if (foundClear) {
return new ParseResult.Fail("Cannot use PREREQs when using .CLEAR in " + getTokenName(), context);
}
while (true) {
Prerequisite prereq = getPrerequisite(tok);
if (prereq == null) {
return new ParseResult.Fail(" (Did you put feats after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
}
for (PrereqObject pro : toAdd) {
pro.addPrerequisite(prereq);
}
if (!pipeTok.hasMoreTokens()) {
break;
}
tok = pipeTok.nextToken();
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.
the class AbilityListTokenTest method testEntriesWithAssoc.
/**
* Test that entries with associated choices are parsed correctly
*/
public void testEntriesWithAssoc() {
AbilityCategory aCat = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "TestCat");
aCat.setAbilityCategory(CDOMDirectSingleRef.getRef(AbilityCategory.FEAT));
assertFalse("Test category should start with an empty list of keys", aCat.hasDirectReferences());
assertEquals("Test category should start with an empty list of keys", 0, aCat.getAbilityRefs().size());
AbilityListToken token = new AbilityListToken();
Ability pbs = buildFeat(context, "Point Blank Shot");
Ability sf = buildFeat(context, "Skill Focus");
token.parseToken(context, aCat, "Point Blank Shot|Skill Focus (Ride)|Skill Focus (Bluff)");
assertEquals("Test category should now have 3 keys", 3, aCat.getAbilityRefs().size());
assertContains(aCat, pbs, true);
//Because this tests LST format
assertContains(aCat, sf, false);
context.getReferenceContext().validate(new LoadValidator(new ArrayList<>()));
assertTrue(context.getReferenceContext().resolveReferences(null));
Collection<CDOMSingleRef<Ability>> refs = aCat.getAbilityRefs();
boolean found = false;
for (CDOMSingleRef<Ability> ref : refs) {
found |= ref.contains(pbs);
}
assertTrue("Expected Point Blank Shot Ability", found);
found = false;
for (CDOMSingleRef<Ability> ref : refs) {
found |= ref.contains(sf);
}
assertTrue("Expected Skill Focus Ability", found);
}
use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.
the class UnlockedStatFacet method dataAdded.
/**
* Adds a PCStat to this facet if the PCStat was unlocked by a CDOMObject
* which has been added to a Player Character.
*
* Triggered when one of the Facets to which UnlockedStatFacet listens fires
* a DataFacetChangeEvent to indicate a CDOMObject was added to a Player
* Character.
*
* @param dfce
* The DataFacetChangeEvent containing the information about the
* change
*
* @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
*/
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
CDOMObject cdo = dfce.getCDOMObject();
List<CDOMSingleRef<PCStat>> unlocked = cdo.getListFor(ListKey.UNLOCKED_STATS);
if (unlocked != null) {
CharID charID = dfce.getCharID();
for (CDOMSingleRef<PCStat> ref : unlocked) {
add(charID, ref.get(), cdo);
}
}
}
use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.
the class CharacterFacadeImpl method processDomainList.
private void processDomainList(CDOMObject obj, final List<DomainFacadeImpl> availDomainList) {
for (QualifiedObject<CDOMSingleRef<Domain>> qo : obj.getSafeListFor(ListKey.DOMAIN)) {
CDOMSingleRef<Domain> ref = qo.getRawObject();
Domain domain = ref.get();
if (!isDomainInList(availDomainList, domain)) {
availDomainList.add(new DomainFacadeImpl(domain, qo.getPrerequisiteList()));
}
}
}
use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.
the class WieldCategoryLoader method parseLine.
/**
* Parse the WIELDCATEGORY line
*
* @param gameMode
* @param lstLine
* @throws PersistenceLayerException
*/
public void parseLine(GameMode gameMode, String lstLine, URI source) throws PersistenceLayerException {
LoadContext context = gameMode.getModeContext();
StringTokenizer colToken = new StringTokenizer(lstLine, SystemLoader.TAB_DELIM);
WieldCategory cat = null;
String preKey = null;
CDOMSingleRef<WieldCategory> preVal = null;
while (colToken.hasMoreTokens()) {
final String colString = colToken.nextToken().trim();
final int idxColon = colString.indexOf(':');
String key = "";
try {
key = colString.substring(0, idxColon);
} catch (StringIndexOutOfBoundsException e) {
// TODO Deal with Exception
}
if (key.equals("WIELDCATEGORY")) {
final String value = colString.substring(idxColon + 1).trim();
cat = context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, value);
if (cat == null) {
cat = new WieldCategory();
cat.setName(value.intern());
gameMode.addWieldCategory(cat);
}
} else if (colString.startsWith("PREVAR")) {
//TODO ensure preKey is null
// a PREVARxx formula used to switch
// weapon categories based on size
preKey = colString;
} else if (key.equals("SWITCH")) {
//TODO ensure preVal is null
// If matches PRE, switch category to this
preVal = context.getReferenceContext().getCDOMReference(WieldCategory.class, colString.substring(7));
} else {
final String value = colString.substring(idxColon + 1).trim();
if (context.processToken(cat, key, value)) {
context.commit();
} else {
context.rollback();
Logging.replayParsedMessages();
}
Logging.clearParseMessages();
}
}
//TODO Error checking if preVal w/o preKey, vice versa, etc.
if ((cat != null) && (preVal != null) && (preKey != null)) {
try {
QualifiedObject<CDOMSingleRef<WieldCategory>> qo = new QualifiedObject<>(preVal);
qo.addPrerequisite(prereqParser.parse(preKey));
cat.addCategorySwitch(qo);
} catch (PersistenceLayerException ple) {
Logging.errorPrint("Error parsing Prerequisite in " + source + ": " + preKey + "\n " + ple.getMessage());
}
}
}
Aggregations