Added item stat grouping (needs optimization)

This commit is contained in:
Collin Smith 2019-03-22 02:03:01 -07:00
parent 852dc8c889
commit 703571c989
2 changed files with 63 additions and 4 deletions

View File

@ -10,6 +10,8 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.IntSet;
import com.riiablo.Riiablo;
import com.riiablo.codec.DC6;
import com.riiablo.codec.Index;
@ -780,6 +782,41 @@ public class Item extends Actor implements Disposable {
for (int i = 0; i < stats.length; i++) {
Array<Stat.Instance> stats = Item.this.stats[i];
if (stats == null) continue;
// TODO: This can be cleaned up later
IntMap<Array<Stat.Instance>> groups = new IntMap<>();
for (Stat.Instance stat : stats) {
int dgrp = stat.stat.entry().dgrp;
if (dgrp > 0) {
Array<Stat.Instance> group = groups.get(dgrp);
if (group == null) groups.put(dgrp, group = new Array<>());
group.add(stat);
}
}
IntSet groupReplaced = new IntSet();
IntMap<Stat.Instance> groupReplacements = new IntMap<>();
for (IntMap.Entry<Array<Stat.Instance>> group : groups) {
switch (group.key) {
case 1:
case 2:
if (group.value.size == 4) {
boolean allEqual = true;
Stat.Instance first = group.value.first();
for (int j = 1; allEqual && j < group.value.size; j++) {
Stat.Instance stat = group.value.get(j);
allEqual = (stat.value == first.value) && (stat.param == first.param);
}
if (allEqual) {
groupReplacements.put(group.key, first);
}
}
break;
default:
}
}
stats.sort(new Comparator<Stat.Instance>() {
@Override
public int compare(Stat.Instance o1, Stat.Instance o2) {
@ -788,7 +825,20 @@ public class Item extends Actor implements Disposable {
});
for (Stat.Instance stat : stats) {
Label label = new Label(stat.format(), font);
Label label;
int dgrp = stat.stat.entry().dgrp;
boolean group = false;
if (dgrp > 0) {
if (groupReplaced.contains(dgrp)) continue;
Stat.Instance grp = groupReplacements.get(dgrp);
if (grp != null) {
stat = grp;
group = true;
groupReplaced.add(dgrp);
}
}
label = new Label(stat.format(group), font);
add(label).center().space(SPACING).row();
}
}

View File

@ -424,12 +424,12 @@ public enum Stat {
this.param = param;
}
public String format() {
public String format(boolean group) {
CharStats.Entry entry;
Skills.Entry skill;
SkillDesc.Entry desc;
switch (stat.entry.descfunc) {
case 1: return String.format("+%d %s", value, descstr());
switch (group ? stat.entry.dgrpfunc : stat.entry.descfunc) {
case 1: return String.format("+%d %s", value, descstr(group));
case 2: return String.format("%d%% %s", value, descstr());
case 3: return String.format("%d %s", value, descstr());
case 4: return String.format("+%d%% %s", value, descstr());
@ -455,6 +455,7 @@ public enum Stat {
skill = Riiablo.files.skills.get(param);
desc = Riiablo.files.skilldesc.get(skill.skilldesc);
return Riiablo.string.format(stat.entry.descstrpos, value, Riiablo.string.lookup(desc.str_name));
case 19: return String.format(descstr(group), value);
case 20: return String.format("%d%% %s", -value, descstr());
case 22: return toString();
case 23: return toString();
@ -483,6 +484,14 @@ public enum Stat {
return Riiablo.string.lookup(value < 0 ? stat.entry.descstrneg : stat.entry.descstrpos);
}
private String descstr(boolean group) {
if (group) {
return Riiablo.string.lookup(value < 0 ? stat.entry.dgrpstrneg : stat.entry.dgrpstrpos);
} else {
return Riiablo.string.lookup(value < 0 ? stat.entry.descstrneg : stat.entry.descstrpos);
}
}
private String descstr2() {
return Riiablo.string.lookup(stat.entry.descstr2);
}