use of pcgen.cdom.reference.CDOMDirectSingleRef in project pcgen by PCGen.
the class VisionLst method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
StringTokenizer aTok = new StringTokenizer(value, Constants.PIPE);
String visionString = aTok.nextToken();
if (looksLikeAPrerequisite(visionString)) {
return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName() + ": " + value, context);
}
ArrayList<AssociatedPrereqObject> edgeList = new ArrayList<>();
boolean foundClear = false;
while (true) {
if (Constants.LST_DOT_CLEAR.equals(visionString)) {
context.getListContext().removeAllFromList(getTokenName(), obj, Vision.VISIONLIST);
foundClear = true;
} else if (visionString.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
try {
Vision vis = Vision.getVision(visionString.substring(7));
context.getListContext().removeFromList(getTokenName(), obj, Vision.VISIONLIST, new CDOMDirectSingleRef<>(vis));
} catch (IllegalArgumentException e) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Bad Syntax for Cleared Vision in " + getTokenName());
cpr.addErrorMessage(e.getMessage());
return cpr;
}
foundClear = true;
} else if (looksLikeAPrerequisite(visionString)) {
break;
} else {
try {
Vision vision = Vision.getVision(visionString);
AssociatedPrereqObject edge = context.getListContext().addToList(getTokenName(), obj, Vision.VISIONLIST, new CDOMDirectSingleRef<>(vision));
edgeList.add(edge);
} catch (IllegalArgumentException e) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Bad Syntax for Vision in " + getTokenName());
cpr.addErrorMessage(e.getMessage());
return cpr;
}
}
if (!aTok.hasMoreTokens()) {
return ParseResult.SUCCESS;
}
visionString = aTok.nextToken();
}
if (foundClear) {
return new ParseResult.Fail("Cannot use PREREQs when using .CLEAR or .CLEAR. in " + getTokenName(), context);
}
while (true) {
Prerequisite prereq = getPrerequisite(visionString);
if (prereq == null) {
return new ParseResult.Fail(" (Did you put vision after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
}
for (AssociatedPrereqObject edge : edgeList) {
edge.addPrerequisite(prereq);
}
if (!aTok.hasMoreTokens()) {
break;
}
visionString = aTok.nextToken();
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.reference.CDOMDirectSingleRef in project pcgen by PCGen.
the class VisionFacetTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
CDOMObject cdo1 = new PCTemplate();
cdo1.setName("Template1");
CDOMObject cdo2 = new Race();
cdo2.setName("Race1");
Vision vision1 = new Vision(VisionType.getVisionType("Normal"), FormulaFactory.getFormulaFor(30));
Vision vision2 = new Vision(VisionType.getVisionType("Darkvision"), FormulaFactory.getFormulaFor(20));
CDOMDirectSingleRef<Vision> ref1 = new CDOMDirectSingleRef<>(vision1);
SimpleAssociatedObject apo1 = new SimpleAssociatedObject();
cdo1.putToList(Vision.VISIONLIST, ref1, apo1);
CDOMDirectSingleRef<Vision> ref2 = new CDOMDirectSingleRef<>(vision2);
SimpleAssociatedObject apo2 = new SimpleAssociatedObject();
cdo2.putToList(Vision.VISIONLIST, ref2, apo2);
QualifiedObject<Vision> st1 = new QualifiedObject<>(vision1);
QualifiedObject<Vision> st2 = new QualifiedObject<>(vision2);
source = new CDOMObject[] { cdo1, cdo2 };
target = new QualifiedObject[] { st1, st2 };
}
use of pcgen.cdom.reference.CDOMDirectSingleRef in project pcgen by PCGen.
the class PlayerCharacterTest method testGetAvailableFollowers.
/**
* Validate the getAvailableFollowers function.
*/
public void testGetAvailableFollowers() {
readyToRun();
Ability ab = TestHelper.makeAbility("Tester1", AbilityCategory.FEAT, "Empty Container");
Ability mab = TestHelper.makeAbility("Tester2", AbilityCategory.FEAT, "Mount Container");
Ability fab = TestHelper.makeAbility("Tester3", AbilityCategory.FEAT, "Familiar Container");
PlayerCharacter pc = getCharacter();
CharacterDisplay display = pc.getDisplay();
addAbility(AbilityCategory.FEAT, ab);
CDOMSingleRef<CompanionList> ref = new CDOMSimpleSingleRef<>(CompanionList.class, "Mount");
CDOMReference<Race> race = new CDOMDirectSingleRef<>(giantRace);
FollowerOption option = new FollowerOption(race, ref);
mab.addToListFor(ListKey.COMPANIONLIST, option);
ref = new CDOMSimpleSingleRef<>(CompanionList.class, "Familiar");
race = new CDOMDirectSingleRef<>(human);
option = new FollowerOption(race, ref);
fab.addToListFor(ListKey.COMPANIONLIST, option);
Set<FollowerOption> fo = display.getAvailableFollowers("Familiar", null).keySet();
assertTrue("Initially familiar list should be empty", fo.isEmpty());
fo = display.getAvailableFollowers("MOUNT", null).keySet();
assertTrue("Initially mount list should be empty", fo.isEmpty());
addAbility(AbilityCategory.FEAT, mab);
fo = display.getAvailableFollowers("Familiar", null).keySet();
assertTrue("Familiar list should still be empty", fo.isEmpty());
fo = display.getAvailableFollowers("MOUNT", null).keySet();
assertFalse("Mount list should not be empty anymore", fo.isEmpty());
assertEquals("Mount should be the giant race", giantRace.getKeyName(), fo.iterator().next().getRace().getKeyName());
assertEquals("Mount list should only have one entry", 1, fo.size());
addAbility(AbilityCategory.FEAT, fab);
fo = display.getAvailableFollowers("Familiar", null).keySet();
assertFalse("Familiar list should not be empty anymore", fo.isEmpty());
assertEquals("Familiar should be the human race", human.getKeyName(), fo.iterator().next().getRace().getKeyName());
assertEquals("Familiar list should only have one entry", 1, fo.size());
fo = display.getAvailableFollowers("MOUNT", null).keySet();
assertFalse("Mount list should not be empty anymore", fo.isEmpty());
assertEquals("Mount should be the giant race", giantRace.getKeyName(), fo.iterator().next().getRace().getKeyName());
assertEquals("Mount list should only have one entry", 1, fo.size());
}
use of pcgen.cdom.reference.CDOMDirectSingleRef in project pcgen by PCGen.
the class CompanionSupportFacadeImplTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
uiDelegate = new MockUIDelegate();
todoManager = new TodoManager();
ListFacade<CampaignFacade> campaigns = new DefaultListFacade<>();
dataSetFacade = new DataSet(Globals.getContext(), SettingsHandler.getGame(), campaigns);
masterRace = TestHelper.makeRace("Wood Elf");
companionRace = TestHelper.makeRace("Weasel");
CDOMReference<Race> race = new CDOMDirectSingleRef<>(companionRace);
CDOMSingleRef<CompanionList> ref = new CDOMSimpleSingleRef<>(CompanionList.class, companionList.getKeyName());
FollowerOption option = new FollowerOption(race, ref);
masterRace.addToListFor(ListKey.COMPANIONLIST, option);
}
use of pcgen.cdom.reference.CDOMDirectSingleRef in project pcgen by PCGen.
the class AbilityLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Collection<CDOMReference<? extends CDOMList<?>>> changedLists = context.getListContext().getChangedLists(obj, AbilityList.class);
Changes<ListKey<ChooseSelectionActor<?>>> actors = context.getObjectContext().getListChanges(obj, ListKey.GA_CAKEYS);
Set<String> returnSet = new TreeSet<>();
TripleKeyMapToList<Nature, CDOMSingleRef<AbilityCategory>, List<Prerequisite>, CDOMReference<Ability>> m = new TripleKeyMapToList<>();
TripleKeyMapToList<Nature, CDOMSingleRef<AbilityCategory>, List<Prerequisite>, CDOMReference<Ability>> clear = new TripleKeyMapToList<>();
Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
if (listAdded != null && !listAdded.isEmpty()) {
for (ChooseSelectionActor<?> csa : listAdded) {
if (csa.getSource().equals(getTokenName())) {
try {
AbilitySelector as = (AbilitySelector) csa;
StringBuilder sb = new StringBuilder();
sb.append(as.getAbilityCategory().getLSTformat(false)).append(Constants.PIPE);
sb.append(as.getNature()).append(Constants.PIPE);
sb.append(as.getLstFormat());
returnSet.add(sb.toString());
} catch (PersistenceLayerException e) {
context.addWriteMessage(getTokenName() + " encountered error: " + e.getMessage());
return null;
}
}
}
}
for (CDOMReference ref : changedLists) {
AssociatedChanges<CDOMReference<Ability>> changes = context.getListContext().getChangesInList(getTokenName(), obj, ref);
if (changes.includesGlobalClear()) {
CDOMDirectSingleRef<AbilityList> dr = (CDOMDirectSingleRef<AbilityList>) ref;
AbilityList al = dr.get();
StringBuilder sb = new StringBuilder();
sb.append(al.getCategory().getLSTformat(false)).append(Constants.PIPE);
sb.append(al.getNature()).append(Constants.PIPE);
sb.append(Constants.LST_DOT_CLEAR);
returnSet.add(sb.toString());
}
MapToList<CDOMReference<Ability>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
if (mtl != null) {
for (CDOMReference<Ability> ab : mtl.getKeySet()) {
for (AssociatedPrereqObject assoc : mtl.getListFor(ab)) {
Nature nature = assoc.getAssociation(AssociationKey.NATURE);
CDOMSingleRef<AbilityCategory> cat = assoc.getAssociation(AssociationKey.CATEGORY);
m.addToListFor(nature, cat, assoc.getPrerequisiteList(), ab);
}
}
}
mtl = changes.getRemovedAssociations();
if (mtl != null) {
for (CDOMReference<Ability> ab : mtl.getKeySet()) {
for (AssociatedPrereqObject assoc : mtl.getListFor(ab)) {
Nature nature = assoc.getAssociation(AssociationKey.NATURE);
CDOMSingleRef<AbilityCategory> cat = assoc.getAssociation(AssociationKey.CATEGORY);
clear.addToListFor(nature, cat, assoc.getPrerequisiteList(), ab);
}
}
}
}
for (Nature nature : m.getKeySet()) {
for (CDOMSingleRef<AbilityCategory> category : m.getSecondaryKeySet(nature)) {
for (List<Prerequisite> prereqs : m.getTertiaryKeySet(nature, category)) {
StringBuilder sb = new StringBuilder();
sb.append(category.getLSTformat(false)).append(Constants.PIPE);
sb.append(nature);
List<CDOMReference<Ability>> clearList = clear.removeListFor(nature, category, prereqs);
if (clearList != null && !clearList.isEmpty()) {
sb.append(Constants.PIPE);
sb.append(Constants.LST_DOT_CLEAR_DOT);
sb.append(ReferenceUtilities.joinLstFormat(clearList, Constants.PIPE + Constants.LST_DOT_CLEAR_DOT));
}
sb.append(Constants.PIPE);
sb.append(ReferenceUtilities.joinLstFormat(m.getListFor(nature, category, prereqs), Constants.PIPE));
if (prereqs != null && !prereqs.isEmpty()) {
sb.append(Constants.PIPE);
sb.append(getPrerequisiteString(context, prereqs));
}
returnSet.add(sb.toString());
}
}
}
for (Nature nature : clear.getKeySet()) {
for (CDOMSingleRef<AbilityCategory> category : clear.getSecondaryKeySet(nature)) {
for (List<Prerequisite> prereqs : clear.getTertiaryKeySet(nature, category)) {
StringBuilder sb = new StringBuilder();
sb.append(category.getLSTformat(false)).append(Constants.PIPE);
sb.append(nature).append(Constants.PIPE).append(Constants.LST_DOT_CLEAR_DOT);
sb.append(ReferenceUtilities.joinLstFormat(clear.getListFor(nature, category, prereqs), Constants.PIPE + Constants.LST_DOT_CLEAR_DOT));
if (prereqs != null && !prereqs.isEmpty()) {
sb.append(Constants.PIPE);
sb.append(getPrerequisiteString(context, prereqs));
}
returnSet.add(sb.toString());
}
}
}
Collection<ListKey<ChooseSelectionActor<?>>> addedActors = actors.getAdded();
if (addedActors != null) {
for (ListKey<ChooseSelectionActor<?>> lk : addedActors) {
Changes<ChooseSelectionActor<?>> cras = context.getObjectContext().getListChanges(obj, lk);
for (ChooseSelectionActor<?> cra : cras.getAdded()) {
if (getTokenName().equals(cra.getSource())) {
try {
AbilityTargetSelector ats = (AbilityTargetSelector) cra;
StringBuilder sb = new StringBuilder();
sb.append(ats.getAbilityCategory().getLSTformat(false)).append(Constants.PIPE);
sb.append(ats.getNature()).append(Constants.PIPE).append(cra.getLstFormat());
List<Prerequisite> prereqs = ats.getPrerequisiteList();
if (prereqs != null && !prereqs.isEmpty()) {
sb.append(Constants.PIPE);
sb.append(getPrerequisiteString(context, prereqs));
}
returnSet.add(sb.toString());
} catch (PersistenceLayerException e) {
context.addWriteMessage(getTokenName() + " encountered error: " + e.getMessage());
return null;
}
}
}
}
}
if (returnSet.isEmpty()) {
return null;
}
return returnSet.toArray(new String[returnSet.size()]);
}
Aggregations