Browse Source

Moving the calculations for highestSpellLevel known into DDCharacterClass.
Removing the concept of the renew function, because it was bad. Instead, spontaneous casters and others would just pass in null, generating a list.

Sam Jaffe 8 years ago
parent
commit
5d8ecc5427

+ 8 - 0
src/org/leumasjaffe/charsheet/model/DDCharacterClass.java

@@ -1,5 +1,6 @@
 package org.leumasjaffe.charsheet.model;
 
+import java.util.List;
 import java.util.Optional;
 
 import org.leumasjaffe.charsheet.model.magic.DDSpellbook;
@@ -76,4 +77,11 @@ public class DDCharacterClass {
 	public DDClass getProto() {
 		return name.base;
 	}
+	
+	public int getHighestSpellLevel() {
+		// TODO: Bonus levels to spellsKnown/spellsPerDay?
+		final List<Integer> list = getProto().getSpells().get().getPerDay().get(getLevel()-1);
+		final int level = list.size() - 1;
+		return list.get(level) == 0 ? level : level + 1;
+	}
 }

+ 1 - 1
src/org/leumasjaffe/charsheet/model/magic/DDSpellbook.java

@@ -36,5 +36,5 @@ public interface DDSpellbook {
 	
 	void castSpell( int level, final DDSpell spell );
 	
-	void renew();
+	void prepareSpells(int level, List<DDSpell> spells);
 }

+ 0 - 3
src/org/leumasjaffe/charsheet/model/magic/impl/Prepared.java

@@ -14,7 +14,4 @@ public interface Prepared extends DDSpellbook {
 	@NonNull List<DDSpell> getSpellsPreparedPreviouslyForLevel(int level);
 	
 	void prepareSpells(int level, List<DDSpell> spells);
-	
-	@Override
-	default void renew() { throw new UnsupportedOperationException(); }
 }

+ 6 - 0
src/org/leumasjaffe/charsheet/model/magic/impl/Spontaneous.java

@@ -61,4 +61,10 @@ public class Spontaneous implements DDSpellbook {
 	private Level get(int level) {
 		return spellInfo.getOrDefault(level, new Level(Collections.emptyList(), 0, 0));
 	}
+
+	@Override
+	public void prepareSpells(int level, List<DDSpell> spells) {
+		final Level lInfo = get(level);
+		lInfo.spellsPerDayRemaining = lInfo.spellsPerDay;
+	}
 }

+ 4 - 2
src/org/leumasjaffe/charsheet/view/D20Sheet.java

@@ -124,9 +124,11 @@ public class D20Sheet extends JFrame {
 			for (DDCharacterClass dclass : model.getClasses()) {
 				dclass.getSpellBook().ifPresent(sb -> {
 					if (sb.preparesSpells()) {
-						
+						// TODO: dialogue
 					} else {
-						sb.renew();
+						for (int i = 0; i < dclass.getHighestSpellLevel(); ++i) {
+							sb.prepareSpells(i, null);
+						}
 					}
 				});
 			}

+ 1 - 11
src/org/leumasjaffe/charsheet/view/magic/SpellPanel.java

@@ -4,7 +4,6 @@ import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 
 import java.awt.GridBagLayout;
-import java.util.List;
 import java.util.function.Function;
 
 import javax.swing.JTabbedPane;
@@ -30,11 +29,9 @@ public class SpellPanel extends JPanel {
 	private static final long serialVersionUID = 1L;
 	DDCharacterClass dclass;
 	VoidVoidFunction _reload;
-	int highestSpellLevel;
 
 	public SpellPanel(DDCharacter chara, final DDCharacterClass cclass) {
 		dclass = cclass;
-		highestSpellLevel = calcHighestSpellLevel(cclass);
 		final DDSpellbook model = cclass.getSpellBook().get();
 		
 		GridBagLayout gridBagLayout = new GridBagLayout();
@@ -71,18 +68,11 @@ public class SpellPanel extends JPanel {
 		_reload.apply();
 	}
 
-	private static int calcHighestSpellLevel(final DDCharacterClass cclass) {
-		// TODO: Bonus levels to spellsKnown/spellsPerDay?
-		final List<Integer> list = cclass.getProto().getSpells().get().getPerDay().get(cclass.getLevel()-1);
-		final int level = list.size() - 1;
-		return list.get(level) == 0 ? level : level + 1;
-	}
-
 	private void generateSpellTree(final Function<Integer, JPanel> getPanel, final JScrollPane preparedPane) {
 		JPanel root = new JPanel();
 		root.setLayout(new VerticalLayout());
 		
-		for (int i = 0; i < highestSpellLevel; ++i) {
+		for (int i = 0; i < dclass.getHighestSpellLevel(); ++i) {
 			if (dclass.getSpellBook().get().numSpellsKnownAtLevel(i) == 0) continue;
 			root.add(getPanel.apply(i));
 		}