use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.
the class PreSubClassWriter method write.
/**
* @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#write(java.io.Writer, pcgen.core.prereq.Prerequisite)
*/
@Override
public void write(Writer writer, Prerequisite prereq) throws PersistenceLayerException {
checkValidOperator(prereq, operatorsHandled());
try {
if (prereq.getOperator().equals(PrerequisiteOperator.LT)) {
writer.write('!');
}
writer.write("PRESUBCLASS:" + (prereq.isOverrideQualify() ? "Q:" : "") + "1,");
writer.write(prereq.getKey());
} catch (IOException e) {
throw new PersistenceLayerException(e.getMessage());
}
}
use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.
the class PreSpellBookWriter method write.
/**
* @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#write(java.io.Writer, pcgen.core.prereq.Prerequisite)
*/
@Override
public void write(Writer writer, Prerequisite prereq) throws PersistenceLayerException {
checkValidOperator(prereq, operatorsHandled());
try {
if (prereq.getOperator().equals(PrerequisiteOperator.NEQ)) {
writer.write('!');
}
writer.write("PRESPELLBOOK:" + (prereq.isOverrideQualify() ? "Q:" : ""));
writer.write(prereq.getKey());
} catch (IOException e) {
throw new PersistenceLayerException(e.getMessage());
}
}
use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.
the class PrePointBuyMethodWriter method write.
/**
* @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#write(java.io.Writer, pcgen.core.prereq.Prerequisite)
*/
@Override
public void write(Writer writer, Prerequisite prereq) throws PersistenceLayerException {
checkValidOperator(prereq, operatorsHandled());
try {
if (prereq.getOperator().equals(PrerequisiteOperator.LT)) {
writer.write('!');
}
writer.write("PREPOINTBUYMETHOD:" + (prereq.isOverrideQualify() ? "Q:" : ""));
writer.write(prereq.getOperand());
writer.write(',');
writer.write(prereq.getKey());
} catch (IOException e) {
throw new PersistenceLayerException(e.getMessage());
}
}
use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.
the class PreReachWriter method write.
/**
* @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#write(java.io.Writer, pcgen.core.prereq.Prerequisite)
*/
@Override
public void write(Writer writer, Prerequisite prereq) throws PersistenceLayerException {
try {
writer.write("PREREACH" + (prereq.isOverrideQualify() ? "Q:" : ""));
writer.write(prereq.getOperator().toString().toUpperCase());
writer.write(':');
writer.write(prereq.getOperand());
} catch (IOException e) {
throw new PersistenceLayerException(e.getMessage());
}
}
use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.
the class DomainsToken method unparse.
@Override
public String[] unparse(LoadContext context, Spell spell) {
DoubleKeyMapToList<Prerequisite, Integer, CDOMReference<DomainSpellList>> dkmtl = new DoubleKeyMapToList<>();
List<String> list = new ArrayList<>();
Changes<CDOMReference<DomainSpellList>> masterChanges = context.getListContext().getMasterListChanges(getTokenName(), spell, SPELLLIST_CLASS);
if (masterChanges.includesGlobalClear()) {
list.add(Constants.LST_DOT_CLEAR_ALL);
}
if (masterChanges.hasRemovedItems()) {
for (CDOMReference<DomainSpellList> swl : masterChanges.getRemoved()) {
AssociatedChanges<Spell> changes = context.getListContext().getChangesInMasterList(getTokenName(), spell, swl);
MapToList<Spell, AssociatedPrereqObject> map = changes.getRemovedAssociations();
if (map != null && !map.isEmpty()) {
for (Spell added : map.getKeySet()) {
if (!spell.getLSTformat().equals(added.getLSTformat())) {
context.addWriteMessage("Spell " + getTokenName() + " token cannot remove another Spell " + "(must only remove itself)");
return null;
}
for (AssociatedPrereqObject assoc : map.getListFor(added)) {
List<Prerequisite> prereqs = assoc.getPrerequisiteList();
if (prereqs != null && !prereqs.isEmpty()) {
context.addWriteMessage("Incoming Remove " + "Edge to " + spell.getKeyName() + " had a " + "Prerequisite: " + prereqs.size());
return null;
}
dkmtl.addToListFor(null, -1, swl);
}
}
}
}
}
for (CDOMReference<DomainSpellList> swl : masterChanges.getAdded()) {
AssociatedChanges<Spell> changes = context.getListContext().getChangesInMasterList(getTokenName(), spell, swl);
Collection<Spell> removedItems = changes.getRemoved();
if (removedItems != null && !removedItems.isEmpty() || changes.includesGlobalClear()) {
context.addWriteMessage(getTokenName() + " does not support .CLEAR.");
return null;
}
MapToList<Spell, AssociatedPrereqObject> map = changes.getAddedAssociations();
if (map != null && !map.isEmpty()) {
for (Spell added : map.getKeySet()) {
if (!spell.getLSTformat().equals(added.getLSTformat())) {
context.addWriteMessage("Spell " + getTokenName() + " token cannot allow another Spell " + "(must only allow itself)");
return null;
}
for (AssociatedPrereqObject assoc : map.getListFor(added)) {
List<Prerequisite> prereqs = assoc.getPrerequisiteList();
Prerequisite prereq;
if (prereqs == null || prereqs.isEmpty()) {
prereq = null;
} else if (prereqs.size() == 1) {
prereq = prereqs.get(0);
} else {
context.addWriteMessage("Incoming Edge to " + spell.getKeyName() + " had more than one " + "Prerequisite: " + prereqs.size());
return null;
}
Integer level = assoc.getAssociation(AssociationKey.SPELL_LEVEL);
if (level == null) {
context.addWriteMessage("Incoming Allows Edge to " + spell.getKeyName() + " had no Spell Level defined");
return null;
}
if (level.intValue() < 0) {
context.addWriteMessage("Incoming Allows Edge to " + spell.getKeyName() + " had invalid Level: " + level + ". Must be >= 0.");
return null;
}
dkmtl.addToListFor(prereq, level, swl);
}
}
}
}
if (dkmtl.isEmpty()) {
if (list.isEmpty()) {
// Legal if no DOMAINS was present in the Spell
return null;
} else {
return list.toArray(new String[list.size()]);
}
}
PrerequisiteWriter prereqWriter = new PrerequisiteWriter();
SortedSet<CDOMReference<DomainSpellList>> set = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
SortedSet<Integer> levelSet = new TreeSet<>();
for (Prerequisite prereq : dkmtl.getKeySet()) {
StringBuilder sb = new StringBuilder();
boolean needPipe = false;
levelSet.clear();
levelSet.addAll(dkmtl.getSecondaryKeySet(prereq));
for (Integer i : levelSet) {
set.clear();
set.addAll(dkmtl.getListFor(prereq, i));
if (needPipe) {
sb.append(Constants.PIPE);
}
sb.append(ReferenceUtilities.joinLstFormat(set, Constants.COMMA));
sb.append('=').append(i);
needPipe = true;
}
if (prereq != null) {
sb.append('[');
StringWriter swriter = new StringWriter();
try {
prereqWriter.write(swriter, prereq);
} catch (PersistenceLayerException e) {
context.addWriteMessage("Error writing Prerequisite: " + e);
return null;
}
sb.append(swriter.toString());
sb.append(']');
}
list.add(sb.toString());
}
return list.toArray(new String[list.size()]);
}
Aggregations