From: <th...@us...> - 2008-09-28 20:15:18
|
Revision: 7828 http://pcgen.svn.sourceforge.net/pcgen/?rev=7828&view=rev Author: thpr Date: 2008-09-28 20:15:01 +0000 (Sun, 28 Sep 2008) Log Message: ----------- SR token update Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/cdom/base/JEPFormula.java Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/ObjectKey.java Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/StringKey.java Trunk/pcgen/code/src/java/pcgen/core/EquipmentModifier.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/core/PlayerCharacter.java Trunk/pcgen/code/src/java/pcgen/core/analysis/TemplateSR.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/pcgen/rules/context/ConsolidatedObjectCommitStrategy.java Trunk/pcgen/code/src/java/pcgen/rules/context/ObjectCommitStrategy.java Trunk/pcgen/code/src/java/pcgen/rules/context/ObjectContext.java Trunk/pcgen/code/src/java/plugin/lsttokens/SrLst.java Added Paths: ----------- Trunk/pcgen/code/src/java/pcgen/cdom/content/SpellResistance.java Modified: Trunk/pcgen/code/src/java/pcgen/cdom/base/JEPFormula.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/cdom/base/JEPFormula.java 2008-09-28 18:34:01 UTC (rev 7827) +++ Trunk/pcgen/code/src/java/pcgen/cdom/base/JEPFormula.java 2008-09-28 20:15:01 UTC (rev 7828) @@ -97,8 +97,8 @@ } public Number resolve(Equipment equipment, boolean primary, - PlayerCharacter apc, String string) + PlayerCharacter apc, String source) { - return equipment.getVariableValue(formula, "", primary, apc); + return equipment.getVariableValue(formula, source, primary, apc); } } Added: Trunk/pcgen/code/src/java/pcgen/cdom/content/SpellResistance.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/cdom/content/SpellResistance.java (rev 0) +++ Trunk/pcgen/code/src/java/pcgen/cdom/content/SpellResistance.java 2008-09-28 20:15:01 UTC (rev 7828) @@ -0,0 +1,68 @@ +/* + * Copyright 2007 (C) Tom Parker <th...@us...> + * + * This library 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 library 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., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package pcgen.cdom.content; + +import pcgen.base.formula.Formula; +import pcgen.cdom.base.ConcretePrereqObject; + +public class SpellResistance extends ConcretePrereqObject +{ + + public static final SpellResistance NONE = new SpellResistance(Formula.ZERO); + + private final Formula reduction; + + public SpellResistance(Formula aReduction) + { + super(); + reduction = aReduction; + } + + public Formula getReduction() + { + return reduction; + } + + @Override + public String toString() + { + return reduction.toString(); + } + + @Override + public boolean equals(Object other) + { + if (other instanceof SpellResistance) + { + SpellResistance othSR = (SpellResistance) other; + return reduction.equals(othSR.reduction); + } + return false; + } + + @Override + public int hashCode() + { + return reduction.hashCode(); + } + + public String getLSTformat() + { + return reduction.toString(); + } +} Modified: Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/ObjectKey.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/ObjectKey.java 2008-09-28 18:34:01 UTC (rev 7827) +++ Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/ObjectKey.java 2008-09-28 20:15:01 UTC (rev 7828) @@ -39,6 +39,7 @@ import pcgen.cdom.content.LevelCommandFactory; import pcgen.cdom.content.LevelExchange; import pcgen.cdom.content.Modifier; +import pcgen.cdom.content.SpellResistance; import pcgen.cdom.list.ClassSkillList; import pcgen.cdom.list.ClassSpellList; import pcgen.cdom.list.DomainSpellList; @@ -217,6 +218,8 @@ public static final ObjectKey<CDOMSingleRef<PCClass>> EX_CLASS = new ObjectKey<CDOMSingleRef<PCClass>>(null); + public static final ObjectKey<SpellResistance> SR = new ObjectKey<SpellResistance>(SpellResistance.NONE); + public static final ObjectKey<SizeAdjustment> BASESIZE; public static final ObjectKey<SizeAdjustment> SIZE; Modified: Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/StringKey.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/StringKey.java 2008-09-28 18:34:01 UTC (rev 7827) +++ Trunk/pcgen/code/src/java/pcgen/cdom/enumeration/StringKey.java 2008-09-28 20:15:01 UTC (rev 7828) @@ -37,7 +37,7 @@ MASTER_BAB_FORMULA, BIRTHPLACE, BIRTHDAY, CATEGORY, BOOK_TYPE, CHOICE_STRING, DESTINATION, PAGE_USAGE, MINDEVVER, MINVER, ADD, BIO, DESCRIPTION, GENRE, HELP, APPEARANCE, CATCH_PHRASE, OUTPUT_NAME, INFO_TEXT, CHOICE_TO_MODIFY, PUB_NAME_LONG, COST, PUB_NAME_SHORT, - CURRENT_EQUIP_SET_NAME, REGION, PUB_NAME_WEB, SETTING, SR_FORMULA, TEMP_DESCRIPTION, TRAIT2, + CURRENT_EQUIP_SET_NAME, REGION, PUB_NAME_WEB, SETTING, TEMP_DESCRIPTION, TRAIT2, TRAIT1, SKIN_COLOR, HAIR_COLOR, SUB_REGION, SPEECH_TENDENCY, PHOBIAS, INTERESTS, RESIDENCE, SPELLBOOK_AUTO_ADD_KNOWN, PLAYERS_NAME, HANDED, HAIR_STYLE, PORTRAIT_PATH, EYE_COLOR, LOCATION, FILE_NAME, ABB, TARGET_AREA, NAME_TEXT, DAMAGE, DAMAGE_OVERRIDE, RATE_OF_FIRE, FUMBLE_RANGE, Modified: Trunk/pcgen/code/src/java/pcgen/core/EquipmentModifier.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/EquipmentModifier.java 2008-09-28 18:34:01 UTC (rev 7827) +++ Trunk/pcgen/code/src/java/pcgen/core/EquipmentModifier.java 2008-09-28 20:15:01 UTC (rev 7828) @@ -32,7 +32,10 @@ import java.util.Set; import java.util.StringTokenizer; +import pcgen.base.formula.Formula; import pcgen.cdom.base.Constants; +import pcgen.cdom.base.FormulaFactory; +import pcgen.cdom.content.SpellResistance; import pcgen.cdom.enumeration.FormulaKey; import pcgen.cdom.enumeration.IntegerKey; import pcgen.cdom.enumeration.ListKey; @@ -46,7 +49,6 @@ import pcgen.core.utils.MessageType; import pcgen.core.utils.ShowMessageDelegate; import pcgen.util.Delta; -import pcgen.util.Logging; import pcgen.util.chooser.ChooserFactory; import pcgen.util.chooser.ChooserInterface; @@ -59,6 +61,7 @@ public final class EquipmentModifier extends PObject implements Comparable<Object> { private static final String s_CHARGES = "CHARGES"; + private static final Formula CHOICE_FORMULA = FormulaFactory.getFormulaFor("%CHOICE"); /** * returns all BonusObj's that are "active", for example, ones that pass all @@ -353,34 +356,20 @@ return getKeyName(); } - @Override - public int getSR(final PlayerCharacter aPC) - { - Logging.errorPrint("Should not call getSR(PlayerCharacter) on EqMod"); - return 0; - } - public int getSR(Equipment parent, PlayerCharacter aPC) { - if (getSRFormula() == null) + SpellResistance sr = get(ObjectKey.SR); + if (sr == null) { return 0; } - if ("%CHOICE".equals(getSRFormula()) && parent.hasAssociations(this)) + if (sr.getReduction().equals(CHOICE_FORMULA)&& parent.hasAssociations(this)) { return Delta.parseInt(parent.getFirstAssociation(this)); } - final String srFormula = getSRFormula(); - - //if there's a current PC, go ahead and evaluate the formula - if (srFormula != null) - { - return parent.getVariableValue(srFormula, getQualifiedKey(), aPC).intValue(); - } - - return 0; + return sr.getReduction().resolve(parent, true, aPC, getQualifiedKey()).intValue(); } /** Modified: Trunk/pcgen/code/src/java/pcgen/core/PCClass.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PCClass.java 2008-09-28 18:34:01 UTC (rev 7827) +++ Trunk/pcgen/code/src/java/pcgen/core/PCClass.java 2008-09-28 20:15:01 UTC (rev 7828) @@ -126,12 +126,6 @@ private String specialty = null; /* - * FINALALLCLASSLEVELS The SR List is level dependent - heck, it's in a - * LevelProperty, so that should be pretty obvious :) - */ - private List<LevelProperty<String>> SR = null; - - /* * FINALALLCLASSLEVELS This is pretty obvious, as these are already in a * LevelProperty... these go into the PCClassLevel */ @@ -2042,117 +2036,7 @@ return true; } - /** - * should be "5|4/-" where 5 = level, 4/- is the SR value. - * - * @param srString - */ - /* - * FINALPCCLASSANDLEVEL Input from a Tag, and factory creation of a PCClassLevel - * require this method - */ @Override - public void setSR(int aLevel, String srString) - { - if (SR == null) - { - SR = new ArrayList<LevelProperty<String>>(); - } - SR.add(LevelProperty.getLevelProperty(aLevel, srString)); - } - - /* - * FINALPCCLASSONLY Since this is part of LST file import - */ - public void clearSR() - { - SR = null; - } - - /* - * FINALPCCLASSLEVELONLY This is required to fetch the SR - * - * UNWIND the level checking will have to be unwound into the users of this - * class, as these SRs will not pass from one PCClassLevel to another unless - * they are specified... - */ - @Override - public int getSR(PlayerCharacter aPC) - { - if (aPC == null) - { - return 0; - } - - LevelProperty<String> activeLP = null; - - if (SR != null) - { - final int lvl = level; - for (LevelProperty<String> lp : SR) - { - if (lp.getLevel() > lvl) - { - continue; - } - if (activeLP == null || activeLP.getLevel() < lp.getLevel()) - { - activeLP = lp; - continue; - } - } - } - - //if there's a current PC, go ahead and evaluate the formula - if (activeLP != null) - { - return aPC - .getVariableValue(activeLP.getObject(), getQualifiedKey()) - .intValue(); - } - - return 0; - - } - - /* - * FINALPCCLASSONLY This is for building a PCClass - */ - public List<LevelProperty<String>> getSRlist() - { - if (SR == null) - { - /* - * CONSIDER This is a heavy-weight get... and inconsistent with - * getFeatList, et al. What should be the proper method (should the - * caller be required to gate on null, should these be safe gets, - * should the variables be initialized empty lists??) - thpr - * 11/10/06 - */ - SR = new ArrayList<LevelProperty<String>>(); - } - return SR; - } - - /* - * FINALPCCLASSONLY This is for editing classes - */ - public LevelProperty<String> getSRforLevel(int aLevel) - { - if (SR != null) - { - for (LevelProperty<String> lp : SR) - { - if (lp.getLevel() == aLevel) - { - return lp; - } - } - } - return null; - } - - @Override public String getPCCText() { final StringBuffer pccTxt = new StringBuffer(200); @@ -2195,15 +2079,6 @@ .unparse(me.getValue()), "\t")); } - if (SR != null) - { - for (LevelProperty<String> lp : SR) - { - pccTxt.append(lineSep).append(lp.getLevel()).append("\tSR:") - .append(lp.getObject()); - } - } - // Output the list of spells associated with the class. int cap = getSpellSupport().getMaxSpellListLevel(); if (hasMaxLevel() && cap > getSafe(IntegerKey.LEVEL_LIMIT)) @@ -4947,11 +4822,6 @@ addAllToListFor(ListKey.DAMAGE_REDUCTION, otherClass .getListFor(ListKey.DAMAGE_REDUCTION)); - if (otherClass.SR != null) - { - SR = new ArrayList<LevelProperty<String>>(otherClass.SR); - } - for (CDOMReference<Vision> ref : otherClass .getSafeListMods(Vision.VISIONLIST)) { Modified: Trunk/pcgen/code/src/java/pcgen/core/PObject.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2008-09-28 18:34:01 UTC (rev 7827) +++ Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2008-09-28 20:15:01 UTC (rev 7828) @@ -735,32 +735,6 @@ } /** - * Set the SR - * @param newSR - */ - public void setSR(int aLevel, String newSR) - { - put(StringKey.SR_FORMULA, newSR); - } - - /** - * Clear the SR - */ - public void clearSRList() - { - remove(StringKey.SR_FORMULA); - } - - /** - * Get the SR Formula - * @return the SR Formula - */ - public String getSRFormula() - { - return get(StringKey.SR_FORMULA); - } - - /** * Set the source file for this object * @param sourceFile */ @@ -1631,19 +1605,6 @@ return displayName; } - public int getSR(final PlayerCharacter aPC) - { - final String srFormula = getSRFormula(); - - //if there's a current PC, go ahead and evaluate the formula - if ((srFormula != null) && (aPC != null)) - { - return aPC.getVariableValue(srFormula, getQualifiedKey()).intValue(); - } - - return 0; - } - /** * Get the PCC text with the saved name * @return the PCC text with the saved name @@ -1761,12 +1722,6 @@ } } - String SR = get(StringKey.SR_FORMULA); - if (!(this instanceof PCClass) && (SR != null) && (SR.length() != 0)) - { - txt.append("\tSR:").append(SR); - } - if (getMyTypeCount() != 0) { txt.append('\t').append(Constants.s_TAG_TYPE).append(getType()); Modified: Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2008-09-28 18:34:01 UTC (rev 7827) +++ Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2008-09-28 20:15:01 UTC (rev 7828) @@ -8890,39 +8890,40 @@ public int calcSR(final boolean includeEquipment) { - int SR = race.getSR(this); + int SR = race.getSafe(ObjectKey.SR).getReduction().resolve(this, race.getQualifiedKey()).intValue(); if (deity != null) { - SR = Math.max(SR, deity.getSR(this)); + SR = Math.max(SR, deity.getSafe(ObjectKey.SR).getReduction().resolve(this, deity.getQualifiedKey()).intValue()); } for (CompanionMod cMod : companionModList) { - SR = Math.max(SR, cMod.getSR(this)); + SR = Math.max(SR, cMod.getSafe(ObjectKey.SR).getReduction().resolve(this, cMod.getQualifiedKey()).intValue()); } for (PCClass pcClass : classList) { - SR = Math.max(SR, pcClass.getSR(this)); + SR = Math.max(SR, pcClass.getSafe(ObjectKey.SR).getReduction().resolve(this, pcClass.getQualifiedKey()).intValue()); } for (Ability aFeat : getFullAbilitySet()) { - SR = Math.max(SR, aFeat.getSR(this)); + SR = Math.max(SR, aFeat.getSafe(ObjectKey.SR).getReduction().resolve(this, aFeat.getQualifiedKey()).intValue()); } final List<Skill> skillList = new ArrayList<Skill>(getSkillList()); for (Skill skill : skillList) { - SR = Math.max(SR, skill.getSR(this)); + SR = Math.max(SR, skill.getSafe(ObjectKey.SR).getReduction().resolve(this, skill.getQualifiedKey()).intValue()); } for (CharacterDomain cd : characterDomainList) { if (cd.getDomain() != null) { - SR = Math.max(cd.getDomain().getSR(this), SR); + Domain r = cd.getDomain(); + SR = Math.max(r.getSafe(ObjectKey.SR).getReduction().resolve(this, r.getQualifiedKey()).intValue(), SR); } } @@ -8932,7 +8933,7 @@ { if (eq.isEquipped()) { - SR = Math.max(SR, eq.getSR(this)); + SR = Math.max(SR, eq.getSafe(ObjectKey.SR).getReduction().resolve(this, eq.getQualifiedKey()).intValue()); for (EquipmentModifier eqMod : eq.getEqModifierList(true)) { Modified: Trunk/pcgen/code/src/java/pcgen/core/analysis/TemplateSR.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/analysis/TemplateSR.java 2008-09-28 18:34:01 UTC (rev 7827) +++ Trunk/pcgen/code/src/java/pcgen/core/analysis/TemplateSR.java 2008-09-28 20:15:01 UTC (rev 7828) @@ -2,6 +2,7 @@ import pcgen.cdom.enumeration.IntegerKey; import pcgen.cdom.enumeration.ListKey; +import pcgen.cdom.enumeration.ObjectKey; import pcgen.core.PCTemplate; import pcgen.core.PlayerCharacter; @@ -29,7 +30,9 @@ public static int getSR(PCTemplate pct, int level, int hitdice, PlayerCharacter aPC) { - int aSR = pct.getSR(aPC); + String qualifiedKey = pct.getQualifiedKey(); + int aSR = pct.getSafe(ObjectKey.SR).getReduction().resolve(aPC, + qualifiedKey).intValue(); for (PCTemplate rlt : pct.getSafeListFor(ListKey.REPEATLEVEL_TEMPLATES)) { @@ -37,7 +40,8 @@ { if (lt.get(IntegerKey.LEVEL) <= level) { - aSR = Math.max(aSR, lt.getSR(aPC)); + aSR = Math.max(aSR, lt.getSafe(ObjectKey.SR).getReduction() + .resolve(aPC, qualifiedKey).intValue()); } } } @@ -46,7 +50,8 @@ { if (lt.get(IntegerKey.LEVEL) <= level) { - aSR = Math.max(aSR, lt.getSR(aPC)); + aSR = Math.max(aSR, lt.getSafe(ObjectKey.SR).getReduction() + .resolve(aPC, qualifiedKey).intValue()); } } @@ -55,7 +60,8 @@ if (lt.get(IntegerKey.HD_MAX) <= hitdice && lt.get(IntegerKey.HD_MIN) >= hitdice) { - aSR = Math.max(aSR, lt.getSR(aPC)); + aSR = Math.max(aSR, lt.getSafe(ObjectKey.SR).getReduction() + .resolve(aPC, qualifiedKey).intValue()); } } Modified: Trunk/pcgen/code/src/java/pcgen/gui/editor/ClassLevelPanel.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/editor/ClassLevelPanel.java 2008-09-28 18:34:01 UTC (rev 7827) +++ Trunk/pcgen/code/src/java/pcgen/gui/editor/ClassLevelPanel.java 2008-09-28 20:15:01 UTC (rev 7828) @@ -53,8 +53,10 @@ import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.Constants; import pcgen.cdom.base.TransitionChoice; +import pcgen.cdom.content.SpellResistance; import pcgen.cdom.enumeration.IntegerKey; import pcgen.cdom.enumeration.ListKey; +import pcgen.cdom.enumeration.ObjectKey; import pcgen.cdom.enumeration.VariableKey; import pcgen.cdom.inst.PCClassLevel; import pcgen.core.Campaign; @@ -64,7 +66,6 @@ import pcgen.core.Domain; import pcgen.core.Globals; import pcgen.core.Kit; -import pcgen.core.LevelProperty; import pcgen.core.PCClass; import pcgen.core.PCSpell; import pcgen.core.PObject; @@ -309,12 +310,6 @@ } } - - for (LevelProperty<String> lp : obj.getSRlist()) - { - levelTagList.add(new LevelTag(lp.getLevel(), LevelTag.TAG_SR, lp.getObject())); - } - /* aCol = obj.vFeatList(); if (aCol != null) @@ -340,18 +335,25 @@ for (PCClassLevel pcl : obj.getClassLevelCollection()) { + Integer cl = pcl.get(IntegerKey.LEVEL); for (Iterator<TransitionChoice<Kit>> it = obj.getSafeListFor( ListKey.KIT_CHOICE).iterator(); it.hasNext();) { TransitionChoice<Kit> s = it.next(); - LevelTag lt = new LevelTag(pcl.get(IntegerKey.LEVEL), + LevelTag lt = new LevelTag(cl, LevelTag.TAG_KIT, s.getCount() + "|" + s.getChoices().getLSTformat()); levelTagList.add(lt); } + + SpellResistance sr = obj.get(ObjectKey.SR); + if (sr != null) + { + levelTagList.add(new LevelTag(cl, LevelTag.TAG_SR, sr + .getLSTformat())); + } } - String s = obj.getRegionString(); if ((s != null) && !s.equals("")) Modified: Trunk/pcgen/code/src/java/pcgen/gui/editor/EditorMainForm.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/editor/EditorMainForm.java 2008-09-28 18:34:01 UTC (rev 7827) +++ Trunk/pcgen/code/src/java/pcgen/gui/editor/EditorMainForm.java 2008-09-28 20:15:01 UTC (rev 7828) @@ -55,6 +55,7 @@ import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.Constants; import pcgen.cdom.base.SimpleAssociatedObject; +import pcgen.cdom.content.SpellResistance; import pcgen.cdom.enumeration.AssociationKey; import pcgen.cdom.enumeration.IntegerKey; import pcgen.cdom.enumeration.ListKey; @@ -620,7 +621,7 @@ thisPObject.removeListFor(ListKey.DAMAGE_REDUCTION); thisPObject.clearPrerequisiteList(); thisPObject.clearAllSABLists(); - thisPObject.clearSRList(); + thisPObject.remove(ObjectKey.SR); thisPObject.getSpellSupport().clearSpellList(); thisPObject.clearAutoMap(); @@ -3134,11 +3135,11 @@ } } - String srString = thisPObject.getSRFormula(); + SpellResistance sr = thisPObject.get(ObjectKey.SR); - if (srString != null) + if (sr != null) { - selectedList.add("SR:" + srString); + selectedList.add("SR:" + sr.getLSTformat()); } if (anEditType != EditorConstants.EDIT_DOMAIN) Modified: Trunk/pcgen/code/src/java/pcgen/rules/context/ConsolidatedObjectCommitStrategy.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/rules/context/ConsolidatedObjectCommitStrategy.java 2008-09-28 18:34:01 UTC (rev 7827) +++ Trunk/pcgen/code/src/java/pcgen/rules/context/ConsolidatedObjectCommitStrategy.java 2008-09-28 20:15:01 UTC (rev 7828) @@ -117,6 +117,11 @@ cdo.put(sk, s); } + public void remove(CDOMObject cdo, ObjectKey<?> sk) + { + cdo.remove(sk); + } + public void put(CDOMObject cdo, IntegerKey ik, Integer i) { cdo.put(ik, i); Modified: Trunk/pcgen/code/src/java/pcgen/rules/context/ObjectCommitStrategy.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/rules/context/ObjectCommitStrategy.java 2008-09-28 18:34:01 UTC (rev 7827) +++ Trunk/pcgen/code/src/java/pcgen/rules/context/ObjectCommitStrategy.java 2008-09-28 20:15:01 UTC (rev 7828) @@ -39,6 +39,8 @@ public <T> void put(CDOMObject cdo, ObjectKey<T> sk, T s); + public void remove(CDOMObject cdo, ObjectKey<?> sk); + public void put(CDOMObject cdo, IntegerKey ik, Integer i); public void put(CDOMObject cdo, FormulaKey fk, Formula f); Modified: Trunk/pcgen/code/src/java/pcgen/rules/context/ObjectContext.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/rules/context/ObjectContext.java 2008-09-28 18:34:01 UTC (rev 7827) +++ Trunk/pcgen/code/src/java/pcgen/rules/context/ObjectContext.java 2008-09-28 20:15:01 UTC (rev 7828) @@ -110,6 +110,11 @@ edits.put(cdo, sk, s); } + public void remove(CDOMObject cdo, ObjectKey<?> sk) + { + edits.remove(cdo, sk); + } + public void put(CDOMObject cdo, StringKey sk, String s) { edits.put(cdo, sk, s); @@ -430,6 +435,11 @@ getPositive(sourceURI, cdo).put(sk, s); } + public void remove(CDOMObject cdo, ObjectKey<?> sk) + { + getPositive(sourceURI, cdo).remove(sk); + } + public void put(CDOMObject cdo, IntegerKey ik, Integer i) { getPositive(sourceURI, cdo).put(ik, i); @@ -498,6 +508,9 @@ } else { + /* + * TODO is this correct (order of ops?)? + */ return null; } } Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/SrLst.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/lsttokens/SrLst.java 2008-09-28 18:34:01 UTC (rev 7827) +++ Trunk/pcgen/code/src/java/plugin/lsttokens/SrLst.java 2008-09-28 20:15:01 UTC (rev 7828) @@ -4,42 +4,61 @@ */ package plugin.lsttokens; -import pcgen.core.PObject; -import pcgen.persistence.lst.GlobalLstToken; +import pcgen.cdom.base.CDOMObject; +import pcgen.cdom.base.FormulaFactory; +import pcgen.cdom.content.SpellResistance; +import pcgen.cdom.enumeration.ObjectKey; +import pcgen.rules.context.LoadContext; +import pcgen.rules.persistence.token.CDOMPrimaryToken; /** * @author djones4 - * + * */ -public class SrLst implements GlobalLstToken +public class SrLst implements CDOMPrimaryToken<CDOMObject> { - /* - * FIXME This can only be converted after associations are no longer stored - * in the object, but instead are stored in the PC. This is due to the - * %CHOICE usage in EquipmentModifier not being handled by JEP due to use of % - * [which is the modulo function to JEP] - */ - /* - * Note: Don't need to wait for Template's LevelToken before this can be converted - * as there is no level support in templates for this token - */ - public String getTokenName() { return "SR"; } - public boolean parse(PObject obj, String value, int anInt) + public boolean parse(LoadContext context, CDOMObject obj, String value) { if (".CLEAR".equals(value)) { - obj.clearSRList(); + context.getObjectContext().remove(obj, ObjectKey.SR); } else { - obj.setSR(anInt, value); + context.getObjectContext().put(obj, ObjectKey.SR, + getSpellResistance(value)); } return true; } + + private SpellResistance getSpellResistance(String value) + { + return new SpellResistance(FormulaFactory.getFormulaFor(value)); + } + + public String[] unparse(LoadContext context, CDOMObject obj) + { + SpellResistance sr = context.getObjectContext().getObject(obj, + ObjectKey.SR); + /* + * TODO This can't unparse .CLEAR + */ + if (sr == null) + { + // Zero indicates no Token (so nothing to do) + return null; + } + return new String[] { sr.getLSTformat() }; + } + + public Class<CDOMObject> getTokenClass() + { + return CDOMObject.class; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |