Skip to content

Commit

Permalink
Update 24.06.03
Browse files Browse the repository at this point in the history
Stream translation text when loading. No need to allocate a few thousand strings and an array.
  • Loading branch information
kwsch committed Jun 4, 2024
1 parent 3ccdba4 commit 0bbba81
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>24.05.05</Version>
<Version>24.06.03</Version>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
Binary file modified PKHeX.Core/Resources/legality/mgdb/wc7full.pkl
Binary file not shown.
Binary file modified PKHeX.Core/Resources/legality/mgdb/wc9.pkl
Binary file not shown.
Binary file modified PKHeX.Core/Resources/legality/wild/encounter_go_home.pkl
Binary file not shown.
Binary file modified PKHeX.Core/Resources/legality/wild/encounter_go_lgpe.pkl
Binary file not shown.
6 changes: 3 additions & 3 deletions PKHeX.Core/Util/ResourceUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ public static string[] GetStringList(string fileName)
if (IsStringListCached(fileName, out var result))
return result;
var txt = GetStringResource(fileName); // Fetch File, \n to list.
if (txt is null)
return [];
return LoadStringList(fileName, txt);
}

Expand All @@ -168,10 +170,8 @@ public static bool IsStringListCached(string fileName, [NotNullWhen(true)] out s
/// Loads a text <see cref="file"/> into the program with a value of <see cref="txt"/>.
/// </summary>
/// <remarks>Caches the result array for future fetches.</remarks>
public static string[] LoadStringList(string file, string? txt)
private static string[] LoadStringList(string file, string txt)
{
if (txt == null)
return [];
string[] raw = FastSplit(txt);

// Make sure only one thread can write to the cache
Expand Down
19 changes: 18 additions & 1 deletion PKHeX.WinForms/Resources/text/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
PKHeX - By Kaphotics
http://projectpokemon.org/pkhex/

24/05/05 - New Update:
24/06/03 - New Update:
- Legality: Added automatic (basic) Trash Byte checks for Switch-era (Gen7b+) files. Further refinement & expansion in the future.
- - Fixed: Mystery gifts distributed with nicknames no longer flag IsNicknamed as invalid.
- Added: Entity editor move dropdown now displays the move's type on the left side.
- Added: Entire boxes can be dragged & dropped. Must enable via setting as it is not intuitive. Drag from the Box tab rectangle.
- Added: Report grid can now specify extra properties to show, as well as properties to hide. Change via settings.
- Added: Gen1-3 save file language/version detection updated for more edge cases.
- Added: Gen2-5 localization text files added for less popular languages. Thanks @abcboy101 !
- Added: Gen3 GBA<->GC string conversion logic to handle special text entry. Thanks @abcboy101 !
- Added: Gen4 Seal/Accessory/Backdrop editors. Thanks @abcboy101 !
- Added: Gen5 Geonet/Unity Tower can now edit country/region data. Thanks @abcboy101 !
- Fixed: Gen6/7 entities now save the volatile status effect rather than wiping it (see previous release notes).
- Fixed: Gen3-7 Nidoran/Farfetch'd text char quirks updated to better align with GameFreak's mess.
- Fixed: Gen1/2 quirks with box data have been rewritten and resolved.
- Changed: Gen1-3 emulator save formats that store RTC data are now detected more reliably.
- Changed: More performance improvements as always! Additionally, translations can now handle Enum localization.

24/05/05 - New Update: (101440) [8778313]
- Legality: Added Regulation G.
- Added: Entity editor can now modify battle-Status effects (Burn, Paralyze, etc). Click the bottom right corner of the window for the GUI.
- Added: Gen5 trainer records can now be edited via Misc editor. Not documented well, but exposes the values for editing.
Expand Down
20 changes: 10 additions & 10 deletions PKHeX.WinForms/Util/WinFormsTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,19 @@ private static void TranslateControl(object c, TranslationContext context, ReadO
}
}

private static ReadOnlySpan<string> GetTranslationFile(ReadOnlySpan<char> lang)
private static ReadOnlySpan<char> GetTranslationFile(ReadOnlySpan<char> lang)
{
var file = GetTranslationFileNameInternal(lang);
// Check to see if the desired translation file exists in the same folder as the executable
string externalLangPath = GetTranslationFileNameExternal(file);
if (File.Exists(externalLangPath))
{
try { return File.ReadAllLines(externalLangPath); }
try { return File.ReadAllText(externalLangPath); }
catch { /* In use? Just return the internal resource. */ }
}

if (Util.IsStringListCached(file, out var result))
return result;
var txt = (string?)Properties.Resources.ResourceManager.GetObject(file);
return Util.LoadStringList(file, txt);
return txt ?? "";
}

private static IEnumerable<object> GetTranslatableControls(Control f)
Expand Down Expand Up @@ -320,9 +318,10 @@ public sealed class TranslationContext

public void Clear() => Translation.Clear();

public TranslationContext(ReadOnlySpan<string> content, char separator = Separator)
public TranslationContext(ReadOnlySpan<char> content, char separator = Separator)
{
foreach (var line in content)
var iterator = content.EnumerateLines();
foreach (var line in iterator)
LoadLine(line, separator);
}

Expand Down Expand Up @@ -352,18 +351,19 @@ public IEnumerable<string> Write(char separator = Separator)
return Translation.Select(z => $"{z.Key}{separator}{z.Value}").OrderBy(z => z.Contains('.')).ThenBy(z => z);
}

public void UpdateFrom(ReadOnlySpan<string> lines)
public void UpdateFrom(ReadOnlySpan<char> text)
{
var lines = text.EnumerateLines();
foreach (var line in lines)
{
var split = line.IndexOf(Separator);
if (split < 0)
continue;
var key = line[..split];
var key = line[..split].ToString();

ref var exist = ref CollectionsMarshal.GetValueRefOrNullRef(Translation, key);
if (!Unsafe.IsNullRef(ref exist))
exist = line[(split + 1)..];
exist = line[(split + 1)..].ToString();
}
}

Expand Down

0 comments on commit 0bbba81

Please sign in to comment.