Search in sources :

Example 1 with ObjectCache

use of pcgen.cdom.inst.ObjectCache in project pcgen by PCGen.

the class PlayerCharacter method setDirty.

/**
	 * Sets the character changed since last save.
	 * NB: This is not a 'safe' call - its use should be considered carefully and in
	 * particular it should not be called from a method used as part of PlayerCharacter
	 * cloning as this can mean conditional abilities get dropped when they are actually
	 * qualified for, just not at that point in the clone.
	 *
	 * @param dirtyState the new "dirty" value (may be false to indicate no change)
	 */
public void setDirty(final boolean dirtyState) {
    if (dirtyState) {
        serial++;
        cache = new ObjectCache();
        variableProcessor.setSerial(serial);
        cabFacet.update(id);
        cAvSpellFacet.update(id);
        cKnSpellFacet.update(id);
        condLangFacet.update(id);
        bonusSkillRankChangeFacet.reset(id);
    }
    dirtyFlag = dirtyState;
}
Also used : ObjectCache(pcgen.cdom.inst.ObjectCache)

Example 2 with ObjectCache

use of pcgen.cdom.inst.ObjectCache in project pcgen by PCGen.

the class AbstractPreRoundRobin method runSimpleRoundRobin.

public static void runSimpleRoundRobin(String s, String d) {
    try {
        Prerequisite p = PreParserFactory.getInstance().parse(s);
        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);
        assertEquals(d, w.toString());
        /*
			 * Now try new system
			 */
        LoadContext context = new EditorLoadContext();
        CDOMObject obj = new ObjectCache();
        int colonLoc = s.indexOf(':');
        String key = s.substring(0, colonLoc);
        String value = s.substring(colonLoc + 1);
        if (context.processToken(obj, key, value)) {
            context.commit();
        } else {
            context.rollback();
            Logging.replayParsedMessages();
            fail();
        }
        Logging.clearParseMessages();
        Collection<String> output = context.unparse(obj);
        if (output == null || output.isEmpty()) {
            // Uh Oh
            fail("Unable to unparse: " + key + ":" + value);
        }
        assertEquals(1, output.size());
        assertEquals(d, output.iterator().next());
    } catch (PersistenceLayerException e) {
        e.printStackTrace();
        fail(e.getLocalizedMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) EditorLoadContext(pcgen.rules.context.EditorLoadContext) StringWriter(java.io.StringWriter) CDOMObject(pcgen.cdom.base.CDOMObject) ObjectCache(pcgen.cdom.inst.ObjectCache) EditorLoadContext(pcgen.rules.context.EditorLoadContext) LoadContext(pcgen.rules.context.LoadContext) PrerequisiteWriterInterface(pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 3 with ObjectCache

use of pcgen.cdom.inst.ObjectCache in project pcgen by PCGen.

the class BonusConvertPlugin method process.

private String process(EditorLoadContext context, ConversionDecider decider, String objectName, String token) {
    final int colonLoc = token.indexOf(':');
    if (colonLoc == -1) {
        Logging.errorPrint("Invalid Token - does not contain a colon: " + token);
        return null;
    } else if (colonLoc == 0) {
        Logging.errorPrint("Invalid Token - starts with a colon: " + token);
        return null;
    }
    String key = token.substring(0, colonLoc);
    String value = (colonLoc == token.length() - 1) ? null : token.substring(colonLoc + 1);
    CDOMObject cdo = new ObjectCache();
    cdo.setName("BONUS" + bonusCount++);
    TokenProcessEvent tpe = new TokenProcessEvent(context, decider, key, value, objectName, cdo);
    String error = TokenConverter.process(tpe);
    context.purge(cdo);
    TokenConverter.clearConstants();
    if (tpe.isConsumed()) {
        return tpe.getResult();
    } else {
        Logging.errorPrint(error);
    }
    return null;
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) ObjectCache(pcgen.cdom.inst.ObjectCache) TokenProcessEvent(pcgen.gui2.converter.event.TokenProcessEvent)

Aggregations

ObjectCache (pcgen.cdom.inst.ObjectCache)3 CDOMObject (pcgen.cdom.base.CDOMObject)2 StringWriter (java.io.StringWriter)1 Prerequisite (pcgen.core.prereq.Prerequisite)1 TokenProcessEvent (pcgen.gui2.converter.event.TokenProcessEvent)1 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)1 PrerequisiteWriterInterface (pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface)1 EditorLoadContext (pcgen.rules.context.EditorLoadContext)1 LoadContext (pcgen.rules.context.LoadContext)1