Search in sources :

Example 1 with Dynamic

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

the class DynamicFacet method dataAdded.

/**
	 * Adds the active Dynamic to this facet.
	 * 
	 * Triggered when one of the Facets to which DynamicFacet listens fires a
	 * DataFacetChangeEvent to indicate Dynamic was added to a Player Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataAdded(DataFacetChangeEvent<CharID, Dynamic> dfce) {
    Dynamic cdo = dfce.getCDOMObject();
    add(dfce.getCharID(), cdo.getCDOMCategory(), cdo, dfce.getSource());
}
Also used : Dynamic(pcgen.cdom.inst.Dynamic)

Example 2 with Dynamic

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

the class DynamicFacet method dataRemoved.

/**
	 * Removes the no-longer active Dynamic from this facet.
	 * 
	 * Triggered when one of the Facets to which DynamicFacet listens fires a
	 * DataFacetChangeEvent to indicate Dynamic was removed from a Player
	 * Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataRemoved(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataRemoved(DataFacetChangeEvent<CharID, Dynamic> dfce) {
    Dynamic cdo = dfce.getCDOMObject();
    remove(dfce.getCharID(), cdo.getCDOMCategory(), cdo, dfce.getSource());
}
Also used : Dynamic(pcgen.cdom.inst.Dynamic)

Example 3 with Dynamic

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

the class DynamicLoader method getLoadable.

@Override
protected Dynamic getLoadable(LoadContext context, String token, URI sourceURI) {
    final int colonLoc = token.indexOf(':');
    if (colonLoc == -1) {
        Logging.errorPrint("Invalid Token - does not contain a colon: '" + token + "' in " + sourceURI);
        return null;
    } else if (colonLoc == 0) {
        Logging.errorPrint("Invalid Token - starts with a colon: '" + token + "' in " + sourceURI);
        return null;
    } else if (colonLoc == (token.length() - 1)) {
        Logging.errorPrint("Invalid Token - " + "ends with a colon (no value): '" + token + "' in " + sourceURI);
        return null;
    }
    String key = token.substring(0, colonLoc);
    DynamicCategory dynamicCategory = context.getReferenceContext().silentlyGetConstructedCDOMObject(DynamicCategory.class, key);
    if (dynamicCategory == null) {
        Logging.addParseMessage(Logging.LST_ERROR, "Unsure what to do with line with prefix " + "(no DYNAMICSCOPE of this type was defined): " + key + ".  Line started with: " + token + " in file: " + sourceURI);
        return null;
    }
    String name = token.substring(colonLoc + 1);
    if ((name == null) || (name.isEmpty())) {
        Logging.errorPrint("Invalid Token '" + key + "' had no value in " + sourceURI);
        return null;
    }
    //Only load once / allow duplicates in different files
    Dynamic d = context.getReferenceContext().silentlyGetConstructedCDOMObject(DYNAMIC_CLASS, dynamicCategory, name);
    if (d == null) {
        d = new Dynamic();
        d.setName(name);
        d.setCDOMCategory(dynamicCategory);
        d.setSourceURI(sourceURI);
        context.getReferenceContext().importObject(d);
    }
    return d;
}
Also used : DynamicCategory(pcgen.cdom.inst.DynamicCategory) Dynamic(pcgen.cdom.inst.Dynamic)

Example 4 with Dynamic

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

the class GrantLst 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 tok = new StringTokenizer(value, Constants.PIPE);
    String scope = tok.nextToken();
    if (!tok.hasMoreTokens()) {
        return new ParseResult.Fail(getTokenName() + " must have identifier(s), " + "Format is: DYNAMICSCOPE|DynamicName: " + value, context);
    }
    ReferenceManufacturer<Dynamic> rm = context.getReferenceContext().getManufacturer(DYNAMIC_CLASS, DYNAMIC_CATEGORY_CLASS, scope);
    if (rm == null) {
        return new ParseResult.Fail("Could not get Reference Manufacturer for Dynamic Scope: " + scope, context);
    }
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        CDOMReference<Dynamic> dynamic = rm.getReference(token);
        if (dynamic == null) {
            return ParseResult.INTERNAL_ERROR;
        }
        context.getObjectContext().addToList(obj, ListKey.GRANTED, dynamic);
    }
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) Dynamic(pcgen.cdom.inst.Dynamic) Ungranted(pcgen.cdom.base.Ungranted)

Aggregations

Dynamic (pcgen.cdom.inst.Dynamic)4 StringTokenizer (java.util.StringTokenizer)1 Ungranted (pcgen.cdom.base.Ungranted)1 DynamicCategory (pcgen.cdom.inst.DynamicCategory)1