From: <th...@us...> - 2008-06-22 11:33:52
|
Revision: 6785 http://pcgen.svn.sourceforge.net/pcgen/?rev=6785&view=rev Author: thpr Date: 2008-06-21 15:11:06 -0700 (Sat, 21 Jun 2008) Log Message: ----------- new UMULT token Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/IntegerKey.java Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/ListKey.java Trunk/pcgen/code/src/java/pcgen/core/PCClass.java Trunk/pcgen/code/src/java/pcgen/core/PObject.java Trunk/pcgen/code/src/java/pcgen/gui/editor/ClassLevelPanel.java Trunk/pcgen/code/src/java/pcgen/gui/editor/EditorMainForm.java Trunk/pcgen/code/src/java/plugin/lsttokens/UmultLst.java Added Paths: ----------- Trunk/pcgen/code/src/utest/plugin/lsttokens/UmultLstTest.java Modified: Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/IntegerKey.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/IntegerKey.java 2008-06-21 21:32:33 UTC (rev 6784) +++ Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/IntegerKey.java 2008-06-21 22:11:06 UTC (rev 6785) @@ -119,6 +119,8 @@ public static final IntegerKey HD_MAX = getConstant("HD_MAX"); + public static final IntegerKey UMULT = getConstant("UMULT"); + /* * TODO Okay, this is a hack. This should probably be a FormulaKey rather * than an IntegerKey in order to properly handle this strange delegation. Modified: Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/ListKey.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/ListKey.java 2008-06-21 21:32:33 UTC (rev 6784) +++ Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/ListKey.java 2008-06-21 22:11:06 UTC (rev 6785) @@ -143,8 +143,6 @@ public static final ListKey<BonusObj> TEMP_BONUS = new ListKey<BonusObj>(); /** UDAM - a ListKey */ public static final ListKey<String> UDAM = new ListKey<String>(); - /** UMULT - a ListKey */ - public static final ListKey<String> UMULT = new ListKey<String>(); /** Key for a list of virtual feats (feats granted regardless of the prereqs) */ public static final ListKey<Ability> VIRTUAL_FEATS = new ListKey<Ability>(); // /** Key for a list of weapon proficiencies */ Modified: Trunk/pcgen/code/src/java/pcgen/core/PCClass.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PCClass.java 2008-06-21 21:32:33 UTC (rev 6784) +++ Trunk/pcgen/code/src/java/pcgen/core/PCClass.java 2008-06-21 22:11:06 UTC (rev 6785) @@ -2488,17 +2488,6 @@ } } - List<String> umultList = getListFor(ListKey.UMULT); - if (umultList != null) - { - for (String st : umultList) - { - final int sepPos = st.indexOf("|"); - pccTxt.append(lineSep).append(st.substring(0, sepPos)).append( - "\tUMULT:").append(st.substring(sepPos + 1)); - } - } - return pccTxt.toString(); } @@ -3775,12 +3764,28 @@ if (includeCrit) { - final String dString = getUMultForLevel(aLevel); - - if (!"0".equals(dString)) + Integer active = null; + for (int i = aLevel; i >= 0; i--) { - aString.append("(x").append(dString).append(')'); + PCClassLevel pcl = levelMap.get(i); + if (pcl != null) + { + active = pcl.get(IntegerKey.UMULT); + if (active != null) + { + break; + } + } } + if (active == null) + { + //Could be in the class + active = get(IntegerKey.UMULT); + } + if (active != null) + { + aString.append("(x").append(active).append(')'); + } } return aString.toString(); @@ -4827,34 +4832,6 @@ } /* - * PCCLASSLEVELONLY Since this is a level dependent calculation, this should - * be performed by the PCClassLevel. - */ - private String getUMultForLevel(final int aLevel) - { - String aString = "0"; - - List<String> umultList = getListFor(ListKey.UMULT); - if ((umultList == null) || umultList.isEmpty()) - { - return aString; - } - - for (String umult : umultList) - { - final int pos = umult.lastIndexOf('|'); - - if ((pos >= 0) - && (aLevel <= Integer.parseInt(umult.substring(0, pos)))) - { - aString = umult.substring(pos + 1); - } - } - - return aString; - } - - /* * REFACTOR This should really be better at recognizing level dependent * items and storing them appropriately and not relying on PObject to ever * be level aware. This is a general problem across PCClass and I would like Modified: Trunk/pcgen/code/src/java/pcgen/core/PObject.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2008-06-21 21:32:33 UTC (rev 6784) +++ Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2008-06-21 22:11:06 UTC (rev 6785) @@ -48,6 +48,7 @@ import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.Constants; +import pcgen.cdom.enumeration.IntegerKey; import pcgen.cdom.enumeration.ListKey; import pcgen.cdom.enumeration.ObjectKey; import pcgen.cdom.enumeration.StringKey; @@ -910,22 +911,6 @@ } /** - * Add the U multiplier - * @param mult - */ - public final void addUmult(final String mult) - { - if (".CLEAR".equals(mult)) - { - removeListFor(ListKey.UMULT); - } - else - { - addToListFor(ListKey.UMULT, mult); - } - } - - /** * Add a variable to the variable list * @param level * @param variableName @@ -3027,14 +3012,12 @@ aString.append(String.valueOf(b)); } - List<String> umultList = getListFor(ListKey.UMULT); - if (includeCrit && (umultList != null) && !umultList.isEmpty()) + if (includeCrit) { - final String dString = umultList.get(0); - - if (!"0".equals(dString)) + Integer umult = get(IntegerKey.UMULT); + if (umult != null) { - aString.append("(x").append(dString).append(')'); + aString.append("(x").append(umult).append(')'); } } Modified: Trunk/pcgen/code/src/java/pcgen/gui/editor/ClassLevelPanel.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/editor/ClassLevelPanel.java 2008-06-21 21:32:33 UTC (rev 6784) +++ Trunk/pcgen/code/src/java/pcgen/gui/editor/ClassLevelPanel.java 2008-06-21 22:11:06 UTC (rev 6785) @@ -371,21 +371,19 @@ } } } - - List<String> sList = obj.getListFor(ListKey.UMULT); - - if ((sList != null) && (sList.size() != 0)) + + for (PCClassLevel pcl : obj.getClassLevelCollection()) { - for (Iterator<String> se = sList.iterator(); se.hasNext();) + Integer umult = pcl.get(IntegerKey.UMULT); + if (umult != null) { - String c = se.next(); - int y = c.indexOf('|'); - LevelTag lt = new LevelTag(c.substring(0, y), LevelTag.TAG_UMULT, c.substring(y + 1)); + LevelTag lt = new LevelTag(obj.getPCClassLevel(pcl), + LevelTag.TAG_UMULT, umult.toString()); levelTagList.add(lt); } } - sList = obj.getListFor(ListKey.UDAM); + List<String> sList = obj.getListFor(ListKey.UDAM); if (sList != null) { Modified: Trunk/pcgen/code/src/java/pcgen/gui/editor/EditorMainForm.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/editor/EditorMainForm.java 2008-06-21 21:32:33 UTC (rev 6784) +++ Trunk/pcgen/code/src/java/pcgen/gui/editor/EditorMainForm.java 2008-06-21 22:11:06 UTC (rev 6785) @@ -56,9 +56,11 @@ import pcgen.cdom.base.Constants; import pcgen.cdom.base.SimpleAssociatedObject; import pcgen.cdom.enumeration.AssociationKey; +import pcgen.cdom.enumeration.IntegerKey; import pcgen.cdom.enumeration.ListKey; import pcgen.cdom.enumeration.ObjectKey; import pcgen.cdom.enumeration.Pantheon; +import pcgen.cdom.inst.PCClassLevel; import pcgen.cdom.list.ClassSkillList; import pcgen.cdom.list.DomainList; import pcgen.cdom.reference.CDOMDirectSingleRef; @@ -981,7 +983,11 @@ thisPCClass.removeListFor(ListKey.TEMPLATE); thisPCClass.removeListFor(ListKey.TEMPLATE_CHOOSE); thisPCClass.removeListFor(ListKey.TEMPLATE_ADDCHOICE); - thisPCClass.addUmult(".CLEAR"); + thisPCClass.remove(IntegerKey.UMULT); + for (PCClassLevel pcl : thisPCClass.getClassLevelCollection()) + { + pcl.remove(IntegerKey.UMULT); + } thisPCClass.clearUdamList(); break; Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/UmultLst.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/lsttokens/UmultLst.java 2008-06-21 21:32:33 UTC (rev 6784) +++ Trunk/pcgen/code/src/java/plugin/lsttokens/UmultLst.java 2008-06-21 22:11:06 UTC (rev 6785) @@ -4,36 +4,73 @@ */ package plugin.lsttokens; -import pcgen.core.PObject; -import pcgen.persistence.lst.GlobalLstToken; +import pcgen.cdom.base.CDOMObject; +import pcgen.cdom.base.Constants; +import pcgen.cdom.enumeration.IntegerKey; +import pcgen.rules.context.LoadContext; +import pcgen.rules.persistence.token.CDOMPrimaryToken; +import pcgen.util.Logging; /** * @author djones4 - * + * */ -public class UmultLst implements GlobalLstToken +public class UmultLst implements CDOMPrimaryToken<CDOMObject> { - /* - * FIXME Template's LevelToken needs adjustment before this can be converted - * to the new syntax, since this is level-dependent - */ - public String getTokenName() { return "UMULT"; } - public boolean parse(PObject obj, String value, int anInt) + public boolean parse(LoadContext context, CDOMObject obj, String value) { - if (anInt > -9) + if (Constants.LST_DOT_CLEAR.equals(value)) { - obj.addUmult(anInt + "|" + value); + context.getObjectContext().put(obj, IntegerKey.UMULT, null); } else { - obj.addUmult(value); + try + { + Integer i = Integer.valueOf(value); + if (i.intValue() <= 0) + { + Logging.errorPrint("Invalid " + getTokenName() + ": " + + value); + Logging.errorPrint(" Expecting a positive integer"); + return false; + } + context.getObjectContext().put(obj, IntegerKey.UMULT, i); + } + catch (NumberFormatException nfe) + { + Logging.errorPrint("Invalid " + getTokenName() + ": " + value); + Logging.errorPrint(" Expecting an integer"); + return false; + } } return true; } + + public String[] unparse(LoadContext context, CDOMObject obj) + { + Integer mult = context.getObjectContext().getInteger(obj, + IntegerKey.UMULT); + if (mult == null) + { + return null; + } + if (mult.intValue() <= 0) + { + context.addWriteMessage(getTokenName() + " must be an integer > 0"); + return null; + } + return new String[] { mult.toString() }; + } + + public Class<CDOMObject> getTokenClass() + { + return CDOMObject.class; + } } Added: Trunk/pcgen/code/src/utest/plugin/lsttokens/UmultLstTest.java =================================================================== --- Trunk/pcgen/code/src/utest/plugin/lsttokens/UmultLstTest.java (rev 0) +++ Trunk/pcgen/code/src/utest/plugin/lsttokens/UmultLstTest.java 2008-06-21 22:11:06 UTC (rev 6785) @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2007 Tom Parker <th...@us...> + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ +package plugin.lsttokens; + +import pcgen.cdom.base.CDOMObject; +import pcgen.cdom.enumeration.IntegerKey; +import pcgen.core.PCTemplate; +import pcgen.rules.persistence.CDOMLoader; +import pcgen.rules.persistence.CDOMTokenLoader; +import pcgen.rules.persistence.token.CDOMPrimaryToken; +import plugin.lsttokens.testsupport.AbstractGlobalIntegerTokenTestCase; + +public class UmultLstTest extends AbstractGlobalIntegerTokenTestCase +{ + + @Override + public IntegerKey getIntegerKey() + { + return IntegerKey.UMULT; + } + + @Override + public boolean isNegativeAllowed() + { + return false; + } + + @Override + public boolean isPositiveAllowed() + { + return true; + } + + @Override + public boolean isZeroAllowed() + { + return false; + } + + static CDOMPrimaryToken<CDOMObject> token = new UmultLst(); + static CDOMTokenLoader<PCTemplate> loader = new CDOMTokenLoader<PCTemplate>( + PCTemplate.class); + + @Override + public CDOMLoader<PCTemplate> getLoader() + { + return loader; + } + + @Override + public Class<PCTemplate> getCDOMClass() + { + return PCTemplate.class; + } + + @Override + public CDOMPrimaryToken<CDOMObject> getToken() + { + return token; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |