Search in sources :

Example 26 with AbstractReferenceContext

use of pcgen.rules.context.AbstractReferenceContext in project pcgen by PCGen.

the class UDam method unparseToken.

/**
	 * Unparse the bonus token.
	 * @see pcgen.core.bonus.BonusObj#unparseToken(java.lang.Object)
	 * @param obj The object to unparse
	 * @return The unparsed string.
	 */
@Override
protected String unparseToken(final Object obj) {
    if (obj instanceof String) {
        String sObj = (String) obj;
        final AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
        final PCClass aClass = ref.silentlyGetConstructedCDOMObject(PCClass.class, sObj);
        if (aClass != null) {
            replaceBonusInfo(obj, aClass);
        }
        return Constants.LST_CLASS_DOT + obj;
    }
    return Constants.LST_CLASS_DOT + ((PCClass) obj).getKeyName();
}
Also used : AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) PCClass(pcgen.core.PCClass)

Example 27 with AbstractReferenceContext

use of pcgen.rules.context.AbstractReferenceContext in project pcgen by PCGen.

the class PCGVer2Parser method parseSpellListLines.

/*
	 * ###############################################################
	 * Spell List Information methods
	 * ###############################################################
	 */
/*
	 * #Spell List Information
	 * SPELLLIST:sourceclassname|spelllistentry|spelllistentry
	 */
private void parseSpellListLines(final String line) {
    final String subLine = line.substring(IOConstants.TAG_SPELLLIST.length() + 1);
    final StringTokenizer stok = new StringTokenizer(subLine, IOConstants.TAG_SEPARATOR, false);
    final String classKey = stok.nextToken();
    final PCClass aClass = thePC.getClassKeyed(classKey);
    AbstractReferenceContext refContext = Globals.getContext().getReferenceContext();
    while ((aClass != null) && stok.hasMoreTokens()) {
        final String tok = stok.nextToken();
        if (tok.startsWith("CLASS.")) {
            ClassSpellList csl = refContext.silentlyGetConstructedCDOMObject(ClassSpellList.class, tok.substring(6));
            thePC.addClassSpellList(csl, aClass);
        } else if (tok.startsWith("DOMAIN.")) {
            DomainSpellList dsl = refContext.silentlyGetConstructedCDOMObject(DomainSpellList.class, tok.substring(7));
            thePC.addClassSpellList(dsl, aClass);
        } else {
            /*
				 * This is 5.14-ish, but have to try anyway:
				 */
            ClassSpellList csl = refContext.silentlyGetConstructedCDOMObject(ClassSpellList.class, tok);
            if (csl == null) {
                DomainSpellList dsl = refContext.silentlyGetConstructedCDOMObject(DomainSpellList.class, tok);
                if (dsl != null) {
                    thePC.addClassSpellList(dsl, aClass);
                }
            } else {
                thePC.addClassSpellList(csl, aClass);
            }
        }
    }
}
Also used : DomainSpellList(pcgen.cdom.list.DomainSpellList) StringTokenizer(java.util.StringTokenizer) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) ClassSpellList(pcgen.cdom.list.ClassSpellList) PCClass(pcgen.core.PCClass)

Example 28 with AbstractReferenceContext

use of pcgen.rules.context.AbstractReferenceContext in project pcgen by PCGen.

the class SortKeyLst method process.

/**
	 * Enforces that SORTKEY exists on any object which carries the
	 * SortKeyRequired interface.
	 * 
	 * All such objects must have a SORTKEY and in PCGen 6.5/6.6, the file order
	 * must match the SORTKEY order.
	 * 
	 * @see pcgen.rules.persistence.token.PostValidationToken#process(pcgen.rules.context.LoadContext,
	 *      java.util.Collection)
	 */
@Override
public boolean process(LoadContext context, Collection<? extends CDOMObject> allObjects) {
    if (allObjects.isEmpty()) {
        return true;
    }
    CDOMObject sample = allObjects.iterator().next();
    Class<? extends CDOMObject> cl = sample.getClass();
    //This Interface tag is placed on classes where SORTKEY is required
    boolean sortKeyRequired = sample instanceof SortKeyRequired;
    for (CDOMObject obj : allObjects) {
        String sortkey = obj.get(stringKey());
        if (sortkey == null) {
            /*
				 * Do not join IFs, we want sortkey == null and not required to
				 * not process the map
				 */
            if (sortKeyRequired) {
                //This becomes an error in PCGen 6.7
                Logging.deprecationPrint("Objects of type " + obj.getClass().getName() + " will require a SORTKEY " + "in the next version of PCGen (6.7).  " + "Use without a SORTKEY is deprecated", context);
            }
        }
    }
    /*
		 * This is likely permanent, as certain objects (e.g. Alignment/Stat)
		 * will "always" need a sort unique from the order in the file, and this
		 * is a good nudge to indicate to data writers that the items are sort
		 * order sensitive.
		 */
    if (!sortKeyRequired) {
        //Break out now if these aren't SortKeyRequired objects
        return true;
    }
    /*
		 * Per the transition rules, the sort key must match the existing order
		 * in the files (PCGen 6.5/6.6)
		 */
    AbstractReferenceContext refContext = context.getReferenceContext();
    List<? extends CDOMObject> sortKeySort = new ArrayList<>(refContext.getSortOrderedList(cl));
    List<? extends CDOMObject> orderSort = refContext.getOrderSortedCDOMObjects(cl);
    //This IF is order sensitive ... want to have ArrayList first to use its .equals()
    if (!sortKeySort.equals(orderSort)) {
        Logging.log(Logging.LST_ERROR, "For " + sample.getClass().getSimpleName() + ", the file order was: " + StringUtil.join(new ArrayList<CDOMObject>(orderSort), ", ") + " while the order based on SORTKEY was: " + StringUtil.join(sortKeySort, ", ") + ".  These lists must match.");
        return false;
    }
    return true;
}
Also used : SortKeyRequired(pcgen.cdom.base.SortKeyRequired) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList)

Example 29 with AbstractReferenceContext

use of pcgen.rules.context.AbstractReferenceContext in project pcgen by PCGen.

the class PreSizeTester method getTargetSizeInt.

private int getTargetSizeInt(String size) {
    AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
    SizeAdjustment sa = ref.silentlyGetConstructedCDOMObject(SizeAdjustment.class, size);
    return sa.get(IntegerKey.SIZEORDER);
}
Also used : AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) SizeAdjustment(pcgen.core.SizeAdjustment)

Aggregations

AbstractReferenceContext (pcgen.rules.context.AbstractReferenceContext)29 PCStat (pcgen.core.PCStat)7 GameMode (pcgen.core.GameMode)6 ArrayList (java.util.ArrayList)3 SizeAdjustment (pcgen.core.SizeAdjustment)3 LoadContext (pcgen.rules.context.LoadContext)3 CDOMObject (pcgen.cdom.base.CDOMObject)2 DirectAbilityFacet (pcgen.cdom.facet.DirectAbilityFacet)2 ActiveEqModFacet (pcgen.cdom.facet.model.ActiveEqModFacet)2 AlignmentFacet (pcgen.cdom.facet.model.AlignmentFacet)2 BioSetFacet (pcgen.cdom.facet.model.BioSetFacet)2 CheckFacet (pcgen.cdom.facet.model.CheckFacet)2 ClassFacet (pcgen.cdom.facet.model.ClassFacet)2 ClassLevelFacet (pcgen.cdom.facet.model.ClassLevelFacet)2 CompanionModFacet (pcgen.cdom.facet.model.CompanionModFacet)2 DeityFacet (pcgen.cdom.facet.model.DeityFacet)2 DomainFacet (pcgen.cdom.facet.model.DomainFacet)2 ExpandedCampaignFacet (pcgen.cdom.facet.model.ExpandedCampaignFacet)2 LanguageFacet (pcgen.cdom.facet.model.LanguageFacet)2 SizeFacet (pcgen.cdom.facet.model.SizeFacet)2