Handle and ' behaviors for 4->5->6

Gen5 does not use the slanted apostrophe for anything. 4->5 converts to ' for both strings.
Gen6 fixes all to be slanted. Even nicknames.
Importing to HOME (PK7, GO) resets nicknames, and the default name is not slanted. Nicknames/OTs are unaltered; again, only the "default" species name is wrong.

Closes #4066
This commit is contained in:
Kurt
2024-05-11 11:35:55 -05:00
parent d2e8d722e7
commit 326e790e4b
5 changed files with 27 additions and 3 deletions

View File

@@ -139,7 +139,7 @@ public PKM ConvertToPKM(ITrainerInfo tr, EncounterCriteria criteria)
}
SetPINGA(pk, criteria);
EncounterUtil.SetEncounterMoves(pk, Version, LevelMin);
pk.Nickname = SpeciesName.GetSpeciesNameGeneration(Species, lang, Generation);
pk.Nickname = SpeciesName.GetSpeciesNameImportHOME(Species, lang, Generation);
SetEncounterMoves(pk, LevelMin);
if (pk is IScaledSize s2)

View File

@@ -186,6 +186,8 @@ public bool IsNicknameMatch(PKM pk, ReadOnlySpan<char> nickname, int language)
Span<char> tmp = stackalloc char[name.Length];
StringConverter345.TransferGlyphs34(name, language, tmp);
if (pk.Context == EntityContext.Gen5)
StringConverter345.TransferGlyphs45(tmp); // Apostrophe ' vs
return nickname.SequenceEqual(tmp);
}

View File

@@ -114,7 +114,7 @@ public void CopyFrom(PK7 pk, PKH pkh)
pkh.MarkingValue &= 0b1111_1111_1111;
if (!pk.IsNicknamed)
pkh.Nickname = SpeciesName.GetSpeciesNameGeneration(pk.Species, pk.Language, 8);
pkh.Nickname = SpeciesName.GetSpeciesNameImportHOME(pk.Species, pk.Language, 8);
if (FormInfo.IsTotemForm(pk.Species, pk.Form))
pkh.Form = FormInfo.GetTotemBaseForm(pk.Species, pk.Form);
}

View File

@@ -100,6 +100,8 @@ public static void TransferGlyphs45(Span<char> input)
{
if (IsInvalid45(input[i]))
input[i] = '?';
if (input[i] == '') // Farfetchd and CHDING nicknames
input[i] = '\''; // Wrong apostrophe, nice. Only is corrected when converted to Gen6.
}
}
@@ -120,6 +122,8 @@ public static void TransferGlyphs56(Span<byte> input)
var c = ReadUInt16LittleEndian(span);
if (IsPrivateUseChar(c))
WriteUInt16LittleEndian(span, GetMigratedPrivateChar(c));
else if (c is '\'') // Fix all apostrophes. ' ->
WriteUInt16LittleEndian(span, '');
}
}

View File

@@ -62,8 +62,8 @@ public static class SpeciesName
var result = new Dictionary<int, ushort>[names.Count];
for (int i = 0; i < result.Length; i++)
{
var dict = new Dictionary<int, ushort>();
var speciesList = names[i];
var dict = new Dictionary<int, ushort>(speciesList.Count - 1);
for (ushort species = 1; species < speciesList.Count; species++)
{
var name = speciesList[species];
@@ -97,6 +97,8 @@ public static string GetSpeciesName(ushort species, int language)
return arr[species];
}
private static bool IsApostropheFarfetchdLanguage(int language) => language is 2 or 4 or 7;
/// <summary>
/// Gets a Pokémon's default name for the desired language ID and generation.
/// </summary>
@@ -107,10 +109,26 @@ public static string GetSpeciesName(ushort species, int language)
public static string GetSpeciesNameGeneration(ushort species, int language, byte generation) => generation switch
{
<= 4 => GetSpeciesName1234(species, language, generation),
5 when species is (int)Species.Farfetchd && IsApostropheFarfetchdLanguage(language) => "Farfetch'd", // Gen5 does not have slanted apostrophes.
7 when language == (int) LanguageID.ChineseS => GetSpeciesName7ZH(species, language),
_ => GetSpeciesName(species, language),
};
/// <inheritdoc cref="GetSpeciesNameGeneration"/>
/// <summary>
/// Gets the initial Species name for HOME imports.
/// </summary>
public static string GetSpeciesNameImportHOME(ushort species, int language, byte generation)
{
// Default fetched names have the wrong apostrophes.
var result = GetSpeciesNameGeneration(species, language, generation);
if (species is (int)Species.Farfetchd && IsApostropheFarfetchdLanguage(language))
return "Farfetch'd";
if (species is (int)Species.Sirfetchd && IsApostropheFarfetchdLanguage(language))
return "Sirfetch'd";
return result;
}
/// <summary>
/// Gets a Pokémon's egg name for the desired language ID and generation.
/// </summary>