static List<Pokemon> decodeBoxPokemonList(byte[] bytes) { final int numPokemon = bytes[0]; if (numPokemon < 0 || numPokemon > MAX_BOX_SLOTS) { return Collections.emptyList(); } final List<Pokemon> pokemon = new ArrayList<>(numPokemon); final int capacity = 20; for (int i = 0; i < numPokemon; i++) { final PokemonBuilder pokemonBuilder = decodeBoxPokemon( ByteUtil.getBytes(bytes, capacity + 2 + i * BOX_POKEMON_LENGTH, BOX_POKEMON_LENGTH)); final int trainerNameOffset = 1 + (capacity + 1) + capacity * BOX_POKEMON_LENGTH + i * NAME_LENGTH; pokemonBuilder.setOriginalTrainerName( CharacterDecoder.decodeCharacters( ByteUtil.getBytes(bytes, trainerNameOffset, NAME_LENGTH))); final int nicknameOffset = 1 + (capacity + 1) + capacity * BOX_POKEMON_LENGTH + capacity * NAME_LENGTH + i * NAME_LENGTH; pokemonBuilder.setNickname( CharacterDecoder.decodeCharacters(ByteUtil.getBytes(bytes, nicknameOffset, NAME_LENGTH))); pokemon.add(pokemonBuilder.createPokemon()); } return pokemon; }
static List<Pokemon> decodePokemonPartyList(byte[] bytes) { final int numPokemon = bytes[0]; final List<Pokemon> pokemon = new ArrayList<>(numPokemon); final int capacity = 6; for (int i = 0; i < numPokemon; i++) { final PokemonBuilder pokemonBuilder = decodePartyPokemon( ByteUtil.getBytes( bytes, capacity + 2 + i * PARTY_POKEMON_LENGTH, PARTY_POKEMON_LENGTH)); final int trainerNameOffset = 1 + (capacity + 1) + capacity * PARTY_POKEMON_LENGTH + i * NAME_LENGTH; pokemonBuilder.setOriginalTrainerName( CharacterDecoder.decodeCharacters( ByteUtil.getBytes(bytes, trainerNameOffset, NAME_LENGTH))); final int nicknameOffset = 1 + (capacity + 1) + capacity * PARTY_POKEMON_LENGTH + capacity * NAME_LENGTH + i * NAME_LENGTH; pokemonBuilder.setNickname( CharacterDecoder.decodeCharacters(ByteUtil.getBytes(bytes, nicknameOffset, NAME_LENGTH))); pokemon.add(pokemonBuilder.createPokemon()); } return pokemon; }
/** * Transliteration when going to ascii in format 6. This was originally the only place where * transliteration was available. */ @Test public void testTransliterateLatin() { CodeFunctions functions = CodeFunctions.createEncoderForLBL("latin1"); CharacterEncoder encoder = functions.getEncoder(); EncodedText text = encoder.encodeText("Körnerstraße, Velkomezeříčská, Skólavörðustigur"); CharacterDecoder decoder = functions.getDecoder(); byte[] ctext = text.getCtext(); for (int i = 0; i < text.getLength(); i++) { decoder.addByte(ctext[i]); } String result = decoder.getText().getText(); assertEquals("transliterated text", "Körnerstraße, Velkomezerícská, Skólavörðustigur", result); }
/** * Transliteration when going to ascii in format 6. This was originally the only place where * transliteration was available. */ @Test public void testTransliterate6() { CodeFunctions functions = CodeFunctions.createEncoderForLBL(6); CharacterEncoder encoder = functions.getEncoder(); EncodedText text = encoder.encodeText("Körnerstraße, Velkomezeříčská, Skólavörðustigur"); CharacterDecoder decoder = functions.getDecoder(); byte[] ctext = text.getCtext(); for (int i = 0; i < text.getLength(); i++) { decoder.addByte(ctext[i]); } decoder.addByte(0xff); String result = decoder.getText().getText(); assertEquals("transliterated text", "KORNERSTRASSE, VELKOMEZERICSKA, SKOLAVORDUSTIGUR", result); }