|
From: <th...@us...> - 2008-12-31 23:46:07
|
Revision: 8765
http://pcgen.svn.sourceforge.net/pcgen/?rev=8765&view=rev
Author: thpr
Date: 2008-12-31 23:46:04 +0000 (Wed, 31 Dec 2008)
Log Message:
-----------
Kit Token updates & fixes part 1
Modified Paths:
--------------
Trunk/pcgen/code/src/java/pcgen/core/kit/KitSpells.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/ability/AbilityToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/ability/FeatToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/ability/FreeToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/clazz/ClassToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/clazz/LevelToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/clazz/SubclassToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/deity/CountToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/funds/FundsToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/funds/QtyToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/gear/LocationToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/gear/QtyToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/gear/SizeToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/prof/ProfToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/prof/RacialToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/ClassToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/FreeToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/RankToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/SelectionToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/SkillToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/spells/CountToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/spells/SpellsToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/ApplyToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/EquipBuyToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/StartpackToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/VisibleToken.java
Trunk/pcgen/code/src/java/plugin/lsttokens/kit/table/TableToken.java
Modified: Trunk/pcgen/code/src/java/pcgen/core/kit/KitSpells.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/core/kit/KitSpells.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/pcgen/core/kit/KitSpells.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -200,12 +200,9 @@
//
while (true)
{
- xs =
- Globals
- .getChoiceFromList("Choose " + aClass.getKeyName()
- + " spell(s) for " + workingBook, aSpellList,
- new ArrayList<KitSpellBookEntry>(),
- numberOfChoices);
+ xs = Globals.getChoiceFromList("Choose " + aClass.getKeyName()
+ + " spell(s) for " + workingBook, aSpellList,
+ new ArrayList<KitSpellBookEntry>(), numberOfChoices);
if (xs.size() != 0)
{
@@ -305,9 +302,8 @@
if (spLevel == 99)
{
- spLevel =
- SpellLevel.getFirstLevelForKey(spell, pcClass
- .getSpellLists(pc), pc);
+ spLevel = SpellLevel.getFirstLevelForKey(spell, pcClass
+ .getSpellLists(pc), pc);
owner = pcClass;
}
@@ -388,4 +384,21 @@
{
spells.put(ksi, featList, count);
}
+
+ public Collection<KnownSpellIdentifier> getSpells()
+ {
+ return spells.getKeySet();
+ }
+
+ public Collection<List<CDOMSingleRef<Ability>>> getAbilities(
+ KnownSpellIdentifier ksi)
+ {
+ return spells.getSecondaryKeySet(ksi);
+ }
+
+ public Integer getSpellCount(KnownSpellIdentifier ksi,
+ List<CDOMSingleRef<Ability>> abils)
+ {
+ return spells.get(ksi, abils);
+ }
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/ability/AbilityToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/ability/AbilityToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/ability/AbilityToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -88,13 +88,6 @@
+ "in a Kit requires CATEGORY=<cat>|<ability>,<ability>");
return false;
}
- if (pipeLoc != value.lastIndexOf(Constants.PIPE))
- {
- Logging.addParseMessage(Logging.LST_ERROR,
- "Two pipes found. ABILITY token "
- + "in a Kit requires CATEGORY=<cat>|<abilities>");
- return false;
- }
String catString = value.substring(0, pipeLoc);
if (!catString.startsWith("CATEGORY="))
{
@@ -123,7 +116,7 @@
+ "in a Kit requires CATEGORY=<cat>|<abilities>");
return false;
}
- StringTokenizer st = new StringTokenizer(rest, "|");
+ StringTokenizer st = new StringTokenizer(rest, Constants.PIPE);
while (st.hasMoreTokens())
{
@@ -157,7 +150,7 @@
{
Collection<CDOMReference<Ability>> references =
KitAbilities.getAbilityKeys();
- if (references == null)
+ if (references == null || references.isEmpty())
{
return null;
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/ability/FeatToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/ability/FeatToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/ability/FeatToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -74,7 +74,7 @@
public boolean parse(LoadContext context, KitAbilities kitAbil, String value)
{
- if (isEmpty(value))
+ if (isEmpty(value) || hasIllegalSeparator('|', value))
{
return false;
}
@@ -123,7 +123,7 @@
public String[] unparse(LoadContext context, KitAbilities KitAbilities)
{
Collection<CDOMReference<Ability>> ref = KitAbilities.getAbilityKeys();
- if (ref == null)
+ if (ref == null || ref.isEmpty())
{
return null;
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/ability/FreeToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/ability/FreeToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/ability/FreeToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -60,6 +60,10 @@
public boolean parse(LoadContext context, KitAbilities kitAbil, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
Boolean set;
char firstChar = value.charAt(0);
if (firstChar == 'y' || firstChar == 'Y')
@@ -76,13 +80,16 @@
{
if (firstChar != 'N' && firstChar != 'n')
{
- if (value.length() > 1 && !value.equalsIgnoreCase("NO"))
- {
- Logging.errorPrint("You should use 'YES' or 'NO' as the "
+ Logging.errorPrint("You should use 'YES' or 'NO' as the "
+ getTokenName() + ": " + value);
- return false;
- }
+ return false;
}
+ if (value.length() > 1 && !value.equalsIgnoreCase("NO"))
+ {
+ Logging.errorPrint("You should use 'YES' or 'NO' as the "
+ + getTokenName() + ": " + value);
+ return false;
+ }
set = Boolean.FALSE;
}
kitAbil.setFree(set);
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/clazz/ClassToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/clazz/ClassToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/clazz/ClassToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -65,6 +65,10 @@
public boolean parse(LoadContext context, KitClass kitClass, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
CDOMSingleRef<PCClass> ref =
context.ref.getCDOMReference(PCCLASS_CLASS, value);
kitClass.setPcclass(ref);
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/clazz/LevelToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/clazz/LevelToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/clazz/LevelToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -62,6 +62,10 @@
public boolean parse(LoadContext context, KitClass kitClass, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
kitClass.setLevel(FormulaFactory.getFormulaFor(value));
return true;
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/clazz/SubclassToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/clazz/SubclassToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/clazz/SubclassToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -63,6 +63,10 @@
public boolean parse(LoadContext context, KitClass kitClass, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
/*
* This call to kitClass.getPcclass() is safe, as the line is CLASS:
* and thus the CLASS: token is always encountered first
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/deity/CountToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/deity/CountToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/deity/CountToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -62,6 +62,10 @@
public boolean parse(LoadContext context, KitDeity kitDeity, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
kitDeity.setCount(FormulaFactory.getFormulaFor(value));
return true;
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/funds/FundsToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/funds/FundsToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/funds/FundsToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -60,6 +60,10 @@
public boolean parse(LoadContext context, KitFunds kitFunds, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
kitFunds.setName(value);
return true;
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/funds/QtyToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/funds/QtyToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/funds/QtyToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -61,6 +61,10 @@
public boolean parse(LoadContext context, KitFunds kitFunds, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
kitFunds.setQuantity(FormulaFactory.getFormulaFor(value));
return true;
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/gear/LocationToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/gear/LocationToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/gear/LocationToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -59,6 +59,10 @@
public boolean parse(LoadContext context, KitGear kitGear, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
kitGear.setLocation(value);
return true;
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/gear/QtyToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/gear/QtyToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/gear/QtyToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -61,6 +61,10 @@
public boolean parse(LoadContext context, KitGear kitGear, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
kitGear.setQuantity(FormulaFactory.getFormulaFor(value));
return true;
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/gear/SizeToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/gear/SizeToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/gear/SizeToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -30,6 +30,7 @@
import pcgen.rules.context.LoadContext;
import pcgen.rules.persistence.token.AbstractToken;
import pcgen.rules.persistence.token.CDOMSecondaryToken;
+import pcgen.util.Logging;
/**
* SIZE token for KitGear
@@ -70,9 +71,14 @@
}
else
{
- SizeAdjustment size =
- context.ref.getAbbreviatedObject(SizeAdjustment.class,
- value);
+ SizeAdjustment size = context.ref.getAbbreviatedObject(
+ SizeAdjustment.class, value);
+ if (size == null)
+ {
+ Logging.errorPrint(getTokenName()
+ + " found invalid Size abbreviation: " + value);
+ return false;
+ }
kitGear.setSize(size);
}
return true;
@@ -88,8 +94,8 @@
{
return null;
}
- return new String[]{"PC"};
+ return new String[] { "PC" };
}
- return new String[]{sz.getAbbreviation()};
+ return new String[] { sz.getAbbreviation() };
}
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/prof/ProfToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/prof/ProfToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/prof/ProfToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -37,7 +37,6 @@
import pcgen.rules.context.LoadContext;
import pcgen.rules.persistence.token.AbstractToken;
import pcgen.rules.persistence.token.CDOMSecondaryToken;
-import pcgen.util.Logging;
/**
* PROF Token part of Kit Prof Lst Token
@@ -82,22 +81,15 @@
String tokText = tok.nextToken();
CDOMSingleRef<WeaponProf> ref =
context.ref.getCDOMReference(WEAPONPROF_CLASS, tokText);
- if (ref == null)
- {
- Logging
- .errorPrint(" Error was encountered while parsing KitProf. "
- + tokText + " is not a valid WeaponProf");
- continue;
- }
obj.addProficiency(ref);
}
- return false;
+ return true;
}
public String[] unparse(LoadContext context, KitProf obj)
{
Collection<CDOMSingleRef<WeaponProf>> ref = obj.getProficiencies();
- if (ref == null)
+ if (ref == null || ref.isEmpty())
{
return null;
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/prof/RacialToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/prof/RacialToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/prof/RacialToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -46,21 +46,6 @@
return "RACIAL";
}
- /**
- * parse
- *
- * @param kitProf
- * KitProf
- * @param value
- * String
- * @return boolean
- */
- public boolean parse(KitProf kitProf, String value)
- {
- kitProf.setRacialProf(value.startsWith("Y"));
- return true;
- }
-
public Class<KitProf> getTokenClass()
{
return KitProf.class;
@@ -74,6 +59,10 @@
public boolean parse(LoadContext context, KitProf obj, String value)
throws PersistenceLayerException
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
Boolean set;
char firstChar = value.charAt(0);
if (firstChar == 'y' || firstChar == 'Y')
@@ -90,13 +79,16 @@
{
if (firstChar != 'N' && firstChar != 'n')
{
- if (value.length() > 1 && !value.equalsIgnoreCase("NO"))
- {
- Logging.errorPrint("You should use 'YES' or 'NO' as the "
+ Logging.errorPrint("You should use 'YES' or 'NO' as the "
+ getTokenName() + ": " + value);
- return false;
- }
+ return false;
}
+ if (value.length() > 1 && !value.equalsIgnoreCase("NO"))
+ {
+ Logging.errorPrint("You should use 'YES' or 'NO' as the "
+ + getTokenName() + ": " + value);
+ return false;
+ }
set = Boolean.FALSE;
}
obj.setRacialProf(set);
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/ClassToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/ClassToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/ClassToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -64,6 +64,10 @@
public boolean parse(LoadContext context, KitSkill kitSkill, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
CDOMSingleRef<PCClass> ref =
context.ref.getCDOMReference(PCCLASS_CLASS, value);
kitSkill.setPcclass(ref);
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/FreeToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/FreeToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/FreeToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -60,6 +60,10 @@
public boolean parse(LoadContext context, KitSkill kitSkill, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
Boolean set;
char firstChar = value.charAt(0);
if (firstChar == 'y' || firstChar == 'Y')
@@ -67,7 +71,7 @@
if (value.length() > 1 && !value.equalsIgnoreCase("YES"))
{
Logging.errorPrint("You should use 'YES' as the "
- + getTokenName() + ": " + value);
+ + getTokenName() + ": " + value);
return false;
}
set = Boolean.TRUE;
@@ -76,13 +80,16 @@
{
if (firstChar != 'N' && firstChar != 'n')
{
- if (value.length() > 1 && !value.equalsIgnoreCase("NO"))
- {
- Logging.errorPrint("You should use 'YES' or 'NO' as the "
+ Logging.errorPrint("You should use 'YES' or 'NO' as the "
+ getTokenName() + ": " + value);
- return false;
- }
+ return false;
}
+ if (value.length() > 1 && !value.equalsIgnoreCase("NO"))
+ {
+ Logging.errorPrint("You should use 'YES' or 'NO' as the "
+ + getTokenName() + ": " + value);
+ return false;
+ }
set = Boolean.FALSE;
}
kitSkill.setFree(set);
@@ -96,6 +103,6 @@
{
return null;
}
- return new String[]{mult.booleanValue() ? "YES" : "NO"};
+ return new String[] { mult.booleanValue() ? "YES" : "NO" };
}
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/RankToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/RankToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/RankToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -62,6 +62,10 @@
public boolean parse(LoadContext context, KitSkill kitSkill, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
try
{
BigDecimal rank = new BigDecimal(value);
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/SelectionToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/SelectionToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/SelectionToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -91,7 +91,7 @@
public String[] unparse(LoadContext context, KitSkill kitSkill)
{
List<CDOMSingleRef<Language>> ref = kitSkill.getSelections();
- if (ref == null)
+ if (ref == null || ref.isEmpty())
{
return null;
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/SkillToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/SkillToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/skill/SkillToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -79,8 +79,13 @@
while (tok.hasMoreTokens())
{
String tokText = tok.nextToken();
- kitSkill.addSkill(TokenUtilities.getTypeOrPrimitive(context,
- SKILL_CLASS, tokText));
+ CDOMReference<Skill> ref = TokenUtilities.getTypeOrPrimitive(
+ context, SKILL_CLASS, tokText);
+ if (ref == null)
+ {
+ return false;
+ }
+ kitSkill.addSkill(ref);
}
return true;
}
@@ -88,11 +93,11 @@
public String[] unparse(LoadContext context, KitSkill kitSkill)
{
Collection<CDOMReference<Skill>> ref = kitSkill.getSkills();
- if (ref == null)
+ if (ref == null || ref.isEmpty())
{
return null;
}
- return new String[]{ReferenceUtilities.joinLstFormat(ref,
- Constants.PIPE)};
+ return new String[] { ReferenceUtilities.joinLstFormat(ref,
+ Constants.PIPE) };
}
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/spells/CountToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/spells/CountToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/spells/CountToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -61,6 +61,10 @@
public boolean parse(LoadContext context, KitSpells kitSpells, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
kitSpells.setCount(FormulaFactory.getFormulaFor(value));
return true;
}
@@ -72,6 +76,6 @@
{
return null;
}
- return new String[]{bd.toString()};
+ return new String[] { bd.toString() };
}
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/spells/SpellsToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/spells/SpellsToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/spells/SpellsToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -26,12 +26,16 @@
package plugin.lsttokens.kit.spells;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
import java.util.StringTokenizer;
+import pcgen.base.lang.StringUtil;
import pcgen.cdom.base.CDOMReference;
import pcgen.cdom.base.Constants;
import pcgen.cdom.content.KnownSpellIdentifier;
import pcgen.cdom.reference.CDOMSingleRef;
+import pcgen.cdom.reference.ReferenceUtilities;
import pcgen.core.Ability;
import pcgen.core.AbilityCategory;
import pcgen.core.Globals;
@@ -76,6 +80,10 @@
public boolean parse(LoadContext context, KitSpells kitSpell, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
StringTokenizer aTok = new StringTokenizer(value, Constants.PIPE);
while (aTok.hasMoreTokens())
{
@@ -85,30 +93,43 @@
if (kitSpell.getSpellBook() != null)
{
Logging.errorPrint("Cannot reset SPELLBOOK in SPELLS: "
- + value);
+ + value);
return false;
}
- kitSpell.setSpellBook(field.substring(10));
+ String spellBook = field.substring(10);
+ if (spellBook.length() == 0)
+ {
+ Logging.errorPrint("Cannot set SPELLBOOK "
+ + "to empty value in SPELLS: " + value);
+ return false;
+ }
+ kitSpell.setSpellBook(spellBook);
}
else if (field.startsWith("CLASS="))
{
if (kitSpell.getCastingClass() != null)
{
Logging.errorPrint("Cannot reset CLASS" + " in SPELLS: "
- + value);
+ + value);
return false;
}
String className = field.substring(6);
- if (className.equalsIgnoreCase("Default"))
+ if (className.length() == 0)
{
+ Logging.errorPrint("Cannot set CLASS "
+ + "to empty value in SPELLS: " + value);
+ return false;
+ }
+ else if (className.equalsIgnoreCase("Default"))
+ {
Logging
- .deprecationPrint("Use of Default for CLASS= in KIT "
- + "SPELLS line is unnecessary: Ignoring");
+ .deprecationPrint("Use of Default for CLASS= in KIT "
+ + "SPELLS line is unnecessary: Ignoring");
}
else
{
kitSpell.setCastingClass(context.ref.getCDOMReference(
- PCClass.class, className));
+ PCClass.class, className));
}
}
else
@@ -125,59 +146,40 @@
catch (NumberFormatException e)
{
Logging.errorPrint("Expected an Integer COUNT,"
- + " but found: " + countStr + " in " + value);
+ + " but found: " + countStr + " in " + value);
return false;
}
field = field.substring(0, equalLoc);
}
+ if (field.length() == 0)
+ {
+ Logging.errorPrint("Expected an Spell in SPELLS"
+ + " but found: " + value);
+ return false;
+ }
StringTokenizer subTok = new StringTokenizer(field, "[]");
String filterString = subTok.nextToken();
// must satisfy all elements in a comma delimited list
- Integer levelLim = null;
CDOMReference<Spell> sp = null;
- if (filterString.startsWith("LEVEL="))
+ sp = TokenUtilities.getTypeOrPrimitive(context, SPELL_CLASS,
+ filterString);
+ if (sp == null)
{
- // if the argument starts with LEVEL=, compare the level to
- // the desired spellLevel
- try
- {
- levelLim = Integer.valueOf(filterString.substring(6));
- }
- catch (NumberFormatException e)
- {
- Logging.errorPrint("Invalid Number in "
+ Logging.errorPrint(" encountered Invalid limit in "
+ getTokenName() + ": " + value);
- Logging.errorPrint(" Level must be an integer");
- return false;
- }
- sp = context.ref.getCDOMAllReference(SPELL_CLASS);
+ return false;
}
- else
- {
- sp =
- TokenUtilities.getTypeOrPrimitive(context,
- SPELL_CLASS, filterString);
- if (sp == null)
- {
- Logging.errorPrint(" encountered Invalid limit in "
- + getTokenName() + ": " + value);
- return false;
- }
- }
- KnownSpellIdentifier ksi =
- new KnownSpellIdentifier(sp, levelLim);
+ KnownSpellIdentifier ksi = new KnownSpellIdentifier(sp, null);
- ArrayList<CDOMSingleRef<Ability>> featList =
- new ArrayList<CDOMSingleRef<Ability>>();
+ ArrayList<CDOMSingleRef<Ability>> featList = new ArrayList<CDOMSingleRef<Ability>>();
while (subTok.hasMoreTokens())
{
String featName = subTok.nextToken();
- CDOMSingleRef<Ability> feat =
- context.ref.getCDOMReference(ABILITY_CLASS,
- AbilityCategory.FEAT, featName);
+ CDOMSingleRef<Ability> feat = context.ref.getCDOMReference(
+ ABILITY_CLASS, AbilityCategory.FEAT, featName);
featList.add(feat);
}
kitSpell.addSpell(ksi, featList, count);
@@ -190,19 +192,69 @@
return true;
}
- public String[] unparse(LoadContext context, KitSpells kitSkill)
+ public String[] unparse(LoadContext context, KitSpells kitSpell)
{
- return null;
+ StringBuilder sb = new StringBuilder();
+ String spellBook = kitSpell.getSpellBook();
+ String globalSpellbook = Globals.getDefaultSpellBook();
+ if (spellBook != null && !globalSpellbook.equals(spellBook))
+ {
+ sb.append("SPELLBOOK=").append(spellBook);
+ }
+ CDOMSingleRef<PCClass> castingClass = kitSpell.getCastingClass();
+ if (castingClass != null)
+ {
+ if (sb.length() != 0)
+ {
+ sb.append(Constants.PIPE);
+ }
+ sb.append("CLASS=").append(castingClass.getLSTformat());
+ }
+ Collection<KnownSpellIdentifier> spells = kitSpell.getSpells();
+ if (spells != null)
+ {
+ boolean needPipe = sb.length() > 0;
+ for (KnownSpellIdentifier ksi : spells)
+ {
+ if (needPipe)
+ {
+ sb.append(Constants.PIPE);
+ }
+ needPipe = true;
+ Collection<List<CDOMSingleRef<Ability>>> abilities = kitSpell
+ .getAbilities(ksi);
+ for (List<CDOMSingleRef<Ability>> abils : abilities)
+ {
+ StringBuilder spell = new StringBuilder();
+ spell.append(StringUtil.replaceAll(ksi.getLSTformat(),
+ Constants.LST_TYPE, Constants.LST_TYPE_OLD));
+ if (abils != null && !abils.isEmpty())
+ {
+ spell.append('[');
+ spell.append(ReferenceUtilities.joinLstFormat(abils,
+ "]["));
+ spell.append(']');
+ }
+ Integer count = kitSpell.getSpellCount(ksi, abils);
+ if (count != 1)
+ {
+ spell.append('=').append(count);
+ }
+ sb.append(spell);
+ }
+ }
+ }
+ if (sb.length() == 0)
+ {
+ return null;
+ }
+ return new String[] { sb.toString() };
}
-
- //TODO DeferredToken
+ // TODO DeferredToken
/*
- if (!aClass.getSafe(ObjectKey.MEMORIZE_SPELLS)
- && !spellBook.equals(Globals.getDefaultSpellBook()))
- {
- warnings.add("SPELLS: " + aClass.getDisplayName()
- + " can only add to " + Globals.getDefaultSpellBook());
- return false;
- }
+ * if (!aClass.getSafe(ObjectKey.MEMORIZE_SPELLS) &&
+ * !spellBook.equals(Globals.getDefaultSpellBook())) { warnings.add("SPELLS: " +
+ * aClass.getDisplayName() + " can only add to " +
+ * Globals.getDefaultSpellBook()); return false; }
*/
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/ApplyToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/ApplyToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/ApplyToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -31,12 +31,12 @@
import pcgen.rules.context.LoadContext;
import pcgen.rules.persistence.token.AbstractToken;
import pcgen.rules.persistence.token.CDOMPrimaryToken;
+import pcgen.util.Logging;
/**
- * Deals with APPLY lst token within KitStartpack
+ * Deals with APPLY lst token within KitStartpack
*/
-public class ApplyToken extends AbstractToken implements
- CDOMPrimaryToken<Kit>
+public class ApplyToken extends AbstractToken implements CDOMPrimaryToken<Kit>
{
/**
* Gets the name of the tag this class will parse.
@@ -54,16 +54,24 @@
return Kit.class;
}
- public String getParentToken()
- {
- return "*KITTOKEN";
- }
-
public boolean parse(LoadContext context, Kit kit, String value)
{
- KitApply ka = KitApply.valueOf(value);
- kit.put(ObjectKey.APPLY_MODE, ka);
- return true;
+ if (isEmpty(value))
+ {
+ return false;
+ }
+ try
+ {
+ KitApply ka = KitApply.valueOf(value);
+ kit.put(ObjectKey.APPLY_MODE, ka);
+ return true;
+ }
+ catch (IllegalArgumentException e)
+ {
+ Logging.errorPrint(getTokenName()
+ + " encountered unexpected application type: " + value);
+ return false;
+ }
}
public String[] unparse(LoadContext context, Kit kit)
@@ -73,6 +81,6 @@
{
return null;
}
- return new String[]{bd.toString()};
+ return new String[] { bd.toString() };
}
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/EquipBuyToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/EquipBuyToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/EquipBuyToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -63,11 +63,6 @@
return Kit.class;
}
- public String getParentToken()
- {
- return "*KITTOKEN";
- }
-
public boolean parse(LoadContext context, Kit kit, String value)
{
if (isEmpty(value) || hasIllegalSeparator('|', value))
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/StartpackToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/StartpackToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/StartpackToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -29,13 +29,13 @@
import pcgen.persistence.PersistenceLayerException;
import pcgen.rules.context.LoadContext;
import pcgen.rules.persistence.token.AbstractToken;
-import pcgen.rules.persistence.token.CDOMSecondaryToken;
+import pcgen.rules.persistence.token.CDOMPrimaryToken;
/**
* STARTPACK token for Kit Startpack
*/
public class StartpackToken extends AbstractToken implements
- CDOMSecondaryToken<Kit>
+ CDOMPrimaryToken<Kit>
{
/**
* Gets the name of the tag this class will parse.
@@ -48,11 +48,6 @@
return "STARTPACK";
}
- public String getParentToken()
- {
- return "*KITTOKEN";
- }
-
public Class<Kit> getTokenClass()
{
return Kit.class;
@@ -61,6 +56,10 @@
public boolean parse(LoadContext context, Kit kit, String value)
throws PersistenceLayerException
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
return true;
}
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/VisibleToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/VisibleToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/startpack/VisibleToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -55,13 +55,12 @@
return Kit.class;
}
- public String getParentToken()
- {
- return "*KITTOKEN";
- }
-
public boolean parse(LoadContext context, Kit kit, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
Visibility vis;
if (value.equals("QUALIFY"))
{
Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/kit/table/TableToken.java
===================================================================
--- Trunk/pcgen/code/src/java/plugin/lsttokens/kit/table/TableToken.java 2008-12-31 20:17:37 UTC (rev 8764)
+++ Trunk/pcgen/code/src/java/plugin/lsttokens/kit/table/TableToken.java 2008-12-31 23:46:04 UTC (rev 8765)
@@ -64,6 +64,10 @@
public boolean parse(LoadContext context, KitTable kitTable, String value)
{
+ if (isEmpty(value))
+ {
+ return false;
+ }
kitTable.setTableName(value);
return true;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|