MCPcopy Create free account
hub / github.com/PCGen/pcgen / parseSpellBookLines

Method parseSpellBookLines

code/src/java/pcgen/io/PCGVer2Parser.java:3719–3778  ·  view source on GitHub ↗
(final String line)

Source from the content-addressed store, hash-verified

3717 * SPELLBOOK:bookname|TYPE:spellbooktype
3718 */
3719 private void parseSpellBookLines(final String line)
3720 {
3721 final PCGTokenizer tokens;
3722
3723 try
3724 {
3725 tokens = new PCGTokenizer(line);
3726 }
3727 catch (PCGParseException pcgpex)
3728 {
3729 final String message =
3730 "Illegal Spell book ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
3731 warnings.add(message);
3732
3733 return;
3734 }
3735
3736 SpellBook aSpellBook = null;
3737
3738 for (PCGElement element : tokens.getElements())
3739 {
3740 final String tag = element.getName();
3741
3742 if (IOConstants.TAG_SPELLBOOK.equals(tag))
3743 {
3744 final String bookName = EntityEncoder.decode(element.getText());
3745
3746 aSpellBook = new SpellBook(bookName, SpellBook.TYPE_PREPARED_LIST);
3747 }
3748 else if (IOConstants.TAG_TYPE.equals(tag))
3749 {
3750 try
3751 {
3752 aSpellBook.setType(Integer.parseInt(element.getText()));
3753 }
3754 catch (NumberFormatException nfe)
3755 {
3756 // nothing we can do about it
3757 final String message = "Spell book " + aSpellBook.getName() + " had an illegal type: "
3758 + element.getText() + " in line " + line;
3759 warnings.add(message);
3760 }
3761 }
3762 else if (IOConstants.TAG_AUTOADDKNOWN.equals(tag))
3763 {
3764 if (IOConstants.VALUE_Y.equals(element.getText()))
3765 {
3766 thePC.setSpellBookNameToAutoAddKnown(aSpellBook.getName());
3767 }
3768 }
3769 }
3770 if (aSpellBook == null)
3771 {
3772 warnings.add("Internal Error: Did not build Spell Book from SPELLBOOK line");
3773 }
3774 else
3775 {
3776 thePC.addSpellBook(aSpellBook);

Callers 1

parseCachedLinesMethod · 0.95

Calls 12

getElementsMethod · 0.95
decodeMethod · 0.95
setTypeMethod · 0.95
getNameMethod · 0.95
parseIntMethod · 0.80
addSpellBookMethod · 0.80
getMessageMethod · 0.65
addMethod · 0.65
getNameMethod · 0.65
equalsMethod · 0.65
getTextMethod · 0.45

Tested by

no test coverage detected