PK1/2 edit: Use save language when detecting lang

GBPKM allow spa/ita lang as fallback (so that nicknamed species just use fallback)
SK2 GetNonNickname reuse the passed language ID instead of recomputing
This commit is contained in:
Kurt 2024-05-17 13:18:25 -05:00
parent 417231a67c
commit da51291364
4 changed files with 15 additions and 6 deletions

View file

@ -137,7 +137,7 @@ public sealed class SK2 : GBPKM, ICaughtData2
protected override void GetNonNickname(int language, Span<byte> data)
{
var name = SpeciesName.GetSpeciesNameGeneration(Species, language, 2);
StringConverter2.SetString(data, name, data.Length, Language, StringConverterOption.Clear50);
StringConverter2.SetString(data, name, data.Length, language, StringConverterOption.Clear50);
}
public override void SetNotNicknamed(int language) => GetNonNickname(language, NicknameTrash);

View file

@ -187,12 +187,20 @@ public abstract class GBPKM : PKM
public void SetNotNicknamed() => SetNotNicknamed(GuessedLanguage());
public abstract void SetNotNicknamed(int language);
public bool IsSpeciesNameMatch(int language)
{
var expect = SpeciesName.GetSpeciesNameGeneration(Species, language, 2);
Span<char> current = stackalloc char[TrashCharCountNickname];
int len = LoadString(NicknameTrash, current);
return current[..len].SequenceEqual(expect);
}
public int GuessedLanguage(int fallback = (int)LanguageID.English)
{
int lang = Language;
if (lang > 0)
return lang;
if (fallback is (int)LanguageID.French or (int)LanguageID.German) // only other permitted besides English
if (fallback is (int)LanguageID.French or (int)LanguageID.German or (int)LanguageID.Italian or (int)LanguageID.Spanish) // only other permitted besides English
return fallback;
return (int)LanguageID.English;
}
@ -205,8 +213,7 @@ public abstract class GBPKM : PKM
protected int TransferLanguage(int destLanguage)
{
// if the Species name of the destination language matches the current nickname, transfer with that language.
var expect = SpeciesName.GetSpeciesNameGeneration(Species, destLanguage, 2);
if (Nickname == expect)
if (IsSpeciesNameMatch(destLanguage))
return destLanguage;
return GuessedLanguage(destLanguage);
}

View file

@ -15,7 +15,8 @@ public partial class PKMEditor
CR_PK1.LoadPK1(pk1);
// Attempt to detect language
CB_Language.SelectedValue = pk1.GuessedLanguage();
var language = RequestSaveFile.Language;
CB_Language.SelectedValue = pk1.IsSpeciesNameMatch(language) ? language : pk1.GuessedLanguage(language);
LoadPartyStats(pk1);
UpdateStats();

View file

@ -24,7 +24,8 @@ public partial class PKMEditor
CB_MetTimeOfDay.SelectedIndex = c2.MetTimeOfDay;
// Attempt to detect language
CB_Language.SelectedValue = pk2.GuessedLanguage();
var language = RequestSaveFile.Language;
CB_Language.SelectedValue = pk2.IsSpeciesNameMatch(language) ? language : pk2.GuessedLanguage(language);
LoadPartyStats(pk2);
UpdateStats();