Ver código fonte

Updating to observer:0.3

Sam Jaffe 8 anos atrás
pai
commit
d3583670c1
23 arquivos alterados com 41 adições e 36 exclusões
  1. 1 1
      pom.xml
  2. 1 1
      src/main/lombok/org/leumasjaffe/charsheet/controller/EquipItemController.java
  3. 1 1
      src/main/lombok/org/leumasjaffe/charsheet/model/Ability.java
  4. 1 1
      src/main/lombok/org/leumasjaffe/charsheet/model/DDCharacter.java
  5. 1 1
      src/main/lombok/org/leumasjaffe/charsheet/model/DDCharacterClass.java
  6. 1 1
      src/main/lombok/org/leumasjaffe/charsheet/model/inventory/DDEquipment.java
  7. 1 1
      src/main/lombok/org/leumasjaffe/charsheet/model/inventory/DDInventory.java
  8. 1 1
      src/main/lombok/org/leumasjaffe/charsheet/model/inventory/Money.java
  9. 1 1
      src/main/lombok/org/leumasjaffe/charsheet/model/magic/DDSpellbook.java
  10. 3 2
      src/main/lombok/org/leumasjaffe/charsheet/model/observable/BoolGate.java
  11. 1 1
      src/main/lombok/org/leumasjaffe/charsheet/model/observable/IntValue.java
  12. 1 1
      src/main/lombok/org/leumasjaffe/charsheet/model/observable/ObjectValue.java
  13. 1 1
      src/main/lombok/org/leumasjaffe/charsheet/model/observable/StringValue.java
  14. 7 5
      src/main/lombok/org/leumasjaffe/charsheet/observer/ObserverHelper.java
  15. 3 2
      src/main/lombok/org/leumasjaffe/charsheet/observer/helper/IntValueHelper.java
  16. 3 2
      src/main/lombok/org/leumasjaffe/charsheet/observer/helper/StringValueHelper.java
  17. 2 2
      src/main/lombok/org/leumasjaffe/charsheet/view/inventory/EquipmentInfoMenu.java
  18. 2 2
      src/main/lombok/org/leumasjaffe/charsheet/view/inventory/ItemInfoMenu.java
  19. 1 1
      src/main/lombok/org/leumasjaffe/charsheet/view/inventory/LoadoutMenu.java
  20. 1 1
      src/main/lombok/org/leumasjaffe/charsheet/view/level/ExperienceDialog.java
  21. 3 3
      src/main/lombok/org/leumasjaffe/charsheet/view/level/UpdateClassWithLevelPanel.java
  22. 1 1
      src/main/lombok/org/leumasjaffe/charsheet/view/magic/SpellMenu.java
  23. 3 3
      src/main/lombok/org/leumasjaffe/charsheet/view/skills/SkillLevelUpLine.java

+ 1 - 1
pom.xml

@@ -171,7 +171,7 @@
     <dependency>
       <groupId>org.leumasjaffe</groupId>
       <artifactId>observer</artifactId>
-      <version>0.1</version>
+      <version>0.3</version>
     </dependency>
     <dependency>
       <groupId>org.leumasjaffe</groupId>

+ 1 - 1
src/main/lombok/org/leumasjaffe/charsheet/controller/EquipItemController.java

@@ -19,7 +19,7 @@ public class EquipItemController {
 		if (inv.canEquip(item) || new Helper(inv).getReplaceItem(item.getSlot())) {
 			item.adjustCounEquipped(+1);
 			inv.equipNext(item);
-			ObserverDispatch.notifySubscribers(inv, null);
+			ObserverDispatch.notifySubscribers(inv);
 		}
 	}
 

+ 1 - 1
src/main/lombok/org/leumasjaffe/charsheet/model/Ability.java

@@ -39,7 +39,7 @@ public class Ability {
 	@AllArgsConstructor
 	@EqualsAndHashCode(callSuper=false)
 	@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
-	public static class Scores extends Observable {
+	public static class Scores extends Observable.Instance {
 		IntValue base, temp;
 		
 		@JsonCreator

+ 1 - 1
src/main/lombok/org/leumasjaffe/charsheet/model/DDCharacter.java

@@ -32,7 +32,7 @@ import lombok.experimental.FieldDefaults;
 @Data @EqualsAndHashCode(callSuper=false)
 @FieldDefaults(level=AccessLevel.PRIVATE)
 @JsonIgnoreProperties(ignoreUnknown=true)
-public class DDCharacter extends Observable {
+public class DDCharacter extends Observable.Instance {
 	@NonNull String name = "";
 	
 	@NonNull String player = "";

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

@@ -24,7 +24,7 @@ import lombok.experimental.FieldDefaults;
 @Data @AllArgsConstructor
 @EqualsAndHashCode(callSuper=false)
 @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
-public class DDCharacterClass extends Observable implements Comparable<DDCharacterClass> {
+public class DDCharacterClass extends Observable.Instance implements Comparable<DDCharacterClass> {
 	private static final class Reference {
 		DDClass base;
 		

+ 1 - 1
src/main/lombok/org/leumasjaffe/charsheet/model/inventory/DDEquipment.java

@@ -18,7 +18,7 @@ import lombok.experimental.FieldDefaults;
 @ToString
 @EqualsAndHashCode(callSuper=false)
 @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
-public class DDEquipment extends Observable {
+public class DDEquipment extends Observable.Instance {
 	@NonNull Map<EquipmentSlot, DDItem> equipment = new EnumMap<>(EquipmentSlot.class);
 
 	public boolean canEquip(final DDItem item) {

+ 1 - 1
src/main/lombok/org/leumasjaffe/charsheet/model/inventory/DDInventory.java

@@ -16,7 +16,7 @@ import lombok.experimental.NonFinal;
 @Getter @Setter @ToString
 @EqualsAndHashCode(callSuper=false)
 @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
-public class DDInventory extends Observable {
+public class DDInventory extends Observable.Instance {
 	@AllArgsConstructor
 	public static class Serializable {
 		@NonNull List<DDItem> items;

+ 1 - 1
src/main/lombok/org/leumasjaffe/charsheet/model/inventory/Money.java

@@ -11,7 +11,7 @@ import lombok.experimental.FieldDefaults;
 @AllArgsConstructor
 @Data @EqualsAndHashCode(callSuper=false)
 @FieldDefaults(level=AccessLevel.PRIVATE)
-public class Money extends Observable implements Comparable<Money> {
+public class Money extends Observable.Instance implements Comparable<Money> {
 	int pp, gp, sp, cp;
 	
 	public Money assign(final Money other) {

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

@@ -13,7 +13,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
 import lombok.NonNull;
 
 @JsonTypeInfo(use = Id.MINIMAL_CLASS)
-public abstract class DDSpellbook extends Observable {
+public abstract class DDSpellbook extends Observable.Instance {
 	@NonNull public abstract Collection<DDSpell> spellsKnownAtLevel( int level );
 	@NonNull public abstract List<DDSpell> spellsPreparedAtLevel( int level );
 	

+ 3 - 2
src/main/lombok/org/leumasjaffe/charsheet/model/observable/BoolGate.java

@@ -10,7 +10,7 @@ import lombok.AllArgsConstructor;
 import lombok.experimental.FieldDefaults;
 
 @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
-public class BoolGate extends Observable {
+public class BoolGate extends Observable.Instance {
 	boolean[] data;
 	int size;
 	
@@ -20,9 +20,10 @@ public class BoolGate extends Observable {
 		int index;
 		public boolean get() { return BoolGate.this.get(index); }
 		public void set(Object source, boolean bool) {
+			// FIXME
 			if (bool != get()) {
 				BoolGate.this.set(index, bool);
-				ObserverDispatch.notifySubscribers(BoolGate.this, source);
+				ObserverDispatch.notifySubscribers(BoolGate.this);
 			}
 		}
 	}

+ 1 - 1
src/main/lombok/org/leumasjaffe/charsheet/model/observable/IntValue.java

@@ -14,7 +14,7 @@ import lombok.experimental.Accessors;
 @Data
 @NoArgsConstructor
 @EqualsAndHashCode(callSuper=false)
-public class IntValue extends Observable {
+public class IntValue extends Observable.Instance {
 	@JsonCreator
 	public IntValue(int v) { this.value = v; }
 	private int value = -1;

+ 1 - 1
src/main/lombok/org/leumasjaffe/charsheet/model/observable/ObjectValue.java

@@ -13,7 +13,7 @@ import lombok.experimental.Accessors;
 @Accessors(fluent=true)
 @Data
 @EqualsAndHashCode(callSuper=false)
-public class ObjectValue<T> extends Observable {
+public class ObjectValue<T> extends Observable.Instance {
 	@JsonCreator public ObjectValue(T v) { this.value = v; }
 	private @NonNull T value;
 	

+ 1 - 1
src/main/lombok/org/leumasjaffe/charsheet/model/observable/StringValue.java

@@ -15,7 +15,7 @@ import lombok.experimental.Accessors;
 @NoArgsConstructor
 @Data
 @EqualsAndHashCode(callSuper=false)
-public class StringValue extends Observable {
+public class StringValue extends Observable.Instance {
 	@JsonCreator public StringValue(String v) { this.value = v; }
 	private @NonNull String value = "";
 	

+ 7 - 5
src/main/lombok/org/leumasjaffe/charsheet/observer/ObserverHelper.java

@@ -9,13 +9,15 @@ import lombok.experimental.UtilityClass;
 @UtilityClass
 public class ObserverHelper {
 	public void notifyObservableHierarchy(final DDCharacterClass dclass, final Object src) {
-		ObserverDispatch.notifySubscribers(dclass, src);
-		dclass.getSpellBook().ifPresent(sb -> ObserverDispatch.notifySubscribers(sb, src));
+		ObserverDispatch.notifySubscribers(dclass);
+		// FIXME
+		dclass.getSpellBook().ifPresent(sb -> ObserverDispatch.notifySubscribers(sb));
 	}
 	
 	public void notifyObservableHierarchy(final Ability.Scores abil, final Object src) {
-		ObserverDispatch.notifySubscribers(abil, src);
-		ObserverDispatch.notifySubscribers(abil.getBase(), src);
-		ObserverDispatch.notifySubscribers(abil.getTemp(), src);
+		// FIXME
+		ObserverDispatch.notifySubscribers(abil);
+		ObserverDispatch.notifySubscribers(abil.getBase());
+		ObserverDispatch.notifySubscribers(abil.getTemp());
 	}
 }

+ 3 - 2
src/main/lombok/org/leumasjaffe/charsheet/observer/helper/IntValueHelper.java

@@ -1,9 +1,10 @@
 package org.leumasjaffe.charsheet.observer.helper;
 
+import java.util.function.BiFunction;
+
 import org.leumasjaffe.charsheet.model.observable.IntValue;
-import org.leumasjaffe.observer.helper.Helper;
 
-public class IntValueHelper implements Helper<IntValue> {
+public class IntValueHelper implements BiFunction<String, IntValue, Boolean> {
     public Boolean apply( final String str, final IntValue ref ) {
       if ( ! Character.isDigit(str.charAt(0)) ) return false;
       final int newValue = Integer.parseInt( str );

+ 3 - 2
src/main/lombok/org/leumasjaffe/charsheet/observer/helper/StringValueHelper.java

@@ -1,9 +1,10 @@
 package org.leumasjaffe.charsheet.observer.helper;
 
+import java.util.function.BiFunction;
+
 import org.leumasjaffe.charsheet.model.observable.StringValue;
-import org.leumasjaffe.observer.helper.Helper;
 
-public class StringValueHelper implements Helper<StringValue> {
+public class StringValueHelper implements BiFunction<String, StringValue, Boolean> {
     public Boolean apply( final String str, final StringValue ref ) {
       if ( str.equals( ref.value( ) ) ) return false;
       ref.value( str );

+ 2 - 2
src/main/lombok/org/leumasjaffe/charsheet/view/inventory/EquipmentInfoMenu.java

@@ -37,8 +37,8 @@ class EquipmentInfoMenu extends JPopupMenu {
 					== JOptionPane.YES_OPTION) {
 				item.adjustCounEquipped(-1);
 				equip.unequip(slot);
-				ObserverDispatch.notifySubscribers(equip, null);
-				ObserverDispatch.notifySubscribers(item.getCountEquipped(), null);
+				ObserverDispatch.notifySubscribers(equip);
+				ObserverDispatch.notifySubscribers(item.getCountEquipped());
 			}
 		});
 		add(mntmEquip);

+ 2 - 2
src/main/lombok/org/leumasjaffe/charsheet/view/inventory/ItemInfoMenu.java

@@ -110,8 +110,8 @@ class ItemInfoMenu extends JPopupMenu {
 			item.getCount().value(item.getCount().value() + selected);
 			final Money wealth = inv.getWealth();
 			wealth.assign(wealth.difference(Money.fromCopper(selected * txnPrice)));
-			ObserverDispatch.notifySubscribers(item.getCount(), null);
-			ObserverDispatch.notifySubscribers(wealth, null);
+			ObserverDispatch.notifySubscribers(item.getCount());
+			ObserverDispatch.notifySubscribers(wealth);
 		}
 	}
 }

+ 1 - 1
src/main/lombok/org/leumasjaffe/charsheet/view/inventory/LoadoutMenu.java

@@ -38,7 +38,7 @@ class LoadoutMenu extends JPopupMenu {
 			showLoadDialog().ifPresent(name -> {
 				try {
 					getModel().load(name);
-					ObserverDispatch.notifySubscribers(getModel(), null);
+					ObserverDispatch.notifySubscribers(getModel());
 				} catch (NullPointerException except) {
 					JOptionPane.showMessageDialog(this, "Unable to load equipment, some items are missing", 
 							"Error", JOptionPane.ERROR_MESSAGE);

+ 1 - 1
src/main/lombok/org/leumasjaffe/charsheet/view/level/ExperienceDialog.java

@@ -28,7 +28,7 @@ public class ExperienceDialog {
 		if (exp <= 0) return;
 		final IntValue mdlExp = model.getExperience();
 		mdlExp.value(mdlExp.value()+exp);
-		ObserverDispatch.notifySubscribers(mdlExp, null);
+		ObserverDispatch.notifySubscribers(mdlExp);
 	}
 	
 	public static int computeLevelsNeeded(DDCharacter chara, int bonusLevels) {

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

@@ -83,7 +83,7 @@ class UpdateClassWithLevelPanel extends JPanel {
 		skills = new SkillLevelUpPanel(info.ddCharacter, info.ddClass) {
 			@Override public void setIsReady(boolean b) {
 				readyCount.set(CHOOSE_SKILL_INDEX, b);
-				ObserverDispatch.notifySubscribers(readyCount, null);
+				ObserverDispatch.notifySubscribers(readyCount);
 			}
 		};
 		tabbedPane.addTab("Skills", null, skills, null);
@@ -221,7 +221,7 @@ class UpdateClassWithLevelPanel extends JPanel {
 		final IntValue exp = levelUpInfo.ddCharacter.getExperience();
 		final int neededExp = ExperienceDialog.experienceForLevel(levelUpInfo.ddCharacter.getLevel());
 		if (exp.value() < neededExp) { exp.value(neededExp); }
-		ObserverDispatch.notifySubscribers(exp, this);
-		ObserverDispatch.notifySubscribers(levelUpInfo.ddCharacter, null);
+		ObserverDispatch.notifySubscribers(exp);
+		ObserverDispatch.notifySubscribers(levelUpInfo.ddCharacter);
 	}
 }

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

@@ -40,7 +40,7 @@ class SpellMenu extends JPopupMenu {
 					return;
 				}
 				book.castSpell(spellLevel, spell);
-				ObserverDispatch.notifySubscribers(book, null);
+				ObserverDispatch.notifySubscribers(book);
 			});
 			add(mntmCast);
 		}

+ 3 - 3
src/main/lombok/org/leumasjaffe/charsheet/view/skills/SkillLevelUpLine.java

@@ -204,8 +204,8 @@ class SkillLevelUpLine extends JPanel {
 			pointsAvaliable.value(pointsAvaliable.value() - (value * pointsPerRank));
 			current.value(current.value() + value);
 			points.setText(Integer.toString(current.value()));
-			ObserverDispatch.notifySubscribers(pointsAvaliable, this);
-			ObserverDispatch.notifySubscribers(current, this);
+			ObserverDispatch.notifySubscribers(pointsAvaliable); // TODO (this)?
+			ObserverDispatch.notifySubscribers(current); // TODO (this)?
 			return null;
 		};
 		
@@ -240,7 +240,7 @@ class SkillLevelUpLine extends JPanel {
 
 	public void applyChange() {
 		skill.spendPoints(current.value(), !isClassSkill);
-		ObserverDispatch.notifySubscribers(skill.getRanks(), this);
+		ObserverDispatch.notifySubscribers(skill.getRanks()); // TODO (this)?
 	}
 	
 	@Override