use of pcgen.core.character.Follower in project pcgen by PCGen.
the class PCGVer2Parser method parseMasterLine.
private void parseMasterLine(final String line) {
final PCGTokenizer tokens;
try {
tokens = new PCGTokenizer(line);
} catch (PCGParseException pcgpex) {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.IllegalMaster", line, pcgpex.getMessage());
warnings.add(msg);
return;
}
final Follower aMaster = new Follower(Constants.EMPTY_STRING, Constants.EMPTY_STRING, null);
for (PCGElement element : tokens.getElements()) {
final String tag = element.getName();
if (IOConstants.TAG_MASTER.equals(tag)) {
aMaster.setName(EntityEncoder.decode(element.getText()));
} else if (IOConstants.TAG_TYPE.equals(tag)) {
String cType = EntityEncoder.decode(element.getText());
CompanionList cList = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(CompanionList.class, cType);
if (cList == null) {
Logging.errorPrint("Cannot find CompanionList: " + cType);
} else {
aMaster.setType(cList);
}
} else if (IOConstants.TAG_HITDICE.equals(tag)) {
try {
aMaster.setUsedHD(Integer.parseInt(element.getText()));
} catch (NumberFormatException nfe) {
// nothing we can do about it
}
} else if (IOConstants.TAG_FILE.equals(tag)) {
String inputFileName = EntityEncoder.decode(element.getText());
String masterFileName = makeFilenameAbsolute(inputFileName);
if (masterFileName == null) {
final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
"Warnings.PCGenParser.CantFindMaster", inputFileName);
warnings.add(msg);
} else {
aMaster.setFileName(masterFileName);
}
} else if (IOConstants.TAG_ADJUSTMENT.equals(tag)) {
aMaster.setAdjustment(Integer.parseInt(element.getText()));
}
}
if (!Constants.EMPTY_STRING.equals(aMaster.getFileName()) && !Constants.EMPTY_STRING.equals(aMaster.getName()) && !Constants.EMPTY_STRING.equals(aMaster.getType().toString())) {
thePC.setMaster(aMaster);
}
}
Aggregations