Moved alternate listener to separate CharData.AlternateListener class

This change removed need for EquipAdapter
This commit is contained in:
Collin Smith 2020-01-10 19:22:39 -08:00
parent 997c57ad5e
commit 6cbea53c19
3 changed files with 20 additions and 16 deletions

View File

@ -71,6 +71,8 @@ public class CharData {
private byte[] data; // TODO: replace this reference with D2S.serialize(CharData)
final Array<AlternateListener> alternateListeners = new Array<>(false, 16);
final IntIntMap skills = new IntIntMap();
final Array<Stat> chargedSkills = new Array<>(false, 16);
final Array<SkillListener> 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<Stat> 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);
}
}

View File

@ -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) {}
}

View File

@ -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);
}
}