Fixed square numbers in stats

This commit is contained in:
Anuken
2022-01-21 00:08:56 -05:00
parent b3d4dc06d4
commit a121c4d042
6 changed files with 19 additions and 8 deletions

View File

@@ -54,7 +54,7 @@ public class PayloadConveyor extends Block{
public void setStats(){
super.setStats();
stats.add(Stat.payloadCapacity, (payloadLimit), StatUnit.blocksSquared);
stats.add(Stat.payloadCapacity, StatValues.squared(payloadLimit, StatUnit.blocksSquared));
}
@Override

View File

@@ -78,7 +78,7 @@ public class PayloadMassDriver extends PayloadBlock{
public void setStats(){
super.setStats();
stats.add(Stat.payloadCapacity, maxPayloadSize, StatUnit.blocksSquared);
stats.add(Stat.payloadCapacity, StatValues.squared(maxPayloadSize, StatUnit.blocksSquared));
stats.add(Stat.reload, 60f / (chargeTime + reloadTime), StatUnit.seconds);
}

View File

@@ -34,11 +34,22 @@ public class StatValues{
return table -> table.add(!value ? "@no" : "@yes");
}
public static String fixValue(float value){
int precision = Math.abs((int)value - value) <= 0.001f ? 0 : Math.abs((int)(value * 10) - value * 10) <= 0.001f ? 1 : 2;
return Strings.fixed(value, precision);
}
public static StatValue squared(float value, StatUnit unit){
return table -> {
String fixed = fixValue(value);
table.add(fixed + "x" + fixed);
table.add((unit.space ? " " : "") + unit.localized());
};
}
public static StatValue number(float value, StatUnit unit, boolean merge){
return table -> {
int precision = Math.abs((int)value - value) <= 0.001f ? 0 : Math.abs((int)(value * 10) - value * 10) <= 0.001f ? 1 : 2;
String l1 = Strings.fixed(value, precision), l2 = (unit.space ? " " : "") + unit.localized();
String l1 = fixValue(value), l2 = (unit.space ? " " : "") + unit.localized();
if(merge){
table.add(l1 + l2);