|
From: <th...@us...> - 2014-04-05 20:24:20
|
Revision: 23595
http://sourceforge.net/p/pcgen/code/23595
Author: thpr
Date: 2014-04-05 20:24:13 +0000 (Sat, 05 Apr 2014)
Log Message:
-----------
Fix: Update Spell Memory Usage
Issue#: CODE-2501
Modified Paths:
--------------
Trunk/pcgen/code/src/itest/tokencontent/GlobalSpellKnownTest.java
Trunk/pcgen/code/src/itest/tokencontent/SpellClassesTest.java
Trunk/pcgen/code/src/java/applicationContext.xml
Trunk/pcgen/code/src/java/pcgen/cdom/facet/AvailableSpellFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/AvailableSpellInputFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/ClassSpellListFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyAvailableSpellFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyGrantedAvailableSpellFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyGrantedKnownSpellFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyKnownSpellFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/DomainSpellListFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/FacetInitialization.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/KnownSpellFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/KnownSpellInputFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/base/AbstractSubScopeFacet.java
Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java
Trunk/pcgen/code/src/test/pcgen/core/PCClassTest.java
Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterSpellTest.java
Trunk/pcgen/code/src/test/pcgen/core/analysis/SpellLevelTest.java
Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java
Trunk/pcgen/code/src/test/pcgen/core/prereq/PreMultTest.java
Trunk/pcgen/code/src/test/pcgen/core/prereq/PreSpellDescriptorTest.java
Trunk/pcgen/code/src/test/pcgen/core/prereq/PreSpellSchoolTest.java
Trunk/pcgen/code/src/test/pcgen/core/prereq/PreSpellSubSchoolTest.java
Trunk/pcgen/code/src/test/pcgen/io/exporttoken/SpellMemTokenTest.java
Trunk/pcgen/code/testsuite/csheets/35e_test_Jango.xml
Trunk/pcgen/code/testsuite/csheets/35e_test_Lauren.xml
Trunk/pcgen/code/testsuite/csheets/35e_test_Mallory.xml
Trunk/pcgen/code/testsuite/csheets/BarJack.xml
Trunk/pcgen/code/testsuite/csheets/Bob.xml
Trunk/pcgen/code/testsuite/csheets/BrdJoe.xml
Trunk/pcgen/code/testsuite/csheets/CleElf.xml
Trunk/pcgen/code/testsuite/csheets/CloudGiantHalfDragon.xml
Trunk/pcgen/code/testsuite/csheets/Ivan.xml
Trunk/pcgen/code/testsuite/csheets/PFRPGCleric.xml
Trunk/pcgen/code/testsuite/csheets/PFRPGPaladin.xml
Trunk/pcgen/code/testsuite/csheets/Quasvin.xml
Trunk/pcgen/code/testsuite/csheets/SWizSam.xml
Trunk/pcgen/code/testsuite/csheets/WizShar.xml
Trunk/pcgen/code/testsuite/csheets/pf_goldielocks.xml
Added Paths:
-----------
Trunk/pcgen/code/src/java/pcgen/cdom/facet/MasterAvailableSpellFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/SpellListToAvailableSpellFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/helper/AvailableSpell.java
Removed Paths:
-------------
Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionalMasterAvailableSpellFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyGrantedMasterAvailableSpellFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/MasterAvailableSpellInitializationFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/base/AbstractConditionalSpellFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/base/AbstractConditionalSpellStorageFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/base/AbstractSpellInputFacet.java
Trunk/pcgen/code/src/java/pcgen/cdom/facet/base/AbstractSpellStorageFacet.java
Modified: Trunk/pcgen/code/src/itest/tokencontent/GlobalSpellKnownTest.java
===================================================================
--- Trunk/pcgen/code/src/itest/tokencontent/GlobalSpellKnownTest.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/itest/tokencontent/GlobalSpellKnownTest.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -18,7 +18,6 @@
package tokencontent;
import java.util.Collection;
-import java.util.Map;
import pcgen.cdom.base.CDOMObject;
import pcgen.cdom.base.FormulaFactory;
@@ -95,14 +94,19 @@
protected boolean containsExpected()
{
//Cannot use contains because facet is using instance identity
- Map<Integer, Collection<Spell>> levelMap = knownSpellFacet.getKnownSpells(id, wizardSpellList);
- int size = levelMap.size();
+ Collection<Integer> levels = knownSpellFacet.getScopes2(id, wizardSpellList);
+ int size = levels.size();
if (size != 1)
{
System.err.println("Size Incorrect");
return false;
}
- Collection<Spell> spells = levelMap.get(2);
+ if (!levels.contains(2))
+ {
+ System.err.println("Level Incorrect");
+ return false;
+ }
+ Collection<Spell> spells = knownSpellFacet.getSet(id, wizardSpellList, 2);
if (spells.size() != 1)
{
System.err.println("Spell Size Incorrect");
@@ -114,12 +118,7 @@
@Override
protected int targetFacetCount()
{
- Map<Integer, Collection<Spell>> levelMap = knownSpellFacet.getKnownSpells(id, wizardSpellList);
- if (levelMap.isEmpty())
- {
- return 0;
- }
- Collection<Spell> spells = levelMap.get(2);
+ Collection<Spell> spells = knownSpellFacet.getSet(id, wizardSpellList, 2);
return (spells == null) ? 0 : spells.size();
}
Modified: Trunk/pcgen/code/src/itest/tokencontent/SpellClassesTest.java
===================================================================
--- Trunk/pcgen/code/src/itest/tokencontent/SpellClassesTest.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/itest/tokencontent/SpellClassesTest.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -26,6 +26,7 @@
import pcgen.cdom.enumeration.Type;
import pcgen.cdom.facet.AvailableSpellFacet;
import pcgen.cdom.facet.FacetLibrary;
+import pcgen.cdom.facet.SpellListFacet;
import pcgen.core.PCClass;
import pcgen.core.spell.Spell;
import pcgen.gui2.facade.MockUIDelegate;
@@ -67,6 +68,8 @@
finishLoad();
classFacet.addClass(id, dragon);
classFacet.setLevel(id, dragon, 1);
+ //Right now this is done in PCClass
+ FacetLibrary.getFacet(SpellListFacet.class).add(id, dragon.get(ObjectKey.CLASS_SPELLLIST), dragon);
pc.setDirty(true);
HashMapToList<CDOMList<Spell>, Integer> map = availableSpellFacet.getSpellLevelInfo(id, sp);
assertTrue(map.containsListFor(dragon.get(ObjectKey.CLASS_SPELLLIST)));
Modified: Trunk/pcgen/code/src/java/applicationContext.xml
===================================================================
--- Trunk/pcgen/code/src/java/applicationContext.xml 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/applicationContext.xml 2014-04-05 20:24:13 UTC (rev 23595)
@@ -188,9 +188,7 @@
<bean id="conditionalAbilityFacet" class="pcgen.cdom.facet.ConditionalAbilityFacet">
<property name="prerequisiteFacet" ref="prerequisiteFacet"/>
</bean>
- <bean id="conditionallyAvailableSpellFacet" class="pcgen.cdom.facet.ConditionallyAvailableSpellFacet">
- <property name="prerequisiteFacet" ref="prerequisiteFacet"/>
- </bean>
+ <bean id="conditionallyAvailableSpellFacet" class="pcgen.cdom.facet.ConditionallyAvailableSpellFacet"/>
<bean id="conditionallyGrantedAbilityFacet" class="pcgen.cdom.facet.ConditionallyGrantedAbilityFacet">
<property name="conditionalAbilityFacet" ref="conditionalAbilityFacet"/>
</bean>
@@ -202,16 +200,7 @@
<property name="conditionallyKnownSpellFacet" ref="conditionallyKnownSpellFacet"/>
<property name="knownSpellFacet" ref="knownSpellFacet"/>
</bean>
- <bean id="conditionallyGrantedMasterAvailableSpellFacet" class="pcgen.cdom.facet.ConditionallyGrantedMasterAvailableSpellFacet">
- <property name="conditionalMasterAvailableSpellFacet" ref="conditionalMasterAvailableSpellFacet"/>
- <property name="availableSpellFacet" ref="availableSpellFacet"/>
- </bean>
- <bean id="conditionallyKnownSpellFacet" class="pcgen.cdom.facet.ConditionallyKnownSpellFacet">
- <property name="prerequisiteFacet" ref="prerequisiteFacet"/>
- </bean>
- <bean id="conditionalMasterAvailableSpellFacet" class="pcgen.cdom.facet.ConditionalMasterAvailableSpellFacet">
- <property name="prerequisiteFacet" ref="prerequisiteFacet"/>
- </bean>
+ <bean id="conditionallyKnownSpellFacet" class="pcgen.cdom.facet.ConditionallyKnownSpellFacet"/>
<bean id="conditionalTemplateFacet" class="pcgen.cdom.facet.ConditionalTemplateFacet">
<property name="templateFacet" ref="templateFacet"/>
<property name="levelFacet" ref="levelFacet"/>
@@ -380,9 +369,8 @@
<property name="classLevelFacet" ref="classLevelFacet"/>
</bean>
<!-- M -->
- <bean id="masterAvailableSpellInitializationFacet" class="pcgen.cdom.facet.MasterAvailableSpellInitializationFacet">
- <property name="availableSpellFacet" ref="availableSpellFacet"/>
- <property name="conditionalMasterAvailableSpellFacet" ref="conditionalMasterAvailableSpellFacet"/>
+ <bean id="masterAvailableSpellFacet" class="pcgen.cdom.facet.MasterAvailableSpellFacet">
+ <property name="dataSetInitializationFacet" ref="dataSetInitializationFacet"/>
</bean>
<bean id="masterFacet" class="pcgen.cdom.facet.MasterFacet">
<property name="companionModFacet" ref="companionModFacet"/>
@@ -549,6 +537,12 @@
<property name="equipmentFacet" ref="equipmentFacet"/>
</bean>
<bean id="spellListFacet" class="pcgen.cdom.facet.SpellListFacet"/>
+ <bean id="spellListToAvailableSpellFacet" class="pcgen.cdom.facet.SpellListToAvailableSpellFacet">
+ <property name="masterAvailableSpellFacet" ref="masterAvailableSpellFacet"/>
+ <property name="spellListFacet" ref="spellListFacet"/>
+ <property name="conditionallyAvailableSpellFacet" ref="conditionallyAvailableSpellFacet"/>
+ <property name="availableSpellFacet" ref="availableSpellFacet"/>
+ </bean>
<bean id="spellProhibitorFacet" class="pcgen.cdom.facet.SpellProhibitorFacet">
<property name="classFacet" ref="classFacet"/>
</bean>
Modified: Trunk/pcgen/code/src/java/pcgen/cdom/facet/AvailableSpellFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/AvailableSpellFacet.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/AvailableSpellFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -24,8 +24,7 @@
import pcgen.base.util.HashMapToList;
import pcgen.cdom.base.CDOMList;
import pcgen.cdom.enumeration.CharID;
-import pcgen.cdom.facet.base.AbstractSpellStorageFacet;
-import pcgen.cdom.facet.base.AbstractSpellStorageFacet.SpellChangeListener;
+import pcgen.cdom.facet.base.AbstractSubScopeFacet;
import pcgen.cdom.list.ClassSpellList;
import pcgen.cdom.list.DomainSpellList;
import pcgen.core.spell.Spell;
@@ -36,8 +35,8 @@
*
* @author Thomas Parker (thpr [at] yahoo.com)
*/
-public class AvailableSpellFacet extends AbstractSpellStorageFacet implements
- SpellChangeListener
+public class AvailableSpellFacet extends
+ AbstractSubScopeFacet<CDOMList<Spell>, Integer, Spell>
{
/**
@@ -77,7 +76,7 @@
HashMapToList<CDOMList<Spell>, Integer> levelInfo =
new HashMapToList<CDOMList<Spell>, Integer>();
Map<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>> listMap =
- getCachedMap(id);
+ (Map<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>>) getCache(id);
if (listMap == null)
{
return levelInfo;
@@ -106,19 +105,4 @@
}
return levelInfo;
}
-
- @Override
- public void spellAdded(SpellChangeEvent sce)
- {
- add(sce.getCharID(), sce.getSpellList(), sce.getLevel(),
- sce.getSpell(), sce.getSource());
- }
-
- @Override
- public void spellRemoved(SpellChangeEvent sce)
- {
- remove(sce.getCharID(), sce.getSpellList(), sce.getLevel(),
- sce.getSpell(), sce.getSource());
- }
-
}
Modified: Trunk/pcgen/code/src/java/pcgen/cdom/facet/AvailableSpellInputFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/AvailableSpellInputFacet.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/AvailableSpellInputFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -17,41 +17,149 @@
*/
package pcgen.cdom.facet;
+import java.util.Collection;
+import java.util.List;
+
import pcgen.cdom.base.AssociatedPrereqObject;
-import pcgen.cdom.facet.base.AbstractConditionalSpellFacet;
-import pcgen.cdom.facet.base.AbstractSpellInputFacet;
-import pcgen.cdom.facet.base.AbstractSpellStorageFacet;
+import pcgen.cdom.base.CDOMList;
+import pcgen.cdom.base.CDOMObject;
+import pcgen.cdom.base.CDOMReference;
+import pcgen.cdom.base.PrereqObject;
+import pcgen.cdom.enumeration.AssociationKey;
+import pcgen.cdom.enumeration.CharID;
+import pcgen.cdom.facet.event.DataFacetChangeEvent;
+import pcgen.cdom.facet.event.DataFacetChangeListener;
+import pcgen.cdom.helper.AvailableSpell;
+import pcgen.cdom.list.ClassSpellList;
+import pcgen.cdom.list.DomainSpellList;
+import pcgen.core.prereq.Prerequisite;
+import pcgen.core.spell.Spell;
-public class AvailableSpellInputFacet extends AbstractSpellInputFacet
+public class AvailableSpellInputFacet implements
+ DataFacetChangeListener<CharID, CDOMObject>
{
private ConditionallyAvailableSpellFacet conditionallyAvailableSpellFacet;
private AvailableSpellFacet availableSpellFacet;
+ private CDOMObjectConsolidationFacet consolidationFacet;
+
+ /**
+ * Triggered when one of the Facets to which ConditionallyKnownSpellFacet
+ * listens fires a DataFacetChangeEvent to indicate a CDOMObject was added
+ * to a Player Character.
+ *
+ * @param dfce
+ * The DataFacetChangeEvent containing the information about the
+ * change
+ *
+ * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
+ */
@Override
- protected AbstractConditionalSpellFacet getConditionalFacet()
+ public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce)
{
- return conditionallyAvailableSpellFacet;
+ CDOMObject cdo = dfce.getCDOMObject();
+ Collection<CDOMReference<? extends CDOMList<? extends PrereqObject>>> listrefs =
+ cdo.getModifiedLists();
+ CharID id = dfce.getCharID();
+ for (CDOMReference<? extends CDOMList<? extends PrereqObject>> ref : listrefs)
+ {
+ processListRef(id, cdo, ref);
+ }
}
- @Override
- protected boolean meetsAddConditions(AssociatedPrereqObject apo)
+ private void processListRef(CharID id, CDOMObject cdo,
+ CDOMReference<? extends CDOMList<? extends PrereqObject>> listref)
{
- return true;
+ for (CDOMList<? extends PrereqObject> list : listref
+ .getContainedObjects())
+ {
+ if (!(list instanceof ClassSpellList)
+ && !(list instanceof DomainSpellList))
+ {
+ continue;
+ }
+ CDOMList<Spell> spelllist = (CDOMList<Spell>) list;
+ processList(id, spelllist, listref, cdo);
+ }
}
+ private void processList(CharID id, CDOMList<Spell> spelllist,
+ CDOMReference<? extends CDOMList<? extends PrereqObject>> listref,
+ CDOMObject cdo)
+ {
+ for (CDOMReference<Spell> objref : cdo
+ .getListMods((CDOMReference<? extends CDOMList<Spell>>) listref))
+ {
+ for (AssociatedPrereqObject apo : cdo.getListAssociations(listref,
+ objref))
+ {
+ Collection<Spell> spells = objref.getContainedObjects();
+ Integer lvl = apo.getAssociation(AssociationKey.SPELL_LEVEL);
+ if (apo.hasPrerequisites())
+ {
+ List<Prerequisite> prereqs = apo.getPrerequisiteList();
+ for (Spell spell : spells)
+ {
+ AvailableSpell as =
+ new AvailableSpell(spelllist, spell, lvl);
+ as.addAllPrerequisites(prereqs);
+ conditionallyAvailableSpellFacet.add(id, as, cdo);
+ }
+ }
+ else
+ {
+ for (Spell spell : spells)
+ {
+ availableSpellFacet.add(id, spelllist, lvl, spell, cdo);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Triggered when one of the Facets to which ConditionallyKnownSpellFacet
+ * listens fires a DataFacetChangeEvent to indicate a CDOMObject was removed
+ * from a Player Character.
+ *
+ * @param dfce
+ * The DataFacetChangeEvent containing the information about the
+ * change
+ *
+ * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataRemoved(pcgen.cdom.facet.event.DataFacetChangeEvent)
+ */
@Override
- protected AbstractSpellStorageFacet getUnconditionalFacet()
+ public void dataRemoved(DataFacetChangeEvent<CharID, CDOMObject> dfce)
{
- return availableSpellFacet;
+ CharID id = dfce.getCharID();
+ CDOMObject source = dfce.getCDOMObject();
+ conditionallyAvailableSpellFacet.removeAll(id, source);
+ availableSpellFacet.removeAllFromSource(id, source);
}
+ /**
+ * Initializes the connections for KnwonSpellFacet to other facets.
+ *
+ * This method is automatically called by the Spring framework during
+ * initialization of the KnwonSpellFacet.
+ */
+ public void init()
+ {
+ consolidationFacet.addDataFacetChangeListener(this);
+ }
+
+ public void setConsolidationFacet(
+ CDOMObjectConsolidationFacet consolidationFacet)
+ {
+ this.consolidationFacet = consolidationFacet;
+ }
+
public void setConditionallyAvailableSpellFacet(
ConditionallyAvailableSpellFacet conditionallyAvailableSpellFacet)
{
- this.conditionallyAvailableSpellFacet =
- conditionallyAvailableSpellFacet;
+ this.conditionallyAvailableSpellFacet = conditionallyAvailableSpellFacet;
}
public void setAvailableSpellFacet(AvailableSpellFacet availableSpellFacet)
Modified: Trunk/pcgen/code/src/java/pcgen/cdom/facet/ClassSpellListFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/ClassSpellListFacet.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/ClassSpellListFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -17,12 +17,10 @@
*/
package pcgen.cdom.facet;
-import pcgen.cdom.base.CDOMList;
import pcgen.cdom.base.CDOMListObject;
import pcgen.cdom.base.TransitionChoice;
import pcgen.cdom.enumeration.CharID;
import pcgen.cdom.enumeration.ObjectKey;
-import pcgen.cdom.facet.base.AbstractSourcedListFacet;
import pcgen.core.PCClass;
import pcgen.core.PlayerCharacter;
import pcgen.core.spell.Spell;
@@ -34,8 +32,7 @@
*
* @author Thomas Parker (thpr [at] yahoo.com)
*/
-public class ClassSpellListFacet extends
- AbstractSourcedListFacet<CharID, CDOMList<Spell>>
+public class ClassSpellListFacet
{
private final PlayerCharacterTrackingFacet trackingFacet = FacetLibrary
.getFacet(PlayerCharacterTrackingFacet.class);
Deleted: Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionalMasterAvailableSpellFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionalMasterAvailableSpellFacet.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionalMasterAvailableSpellFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2012 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 pcgen.cdom.facet;
-
-import pcgen.cdom.facet.base.AbstractConditionalSpellFacet;
-
-/**
- * The Class <code>ConditionalMasterSpellAvailableFacet</code> tracks
- * conditional available spells from the master lists (CLASSES or DOMAINS in the
- * Spell LST file)
- *
- * @author Tom Parker <th...@us...>
- */
-public class ConditionalMasterAvailableSpellFacet extends
- AbstractConditionalSpellFacet
-{
-}
Modified: Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyAvailableSpellFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyAvailableSpellFacet.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyAvailableSpellFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -1,5 +1,5 @@
/*
- * Copyright (c) Thomas Parker, 2012.
+ * Copyright (c) Thomas Parker, 2014.
*
* 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
@@ -17,15 +17,11 @@
*/
package pcgen.cdom.facet;
-import pcgen.cdom.facet.base.AbstractConditionalSpellFacet;
+import pcgen.cdom.facet.base.AbstractQualifiedListFacet;
+import pcgen.cdom.helper.AvailableSpell;
-/**
- * ConditionallyAvailableSpellFacet is a Facet that tracks the Available Spells
- * (and target objects) that are contained in a Player Character.
- *
- * @author Thomas Parker (thpr [at] yahoo.com)
- */
public class ConditionallyAvailableSpellFacet extends
- AbstractConditionalSpellFacet
+ AbstractQualifiedListFacet<AvailableSpell>
{
+
}
Modified: Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyGrantedAvailableSpellFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyGrantedAvailableSpellFacet.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyGrantedAvailableSpellFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -1,36 +1,30 @@
-/*
- * Copyright (c) Thomas Parker, 2012.
- *
- * 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 pcgen.cdom.facet;
-import pcgen.cdom.facet.base.AbstractConditionalSpellFacet;
-import pcgen.cdom.facet.base.AbstractConditionalSpellStorageFacet;
+import java.util.Collection;
-public class ConditionallyGrantedAvailableSpellFacet extends
- AbstractConditionalSpellStorageFacet
+import pcgen.cdom.enumeration.CharID;
+import pcgen.cdom.helper.AvailableSpell;
+
+public class ConditionallyGrantedAvailableSpellFacet
{
private ConditionallyAvailableSpellFacet conditionallyAvailableSpellFacet;
private AvailableSpellFacet availableSpellFacet;
- @Override
- protected AbstractConditionalSpellFacet getConditionalFacet()
+ public void update(CharID id)
{
- return conditionallyAvailableSpellFacet;
+ Collection<AvailableSpell> set =
+ conditionallyAvailableSpellFacet.getQualifiedSet(id);
+ for (AvailableSpell as : set)
+ {
+ Collection<Object> sources =
+ conditionallyAvailableSpellFacet.getSources(id, as);
+ for (Object source : sources)
+ {
+ availableSpellFacet.add(id, as.getSpelllist(), as.getLevel(),
+ as.getSpell(), source);
+ }
+ }
}
public void setConditionallyAvailableSpellFacet(
@@ -45,8 +39,4 @@
this.availableSpellFacet = availableSpellFacet;
}
- public void init()
- {
- addSpellChangeListener(availableSpellFacet);
- }
}
Modified: Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyGrantedKnownSpellFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyGrantedKnownSpellFacet.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyGrantedKnownSpellFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -17,20 +17,31 @@
*/
package pcgen.cdom.facet;
-import pcgen.cdom.facet.base.AbstractConditionalSpellFacet;
-import pcgen.cdom.facet.base.AbstractConditionalSpellStorageFacet;
+import java.util.Collection;
-public class ConditionallyGrantedKnownSpellFacet extends
- AbstractConditionalSpellStorageFacet
+import pcgen.cdom.enumeration.CharID;
+import pcgen.cdom.helper.AvailableSpell;
+
+public class ConditionallyGrantedKnownSpellFacet
{
private ConditionallyKnownSpellFacet conditionallyKnownSpellFacet;
private KnownSpellFacet knownSpellFacet;
- @Override
- protected AbstractConditionalSpellFacet getConditionalFacet()
+ public void update(CharID id)
{
- return conditionallyKnownSpellFacet;
+ Collection<AvailableSpell> set =
+ conditionallyKnownSpellFacet.getQualifiedSet(id);
+ for (AvailableSpell as : set)
+ {
+ Collection<Object> sources =
+ conditionallyKnownSpellFacet.getSources(id, as);
+ for (Object source : sources)
+ {
+ knownSpellFacet.add(id, as.getSpelllist(), as.getLevel(),
+ as.getSpell(), source);
+ }
+ }
}
public void setConditionallyKnownSpellFacet(
@@ -43,9 +54,5 @@
{
this.knownSpellFacet = knownSpellFacet;
}
-
- public void init()
- {
- addSpellChangeListener(knownSpellFacet);
- }
+
}
Deleted: Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyGrantedMasterAvailableSpellFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyGrantedMasterAvailableSpellFacet.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyGrantedMasterAvailableSpellFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2012 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 pcgen.cdom.facet;
-
-import pcgen.cdom.facet.base.AbstractConditionalSpellFacet;
-import pcgen.cdom.facet.base.AbstractConditionalSpellStorageFacet;
-
-/**
- * The Class <code>ConditionalMasterSpellAvailableFacet</code> tracks
- * conditional available spells from the master lists (CLASSES or DOMAINS in the
- * Spell LST file)
- *
- * @author Tom Parker <th...@us...>
- */
-public class ConditionallyGrantedMasterAvailableSpellFacet extends
- AbstractConditionalSpellStorageFacet
-{
- private ConditionalMasterAvailableSpellFacet conditionalMasterAvailableSpellFacet;
-
- private AvailableSpellFacet availableSpellFacet;
-
- @Override
- protected AbstractConditionalSpellFacet getConditionalFacet()
- {
- return conditionalMasterAvailableSpellFacet;
- }
-
- public void setConditionalMasterAvailableSpellFacet(
- ConditionalMasterAvailableSpellFacet conditionalMasterAvailableSpellFacet)
- {
- this.conditionalMasterAvailableSpellFacet =
- conditionalMasterAvailableSpellFacet;
- }
-
- public void setAvailableSpellFacet(AvailableSpellFacet availableSpellFacet)
- {
- this.availableSpellFacet = availableSpellFacet;
- }
-
- public void init()
- {
- addSpellChangeListener(availableSpellFacet);
- }
-}
Modified: Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyKnownSpellFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyKnownSpellFacet.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/ConditionallyKnownSpellFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -17,7 +17,8 @@
*/
package pcgen.cdom.facet;
-import pcgen.cdom.facet.base.AbstractConditionalSpellFacet;
+import pcgen.cdom.facet.base.AbstractQualifiedListFacet;
+import pcgen.cdom.helper.AvailableSpell;
/**
* ConditionallyKnownSpellFacet is a Facet that tracks the Known Spells (and
@@ -25,6 +26,7 @@
*
* @author Thomas Parker (thpr [at] yahoo.com)
*/
-public class ConditionallyKnownSpellFacet extends AbstractConditionalSpellFacet
+public class ConditionallyKnownSpellFacet extends
+ AbstractQualifiedListFacet<AvailableSpell>
{
}
Modified: Trunk/pcgen/code/src/java/pcgen/cdom/facet/DomainSpellListFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/DomainSpellListFacet.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/DomainSpellListFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -17,16 +17,13 @@
*/
package pcgen.cdom.facet;
-import pcgen.cdom.base.CDOMList;
import pcgen.cdom.enumeration.CharID;
import pcgen.cdom.enumeration.ObjectKey;
-import pcgen.cdom.facet.base.AbstractSourcedListFacet;
import pcgen.cdom.facet.event.DataFacetChangeEvent;
import pcgen.cdom.facet.event.DataFacetChangeListener;
import pcgen.cdom.facet.model.DomainFacet;
import pcgen.cdom.list.DomainSpellList;
import pcgen.core.Domain;
-import pcgen.core.spell.Spell;
/**
* DomainSpellListFacet tracks the Domain Spell Lists granted to a Player
@@ -35,8 +32,7 @@
*
* @author Thomas Parker (thpr [at] yahoo.com)
*/
-public class DomainSpellListFacet extends
- AbstractSourcedListFacet<CharID, CDOMList<Spell>> implements
+public class DomainSpellListFacet implements
DataFacetChangeListener<CharID, Domain>
{
Modified: Trunk/pcgen/code/src/java/pcgen/cdom/facet/FacetInitialization.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/FacetInitialization.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/FacetInitialization.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -164,6 +164,7 @@
* Do dataset-level facets
*/
FacetLibrary.getFacet(MasterSkillFacet.class);
+ FacetLibrary.getFacet(MasterAvailableSpellFacet.class);
FacetLibrary.getFacet(MasterUsableSkillFacet.class);
/*
* TODO These are required because they are "bridges" - meaning they
@@ -188,6 +189,7 @@
FacetLibrary.getFacet(AvailableSpellInputFacet.class);
FacetLibrary.getFacet(KnownSpellInputFacet.class);
FacetLibrary.getFacet(ClassSkillListFacet.class);
+ FacetLibrary.getFacet(SpellListToAvailableSpellFacet.class);
//This one is a just in case
FacetLibrary.getFacet(ChangeProfFacet.class);
//and others just in case...
Modified: Trunk/pcgen/code/src/java/pcgen/cdom/facet/KnownSpellFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/KnownSpellFacet.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/KnownSpellFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -17,88 +17,18 @@
*/
package pcgen.cdom.facet;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
import pcgen.cdom.base.CDOMList;
-import pcgen.cdom.enumeration.CharID;
-import pcgen.cdom.facet.base.AbstractSpellStorageFacet;
-import pcgen.cdom.facet.base.AbstractSpellStorageFacet.SpellChangeListener;
+import pcgen.cdom.facet.base.AbstractSubScopeFacet;
import pcgen.core.spell.Spell;
/**
- * KnownSpellFacet is a Facet that tracks the Available Spells (and target
- * objects) that are contained in a Player Character. These are post-resolution
- * of spells for which the PC is qualified.
+ * KnownSpellFacet is a Facet that tracks the Known Spells (and target objects)
+ * that are contained in a Player Character. These are post-resolution of spells
+ * for which the PC is qualified.
*
* @author Thomas Parker (thpr [at] yahoo.com)
*/
-public class KnownSpellFacet extends AbstractSpellStorageFacet implements
- SpellChangeListener
+public class KnownSpellFacet extends
+ AbstractSubScopeFacet<CDOMList<Spell>, Integer, Spell>
{
-
- public int getKnownSpellCountForLevel(CharID id, CDOMList<Spell> spellList,
- int spellLevel)
- {
- Map<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>> map =
- getCachedMap(id);
- if (map == null)
- {
- return 0;
- }
- Map<Integer, Map<Spell, Set<Object>>> levelMap = map.get(spellList);
- if (levelMap == null)
- {
- return 0;
- }
- Map<Spell, Set<Object>> spellMap = levelMap.get(spellLevel);
- if (spellMap == null)
- {
- return 0;
- }
- return spellMap.size();
- }
-
- public Map<Integer, Collection<Spell>> getKnownSpells(CharID id,
- CDOMList<Spell> csl)
- {
- Map<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>> listMap =
- getCachedMap(id);
- if (listMap == null)
- {
- return Collections.emptyMap();
- }
- Map<Integer, Map<Spell, Set<Object>>> spellMap = listMap.get(csl);
- if (spellMap == null)
- {
- return Collections.emptyMap();
- }
- HashMap<Integer, Collection<Spell>> retMap =
- new HashMap<Integer, Collection<Spell>>();
- for (Map.Entry<Integer, Map<Spell, Set<Object>>> entry : spellMap
- .entrySet())
- {
- retMap.put(entry.getKey(), new ArrayList<Spell>(entry.getValue()
- .keySet()));
- }
- return retMap;
- }
-
- @Override
- public void spellAdded(SpellChangeEvent sce)
- {
- add(sce.getCharID(), sce.getSpellList(), sce.getLevel(),
- sce.getSpell(), sce.getSource());
- }
-
- @Override
- public void spellRemoved(SpellChangeEvent sce)
- {
- remove(sce.getCharID(), sce.getSpellList(), sce.getLevel(),
- sce.getSpell(), sce.getSource());
- }
}
Modified: Trunk/pcgen/code/src/java/pcgen/cdom/facet/KnownSpellInputFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/KnownSpellInputFacet.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/KnownSpellInputFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -17,38 +17,150 @@
*/
package pcgen.cdom.facet;
+import java.util.Collection;
+import java.util.List;
+
import pcgen.cdom.base.AssociatedPrereqObject;
+import pcgen.cdom.base.CDOMList;
+import pcgen.cdom.base.CDOMObject;
+import pcgen.cdom.base.CDOMReference;
+import pcgen.cdom.base.PrereqObject;
import pcgen.cdom.enumeration.AssociationKey;
-import pcgen.cdom.facet.base.AbstractConditionalSpellFacet;
-import pcgen.cdom.facet.base.AbstractSpellInputFacet;
-import pcgen.cdom.facet.base.AbstractSpellStorageFacet;
+import pcgen.cdom.enumeration.CharID;
+import pcgen.cdom.facet.event.DataFacetChangeEvent;
+import pcgen.cdom.facet.event.DataFacetChangeListener;
+import pcgen.cdom.helper.AvailableSpell;
+import pcgen.cdom.list.ClassSpellList;
+import pcgen.cdom.list.DomainSpellList;
+import pcgen.core.prereq.Prerequisite;
+import pcgen.core.spell.Spell;
-public class KnownSpellInputFacet extends AbstractSpellInputFacet
+public class KnownSpellInputFacet implements
+ DataFacetChangeListener<CharID, CDOMObject>
{
private ConditionallyKnownSpellFacet conditionallyKnownSpellFacet;
private KnownSpellFacet knownSpellFacet;
+ private CDOMObjectConsolidationFacet consolidationFacet;
+
+ /**
+ * Triggered when one of the Facets to which ConditionallyKnownSpellFacet
+ * listens fires a DataFacetChangeEvent to indicate a CDOMObject was added
+ * to a Player Character.
+ *
+ * @param dfce
+ * The DataFacetChangeEvent containing the information about the
+ * change
+ *
+ * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
+ */
@Override
- protected AbstractConditionalSpellFacet getConditionalFacet()
+ public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce)
{
- return conditionallyKnownSpellFacet;
+ CDOMObject cdo = dfce.getCDOMObject();
+ Collection<CDOMReference<? extends CDOMList<? extends PrereqObject>>> listrefs =
+ cdo.getModifiedLists();
+ CharID id = dfce.getCharID();
+ for (CDOMReference<? extends CDOMList<? extends PrereqObject>> ref : listrefs)
+ {
+ processListRef(id, cdo, ref);
+ }
}
- @Override
- protected boolean meetsAddConditions(AssociatedPrereqObject apo)
+ private void processListRef(CharID id, CDOMObject cdo,
+ CDOMReference<? extends CDOMList<? extends PrereqObject>> listref)
{
- Boolean known = apo.getAssociation(AssociationKey.KNOWN);
- return (known != null) && known;
+ for (CDOMList<? extends PrereqObject> list : listref
+ .getContainedObjects())
+ {
+ if (!(list instanceof ClassSpellList)
+ && !(list instanceof DomainSpellList))
+ {
+ continue;
+ }
+ CDOMList<Spell> spelllist = (CDOMList<Spell>) list;
+ processList(id, spelllist, listref, cdo);
+ }
}
+ private void processList(CharID id, CDOMList<Spell> spelllist,
+ CDOMReference<? extends CDOMList<? extends PrereqObject>> listref,
+ CDOMObject cdo)
+ {
+ for (CDOMReference<Spell> objref : cdo
+ .getListMods((CDOMReference<? extends CDOMList<Spell>>) listref))
+ {
+ for (AssociatedPrereqObject apo : cdo.getListAssociations(listref,
+ objref))
+ {
+ Boolean known = apo.getAssociation(AssociationKey.KNOWN);
+ if ((known == null) || !known)
+ {
+ continue;
+ }
+ Collection<Spell> spells = objref.getContainedObjects();
+ Integer lvl = apo.getAssociation(AssociationKey.SPELL_LEVEL);
+ if (apo.hasPrerequisites())
+ {
+ List<Prerequisite> prereqs = apo.getPrerequisiteList();
+ for (Spell spell : spells)
+ {
+ AvailableSpell as =
+ new AvailableSpell(spelllist, spell, lvl);
+ as.addAllPrerequisites(prereqs);
+ conditionallyKnownSpellFacet.add(id, as, cdo);
+ }
+ }
+ else
+ {
+ for (Spell spell : spells)
+ {
+ knownSpellFacet.add(id, spelllist, lvl, spell, cdo);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Triggered when one of the Facets to which ConditionallyKnownSpellFacet
+ * listens fires a DataFacetChangeEvent to indicate a CDOMObject was removed
+ * from a Player Character.
+ *
+ * @param dfce
+ * The DataFacetChangeEvent containing the information about the
+ * change
+ *
+ * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataRemoved(pcgen.cdom.facet.event.DataFacetChangeEvent)
+ */
@Override
- protected AbstractSpellStorageFacet getUnconditionalFacet()
+ public void dataRemoved(DataFacetChangeEvent<CharID, CDOMObject> dfce)
{
- return knownSpellFacet;
+ CharID id = dfce.getCharID();
+ CDOMObject source = dfce.getCDOMObject();
+ conditionallyKnownSpellFacet.removeAll(id, source);
+ knownSpellFacet.removeAllFromSource(id, source);
}
+ /**
+ * Initializes the connections for KnwonSpellFacet to other facets.
+ *
+ * This method is automatically called by the Spring framework during
+ * initialization of the KnwonSpellFacet.
+ */
+ public void init()
+ {
+ consolidationFacet.addDataFacetChangeListener(this);
+ }
+
+ public void setConsolidationFacet(
+ CDOMObjectConsolidationFacet consolidationFacet)
+ {
+ this.consolidationFacet = consolidationFacet;
+ }
+
public void setConditionallyKnownSpellFacet(
ConditionallyKnownSpellFacet conditionallyKnownSpellFacet)
{
@@ -59,4 +171,5 @@
{
this.knownSpellFacet = knownSpellFacet;
}
+
}
Added: Trunk/pcgen/code/src/java/pcgen/cdom/facet/MasterAvailableSpellFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/MasterAvailableSpellFacet.java (rev 0)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/MasterAvailableSpellFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2014 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 pcgen.cdom.facet;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import pcgen.cdom.base.AssociatedPrereqObject;
+import pcgen.cdom.base.CDOMList;
+import pcgen.cdom.base.CDOMReference;
+import pcgen.cdom.base.DataSetInitializedFacet;
+import pcgen.cdom.base.MasterListInterface;
+import pcgen.cdom.enumeration.AssociationKey;
+import pcgen.cdom.enumeration.DataSetID;
+import pcgen.cdom.facet.base.AbstractSourcedListFacet;
+import pcgen.cdom.helper.AvailableSpell;
+import pcgen.cdom.list.ClassSpellList;
+import pcgen.cdom.list.DomainSpellList;
+import pcgen.core.Globals;
+import pcgen.core.spell.Spell;
+import pcgen.rules.context.LoadContext;
+
+/**
+ * The Class <code>MasterSkillFacet</code> caches a copy of all class skill
+ * lists. This allows faster checking of whether skills are class skills for a
+ * character class. Note this is a "global" facet in that it does not have
+ * method that depend on CharID (they are not character specific).
+ *
+ * @author Tom Parker <th...@us...>
+ */
+public class MasterAvailableSpellFacet extends
+ AbstractSourcedListFacet<DataSetID, AvailableSpell> implements
+ DataSetInitializedFacet
+{
+ private DataSetInitializationFacet datasetInitializationFacet;
+
+ /**
+ * Initializes the global lists of ClassSkillLists. This method only needs
+ * to be called once for each set of sources that are loaded.
+ */
+ public synchronized void initialize(LoadContext lc)
+ {
+ DataSetID dsID = lc.getDataSetID();
+ MasterListInterface masterLists = Globals.getMasterLists();
+ ArrayList<CDOMReference<CDOMList<Spell>>> useLists =
+ new ArrayList<CDOMReference<CDOMList<Spell>>>();
+ for (CDOMReference ref : masterLists.getActiveLists())
+ {
+ Collection<CDOMList<Spell>> lists = ref.getContainedObjects();
+ for (CDOMList<Spell> list : lists)
+ {
+ if ((list instanceof ClassSpellList)
+ || (list instanceof DomainSpellList))
+ {
+ useLists.add(ref);
+ break;
+ }
+ }
+ }
+ for (CDOMReference<CDOMList<Spell>> ref : useLists)
+ {
+ for (Spell spell : masterLists.getObjects(ref))
+ {
+ Collection<AssociatedPrereqObject> assoc =
+ masterLists.getAssociations(ref, spell);
+ for (AssociatedPrereqObject apo : assoc)
+ {
+ int lvl = apo.getAssociation(AssociationKey.SPELL_LEVEL);
+ for (CDOMList<Spell> list : ref.getContainedObjects())
+ {
+ AvailableSpell as = new AvailableSpell(list, spell, lvl);
+ if (apo.hasPrerequisites())
+ {
+ as.addAllPrerequisites(apo.getPrerequisiteList());
+ }
+ add(dsID, as, lc);
+ }
+ }
+ }
+ }
+ }
+
+ public void setDataSetInitializationFacet(
+ DataSetInitializationFacet datasetInitializationFacet)
+ {
+ this.datasetInitializationFacet = datasetInitializationFacet;
+ }
+
+ public void init()
+ {
+ datasetInitializationFacet.addDataSetInitializedFacet(this);
+ }
+}
Deleted: Trunk/pcgen/code/src/java/pcgen/cdom/facet/MasterAvailableSpellInitializationFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/MasterAvailableSpellInitializationFacet.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/MasterAvailableSpellInitializationFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 2010 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 pcgen.cdom.facet;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import pcgen.cdom.base.AssociatedPrereqObject;
-import pcgen.cdom.base.CDOMList;
-import pcgen.cdom.base.CDOMReference;
-import pcgen.cdom.base.MasterListInterface;
-import pcgen.cdom.enumeration.AssociationKey;
-import pcgen.cdom.enumeration.CharID;
-import pcgen.cdom.list.ClassSpellList;
-import pcgen.cdom.list.DomainSpellList;
-import pcgen.core.Globals;
-import pcgen.core.spell.Spell;
-
-/**
- * The Class <code>MasterSkillFacet</code> caches a copy of all class skill
- * lists. This allows faster checking of whether skills are class skills for a
- * character class. Note this is a "global" facet in that it does not have
- * method that depend on CharID (they are not character specific).
- *
- * @author Tom Parker <th...@us...>
- */
-public class MasterAvailableSpellInitializationFacet
-{
- private ConditionalMasterAvailableSpellFacet conditionalMasterSpellAvailableFacet;
-
- private AvailableSpellFacet availableSpellFacet;
-
- /**
- * Initializes the global lists of ClassSkillLists. This method only needs
- * to be called once for each set of sources that are loaded.
- */
- public void initialize(CharID id)
- {
- MasterListInterface masterLists = Globals.getMasterLists();
- ArrayList<CDOMReference<CDOMList<Spell>>> useLists =
- new ArrayList<CDOMReference<CDOMList<Spell>>>();
- for (CDOMReference ref : masterLists.getActiveLists())
- {
- Collection<CDOMList<Spell>> lists = ref.getContainedObjects();
- for (CDOMList<Spell> list : lists)
- {
- if ((list instanceof ClassSpellList)
- || (list instanceof DomainSpellList))
- {
- useLists.add(ref);
- break;
- }
- }
- }
- for (CDOMReference<CDOMList<Spell>> ref : useLists)
- {
- for (Spell spell : masterLists.getObjects(ref))
- {
- Collection<AssociatedPrereqObject> assoc =
- masterLists.getAssociations(ref, spell);
- for (AssociatedPrereqObject apo : assoc)
- {
- int lvl = apo.getAssociation(AssociationKey.SPELL_LEVEL);
- for (CDOMList<Spell> list : ref.getContainedObjects())
- {
- if (apo.hasPrerequisites())
- {
- conditionalMasterSpellAvailableFacet.add(id, list,
- spell, apo, spell);
- }
- else
- {
- availableSpellFacet.add(id, list, lvl, spell, spell);
- }
- }
- }
- }
- }
- }
-
- public void setConditionalMasterAvailableSpellFacet(
- ConditionalMasterAvailableSpellFacet conditionalMasterSpellAvailableFacet)
- {
- this.conditionalMasterSpellAvailableFacet =
- conditionalMasterSpellAvailableFacet;
- }
-
- public void setAvailableSpellFacet(AvailableSpellFacet availableSpellFacet)
- {
- this.availableSpellFacet = availableSpellFacet;
- }
-
-}
Added: Trunk/pcgen/code/src/java/pcgen/cdom/facet/SpellListToAvailableSpellFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/SpellListToAvailableSpellFacet.java (rev 0)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/SpellListToAvailableSpellFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2014 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 pcgen.cdom.facet;
+
+import java.util.Set;
+
+import pcgen.cdom.base.CDOMList;
+import pcgen.cdom.enumeration.CharID;
+import pcgen.cdom.facet.event.DataFacetChangeEvent;
+import pcgen.cdom.facet.event.DataFacetChangeListener;
+import pcgen.cdom.helper.AvailableSpell;
+import pcgen.core.spell.Spell;
+
+public class SpellListToAvailableSpellFacet implements
+ DataFacetChangeListener<CharID, CDOMList<Spell>>
+{
+ private MasterAvailableSpellFacet masterAvailableSpellFacet;
+ private SpellListFacet spellListFacet;
+ private ConditionallyAvailableSpellFacet conditionallyAvailableSpellFacet;
+ private AvailableSpellFacet availableSpellFacet;
+
+ private void add(CharID id, AvailableSpell as, Object source)
+ {
+ if (as.hasPrerequisites())
+ {
+ conditionallyAvailableSpellFacet.add(id, as, source);
+ }
+ else
+ {
+ availableSpellFacet.add(id, as.getSpelllist(), as.getLevel(),
+ as.getSpell(), source);
+ }
+ }
+
+ private void remove(CharID id, AvailableSpell as, Object source)
+ {
+ if (as.hasPrerequisites())
+ {
+ conditionallyAvailableSpellFacet.remove(id, as, source);
+ }
+ else
+ {
+ availableSpellFacet.remove(id, as.getSpelllist(), as.getLevel(),
+ as.getSpell(), source);
+ }
+ }
+
+ public void dataAdded(DataFacetChangeEvent<CharID, CDOMList<Spell>> dfce)
+ {
+ CharID id = dfce.getCharID();
+ CDOMList<Spell> list = dfce.getCDOMObject();
+ Set<AvailableSpell> spells =
+ masterAvailableSpellFacet.getSet(id.getDatasetID());
+ for (AvailableSpell as : spells)
+ {
+ if (as.getSpelllist().equals(list))
+ {
+ add(id, as, this);
+ }
+ }
+ }
+
+ public void dataRemoved(DataFacetChangeEvent<CharID, CDOMList<Spell>> dfce)
+ {
+ CharID id = dfce.getCharID();
+ CDOMList<Spell> list = dfce.getCDOMObject();
+ Set<AvailableSpell> spells =
+ masterAvailableSpellFacet.getSet(id.getDatasetID());
+ for (AvailableSpell as : spells)
+ {
+ if (as.getSpelllist().equals(list))
+ {
+ remove(id, as, this);
+ }
+ }
+ }
+
+ public void init()
+ {
+ spellListFacet.addDataFacetChangeListener(this);
+ }
+
+ public void setSpellListFacet(
+ SpellListFacet spellListFacet)
+ {
+ this.spellListFacet = spellListFacet;
+ }
+
+ public void setMasterAvailableSpellFacet(
+ MasterAvailableSpellFacet masterAvailableSpellFacet)
+ {
+ this.masterAvailableSpellFacet = masterAvailableSpellFacet;
+ }
+
+ public void setConditionallyAvailableSpellFacet(
+ ConditionallyAvailableSpellFacet conditionallyAvailableSpellFacet)
+ {
+ this.conditionallyAvailableSpellFacet = conditionallyAvailableSpellFacet;
+ }
+
+ public void setAvailableSpellFacet(AvailableSpellFacet availableSpellFacet)
+ {
+ this.availableSpellFacet = availableSpellFacet;
+ }
+}
Deleted: Trunk/pcgen/code/src/java/pcgen/cdom/facet/base/AbstractConditionalSpellFacet.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/cdom/facet/base/AbstractConditionalSpellFacet.java 2014-04-05 17:21:11 UTC (rev 23594)
+++ Trunk/pcgen/code/src/java/pcgen/cdom/facet/base/AbstractConditionalSpellFacet.java 2014-04-05 20:24:13 UTC (rev 23595)
@@ -1,364 +0,0 @@
-/*
- * Copyright (c) Thomas Parker, 2012.
- *
- * 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 pcgen.cdom.facet.base;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.IdentityHashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import pcgen.base.util.WrappedMapSet;
-import pcgen.cdom.base.AssociatedPrereqObject;
-import pcgen.cdom.base.CDOMList;
-import pcgen.cdom.base.CDOMObject;
-import pcgen.cdom.enumeration.AssociationKey;
-import pcgen.cdom.enumeration.CharID;
-import pcgen.cdom.facet.PrerequisiteFacet;
-import pcgen.core.spell.Spell;
-
-/**
- * AbstractConditionalSpellFacet is a Facet that tracks the Spells (and target
- * objects) that are contained in a Player Character. These may be Known or
- * Available spells.
- *
- * @author Thomas Parker (thpr [at] yahoo.com)
- */
-public abstract class AbstractConditionalSpellFacet extends
- AbstractStorageFacet<CharID>
-{
-
- private PrerequisiteFacet prerequisiteFacet;
-
- public void addAll(CharID id, CDOMList<Spell> list,
- Collection<Spell> spells, AssociatedPrereqObject apo, CDOMObject cdo)
- {
- Map<CDOMList<Spell>, Map<Spell, Map<AssociatedPrereqObject, Set<CDOMObject>>>> map =
- getConstructingCachedMap(id);
- Map<Spell, Map<AssociatedPrereqObject, Set<CDOMObject>>> subMap =
- map.get(list);
- boolean fireNew = (subMap == null);
- if (fireNew)
- {
- subMap =
- new HashMap<Spell, Map<AssociatedPrereqObject, Set<CDOMObject>>>();
- map.put(list, subMap);
- }
- for (Spell spell : spells)
- {
- Map<AssociatedPrereqObject, Set<CDOMObject>> assocMap =
- subMap.get(spell);
- if (assocMap == null)
- {
- assocMap =
- new HashMap<AssociatedPrereqObject, Set<CDOMObject>>();
- subMap.put(spell, assocMap);
- }
- Set<CDOMObject> sources = assocMap.get(apo);
- if (sources == null)
- {
- sources = new WrappedMapSet<CDOMObject>(IdentityHashMap.class);
- assocMap.put(apo, sources);
- }
- sources.add(cdo);
- }
- }
-
- public void add(CharID id, CDOMList<Spell> list, Spell spell,
- AssociatedPrereqObject apo, CDOMObject cdo)
- {
- Map<CDOMList<Spell>, Map<Spell, Map<AssociatedPrereqObject, Set<CDOMObject>>>> map =
- getConstructingCachedMap(id);
- Map<Spell, Map<AssociatedPrereqObject, Set<CDOMObject>>> subMap =
- map.get(list);
- boolean fireNew = (subMap == null);
- if (fireNew)
- {
- subMap =
- new HashMap<Spell, Map<AssociatedPrereqObject, Set<CDOMObject>>>();
- map.put(list, subMap);
- }
- Map<AssociatedPrereqObject, Set<CDOMObject>> assocMap =
- subMap.get(spell);
- if (assocMap == null)
- {
- assocMap = new HashMap<AssociatedPrereqObject, Set<CDOMObject>>();
- subMap.put(spell, assocMap);
- }
- Set<CDOMObject> sources = assocMap.get(apo);
- if (sources == null)
- {
- sources = new WrappedMapSet<CDOMObject>(IdentityHashMap.class);
- assocMap.put(apo, sources);
- }
- sources.add(cdo);
- }
-
- /**
- * Returns the type-safe Map for this ConditionallyAvailableSpellFacet and
- * the given CharID. May return null if no information has been set in this
- * ConditionallyAvailableSpellFacet for the given CharID.
- *
- * Note that this method SHOULD NOT be public. The Map is owned by
- * ConditionallyAvailableSpellFacet, and since it can be modified, a
- * reference to that object should not be exposed to any object other than
- * ConditionallyAvailableSpellFacet.
- *
- * @param id
- * The CharID for which the Set should be returned
- * @return The Set for the Player Character represented by the given CharID;
- * null if no information has been set in this
- * ConditionallyAvailableSpellFacet for the Player Character.
- */
- private Map<CDOMList<Spell>, Map<Spell, Map<AssociatedPrereqObject, Set<CDOMObject>>>> getCachedMap(
- CharID id)
- {
- return (Map<CDOMList<Spell>, Map<Spell, Map<AssociatedPrereqObject, Set<CDOMObject>>>>) getCache(
- id);
- }
-
- /**
- * Returns a type-safe Map for this ConditionallyAvailableSpellFacet and the
- * given CharID. Will return a new, empty Map if no information has been set
- * in this ConditionallyAvailableSpellFacet for the given CharID. Will not
- * return null.
- *
- * Note that this method SHOULD NOT be public. The Map object is owned by
- * ConditionallyAvailableSpellFacet, and since it can be modified, a
- * reference to that object should not be exposed to any object other than
- * ConditionallyAvailableSpellFacet.
- *
- * @param id
- * The CharID for which the Map should be returned
- * @return The Map for the Player Character represented by the given CharID.
- */
- private Map<CDOMList<Spell>, Map<Spell, Map<AssociatedPrereqObject, Set<CDOMObject>>>> getConstructingCachedMap(
- CharID id)
- {
- Map<CDOMList<Spell>, Map<Spell, Map<AssociatedPrereqObject, Set<CDOMObject>>>> componentMap =
- getCachedMap(id);
- if (componentMap == null)
- {
- componentMap =
- new HashMap<CDOMList<Spell>, Map<Spell, Map<AssociatedPrereqObject, Set<CDOMObject>>>>();
- setCache(id, componentMap);
- }
- return componentMap;
- }
-
- /**
- * Removes all information for the given source from this
- * ConditionallyAvailableSpellFacet for the PlayerCharacter represented by
- * the given CharID.
- *
- * @param id
- * The CharID representing the Player Character for which items
- * from the given source will be removed
- * @param source
- * The source for the objects to be removed from the list of
- * items stored for the Player Character identified by the given
- * CharID
- */
- public void removeAll(CharID id, Object source)
- {
- Map<CDOMList<Spell>, Map<Spell, Map<AssociatedPrereqObject, Set<CDOMObject>>>> listMap =
- getCachedMap(id);
- if (listMap != null)
- {
- for (Iterator<Map<Spell, Map<AssociatedPrereqObject, Set<CDOMObject>>>> mit =
- listMap.values().iterator(); mit.hasNext();)
- {
- Map<Spell, Map<AssociatedPrereqObject, Set<CDOMObject>>> objMap =
- mit.next();
- for (Iterator<Map<AssociatedPrereqObject, Set<CDOMObject>>> ait =
- objMap.values().iterator(); ait.hasNext();)
- {
- Map<AssociatedPrereqObject, Set<CDOMObject>> apoMap =
- ait.next();
- for (Iterator<Set<CDOMObject>> sit =
- apoMap.values().iterator(); sit.hasNext();)
- {
- Set<CDOMObject> set = sit.next();
- if (set.remove(source) && set.isEmpty())
- {
- sit.remove();
- }
- }
- if (apoMap.isEmpty())
- {
- ait.remove();
- }
- }
- if (objMap.isEmpty())
- {
- mit.remove();
- }
- }
- }
- }
-
- /**
- * Returns a non-null Map of Spells (by spell level) known by the Player
- * Character for the given ClassSpellList.
- *
- * This method is value-semantic in that ownership of the returned Map is
- * transferred to the class calling this method. Modification of the
- * returned Map will not modify this ConditionallyAvailableSpellFacet and
- * modifi...
[truncated message content] |