v2.0.0: code cleanup on use of DecimalFormat

This commit is contained in:
Evan Debenham
2023-02-24 12:17:48 -05:00
parent 697a16fd94
commit c9f6aba915
16 changed files with 38 additions and 54 deletions
@@ -38,8 +38,6 @@ import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle;
import com.watabou.utils.GameMath;
import java.text.DecimalFormat;
public class Berserk extends Buff implements ActionIndicator.Action {
{
@@ -302,7 +300,7 @@ public class Berserk extends Buff implements ActionIndicator.Action {
return (int)(power*100) + "%";
case RECOVERING:
if (levelRecovery > 0) {
return new DecimalFormat("#.#").format(levelRecovery);
return Messages.decimalFormat("#.##", levelRecovery);
} else {
return Integer.toString(turnRecovery);
}
@@ -28,10 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.watabou.noosa.Image;
import com.watabou.utils.Reflection;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.HashSet;
import java.util.Locale;
public class Buff extends Actor {
@@ -135,7 +132,7 @@ public class Buff extends Actor {
//to handle the common case of showing how many turns are remaining in a buff description.
protected String dispTurns(float input){
return new DecimalFormat("#.##", DecimalFormatSymbols.getInstance(Locale.ENGLISH)).format(input);
return Messages.decimalFormat("#.##", input);
}
//buffs act after the hero, so it is often useful to use cooldown+1 when display buff time remaining
@@ -26,8 +26,6 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import java.text.DecimalFormat;
public class Chill extends FlavourBuff {
public static final float DURATION = 10f;
@@ -67,6 +65,6 @@ public class Chill extends FlavourBuff {
@Override
public String desc() {
return Messages.get(this, "desc", dispTurns(), new DecimalFormat("#.##").format((1f-speedFactor())*100f));
return Messages.get(this, "desc", dispTurns(), Messages.decimalFormat("#.##", (1f-speedFactor())*100f));
}
}
@@ -46,7 +46,6 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle;
import java.text.DecimalFormat;
import java.util.ArrayList;
abstract public class ClassArmor extends Armor {
@@ -270,7 +269,7 @@ abstract public class ClassArmor extends Armor {
if (ability != null) {
desc += "\n\n" + ability.shortDesc();
float chargeUse = ability.chargeUse(Dungeon.hero);
desc += " " + Messages.get(this, "charge_use", new DecimalFormat("#.##").format(chargeUse));
desc += " " + Messages.get(this, "charge_use", Messages.decimalFormat("#.##", chargeUse));
} else {
desc += "\n\n" + "_" + Messages.get(this, "no_ability") + "_";
}
@@ -25,8 +25,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import java.text.DecimalFormat;
public class RingOfAccuracy extends Ring {
{
@@ -35,9 +33,9 @@ public class RingOfAccuracy extends Ring {
public String statsInfo() {
if (isIdentified()){
return Messages.get(this, "stats", new DecimalFormat("#.##").format(100f * (Math.pow(1.3f, soloBuffedBonus()) - 1f)));
return Messages.get(this, "stats", Messages.decimalFormat("#.##", 100f * (Math.pow(1.3f, soloBuffedBonus()) - 1f)));
} else {
return Messages.get(this, "typical_stats", new DecimalFormat("#.##").format(30f));
return Messages.get(this, "typical_stats", Messages.decimalFormat("#.##", 30f));
}
}
@@ -25,8 +25,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import java.text.DecimalFormat;
public class RingOfArcana extends Ring {
{
@@ -35,9 +33,9 @@ public class RingOfArcana extends Ring {
public String statsInfo() {
if (isIdentified()){
return Messages.get(this, "stats", new DecimalFormat("#.##").format(100f * (Math.pow(1.175f, soloBuffedBonus()) - 1f)));
return Messages.get(this, "stats", Messages.decimalFormat("#.##", 100f * (Math.pow(1.175f, soloBuffedBonus()) - 1f)));
} else {
return Messages.get(this, "typical_stats", new DecimalFormat("#.##").format(175f));
return Messages.get(this, "typical_stats", Messages.decimalFormat("#.##", 175f));
}
}
@@ -35,7 +35,6 @@ import com.shatteredpixel.shatteredpixeldungeon.items.armor.glyphs.AntiMagic;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import java.text.DecimalFormat;
import java.util.HashSet;
public class RingOfElements extends Ring {
@@ -46,9 +45,9 @@ public class RingOfElements extends Ring {
public String statsInfo() {
if (isIdentified()){
return Messages.get(this, "stats", new DecimalFormat("#.##").format(100f * (1f - Math.pow(0.825f, soloBuffedBonus()))));
return Messages.get(this, "stats", Messages.decimalFormat("#.##", 100f * (1f - Math.pow(0.825f, soloBuffedBonus()))));
} else {
return Messages.get(this, "typical_stats", new DecimalFormat("#.##").format(17.5f));
return Messages.get(this, "typical_stats", Messages.decimalFormat("#.##", 17.5f));
}
}
@@ -28,8 +28,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import java.text.DecimalFormat;
public class RingOfEnergy extends Ring {
{
@@ -39,10 +37,10 @@ public class RingOfEnergy extends Ring {
public String statsInfo() {
if (isIdentified()){
return Messages.get(this, "stats",
new DecimalFormat("#.##").format(100f * (Math.pow(1.15f, soloBuffedBonus()) - 1f)));
Messages.decimalFormat("#.##", 100f * (Math.pow(1.15f, soloBuffedBonus()) - 1f)));
} else {
return Messages.get(this, "typical_stats",
new DecimalFormat("#.##").format(15f));
Messages.decimalFormat("#.##", 15f));
}
}
@@ -25,8 +25,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import java.text.DecimalFormat;
public class RingOfEvasion extends Ring {
{
@@ -35,9 +33,9 @@ public class RingOfEvasion extends Ring {
public String statsInfo() {
if (isIdentified()){
return Messages.get(this, "stats", new DecimalFormat("#.##").format(100f * (Math.pow(1.125f, soloBuffedBonus()) - 1f)));
return Messages.get(this, "stats", Messages.decimalFormat("#.##", 100f * (Math.pow(1.125f, soloBuffedBonus()) - 1f)));
} else {
return Messages.get(this, "typical_stats", new DecimalFormat("#.##").format(12.5f));
return Messages.get(this, "typical_stats", Messages.decimalFormat("#.##", 12.5f));
}
}
@@ -25,8 +25,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import java.text.DecimalFormat;
public class RingOfFuror extends Ring {
{
@@ -35,9 +33,9 @@ public class RingOfFuror extends Ring {
public String statsInfo() {
if (isIdentified()){
return Messages.get(this, "stats", new DecimalFormat("#.##").format(100f * (Math.pow(1.0905f, soloBuffedBonus()) - 1f)));
return Messages.get(this, "stats", Messages.decimalFormat("#.##", 100f * (Math.pow(1.0905f, soloBuffedBonus()) - 1f)));
} else {
return Messages.get(this, "typical_stats", new DecimalFormat("#.##").format(9.05f));
return Messages.get(this, "typical_stats", Messages.decimalFormat("#.##", 9.05f));
}
}
@@ -25,8 +25,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import java.text.DecimalFormat;
public class RingOfHaste extends Ring {
{
@@ -35,9 +33,9 @@ public class RingOfHaste extends Ring {
public String statsInfo() {
if (isIdentified()){
return Messages.get(this, "stats", new DecimalFormat("#.##").format(100f * (Math.pow(1.2f, soloBuffedBonus()) - 1f)));
return Messages.get(this, "stats", Messages.decimalFormat("#.##", 100f * (Math.pow(1.2f, soloBuffedBonus()) - 1f)));
} else {
return Messages.get(this, "typical_stats", new DecimalFormat("#.##").format(20f));
return Messages.get(this, "typical_stats", Messages.decimalFormat("#.##", 20f));
}
}
@@ -28,8 +28,6 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import java.text.DecimalFormat;
public class RingOfMight extends Ring {
{
@@ -77,9 +75,9 @@ public class RingOfMight extends Ring {
public String statsInfo() {
if (isIdentified()){
return Messages.get(this, "stats", soloBonus(), new DecimalFormat("#.##").format(100f * (Math.pow(1.035, soloBuffedBonus()) - 1f)));
return Messages.get(this, "stats", soloBonus(), Messages.decimalFormat("#.##", 100f * (Math.pow(1.035, soloBuffedBonus()) - 1f)));
} else {
return Messages.get(this, "typical_stats", 1, new DecimalFormat("#.##").format(3.5f));
return Messages.get(this, "typical_stats", 1, Messages.decimalFormat("#.##", 3.5f));
}
}
@@ -25,8 +25,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import java.text.DecimalFormat;
public class RingOfSharpshooting extends Ring {
{
@@ -35,9 +33,9 @@ public class RingOfSharpshooting extends Ring {
public String statsInfo() {
if (isIdentified()){
return Messages.get(this, "stats", soloBuffedBonus(), new DecimalFormat("#.##").format(100f * (Math.pow(1.2, soloBonus()) - 1f)));
return Messages.get(this, "stats", soloBuffedBonus(), Messages.decimalFormat("#.##", 100f * (Math.pow(1.2, soloBonus()) - 1f)));
} else {
return Messages.get(this, "typical_stats", 1, new DecimalFormat("#.##").format(20f));
return Messages.get(this, "typical_stats", 1, Messages.decimalFormat("#.##", 20f));
}
}
@@ -25,8 +25,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import java.text.DecimalFormat;
public class RingOfTenacity extends Ring {
{
@@ -35,9 +33,9 @@ public class RingOfTenacity extends Ring {
public String statsInfo() {
if (isIdentified()){
return Messages.get(this, "stats", new DecimalFormat("#.##").format(100f * (1f - Math.pow(0.85f, soloBuffedBonus()))));
return Messages.get(this, "stats", Messages.decimalFormat("#.##", 100f * (1f - Math.pow(0.85f, soloBuffedBonus()))));
} else {
return Messages.get(this, "typical_stats", new DecimalFormat("#.##").format(15f));
return Messages.get(this, "typical_stats", Messages.decimalFormat("#.##", 15f));
}
}
@@ -46,7 +46,6 @@ import com.watabou.utils.Bundle;
import com.watabou.utils.Random;
import com.watabou.utils.Reflection;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashSet;
@@ -61,9 +60,9 @@ public class RingOfWealth extends Ring {
public String statsInfo() {
if (isIdentified()){
return Messages.get(this, "stats", new DecimalFormat("#.##").format(100f * (Math.pow(1.20f, soloBuffedBonus()) - 1f)));
return Messages.get(this, "stats", Messages.decimalFormat("#.##", 100f * (Math.pow(1.20f, soloBuffedBonus()) - 1f)));
} else {
return Messages.get(this, "typical_stats", new DecimalFormat("#.##").format(20f));
return Messages.get(this, "typical_stats", Messages.decimalFormat("#.##", 20f));
}
}
@@ -27,8 +27,11 @@ import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IllegalFormatException;
import java.util.Locale;
@@ -163,6 +166,15 @@ public class Messages {
}
}
private static HashMap<String, DecimalFormat> formatters = new HashMap<>();
public static String decimalFormat( String format, double number ){
if (!formatters.containsKey(format)){
formatters.put(format, new DecimalFormat(format, DecimalFormatSymbols.getInstance(Locale.ENGLISH)));
}
return formatters.get(format).format(number);
}
public static String capitalize( String str ){
if (str.length() == 0) return str;
else return str.substring( 0, 1 ).toUpperCase(locale) + str.substring( 1 );