use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.
the class ClassSkillsLevelTokenTest method testUnparseExclusive.
@Test
public void testUnparseExclusive() throws PersistenceLayerException {
List<CDOMReference<Skill>> refs = new ArrayList<>();
ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("EXCLUSIVE", Skill.class, getAllRef(), ObjectKey.EXCLUSIVE, Boolean.TRUE);
omr.returnIncludesNulls(true);
refs.add(omr);
ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
ChoiceSet<Skill> cs = new ChoiceSet<>(getSubToken().getTokenName(), rcs);
PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
primaryProf.addToListFor(ListKey.ADD, tc);
tc.setChoiceActor(new ClassSkillChoiceActor(fighter, null));
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getSubTokenName() + '|' + "EXCLUSIVE");
}
use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.
the class ClassSkillsLevelTokenTest method testUnparseUntrained.
@Test
public void testUnparseUntrained() throws PersistenceLayerException {
List<CDOMReference<Skill>> refs = new ArrayList<>();
ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("UNTRAINED", Skill.class, getAllRef(), ObjectKey.USE_UNTRAINED, Boolean.TRUE);
omr.returnIncludesNulls(true);
refs.add(omr);
ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
ChoiceSet<Skill> cs = new ChoiceSet<>(getSubToken().getTokenName(), rcs);
PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
primaryProf.addToListFor(ListKey.ADD, tc);
tc.setChoiceActor(new ClassSkillChoiceActor(fighter, null));
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getSubTokenName() + '|' + "UNTRAINED");
}
use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.
the class ClassSkillsTokenTest method testUnparseUntrained.
@Test
public void testUnparseUntrained() throws PersistenceLayerException {
List<CDOMReference<Skill>> refs = new ArrayList<>();
ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("UNTRAINED", Skill.class, getAllRef(), ObjectKey.USE_UNTRAINED, Boolean.TRUE);
omr.returnIncludesNulls(true);
refs.add(omr);
ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
ChoiceSet<Skill> cs = new ChoiceSet<>(getSubToken().getTokenName(), rcs);
PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
primaryProf.addToListFor(ListKey.ADD, tc);
tc.setChoiceActor(new ClassSkillChoiceActor(fighter, null));
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getSubTokenName() + '|' + "UNTRAINED");
}
use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.
the class MoncskillToken method unparse.
@Override
public String[] unparse(LoadContext context, Race race) {
CDOMGroupRef<ClassSkillList> monsterList = context.getReferenceContext().getCDOMTypeReference(ClassSkillList.class, "Monster");
AssociatedChanges<CDOMReference<Skill>> changes = context.getListContext().getChangesInList(getTokenName(), race, monsterList);
Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(race, ListKey.NEW_CHOOSE_ACTOR);
List<String> list = new ArrayList<>();
Collection<CDOMReference<Skill>> removedItems = changes.getRemoved();
if (removedItems != null && !removedItems.isEmpty()) {
if (changes.includesGlobalClear()) {
context.addWriteMessage("Non-sensical relationship in " + getTokenName() + ": global .CLEAR and local .CLEAR. performed");
return null;
}
list.add(Constants.LST_DOT_CLEAR_DOT + ReferenceUtilities.joinLstFormat(removedItems, "|.CLEAR."));
}
Collection<ChooseSelectionActor<?>> listRemoved = listChanges.getRemoved();
if (listRemoved != null && !listRemoved.isEmpty()) {
if (listRemoved.contains(this)) {
list.add(".CLEAR.LIST");
}
}
if (changes.includesGlobalClear()) {
list.add(Constants.LST_DOT_CLEAR);
}
MapToList<CDOMReference<Skill>, AssociatedPrereqObject> map = changes.getAddedAssociations();
if (map != null && !map.isEmpty()) {
Set<CDOMReference<Skill>> added = map.getKeySet();
for (CDOMReference<Skill> ab : added) {
for (AssociatedPrereqObject assoc : map.getListFor(ab)) {
if (!SkillCost.CLASS.equals(assoc.getAssociation(AssociationKey.SKILL_COST))) {
context.addWriteMessage("Skill Cost must be " + "CLASS for Token " + getTokenName());
return null;
}
}
}
list.add(ReferenceUtilities.joinLstFormat(added, Constants.PIPE));
}
Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
if (listAdded != null && !listAdded.isEmpty()) {
for (ChooseSelectionActor<?> csa : listAdded) {
if (csa.getSource().equals(getTokenName())) {
try {
list.add(csa.getLstFormat());
} catch (PersistenceLayerException e) {
context.addWriteMessage("Error writing Prerequisite: " + e);
return null;
}
}
}
}
if (list.isEmpty()) {
// Zero indicates no add or clear
return null;
}
return list.toArray(new String[list.size()]);
}
use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.
the class CskillToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClassLevel obj, String value) {
boolean first = true;
boolean foundAny = false;
boolean foundOther = false;
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
while (tok.hasMoreTokens()) {
String tokText = tok.nextToken();
if (Constants.LST_DOT_CLEAR.equals(tokText)) {
if (!first) {
return new ParseResult.Fail(" Non-sensical " + getTokenName() + ": .CLEAR was not the first list item", context);
}
context.getObjectContext().removeList(obj, ListKey.LOCALCSKILL);
} else if (tokText.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
String clearText = tokText.substring(7);
if (Constants.LST_ALL.equals(clearText)) {
context.getObjectContext().removeFromList(obj, ListKey.LOCALCSKILL, context.getReferenceContext().getCDOMAllReference(SKILL_CLASS));
} else {
CDOMReference<Skill> ref = TokenUtilities.getTypeOrPrimitive(context, SKILL_CLASS, clearText);
if (ref == null) {
return new ParseResult.Fail(" Error was encountered while parsing " + getTokenName(), context);
}
context.getObjectContext().removeFromList(obj, ListKey.LOCALCSKILL, ref);
}
} else {
/*
* Note this HAS to be done one-by-one, because the
* .clearChildNodeOfClass method above does NOT recognize the
* C/CC Skill object and therefore doesn't know how to search
* the sublists
*/
if (Constants.LST_ALL.equals(tokText)) {
foundAny = true;
context.getObjectContext().addToList(obj, ListKey.LOCALCSKILL, context.getReferenceContext().getCDOMAllReference(SKILL_CLASS));
} else {
foundOther = true;
CDOMReference<Skill> ref = getSkillReference(context, tokText);
if (ref == null) {
return new ParseResult.Fail(" Error was encountered while parsing " + getTokenName(), context);
}
context.getObjectContext().addToList(obj, ListKey.LOCALCSKILL, ref);
}
}
first = false;
}
if (foundAny && foundOther) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
}
return ParseResult.SUCCESS;
}
Aggregations