mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-10 06:34:19 +00:00
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:
parent
417231a67c
commit
da51291364
4 changed files with 15 additions and 6 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue