Search in sources :

Example 31 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PreAbilityRoundRobin method testCombineSubCheckMult.

public void testCombineSubCheckMult() {
    // runSimpleRoundRobin("PREMULT:2,[!PRE" + getBaseString() + ":1,"
    // + "CHECKMULT," + getPrefix() + "Foo],[!PRE" + getBaseString()
    // + ":1," + "CHECKMULT," + getPrefix() + "Spot]", "!PRE"
    // + getBaseString() + ":1," + "CHECKMULT," + getPrefix()
    // + "Foo,Spot");
    String original = "PREMULT:2,[!PRE" + getBaseString() + ":1," + "CHECKMULT," + getPrefix() + "Foo],[!PRE" + getBaseString() + ":1," + "CHECKMULT," + getPrefix() + "Spot]";
    String consolidatedPre = "!PRE" + getBaseString() + ":1," + "CHECKMULT," + getPrefix() + "Foo,Spot";
    try {
        Prerequisite p = PreParserFactory.getInstance().parse(original);
        PrerequisiteWriterInterface writer = PrerequisiteWriterFactory.getInstance().getWriter(p.getKind());
        if (writer == null) {
            fail("Could not find Writer for: " + p.getKind());
        }
        StringWriter w = new StringWriter();
        writer.write(w, p);
        boolean consolidated = w.toString().equals(consolidatedPre);
        boolean separate = w.toString().equals(original);
        assertTrue(consolidated || separate);
    } catch (PersistenceLayerException e) {
        fail(e.getLocalizedMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) StringWriter(java.io.StringWriter) PrerequisiteWriterInterface(pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 32 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException 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()]);
}
Also used : ChooseSelectionActor(pcgen.cdom.base.ChooseSelectionActor) ArrayList(java.util.ArrayList) ClassSkillList(pcgen.cdom.list.ClassSkillList) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Skill(pcgen.core.Skill) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 33 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PreSpellSchoolWriter method write.

/*
	 * (non-Javadoc)
	 * 
	 * @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() == PrerequisiteOperator.LT) {
            writer.write('!');
        }
        writer.write("PRE" + kindHandled().toUpperCase() + ':' + (prereq.isOverrideQualify() ? "Q:" : "") + "1,");
        writer.write(prereq.getKey());
        writer.write('=');
        writer.write(prereq.getOperand());
    } catch (IOException e) {
        throw new PersistenceLayerException(e.getMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) IOException(java.io.IOException)

Example 34 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PreSpellTypeWriter 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("PRE" + kindHandled().toUpperCase() + ':' + (prereq.isOverrideQualify() ? "Q:" : "") + "1,");
        writer.write(prereq.getKey());
        writer.write('=');
        writer.write(prereq.getOperand());
    } catch (IOException e) {
        throw new PersistenceLayerException(e.getMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) IOException(java.io.IOException)

Example 35 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PreTemplateWriter 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("PRETEMPLATE:" + (prereq.isOverrideQualify() ? "Q:" : ""));
        writer.write(prereq.getOperand());
        writer.write(',');
        writer.write(prereq.getKey());
    } catch (IOException e) {
        throw new PersistenceLayerException(e.getMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) IOException(java.io.IOException)

Aggregations

PersistenceLayerException (pcgen.persistence.PersistenceLayerException)180 IOException (java.io.IOException)74 Prerequisite (pcgen.core.prereq.Prerequisite)62 StringWriter (java.io.StringWriter)17 StringTokenizer (java.util.StringTokenizer)17 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)15 LoadContext (pcgen.rules.context.LoadContext)14 URI (java.net.URI)12 Campaign (pcgen.core.Campaign)11 ParseResult (pcgen.rules.persistence.token.ParseResult)11 PCClass (pcgen.core.PCClass)10 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)10 PrerequisiteWriterInterface (pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface)10 URISyntaxException (java.net.URISyntaxException)8 TreeSet (java.util.TreeSet)8 CDOMReference (pcgen.cdom.base.CDOMReference)8 PlayerCharacter (pcgen.core.PlayerCharacter)8 PrerequisiteException (pcgen.core.prereq.PrerequisiteException)8 PCClassLoader (pcgen.persistence.lst.PCClassLoader)8