From e7d8f78e42848e11a0d745d0af580d743f8c92be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20D=C3=ADaz?= Date: Sun, 9 Oct 2016 12:46:06 -0400 Subject: [PATCH] Rename ATT, DEF and IV with padding and hexadecimal. Tested. --- .../com/icecream/snorlax/common/Decimals.java | 4 ++ .../module/feature/rename/RenameFormat.java | 52 +++++++++++++- .../feature/rename/RenameFormatTest.java | 68 ++++++++++++++++++- 3 files changed, 122 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/icecream/snorlax/common/Decimals.java b/app/src/main/java/com/icecream/snorlax/common/Decimals.java index 15b0f34..7006071 100644 --- a/app/src/main/java/com/icecream/snorlax/common/Decimals.java +++ b/app/src/main/java/com/icecream/snorlax/common/Decimals.java @@ -40,6 +40,10 @@ public static String format(double value, int integerDigits, int fractionDigits) return getDecimalFormat(integerDigits, fractionDigits).format(value); } + public static String format(int value, int integerDigits, int fractionDigits) { + return getDecimalFormat(integerDigits, fractionDigits).format(value); + } + private Decimals() { throw new AssertionError("No instances"); } diff --git a/app/src/main/java/com/icecream/snorlax/module/feature/rename/RenameFormat.java b/app/src/main/java/com/icecream/snorlax/module/feature/rename/RenameFormat.java index a9bade8..8362d31 100644 --- a/app/src/main/java/com/icecream/snorlax/module/feature/rename/RenameFormat.java +++ b/app/src/main/java/com/icecream/snorlax/module/feature/rename/RenameFormat.java @@ -26,7 +26,6 @@ import com.icecream.snorlax.module.Pokemons; import static POGOProtos.Data.PokemonDataOuterClass.PokemonData; -import static android.R.attr.level; import static java.lang.Integer.parseInt; @Singleton @@ -35,6 +34,9 @@ final class RenameFormat { private static final String BASE_NICK = "NICK"; private static final String BASE_LVL = "LVL"; private static final String BASE_IV = "IV"; + private static final String BASE_ATT = "ATT"; + private static final String BASE_DEF = "DEF"; + private static final String BASE_STA = "STA"; private final Pokemons mPokemons; private final RenamePreferences mRenamePreferences; @@ -114,6 +116,45 @@ private String processIv(String target, double iv) { return null; } + private String processAttack(String target, int attack) { + if (target.equals(BASE_ATT)) { + return Decimals.format(attack, 1, 0); + } + if (target.equals(BASE_ATT.concat("P"))) { + return Decimals.format(attack, 2, 0); + } + if (target.equals(BASE_ATT.concat("H"))) { + return Integer.toHexString(attack).toUpperCase(); + } + return null; + } + + private String processDefense(String target, int defense) { + if (target.equals(BASE_DEF)) { + return Decimals.format(defense, 1, 0); + } + if (target.equals(BASE_DEF.concat("P"))) { + return Decimals.format(defense, 2, 0); + } + if (target.equals(BASE_DEF.concat("H"))) { + return Integer.toHexString(defense).toUpperCase(); + } + return null; + } + + private String processStamina(String target, int stamina) { + if (target.equals(BASE_STA)) { + return Decimals.format(stamina, 1, 0); + } + if (target.equals(BASE_STA.concat("P"))) { + return Decimals.format(stamina, 2, 0); + } + if (target.equals(BASE_STA.concat("H"))) { + return Integer.toHexString(stamina).toUpperCase(); + } + return null; + } + private String processFormat(Pokemons.Data pokemonsData, String command) throws NullPointerException { final String target = command.toUpperCase(); @@ -128,6 +169,15 @@ else if (target.startsWith(BASE_LVL)) { else if (target.startsWith(BASE_IV)) { processed = processIv(target, pokemonsData.getIvRatio() * 100); } + else if (target.startsWith(BASE_ATT)) { + processed = processAttack(target, pokemonsData.getAttack()); + } + else if (target.startsWith(BASE_DEF)) { + processed = processDefense(target, pokemonsData.getDefense()); + } + else if (target.startsWith(BASE_STA)) { + processed = processStamina(target, pokemonsData.getStamina()); + } return Strings.isNullOrEmpty(processed) ? "%" + command + "%" : processed; } diff --git a/app/src/test/java/com/icecream/snorlax/module/feature/rename/RenameFormatTest.java b/app/src/test/java/com/icecream/snorlax/module/feature/rename/RenameFormatTest.java index 834dea5..eb4d47d 100644 --- a/app/src/test/java/com/icecream/snorlax/module/feature/rename/RenameFormatTest.java +++ b/app/src/test/java/com/icecream/snorlax/module/feature/rename/RenameFormatTest.java @@ -283,4 +283,70 @@ public void testIvWithPaddingWrongDecimal() throws Exception { setRenameFormat("%IVP.A%"); } //endregion -} \ No newline at end of file + + //region Attack + @Test + public void testAttack() throws Exception { + mExpected = "1"; + setRenameFormat("%ATT%"); + } + + @Test + public void testAttackWithPadding() throws Exception { + mExpected = "01"; + setRenameFormat("%ATTP%"); + } + + @Test + public void testAttackHex() throws Exception { + Mockito.doReturn(15).when(mPokemonsData).getAttack(); + + mExpected = "F"; + setRenameFormat("%ATTH%"); + } + //endregion + + //region Defense + @Test + public void testDefense() throws Exception { + mExpected = "1"; + setRenameFormat("%DEF%"); + } + + @Test + public void testDefenseWithPadding() throws Exception { + mExpected = "01"; + setRenameFormat("%DEFP%"); + } + + @Test + public void testDefenseHex() throws Exception { + Mockito.doReturn(15).when(mPokemonsData).getDefense(); + + mExpected = "F"; + setRenameFormat("%DEFH%"); + } + //endregion + + //region Stamina + @Test + public void testStamina() throws Exception { + mExpected = "1"; + setRenameFormat("%STA%"); + } + + @Test + public void testStaminaWithPadding() throws Exception { + mExpected = "01"; + setRenameFormat("%STAP%"); + } + + @Test + public void testStaminaHex() throws Exception { + Mockito.doReturn(15).when(mPokemonsData).getStamina(); + + mExpected = "F"; + setRenameFormat("%STAH%"); + } + //endregion +}