use of pcgen.persistence.lst.utils.DeferredLine in project pcgen by PCGen.
the class SubstitutionLevelSupport method qualifiesForSubstitutionLevel.
public static boolean qualifiesForSubstitutionLevel(PCClass cl, SubstitutionClass sc, PlayerCharacter pc, int level) {
List<DeferredLine> levelArray = sc.getListFor(ListKey.SUB_CLASS_LEVEL);
if (levelArray == null) {
return false;
}
for (DeferredLine line : levelArray) {
String aLine = line.lstLine;
final int modLevel = Integer.parseInt(aLine.substring(0, aLine.indexOf("\t")));
if (level == modLevel) {
if (!levelArrayQualifies(level, pc, aLine, line.source, cl)) {
return false;
}
}
}
return true;
}
use of pcgen.persistence.lst.utils.DeferredLine in project pcgen by PCGen.
the class SubstitutionLevelSupport method applyLevelArrayModsToLevel.
/**
* Apply the level mods to a class
* @param aClass
*/
public static void applyLevelArrayModsToLevel(SubstitutionClass sc, final PCClass aClass, final int aLevel, final PlayerCharacter aPC) {
List<DeferredLine> levelArray = sc.getListFor(ListKey.SUB_CLASS_LEVEL);
if (levelArray == null) {
return;
}
List<DeferredLine> newLevels = new ArrayList<>();
for (DeferredLine line : levelArray) {
String aLine = line.lstLine;
final int modLevel = Integer.parseInt(aLine.substring(0, aLine.indexOf("\t")));
if (aLevel == modLevel) {
if (levelArrayQualifies(aLevel, aPC, aLine, line.source, aClass)) {
newLevels.add(line);
}
}
}
// and put into newLevels list.
if (!newLevels.isEmpty()) {
aPC.setSubstitutionLevel(aClass, sc.getOriginalClassLevel(aLevel));
}
}
use of pcgen.persistence.lst.utils.DeferredLine in project pcgen by PCGen.
the class PCClassLoader method parseLine.
/**
* @see pcgen.persistence.lst.LstObjectFileLoader#parseLine(LoadContext, pcgen.cdom.base.CDOMObject, String, SourceEntry)
*/
@Override
public PCClass parseLine(LoadContext context, PCClass target, String lstLine, SourceEntry source) throws PersistenceLayerException {
if (lstLine.startsWith("SUBCLASS:") || lstLine.startsWith("SUBCLASSLEVEL:")) {
if (target == null) {
Logging.errorPrint("Ignoring line: " + lstLine + " as SUBCLASS* type line appeared before CLASS: line");
return null;
}
SubClass subClass = null;
if (lstLine.startsWith("SUBCLASS:")) {
int tabLoc = lstLine.indexOf("\t");
if (tabLoc == -1) {
Logging.errorPrint("Expected SUBCLASS to have " + "additional Tags in " + source.getURI() + " (e.g. COST is a required Tag in a SUBCLASS)");
}
final String n = lstLine.substring(9, tabLoc);
String restOfLine = lstLine.substring(tabLoc);
subClass = target.getSubClassKeyed(n);
if (subClass == null) {
subClass = new SubClass();
subClass.setName(n.intern());
subClass.put(ObjectKey.SOURCE_CAMPAIGN, source.getCampaign());
subClass.setSourceURI(source.getURI());
target.addSubClass(subClass);
}
parseLineIntoClass(context, subClass, source, restOfLine);
} else {
List<SubClass> subClassList = target.getListFor(ListKey.SUB_CLASS);
if (subClassList != null) {
subClass = subClassList.get(subClassList.size() - 1);
subClass.addToListFor(ListKey.SUB_CLASS_LEVEL, new DeferredLine(source, lstLine.substring(14).intern()));
}
}
return target;
}
if (lstLine.startsWith("SUBSTITUTIONCLASS:") || lstLine.startsWith("SUBSTITUTIONLEVEL:")) {
if (target == null) {
Logging.errorPrint("Ignoring line: " + lstLine + " as SUBSTITUTIONCLASS* type line appeared before CLASS: line");
return null;
}
SubstitutionClass substitutionClass = null;
if (lstLine.startsWith("SUBSTITUTIONCLASS:")) {
int tabLoc = lstLine.indexOf("\t");
String name;
String restOfLine;
if (tabLoc > 0) {
name = lstLine.substring(18, tabLoc);
restOfLine = lstLine.substring(tabLoc);
} else {
name = lstLine.substring(18);
restOfLine = null;
}
substitutionClass = target.getSubstitutionClassKeyed(name);
if (substitutionClass == null) {
substitutionClass = new SubstitutionClass();
substitutionClass.setName(name.intern());
substitutionClass.put(ObjectKey.SOURCE_CAMPAIGN, source.getCampaign());
substitutionClass.setSourceURI(source.getURI());
target.addSubstitutionClass(substitutionClass);
}
parseLineIntoClass(context, substitutionClass, source, restOfLine);
} else {
if (lstLine.indexOf('\t') == -1) {
Logging.errorPrint("Ignoring line: " + lstLine + " as SUBSTITUTIONLEVEL line was empty");
return null;
}
List<SubstitutionClass> substitutionClassList = target.getListFor(ListKey.SUBSTITUTION_CLASS);
if (substitutionClassList != null && !substitutionClassList.isEmpty() && lstLine.length() > 18) {
substitutionClass = substitutionClassList.get(substitutionClassList.size() - 1);
substitutionClass.addToListFor(ListKey.SUB_CLASS_LEVEL, new DeferredLine(source, lstLine.substring(18).intern()));
}
}
return target;
}
return parseClassLine(context, lstLine, source, target);
}
use of pcgen.persistence.lst.utils.DeferredLine in project pcgen by PCGen.
the class PCClassLoader method processSubLevelLines.
private void processSubLevelLines(LoadContext context, PCClass cl, PCClass sc) {
for (DeferredLine dl : sc.getSafeListFor(ListKey.SUB_CLASS_LEVEL)) {
context.setSourceURI(dl.source.getURI());
String lstLine = dl.lstLine;
try {
int tabLoc = lstLine.indexOf(SystemLoader.TAB_DELIM);
String lineIdentifier;
String restOfLine;
if (tabLoc == -1) {
lineIdentifier = lstLine;
restOfLine = null;
} else {
lineIdentifier = lstLine.substring(0, tabLoc);
restOfLine = lstLine.substring(tabLoc + 1);
}
parseFullClassLevelLine(context, dl.source, sc, lineIdentifier, restOfLine);
} catch (PersistenceLayerException ple) {
Logging.log(Logging.LST_ERROR, "Error parsing " + sc.getClass().getSimpleName() + " line: " + cl.getKeyName() + " " + sc.getKeyName() + " " + lstLine, ple);
}
}
}
Aggregations