From 6cbea53c19f4faf428cb77a1c56901ac4b1f823d Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Fri, 10 Jan 2020 19:22:39 -0800 Subject: [PATCH] Moved alternate listener to separate CharData.AlternateListener class This change removed need for EquipAdapter --- core/src/com/riiablo/save/CharData.java | 20 +++++++++++++++++++- core/src/com/riiablo/save/EquipAdapter.java | 9 --------- core/src/com/riiablo/save/ItemData.java | 7 +------ 3 files changed, 20 insertions(+), 16 deletions(-) delete mode 100644 core/src/com/riiablo/save/EquipAdapter.java diff --git a/core/src/com/riiablo/save/CharData.java b/core/src/com/riiablo/save/CharData.java index 7a9a1c38..13ebc2af 100644 --- a/core/src/com/riiablo/save/CharData.java +++ b/core/src/com/riiablo/save/CharData.java @@ -71,6 +71,8 @@ public class CharData { private byte[] data; // TODO: replace this reference with D2S.serialize(CharData) + final Array alternateListeners = new Array<>(false, 16); + final IntIntMap skills = new IntIntMap(); final Array chargedSkills = new Array<>(false, 16); final Array skillListeners = new Array<>(false, 16); @@ -156,6 +158,8 @@ public class CharData { mercData.itemData.clear(); golemItemData = null; + alternateListeners.clear(); + skills.clear(); chargedSkills.clear(); skillListeners.clear(); @@ -467,7 +471,7 @@ public class CharData { Item LH = getEquipped(BodyLoc.LARM); Item RH = getEquipped(BodyLoc.RARM); updateStats(); - itemData.notifyEquipmentAlternated(alternate, LH, RH); + notifyAlternated(alternate, LH, RH); } } @@ -494,6 +498,7 @@ public class CharData { public void clearListeners() { itemData.equipListeners.clear(); mercData.itemData.equipListeners.clear(); + alternateListeners.clear(); skillListeners.clear(); } @@ -509,4 +514,17 @@ public class CharData { public interface SkillListener { void onChanged(CharData client, IntIntMap skills, Array chargedSkills); } + + public boolean addAlternateListener(AlternateListener l) { + alternateListeners.add(l); + return true; + } + + private void notifyAlternated(int alternate, Item LH, Item RH) { + for (AlternateListener l : alternateListeners) l.onAlternated(this, alternate, LH, RH); + } + + public interface AlternateListener { + void onAlternated(CharData charData, int alternate, Item LH, Item RH); + } } diff --git a/core/src/com/riiablo/save/EquipAdapter.java b/core/src/com/riiablo/save/EquipAdapter.java deleted file mode 100644 index dc577e97..00000000 --- a/core/src/com/riiablo/save/EquipAdapter.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.riiablo.save; - -import com.riiablo.item.BodyLoc; -import com.riiablo.item.Item; - -public class EquipAdapter implements ItemData.EquipListener { - @Override public void onChanged(ItemData items, BodyLoc bodyLoc, Item oldItem, Item item) {} - @Override public void onAlternated(ItemData items, int alternate, Item LH, Item RH) {} -} diff --git a/core/src/com/riiablo/save/ItemData.java b/core/src/com/riiablo/save/ItemData.java index 4c46cfc7..c30f1520 100644 --- a/core/src/com/riiablo/save/ItemData.java +++ b/core/src/com/riiablo/save/ItemData.java @@ -146,16 +146,11 @@ public class ItemData { return true; } - void notifyEquipmentChanged(BodyLoc bodyLoc, Item oldItem, Item item) { + private void notifyEquipmentChanged(BodyLoc bodyLoc, Item oldItem, Item item) { for (EquipListener l : equipListeners) l.onChanged(this, bodyLoc, oldItem, item); } - void notifyEquipmentAlternated(int alternate, Item LH, Item RH) { - for (EquipListener l : equipListeners) l.onAlternated(this, alternate, LH, RH); - } - public interface EquipListener { void onChanged(ItemData items, BodyLoc bodyLoc, Item oldItem, Item item); - void onAlternated(ItemData items, int alternate, Item LH, Item RH); } }