Browse Source

Fixing all compiler errors from merge

Sam Jaffe 8 years ago
parent
commit
22ac25890e

+ 4 - 4
src/main/lombok/org/leumasjaffe/charsheet/model/DDClass.java

@@ -10,11 +10,11 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.Optional;
 import java.util.Set;
 import java.util.Set;
 
 
+import org.leumasjaffe.charsheet.model.DDCharacterClass.DDSpellbookWrapper;
 import org.leumasjaffe.charsheet.model.features.DDProperty;
 import org.leumasjaffe.charsheet.model.features.DDProperty;
 import org.leumasjaffe.charsheet.model.magic.DDSpell;
 import org.leumasjaffe.charsheet.model.magic.DDSpell;
 import org.leumasjaffe.charsheet.model.magic.DDSpellList;
 import org.leumasjaffe.charsheet.model.magic.DDSpellList;
 import org.leumasjaffe.charsheet.model.magic.DDSpellList.SpellList;
 import org.leumasjaffe.charsheet.model.magic.DDSpellList.SpellList;
-import org.leumasjaffe.charsheet.model.magic.DDSpellbook;
 import org.leumasjaffe.format.StringFormatter;
 import org.leumasjaffe.format.StringFormatter;
 
 
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -83,15 +83,15 @@ public class DDClass {
 			Collections.unmodifiableList(features.get(level-1));
 			Collections.unmodifiableList(features.get(level-1));
 	}
 	}
 
 
-	public Optional<DDSpellbook> createNewSpellBook()  {
+	public Optional<DDSpellbookWrapper> createNewSpellBook()  {
 		return spells.flatMap(sl -> sl.getSpellBookTypeName()).map(st -> createSpellbookImpl(st));
 		return spells.flatMap(sl -> sl.getSpellBookTypeName()).map(st -> createSpellbookImpl(st));
 	}
 	}
 
 
 	@SneakyThrows({JsonMappingException.class, JsonParseException.class, IOException.class})
 	@SneakyThrows({JsonMappingException.class, JsonParseException.class, IOException.class})
-	private DDSpellbook createSpellbookImpl(String st) {
+	private DDSpellbookWrapper createSpellbookImpl(String st) {
 		if (!st.startsWith("{")) {
 		if (!st.startsWith("{")) {
 			st = new StringFormatter("{{\"@c\":\"{}\"}}").format(st);
 			st = new StringFormatter("{{\"@c\":\"{}\"}}").format(st);
 		}
 		}
-		return mapper.readValue(st.getBytes(), DDSpellbook.class);
+		return mapper.readValue(st.getBytes(), DDSpellbookWrapper.class);
 	}
 	}
 }
 }

+ 3 - 3
src/main/lombok/org/leumasjaffe/charsheet/model/magic/impl/Domain.java

@@ -78,13 +78,13 @@ public class Domain extends Prepared implements DDSpellbook.Secondary {
 	}
 	}
 
 
 	@Override
 	@Override
-	public void prepareSpells(int level, List<DDSpell> spells) {
+	public void prepareSpells(int level, Collection<DDSpell> spells) {
 		if (level == 0) return;
 		if (level == 0) return;
 		if (spells.size() != 1) {
 		if (spells.size() != 1) {
 			throw new IllegalArgumentException("Can only prepare one domain spell per domain class");
 			throw new IllegalArgumentException("Can only prepare one domain spell per domain class");
 		}
 		}
-		spellsPrepared.set(level-1, spells.get(0));
-		spellsPreparedPreviously.set(level-1, spells.get(0));
+		spellsPrepared.set(level-1, spells.iterator().next());
+		spellsPreparedPreviously.set(level-1, spells.iterator().next());
 	}
 	}
 
 
 	@Override
 	@Override

+ 1 - 0
src/main/lombok/org/leumasjaffe/charsheet/view/D20Sheet.java

@@ -24,6 +24,7 @@ import javax.swing.UIManager;
 import org.leumasjaffe.charsheet.config.Config;
 import org.leumasjaffe.charsheet.config.Config;
 import org.leumasjaffe.charsheet.model.DDCharacter;
 import org.leumasjaffe.charsheet.model.DDCharacter;
 import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.DDCharacterClass;
+import org.leumasjaffe.charsheet.model.magic.DDSpellbook;
 import org.leumasjaffe.charsheet.observer.ObserverHelper;
 import org.leumasjaffe.charsheet.observer.ObserverHelper;
 import org.leumasjaffe.charsheet.view.level.ExperienceDialog;
 import org.leumasjaffe.charsheet.view.level.ExperienceDialog;
 import org.leumasjaffe.observer.ObservableListener;
 import org.leumasjaffe.observer.ObservableListener;

+ 3 - 3
src/main/lombok/org/leumasjaffe/charsheet/view/level/LevelUpSpellPanel.java

@@ -44,7 +44,7 @@ class LevelUpSpellPanel extends JPanel {
 			@Override
 			@Override
 			public Collection<DDSpell> getAvailableSpells(Info info, int i) {
 			public Collection<DDSpell> getAvailableSpells(Info info, int i) {
 				Collection<DDSpell> spells = new ArrayList<>(info.dclass.getProto().getSpellList(i));
 				Collection<DDSpell> spells = new ArrayList<>(info.dclass.getProto().getSpellList(i));
-				spells.removeAll(info.dclass.getSpellBook().get().spellsKnownAtLevel(i));
+				spells.removeAll(info.spellBook.spellsKnownAtLevel(i));
 				return spells;
 				return spells;
 			}
 			}
 
 
@@ -56,7 +56,7 @@ class LevelUpSpellPanel extends JPanel {
 			}
 			}
 			@Override
 			@Override
 			public Collection<DDSpell> getAvailableSpells(Info info, int i) {
 			public Collection<DDSpell> getAvailableSpells(Info info, int i) {
-				return info.dclass.getSpellBook().get().spellsKnownAtLevel(i);
+				return info.spellBook.spellsKnownAtLevel(i);
 			}
 			}
 		};		
 		};		
 	}
 	}
@@ -128,7 +128,7 @@ class LevelUpSpellPanel extends JPanel {
 	}
 	}
 
 
 	private IntValue getSharedAllowedSlots(Info info) {
 	private IntValue getSharedAllowedSlots(Info info) {
-		return info.dclass.getSpellBook().get().getSharedAllowedSlots();
+		return info.spellBook.getSharedAllowedSlots();
 	}
 	}
 
 
 	private boolean isNewSpellCircle(int i) {
 	private boolean isNewSpellCircle(int i) {

+ 12 - 9
src/main/lombok/org/leumasjaffe/charsheet/view/level/UpdateClassWithLevelPanel.java

@@ -13,6 +13,7 @@ import java.util.function.Consumer;
 import javax.swing.JPanel;
 import javax.swing.JPanel;
 
 
 import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.DDCharacterClass;
+import org.leumasjaffe.charsheet.model.DDCharacterClass.DDSpellbookWrapper;
 import org.leumasjaffe.charsheet.model.magic.DDSpell;
 import org.leumasjaffe.charsheet.model.magic.DDSpell;
 import org.leumasjaffe.charsheet.model.magic.DDSpellbook;
 import org.leumasjaffe.charsheet.model.magic.DDSpellbook;
 import org.leumasjaffe.charsheet.model.observable.BoolGate;
 import org.leumasjaffe.charsheet.model.observable.BoolGate;
@@ -85,13 +86,14 @@ class UpdateClassWithLevelPanel extends JPanel {
 		};
 		};
 		tabbedPane.addTab("Skills", null, skills, null);
 		tabbedPane.addTab("Skills", null, skills, null);
 
 
-		info.ddClass.getSpellBook().ifPresent(sb -> {
+		// FIXME: Provide Work for secondary
+		info.ddClass.getSpellBook().map(DDSpellbookWrapper::getMain).ifPresent(sb -> {
 			readyCount.set(LEARN_SPELL_INDEX, !sb.learnsSpells());
 			readyCount.set(LEARN_SPELL_INDEX, !sb.learnsSpells());
 			readyCount.set(PREPARE_SPELL_INDEX, !sb.preparesSpells());
 			readyCount.set(PREPARE_SPELL_INDEX, !sb.preparesSpells());
 			if (sb.learnsSpells()) {
 			if (sb.learnsSpells()) {
 				createPanelsForLearnSpell(sb);
 				createPanelsForLearnSpell(sb);
 			} else if (sb.preparesSpells()) {
 			} else if (sb.preparesSpells()) {
-				createPanelForPrepareSpells();
+				createPanelForPrepareSpells(sb);
 			}
 			}
 		});
 		});
 
 
@@ -125,22 +127,22 @@ class UpdateClassWithLevelPanel extends JPanel {
 		listener = readyCount.makeListener(setReady);
 		listener = readyCount.makeListener(setReady);
 	}
 	}
 
 
-	private void createPanelForPrepareSpells() {
+	private void createPanelForPrepareSpells(DDSpellbook sb) {
 		prepSpells = Optional.of(new LevelUpSpellPanel(PREPARE,
 		prepSpells = Optional.of(new LevelUpSpellPanel(PREPARE,
-				new SelectSpellsPanel.Info(levelUpInfo.ddCharacter, levelUpInfo.ddClass),
+				new SelectSpellsPanel.Info(levelUpInfo.ddCharacter, levelUpInfo.ddClass, sb),
 				readyCount.handle(PREPARE_SPELL_INDEX)));
 				readyCount.handle(PREPARE_SPELL_INDEX)));
 		tabbedPane.addTab("Prepare Spells", null, prepSpells.get(), null);
 		tabbedPane.addTab("Prepare Spells", null, prepSpells.get(), null);
 	}
 	}
 
 
 	private void createPanelsForLearnSpell(DDSpellbook sb) {
 	private void createPanelsForLearnSpell(DDSpellbook sb) {
 		learnSpells = Optional.of(new LevelUpSpellPanel(LEARN,
 		learnSpells = Optional.of(new LevelUpSpellPanel(LEARN,
-				new SelectSpellsPanel.Info(levelUpInfo.ddCharacter, levelUpInfo.ddClass),
+				new SelectSpellsPanel.Info(levelUpInfo.ddCharacter, levelUpInfo.ddClass, sb),
 				readyCount.handle(LEARN_SPELL_INDEX)));
 				readyCount.handle(LEARN_SPELL_INDEX)));
 		tabbedPane.addTab("Learn Spells", null, learnSpells.get(), null);
 		tabbedPane.addTab("Learn Spells", null, learnSpells.get(), null);
 		if (sb.preparesSpells()) {
 		if (sb.preparesSpells()) {
 			learnAndPrepareListener = new ObservableListener<>(this, (c, v) -> {
 			learnAndPrepareListener = new ObservableListener<>(this, (c, v) -> {
 				if (v.get(LEARN_SPELL_INDEX)) {
 				if (v.get(LEARN_SPELL_INDEX)) {
-					if (!prepSpells.isPresent()) c.createPrepareLearnedSpellPanel(learnSpells.get());
+					if (!prepSpells.isPresent()) c.createPrepareLearnedSpellPanel(learnSpells.get(), sb);
 				} else {
 				} else {
 					prepSpells.ifPresent(c.tabbedPane::remove);
 					prepSpells.ifPresent(c.tabbedPane::remove);
 					c.prepSpells = Optional.empty();
 					c.prepSpells = Optional.empty();
@@ -150,7 +152,7 @@ class UpdateClassWithLevelPanel extends JPanel {
 		}
 		}
 	}
 	}
 
 
-	private void createPrepareLearnedSpellPanel(LevelUpSpellPanel spells) {
+	private void createPrepareLearnedSpellPanel(LevelUpSpellPanel spells, DDSpellbook sb) {
 		LevelUpSpellPanel.SpellPicker pick = new LevelUpSpellPanel.SpellPicker() {
 		LevelUpSpellPanel.SpellPicker pick = new LevelUpSpellPanel.SpellPicker() {
 			@Override
 			@Override
 			public List<List<Integer>> getSpellCounts(Info info) {
 			public List<List<Integer>> getSpellCounts(Info info) {
@@ -168,7 +170,7 @@ class UpdateClassWithLevelPanel extends JPanel {
 		};
 		};
 
 
 		prepSpells = Optional.of(new LevelUpSpellPanel(pick,
 		prepSpells = Optional.of(new LevelUpSpellPanel(pick,
-				new SelectSpellsPanel.Info(levelUpInfo.ddCharacter, levelUpInfo.ddClass),
+				new SelectSpellsPanel.Info(levelUpInfo.ddCharacter, levelUpInfo.ddClass, sb),
 				readyCount.handle(PREPARE_SPELL_INDEX)));
 				readyCount.handle(PREPARE_SPELL_INDEX)));
 		tabbedPane.addTab("Prepare Spells", null, prepSpells.get(), null);
 		tabbedPane.addTab("Prepare Spells", null, prepSpells.get(), null);
 	}
 	}
@@ -205,7 +207,8 @@ class UpdateClassWithLevelPanel extends JPanel {
 	public void commitAllChanges() {
 	public void commitAllChanges() {
 		final String className = levelUpInfo.ddClass.getName();
 		final String className = levelUpInfo.ddClass.getName();
 		skills.commitAllChanges();
 		skills.commitAllChanges();
-		final Optional<DDSpellbook> maybeBook = levelUpInfo.ddClass.getSpellBook();
+		// FIXME: Secondary spellbook here too?
+		final Optional<DDSpellbook> maybeBook = levelUpInfo.ddClass.getSpellBook().map(DDSpellbookWrapper::getMain);
 		maybeBook.ifPresent(this::commitSpellbook);
 		maybeBook.ifPresent(this::commitSpellbook);
 		final SortedSet<DDCharacterClass> classes = new TreeSet<>(levelUpInfo.ddCharacter.getClasses());
 		final SortedSet<DDCharacterClass> classes = new TreeSet<>(levelUpInfo.ddCharacter.getClasses());
 		classes.removeIf(cc -> cc.getName().equals(className));
 		classes.removeIf(cc -> cc.getName().equals(className));

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

@@ -3,13 +3,11 @@ package org.leumasjaffe.charsheet.view.magic;
 import javax.swing.JPanel;
 import javax.swing.JPanel;
 
 
 import org.jdesktop.swingx.VerticalLayout;
 import org.jdesktop.swingx.VerticalLayout;
-import org.leumasjaffe.charsheet.model.Ability;
 import org.leumasjaffe.charsheet.model.DDCharacter;
 import org.leumasjaffe.charsheet.model.DDCharacter;
 import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.magic.DDSpellbook;
 import org.leumasjaffe.charsheet.model.magic.DDSpellbook;
 import org.leumasjaffe.charsheet.model.magic.impl.Prepared;
 import org.leumasjaffe.charsheet.model.magic.impl.Prepared;
 import org.leumasjaffe.charsheet.model.observable.BoolGate;
 import org.leumasjaffe.charsheet.model.observable.BoolGate;
-import org.leumasjaffe.charsheet.util.AbilityHelper;
 import org.leumasjaffe.observer.ObservableListener;
 import org.leumasjaffe.observer.ObservableListener;
 import org.leumasjaffe.observer.ObserverDispatch;
 import org.leumasjaffe.observer.ObserverDispatch;
 
 
@@ -79,13 +77,11 @@ public class PrepareSpellsDialog extends JPanel {
 		JPanel panel = new JPanel(new VerticalLayout(5));
 		JPanel panel = new JPanel(new VerticalLayout(5));
 		scrollPane.setViewportView(panel);
 		scrollPane.setViewportView(panel);
 		
 		
-		final Ability.Scores score = AbilityHelper.get(chara, dclass);
-
 		List<SelectPreparedSpellsPanel> panels = new ArrayList<>();
 		List<SelectPreparedSpellsPanel> panels = new ArrayList<>();
 		final BoolGate gate = new BoolGate(highestSpellLevel);
 		final BoolGate gate = new BoolGate(highestSpellLevel);
 		allReady = gate.makeListener(btnPrepareTheseSpells::setEnabled);
 		allReady = gate.makeListener(btnPrepareTheseSpells::setEnabled);
 		for (int i = 0; i < highestSpellLevel; ++i) {
 		for (int i = 0; i < highestSpellLevel; ++i) {
-			SelectPreparedSpellsPanel lvl = new SelectPreparedSpellsPanel(chara, dclass, gate.handle(i), i, (Prepared) spellBook, score);
+			SelectPreparedSpellsPanel lvl = new SelectPreparedSpellsPanel(chara, dclass, gate.handle(i), i, (Prepared) spellBook);
 			panels.add(lvl);
 			panels.add(lvl);
 			panel.add(lvl);
 			panel.add(lvl);
 		}
 		}

+ 3 - 9
src/main/lombok/org/leumasjaffe/charsheet/view/magic/SelectPreparedSpellsPanel.java

@@ -7,23 +7,17 @@ import org.leumasjaffe.charsheet.model.magic.impl.Prepared;
 import org.leumasjaffe.charsheet.model.observable.BoolGate;
 import org.leumasjaffe.charsheet.model.observable.BoolGate;
 
 
 import lombok.AccessLevel;
 import lombok.AccessLevel;
-import lombok.Getter;
 import lombok.experimental.FieldDefaults;
 import lombok.experimental.FieldDefaults;
 
 
 @SuppressWarnings("serial")
 @SuppressWarnings("serial")
 @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
 @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
 class SelectPreparedSpellsPanel extends SelectSpellsPanel {
 class SelectPreparedSpellsPanel extends SelectSpellsPanel {
 	
 	
-	private SelectPreparedSpellsPanel(DDCharacter chara, DDCharacterClass dclass, 
-			BoolGate.Handle gate, int level, Prepared prep) {
-		super(new SelectSpellsPanel.Info(chara, dclass), gate, level,
+	public SelectPreparedSpellsPanel(DDCharacter chara, DDCharacterClass dclass, BoolGate.Handle gate, int level,
+			Prepared prep) {
+		super(new SelectSpellsPanel.Info(chara, dclass, prep), gate, level, 
 				prep.getSpellsPreparedPreviouslyForLevel(level),
 				prep.getSpellsPreparedPreviouslyForLevel(level),
 				prep.spellsKnownAtLevel(level));
 				prep.spellsKnownAtLevel(level));
 	}
 	}
 
 
-	public SelectPreparedSpellsPanel(DDCharacter chara, DDCharacterClass dclass, BoolGate.Handle gate, int level,
-			Prepared spellBook, Scores score) {
-		this(chara, dclass, gate, level, ((Prepared) dclass.getSpellBook().get()));
-	}
-
 }
 }

+ 8 - 3
src/main/lombok/org/leumasjaffe/charsheet/view/magic/SelectSpellsPanel.java

@@ -10,6 +10,7 @@ import javax.swing.JPopupMenu;
 import javax.swing.JTable;
 import javax.swing.JTable;
 import javax.swing.ListSelectionModel;
 import javax.swing.ListSelectionModel;
 
 
+import org.leumasjaffe.charsheet.model.Ability;
 import org.leumasjaffe.charsheet.model.DDCharacter;
 import org.leumasjaffe.charsheet.model.DDCharacter;
 import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.magic.DDSpell;
 import org.leumasjaffe.charsheet.model.magic.DDSpell;
@@ -45,7 +46,7 @@ public class SelectSpellsPanel extends JPanel {
 	private static final String NONE = "<none>";
 	private static final String NONE = "<none>";
 
 
 	@AllArgsConstructor
 	@AllArgsConstructor
-	private static class SelectSpellModel extends AbstractTableModel {
+	protected static class SelectSpellModel extends AbstractTableModel {
 		/**
 		/**
 		 * 
 		 * 
 		 */
 		 */
@@ -81,6 +82,11 @@ public class SelectSpellsPanel extends JPanel {
 	public static class Info {
 	public static class Info {
 		DDCharacter chara;
 		DDCharacter chara;
 		DDCharacterClass dclass;
 		DDCharacterClass dclass;
+		DDSpellbook spellBook;
+		
+		public Ability.Scores ability() {
+			return AbilityHelper.get(chara, dclass);
+		}
 	}
 	}
 	
 	
 	public static final String READY = "Is Filled Out";
 	public static final String READY = "Is Filled Out";
@@ -94,7 +100,6 @@ public class SelectSpellsPanel extends JPanel {
 			Collection<DDSpell> avail, boolean allowsDuplicates, IntValue sharedValue) {
 			Collection<DDSpell> avail, boolean allowsDuplicates, IntValue sharedValue) {
 		this.allowsDuplicates = allowsDuplicates;
 		this.allowsDuplicates = allowsDuplicates;
 		this.sharedValue = sharedValue;
 		this.sharedValue = sharedValue;
-		final DDSpellbook spellBook = info.dclass.getSpellBook().get();
 		this.prepared = new ArrayList<>(prepared);
 		this.prepared = new ArrayList<>(prepared);
 		final List<DDSpell> known = new ArrayList<>(avail);
 		final List<DDSpell> known = new ArrayList<>(avail);
 		this.modelPrepared = new SelectSpellModel(createPrepareModel(prepared, toPrepare));
 		this.modelPrepared = new SelectSpellModel(createPrepareModel(prepared, toPrepare));
@@ -109,7 +114,7 @@ public class SelectSpellsPanel extends JPanel {
 		gridBagLayout.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
 		gridBagLayout.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
 		setLayout(gridBagLayout);
 		setLayout(gridBagLayout);
 		
 		
-		JPanel panel = new ChooseSpellsPerDayHeader(level, spellBook, AbilityHelper.get(info.chara, info.dclass));
+		JPanel panel = new ChooseSpellsPerDayHeader(level, info.spellBook, info.ability());
 		GridBagConstraints gbc_panel = new GridBagConstraints();
 		GridBagConstraints gbc_panel = new GridBagConstraints();
 		gbc_panel.gridwidth = 3;
 		gbc_panel.gridwidth = 3;
 		gbc_panel.insets = new Insets(0, 0, 5, 5);
 		gbc_panel.insets = new Insets(0, 0, 5, 5);