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();
}
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);
}
}
}
}
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;
}
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);
}
Aggregations