Skip to content

Commit 38c7a4b

Browse files
committed
Refactor MenuArtConverter for extensibility and regex use
- Changed `MenuArtConverter` to a partial static class. - Added `System.Text.RegularExpressions` for regex support. - Introduced `ConvertMenuArtAsync` for asynchronous processing. - Updated file renaming logic to use regex for better matching. - Defined `CoachMatch` method for regex pattern matching. - Added early return in renaming logic to improve efficiency.
1 parent ea11347 commit 38c7a4b

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

JustDanceEditor.Converter/Converters/Images/MenuArtConverter.cs

+16-10
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
using JustDanceEditor.Logging;
33

44
using System.Diagnostics;
5+
using System.Text.RegularExpressions;
56

67
namespace JustDanceEditor.Converter.Converters.Images;
78

8-
public static class MenuArtConverter
9+
public static partial class MenuArtConverter
910
{
1011
public async static Task ConvertMenuArtAsync(ConvertUbiArtToUnity convert) =>
1112
await Task.Run(() => ConvertMenuArt(convert));
@@ -43,15 +44,16 @@ public static void ConvertMenuArt(ConvertUbiArtToUnity convert)
4344
foreach (string pngFile in pngFiles)
4445
{
4546
string fileName = Path.GetFileNameWithoutExtension(pngFile);
46-
// If {song}_coachx.png exists, rename it to {song}_Coach_x.png
47-
if (fileName.Contains("_coach") && !fileName.Contains("_Coach_"))
48-
{
49-
Logger.Log($"Renaming {fileName} to {fileName.Replace("_coach", "_Coach_")}", LogLevel.Warning);
50-
string newFileName = fileName.Replace("_coach", "_Coach_");
51-
string newFilePath = Path.Combine(convert.FileSystem.TempFolders.MenuArtFolder, newFileName + ".png");
52-
if (!File.Exists(newFilePath))
53-
File.Move(pngFile, newFilePath);
54-
}
47+
// If {song}_coachx.png or {song}_coach_x.png exists, rename it to {song}_Coach_x.png
48+
if (CoachMatch().IsMatch(fileName))
49+
{
50+
string newFileName = CoachMatch().Replace(fileName, "_Coach_");
51+
Logger.Log($"Renaming {fileName} to {newFileName}", LogLevel.Warning);
52+
string newFilePath = Path.Combine(convert.FileSystem.TempFolders.MenuArtFolder, newFileName + ".png");
53+
if (!File.Exists(newFilePath))
54+
File.Move(pngFile, newFilePath);
55+
return;
56+
}
5557

5658
// If {song}_AlbumCoach.png exists, rename it to {song}_Cover_AlbumCoach.png
5759
if (fileName.Contains("_AlbumCoach", StringComparison.OrdinalIgnoreCase) && !fileName.Contains("_Cover_AlbumCoach", StringComparison.OrdinalIgnoreCase))
@@ -61,10 +63,14 @@ public static void ConvertMenuArt(ConvertUbiArtToUnity convert)
6163
string newFilePath = Path.Combine(convert.FileSystem.TempFolders.MenuArtFolder, newFileName + ".png");
6264
if (!File.Exists(newFilePath))
6365
File.Move(pngFile, newFilePath);
66+
return;
6467
}
6568
}
6669

6770
stopwatch.Stop();
6871
Logger.Log($"Finished converting menu art files in {stopwatch.ElapsedMilliseconds}ms");
6972
}
73+
74+
[GeneratedRegex("_coach_?")]
75+
private static partial Regex CoachMatch();
7076
}

0 commit comments

Comments
 (0)