Переглянути джерело

Adding spell level to the PerSpellLevel data.
Removing deprecated value() function.

Sam Jaffe 8 роки тому
батько
коміт
91f37dda44

+ 2 - 3
src/main/lombok/org/leumasjaffe/charsheet/model/features/DDProperty.java

@@ -10,7 +10,6 @@ public interface DDProperty {
 	public enum Group {
 		NONE
 	}
-	boolean appliesTo(Object key);
-	@Deprecated <T> T value();
-	void accumulate(Map<String, Object> props);
+	boolean appliesTo(final Object key);
+	void accumulate(final Map<String, Object> props, final Object... data);
 }

+ 1 - 6
src/main/lombok/org/leumasjaffe/charsheet/model/features/impl/Flat.java

@@ -18,13 +18,8 @@ public class Flat implements DDProperty {
 		return applies.accepts(key);
 	}
 
-	@Override @SuppressWarnings("unchecked")
-	public Object value() {
-		return this.value;
-	}
-
 	@Override
-	public void accumulate(Map<String, Object> props) {
+	public void accumulate(Map<String, Object> props, Object... data) {
 		// TODO: use groups
 		props.compute("value", (k, old) -> old == null ? value : value + (Integer) old);
 	}

+ 5 - 9
src/main/lombok/org/leumasjaffe/charsheet/model/features/impl/PerSpellLevel.java

@@ -3,8 +3,10 @@ package org.leumasjaffe.charsheet.model.features.impl;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.features.DDFeaturePredicate;
 import org.leumasjaffe.charsheet.model.features.DDProperty;
+import org.leumasjaffe.charsheet.model.magic.DDSpell;
 
 import lombok.AllArgsConstructor;
 
@@ -21,17 +23,11 @@ public class PerSpellLevel implements DDProperty {
 	}
 
 	@Override @SuppressWarnings("unchecked")
-	public Object value() {
-		return this.value; // TODO consume spell level information
-	}
-
-	@Override @SuppressWarnings("unchecked")
-	public void accumulate(Map<String, Object> props) {
+	public void accumulate(Map<String, Object> props, Object... data) {
+		final int level = DDSpell.class.cast(data[1]).getClassLevel(DDCharacterClass.class.cast(data[0]).getName());
 		// TODO: use groups
 		// TODO: allow multiple things
-		// TODO: consume spell level information
 		props.putIfAbsent("effect", new HashMap<>());
-		((Map<String, Integer>) props.get("effect")).compute("value", 
-				(k, old) -> old == null ? value : value + (Integer) old);
+		((Map<String, Object>) props.get("effect")).put("value", value * level);
 	}
 }

+ 1 - 2
src/main/lombok/org/leumasjaffe/charsheet/model/features/impl/Simple.java

@@ -10,6 +10,5 @@ import lombok.AllArgsConstructor;
 public class Simple implements DDProperty {
 	String name;
 	@Override public boolean appliesTo(Object key) { return false; }
-	@Override public <T> T value() { return null; }
-	@Override public void accumulate(Map<String, Object> props) {}
+	@Override public void accumulate(Map<String, Object> props, Object... data) {}
 }

+ 1 - 1
src/main/lombok/org/leumasjaffe/charsheet/view/magic/SpellInfoPanel.java

@@ -39,7 +39,7 @@ class SpellInfoPanel extends JPanel {
 	public SpellInfoPanel(DDCharacter chara, DDCharacterClass dclass, final DDSpell spell) {
 		final IntValue classLevel = dclass.getLevel();
 		Map<String, Object> props = new HashMap<>();
-		chara.getFeatureBonuses(spell).forEach(p -> p.accumulate(props));
+		chara.getFeatureBonuses(spell).forEach(p -> p.accumulate(props, dclass, spell));
 		
 		GridBagLayout gridBagLayout = new GridBagLayout();
 		gridBagLayout.columnWidths = new int[]{0, 0};

+ 5 - 3
src/main/lombok/org/leumasjaffe/charsheet/view/summary/InitiativeLine.java

@@ -25,6 +25,8 @@ import javax.swing.SwingConstants;
 import java.awt.Dimension;
 import javax.swing.JTextField;
 import java.awt.Insets;
+import java.util.HashMap;
+import java.util.Map;
 
 @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
 public class InitiativeLine extends JPanel {
@@ -141,9 +143,9 @@ public class InitiativeLine extends JPanel {
 	}
 
 	private int getInitiativeBonuses(DDCharacter v) {
-		// FIXME
-		return v.getFeatureBonuses(Constants.INITIATIVE).stream()
-				.mapToInt(f -> (Integer) f.value()).sum();
+		Map<String, Object> props = new HashMap<>();
+		v.getFeatureBonuses(Constants.INITIATIVE).stream().forEach(f -> f.accumulate(props));
+		return props.values().stream().mapToInt(o -> (Integer) o).sum();
 	}
 
 	public void setModel(DDCharacter model) {