diff --git a/app/src/main/java/com/kamron/pogoiv/scanlogic/PokeInfoCalculator.java b/app/src/main/java/com/kamron/pogoiv/scanlogic/PokeInfoCalculator.java index 517b31f29..894d24772 100644 --- a/app/src/main/java/com/kamron/pogoiv/scanlogic/PokeInfoCalculator.java +++ b/app/src/main/java/com/kamron/pogoiv/scanlogic/PokeInfoCalculator.java @@ -67,7 +67,6 @@ public static PokeInfoCalculator getInstance() { */ private PokeInfoCalculator(@NonNull GoIVSettings settings, @NonNull Resources res) { populatePokemon(settings, res); - this.typeNamesArray = res.getStringArray(R.array.typeName); } public List getPokedex() { @@ -146,11 +145,14 @@ private void populatePokemon(@NonNull GoIVSettings settings, @NonNull Resources final int[] devolution = res.getIntArray(R.array.devolutionNumber); final int[] evolutionCandyCost = res.getIntArray(R.array.evolutionCandyCost); final int[] candyNamesArray = res.getIntArray(R.array.candyNames); + final String[] types = res.getStringArray(R.array.type); int pokeListSize = names.length; + typeNamesArray = res.getStringArray(R.array.typeName); + for (int i = 0; i < pokeListSize; i++) { Pokemon p = new Pokemon(names[i], displayNames[i], i, attack[i], defense[i], stamina[i], devolution[i], - evolutionCandyCost[i]); + evolutionCandyCost[i], getTypeNames(types[i])); pokedex.add(p); pokemap.put(names[i].toLowerCase(), p); if (!names[i].equals(displayNames[i])) { @@ -439,7 +441,43 @@ public int getHPAtLevel(IVScanResult ivScanResult, double selectedLevel, Pokemon return averageHP; } - public String getTypeName(int typeNameNum) { - return typeNamesArray[typeNameNum]; + /** + * Get localized pokemon type names as a string array from a base20 value defined in types.xml. + * + * @param typeBase20 a pokemon type value indicated with 2 digits base20 value defined in types.xml + * @return A string array including localized pokemon type names. This array has 2 elements as max-length for a + * multi-type pokemon, or 1 element as min-length for a single type pokemon. + * If invalid value input, currently "N/A" returned as 1 element string array. + */ + private String[] getTypeNames(String typeBase20) { + // check invalid value + if (typeBase20.length() != 2) { + //TODO error handling + String[] typeNames = {"N/A"}; + return typeNames; + } + + Integer[] typeNum = new Integer[2]; + + typeNum[0] = Integer.parseInt(typeBase20.substring(0, 1), 20); // 1st type + typeNum[1] = Integer.parseInt(typeBase20.substring(1, 2), 20); // 2nd type + + // check invalid value + if (!(0 < typeNum[0] && typeNum[0] < typeNamesArray.length) + || !(0 <= typeNum[1] && typeNum[1] < typeNamesArray.length)) { + //TODO error handling + String[] typeNames = {"N/A"}; + return typeNames; + } + + if (typeNum[1] == 0) { + // Single-type Pokemon + String[] typeNames = {typeNamesArray[typeNum[0] - 1]}; + return typeNames; + } else { + // Multi-type Pokemon + String[] typeNames = {typeNamesArray[typeNum[0] - 1], typeNamesArray[typeNum[1] - 1]}; + return typeNames; + } } } diff --git a/app/src/main/java/com/kamron/pogoiv/scanlogic/Pokemon.java b/app/src/main/java/com/kamron/pogoiv/scanlogic/Pokemon.java index 4acd32ced..cf23ad91d 100644 --- a/app/src/main/java/com/kamron/pogoiv/scanlogic/Pokemon.java +++ b/app/src/main/java/com/kamron/pogoiv/scanlogic/Pokemon.java @@ -56,9 +56,10 @@ public String getCharacter() { public final int baseStamina; public final int devoNumber; public final int candyEvolutionCost; + public final String[] types; public Pokemon(String name, String displayName, int number, int baseAttack, int baseDefense, int baseStamina, - int devoNumber, int candyEvolutionCost) { + int devoNumber, int candyEvolutionCost, String[] types) { this.name = name; this.displayName = displayName; this.number = number; @@ -68,6 +69,7 @@ public Pokemon(String name, String displayName, int number, int baseAttack, int this.devoNumber = devoNumber; this.evolutions = new ArrayList<>(); this.candyEvolutionCost = candyEvolutionCost; + this.types = types; } @Override diff --git a/app/src/main/java/com/kamron/pogoiv/scanlogic/PokemonNameCorrector.java b/app/src/main/java/com/kamron/pogoiv/scanlogic/PokemonNameCorrector.java index 91cb96020..9d8ef1d11 100644 --- a/app/src/main/java/com/kamron/pogoiv/scanlogic/PokemonNameCorrector.java +++ b/app/src/main/java/com/kamron/pogoiv/scanlogic/PokemonNameCorrector.java @@ -66,23 +66,23 @@ public PokeDist getPossiblePokemon(String poketext, String candytext, Optional eeveelutionCorrection = new HashMap<>(); - eeveelutionCorrection.put(pokeInfoCalculator.getTypeName(2), //WATER - pokeInfoCalculator.get(133).name); //Vaporeon - eeveelutionCorrection.put(pokeInfoCalculator.getTypeName(3), //ELECTRIC - pokeInfoCalculator.get(134).name); //Jolteon - eeveelutionCorrection.put(pokeInfoCalculator.getTypeName(1), //FIRE - pokeInfoCalculator.get(135).name); //Flareon - eeveelutionCorrection.put(pokeInfoCalculator.getTypeName(10), //PSYCHIC - pokeInfoCalculator.get(195).name); //Espeon - eeveelutionCorrection.put(pokeInfoCalculator.getTypeName(15), //DARK - pokeInfoCalculator.get(196).name); //Umbreon + Pokemon vaporeon = pokeInfoCalculator.get(133); + Pokemon jolteon = pokeInfoCalculator.get(134); + Pokemon flareon = pokeInfoCalculator.get(135); + Pokemon espeon = pokeInfoCalculator.get(195); + Pokemon umbreon = pokeInfoCalculator.get(196); + eeveelutionCorrection.put(vaporeon.types[0], vaporeon.name); //WATER + eeveelutionCorrection.put(jolteon.types[0], jolteon.name); //ELECTRIC + eeveelutionCorrection.put(flareon.types[0], flareon.name); //FIRE + eeveelutionCorrection.put(espeon.types[0], espeon.name); //PSYCHIC + eeveelutionCorrection.put(umbreon.types[0], umbreon.name); //DARK // Preparing for the future.... - // eeveelutionCorrection.put(pokeInfoCalculator.getTypeName(4), //GRASS - // pokeInfoCalculator.get(469).name); //Leafeon - // eeveelutionCorrection.put(pokeInfoCalculator.getTypeName(5), //ICE - // pokeInfoCalculator.get(470).name); //Glaceon - // eeveelutionCorrection.put(pokeInfoCalculator.getTypeName(17), //FAIRY - // pokeInfoCalculator.get(699).name); //Sylveon + // Pokemon leafeon = pokeInfoCalculator.get(469); + // Pokemon glaceon = pokeInfoCalculator.get(470); + // Pokemon sylveon = pokeInfoCalculator.get(699); + // eeveelutionCorrection.put(leafeon.types[0], leafeon.name); //GRASS + // eeveelutionCorrection.put(glaceon.types[0], glaceon.name); //ICE + // eeveelutionCorrection.put(sylveon.types[0], sylveon.name); //FAIRY if (eeveelutionCorrection.containsKey(pokemonType)) { poketext = eeveelutionCorrection.get(pokemonType); guess = new PokeDist(pokeInfoCalculator.get(poketext), 0); diff --git a/app/src/main/res/values-es/pokemons.xml b/app/src/main/res/values-es/pokemons.xml deleted file mode 100644 index 7e2739c59..000000000 --- a/app/src/main/res/values-es/pokemons.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - NORMAL - FUEGO - AGUA - ELÉCTRICO - PLANTA - HIELO - LUCHA - VENENO - TIERRA - VOLADOR - PSÍQUICO - BICHO - ROCA - FANTASMA - DRAGÓN - SINIESTRO - ACERO - HADA - - \ No newline at end of file diff --git a/app/src/main/res/values-es/types.xml b/app/src/main/res/values-es/types.xml new file mode 100644 index 000000000..3465a2d33 --- /dev/null +++ b/app/src/main/res/values-es/types.xml @@ -0,0 +1,25 @@ + + + + + NORMAL + FUEGO + AGUA + PLANTA + ELÉCTRICO + HIELO + LUCHA + VENENO + TIERRA + VOLADOR + PSÍQUICO + BICHO + ROCA + FANTASMA + DRAGÓN + SINIESTRO + ACERO + HADA + + + \ No newline at end of file diff --git a/app/src/main/res/values-it/pokemons.xml b/app/src/main/res/values-it/pokemons.xml deleted file mode 100644 index c626562a4..000000000 --- a/app/src/main/res/values-it/pokemons.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - NORMALE - FUOCO - ACQUA - ELETTRO - ERBA - GHIACCIO - LOTTA - VELENO - TERRA - VOLANTE - PSICO - COLEOTTERO - ROCCIA - SPETTRO - DRAGO - BUIO - ACCIAIO - FOLLETTO - - \ No newline at end of file diff --git a/app/src/main/res/values-it/types.xml b/app/src/main/res/values-it/types.xml new file mode 100644 index 000000000..88b48f3ae --- /dev/null +++ b/app/src/main/res/values-it/types.xml @@ -0,0 +1,25 @@ + + + + + NORMALE + FUOCO + ACQUA + ERBA + ELETTRO + GHIACCIO + LOTTA + VELENO + TERRA + VOLANTE + PSICO + COLEOTTERO + ROCCIA + SPETTRO + DRAGO + BUIO + ACCIAIO + FOLLETTO + + + \ No newline at end of file diff --git a/app/src/main/res/values/pokemons.xml b/app/src/main/res/values/pokemons.xml index 820ef7a4b..c3860c2c7 100644 --- a/app/src/main/res/values/pokemons.xml +++ b/app/src/main/res/values/pokemons.xml @@ -394,24 +394,4 @@ Deoxys_Speed Deoxys - - NORMAL - FIRE - WATER - ELECTRIC - GRASS - ICE - FIGHTING - POISON - GROUND - FLYING - PSYCHIC - BUG - ROCK - GHOST - DRAGON - DARK - STEEL - FAIRY - diff --git a/app/src/main/res/values/types.xml b/app/src/main/res/values/types.xml new file mode 100644 index 000000000..7becaed99 --- /dev/null +++ b/app/src/main/res/values/types.xml @@ -0,0 +1,421 @@ + + + + + NORMAL + FIRE + WATER + GRASS + ELECTRIC + ICE + FIGHTING + POISON + GROUND + FLYING + PSYCHIC + BUG + ROCK + GHOST + DRAGON + DARK + STEEL + FAIRY + + + + + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 30 + 50 + 20 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + B0 + G0 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + 00 + + \ No newline at end of file