use of pcgen.cdom.helper.ShieldProfProvider in project pcgen by PCGen.
the class ShieldProfToken method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Changes<ShieldProfProvider> changes = context.getObjectContext().getListChanges(obj, ListKey.AUTO_SHIELDPROF);
Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
Collection<ShieldProfProvider> added = changes.getAdded();
Set<String> set = new TreeSet<>();
Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
boolean foundAny = false;
boolean foundOther = false;
if (listAdded != null && !listAdded.isEmpty()) {
for (ChooseSelectionActor<?> cra : listAdded) {
if (cra.getSource().equals(getTokenName())) {
try {
set.add(cra.getLstFormat());
foundOther = true;
} catch (PersistenceLayerException e) {
context.addWriteMessage("Error writing Prerequisite: " + e);
return null;
}
}
}
}
if (added != null) {
for (ShieldProfProvider spp : added) {
StringBuilder sb = new StringBuilder();
sb.append(spp.getLstFormat());
if (spp.hasPrerequisites()) {
sb.append('|');
sb.append(getPrerequisiteString(context, spp.getPrerequisiteList()));
}
String ab = sb.toString();
boolean isUnconditionalAll = Constants.LST_ALL.equals(ab);
foundAny |= isUnconditionalAll;
foundOther |= !isUnconditionalAll;
set.add(ab);
}
}
if (foundAny && foundOther) {
context.addWriteMessage("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + set);
return null;
}
if (set.isEmpty()) {
//okay
return null;
}
return set.toArray(new String[set.size()]);
}
use of pcgen.cdom.helper.ShieldProfProvider in project pcgen by PCGen.
the class ShieldProfTokenTest method loadAllReference.
@Override
protected void loadAllReference() {
List<CDOMReference<ShieldProf>> shieldProfs = new ArrayList<>();
List<CDOMReference<Equipment>> equipTypes = new ArrayList<>();
shieldProfs.add(primaryContext.getReferenceContext().getCDOMAllReference(ShieldProf.class));
ShieldProfProvider pp = new ShieldProfProvider(shieldProfs, equipTypes);
primaryProf.addToListFor(ListKey.AUTO_SHIELDPROF, pp);
}
Aggregations