Browse Source

Adding concept of DDPropertyChooser.
This way, a class feature with choices will automatically be transformed into a normal feature.

Sam Jaffe 8 năm trước cách đây
mục cha
commit
97c169c72c

+ 5 - 5
resources/classes/Bard.json

@@ -7,11 +7,11 @@
   "will":"GOOD",
   "features":[
     [
-      {"@c": ".impl.Simple", "name": "Bardic Music"},
-      {"@c": ".impl.Simple", "name": "Bardic Knowledge"},
-      {"@c": ".impl.Simple", "name": "Countersong"},
-      {"@c": ".impl.Simple", "name": "Fascinate"},
-      {"@c": ".impl.Simple", "name": "Inspire Courage +1"}
+      {"@c":".impl.Simple$Chooser", "name":"Bardic Music"},
+      {"@c":".impl.Simple$Chooser", "name":"Bardic Knowledge"},
+      {"@c":".impl.Simple$Chooser", "name":"Countersong"},
+      {"@c":".impl.Simple$Chooser", "name":"Fascinate"},
+      {"@c":".impl.Simple$Chooser", "name":"Inspire Courage +1"}
     ],
     []
   ],

+ 7 - 1
resources/classes/Cleric.json

@@ -8,8 +8,14 @@
   "features":[
     [
       {
-        "@c": ".impl.Simple",
+        "@c":".impl.Simple$Chooser",
         "name":"Turn or Rebuke Undead"
+      },
+      {
+        "@c":".impl.DomainFeature$Chooser",
+        "name":"Domain",
+        "times":2,
+        "choices":["Earth","Plant"]
       }
     ]
   ],

+ 18 - 5
src/main/lombok/org/leumasjaffe/charsheet/model/DDCharacterClass.java

@@ -1,9 +1,9 @@
 package org.leumasjaffe.charsheet.model;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
-import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
 import org.leumasjaffe.charsheet.model.features.DDProperty;
@@ -77,11 +77,17 @@ public class DDCharacterClass extends Observable.Instance implements Comparable<
 					secondary.map(Stream::of).orElse(Stream.empty())).toArray(DDSpellbook[]::new);
 		}
 		
+		public void setSecondary(DDSpellbook book) {
+			assert(!secondary.isPresent());
+			secondary = Optional.of(book);
+		}
+		
 		DDSpellbook main;
 		Optional<DDSpellbook> secondary = Optional.empty();
 	}
 	
 	Optional<DDSpellbookWrapper> spellBook;
+	@Getter(AccessLevel.PRIVATE) List<DDProperty> features = new ArrayList<>();
 	
 	public DDCharacterClass(String name) {
 		this.level = new IntValue(0);
@@ -141,9 +147,16 @@ public class DDCharacterClass extends Observable.Instance implements Comparable<
 	}
 
 	public List<DDProperty> getFeatureBonuses(Object appliesScope) {
-		return IntStream.rangeClosed(1, level.value())
-				.mapToObj(level -> name.base.getFeatures(level).stream())
-				.reduce(Stream.empty(), (l, r) -> Stream.concat(l, r))
-				.filter(p -> p.appliesTo(appliesScope)).collect(Collectors.toList());
+		return this.features.stream().filter(p -> p.appliesTo(appliesScope)).collect(Collectors.toList());
+	}
+	
+	@SuppressWarnings("unused")
+	private void setFeatures(List<DDProperty> feats) {
+		this.features.clear();
+		this.features.addAll(feats);
+	}
+
+	public void addFeature(DDProperty ddProperty) {
+		this.features.add(ddProperty);
 	}
 }

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

@@ -11,7 +11,7 @@ import java.util.Optional;
 import java.util.Set;
 
 import org.leumasjaffe.charsheet.model.DDCharacterClass.DDSpellbookWrapper;
-import org.leumasjaffe.charsheet.model.features.DDProperty;
+import org.leumasjaffe.charsheet.model.features.DDPropertyChooser;
 import org.leumasjaffe.charsheet.model.magic.DDSpell;
 import org.leumasjaffe.charsheet.model.magic.DDSpellList;
 import org.leumasjaffe.charsheet.model.magic.DDSpellList.SpellList;
@@ -48,7 +48,7 @@ public class DDClass {
 	@NonNull SaveQuality ref;
 	@NonNull SaveQuality will;
 	
-	@Getter(AccessLevel.NONE) @NonNull List<List<DDProperty>> features;
+	@Getter(AccessLevel.NONE) @NonNull List<List<DDPropertyChooser>> features;
 	
 	@NonNull Set<String> skills;
 	
@@ -78,7 +78,7 @@ public class DDClass {
 		return skills.contains(skillName);
 	}
 
-	public List<DDProperty> getFeatures(int level) {
+	public List<DDPropertyChooser> getFeatures(int level) {
 		return features.size() < level ? Collections.emptyList() :
 			Collections.unmodifiableList(features.get(level-1));
 	}

+ 20 - 0
src/main/lombok/org/leumasjaffe/charsheet/model/features/DDPropertyChooser.java

@@ -0,0 +1,20 @@
+package org.leumasjaffe.charsheet.model.features;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.leumasjaffe.charsheet.model.DDCharacterClass;
+
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
+
+@JsonTypeInfo(use=Id.MINIMAL_CLASS)
+public interface DDPropertyChooser {
+	default int getTimes() { return 1; }
+	String getHeader();
+	default List<String> getChoices() { return Collections.emptyList(); }
+	public DDProperty get(String forSelection);
+	default void apply(DDCharacterClass to, String forSelection) {
+		to.addFeature(get(forSelection));
+	}
+}

+ 42 - 0
src/main/lombok/org/leumasjaffe/charsheet/model/features/impl/DomainFeature.java

@@ -0,0 +1,42 @@
+package org.leumasjaffe.charsheet.model.features.impl;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.leumasjaffe.charsheet.model.DDCharacterClass;
+import org.leumasjaffe.charsheet.model.features.DDProperty;
+import org.leumasjaffe.charsheet.model.features.DDPropertyChooser;
+import org.leumasjaffe.charsheet.model.features.GroupedBonus;
+import org.leumasjaffe.charsheet.model.magic.impl.Domain;
+import org.leumasjaffe.collections.Tree;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.experimental.Delegate;
+
+@AllArgsConstructor @Getter @Setter
+public class DomainFeature implements DDProperty {
+	private static interface IFaceHelper {
+		void setName(String name);
+		void setDescription(String desc);
+	}
+	@Getter @Setter
+	public static class Chooser implements DDPropertyChooser {
+		@Delegate(types=IFaceHelper.class) DomainFeature impl = new DomainFeature("", "");
+		List<String> choices = Collections.emptyList();
+		int times;
+		
+		@Override public String getHeader() { return impl.getName(); }
+		@Override public DDProperty get(String forSelection) {
+			return new DomainFeature(impl.getName() + " " + forSelection, impl.getDescription());
+		}
+		@Override public void apply(DDCharacterClass to, String forSelection) { 
+			to.addFeature(get(forSelection));
+			to.getSpellBook().get().setSecondary(new Domain());
+		}
+	}
+	String name, description;
+	@Override public boolean appliesTo(Object key) { return false; }
+	@Override public void accumulate(Tree<String, GroupedBonus> props, Object... data) {}
+}

+ 18 - 3
src/main/lombok/org/leumasjaffe/charsheet/model/features/impl/Simple.java

@@ -1,16 +1,31 @@
 package org.leumasjaffe.charsheet.model.features.impl;
 
 import org.leumasjaffe.charsheet.model.features.DDProperty;
+import org.leumasjaffe.charsheet.model.features.DDPropertyChooser;
 import org.leumasjaffe.charsheet.model.features.GroupedBonus;
 import org.leumasjaffe.collections.Tree;
 
 import lombok.AllArgsConstructor;
 import lombok.Getter;
+import lombok.Setter;
+import lombok.experimental.Delegate;
 
-@AllArgsConstructor @Getter
+@AllArgsConstructor @Getter @Setter
 public class Simple implements DDProperty {
-	String name;
-	String description;
+	private static interface IFaceHelper {
+		void setName(String name);
+		void setDescription(String desc);
+	}
+	@Getter @Setter
+	public static class Chooser implements DDPropertyChooser {
+		@Delegate(types=IFaceHelper.class) Simple impl = new Simple("", "");
+		
+		@Override public String getHeader() { return impl.getName(); }
+		@Override public DDProperty get(String selected) { 
+			return new Simple(impl.getName() + selected, impl.getDescription());
+		}
+	}
+	String name, description;
 	@Override public boolean appliesTo(Object key) { return false; }
 	@Override public void accumulate(Tree<String, GroupedBonus> props, Object... data) {}
 }

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

@@ -1,6 +1,5 @@
 package org.leumasjaffe.charsheet.view.level;
 
-import javax.swing.JLabel;
 import javax.swing.JPanel;
 
 import org.jdesktop.swingx.VerticalLayout;
@@ -81,7 +80,9 @@ class LU_FeaturesPanel extends JPanel {
 		gbc_features.gridy = 1;
 		panel_1.add(features, gbc_features);
 		info.ddClass.getProto().getFeatures(info.toLevel).forEach(prop -> {
-			features.add(new JLabel(prop.getName()));
+			for (int i = 0; i < prop.getTimes(); ++i) {
+				features.add(new PropertyChoicePanel(prop));
+			}
 		});
 		
 		abilPanel = new LU_AbilityPanel(info, gate.handle(ABIL_INDEX));

+ 41 - 0
src/main/lombok/org/leumasjaffe/charsheet/view/level/PropertyChoicePanel.java

@@ -0,0 +1,41 @@
+package org.leumasjaffe.charsheet.view.level;
+
+import javax.swing.JPanel;
+
+import org.leumasjaffe.charsheet.model.features.DDPropertyChooser;
+import java.awt.GridBagLayout;
+import javax.swing.JLabel;
+import java.awt.GridBagConstraints;
+import javax.swing.JComboBox;
+import java.awt.Insets;
+
+@SuppressWarnings("serial")
+public class PropertyChoicePanel extends JPanel {
+
+	public PropertyChoicePanel(DDPropertyChooser prop) {
+		GridBagLayout gridBagLayout = new GridBagLayout();
+		gridBagLayout.columnWidths = new int[]{0, 0, 0};
+		gridBagLayout.rowHeights = new int[]{0, 0};
+		gridBagLayout.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
+		gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
+		setLayout(gridBagLayout);
+		
+		JLabel lblName = new JLabel(prop.getHeader());
+		GridBagConstraints gbc_lblName = new GridBagConstraints();
+		gbc_lblName.insets = new Insets(0, 0, 0, 5);
+		gbc_lblName.anchor = GridBagConstraints.EAST;
+		gbc_lblName.gridx = 0;
+		gbc_lblName.gridy = 0;
+		add(lblName, gbc_lblName);
+		
+		if (!prop.getChoices().isEmpty()) {
+			JComboBox<String> comboBox = new JComboBox<>(prop.getChoices().toArray(new String[0]));
+			GridBagConstraints gbc_comboBox = new GridBagConstraints();
+			gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
+			gbc_comboBox.gridx = 1;
+			gbc_comboBox.gridy = 0;
+			add(comboBox, gbc_comboBox);
+		}
+	}
+
+}