From f61f6a7e2883263aa69766c479e06d11d5e1b751 Mon Sep 17 00:00:00 2001 From: Alex <15199219+muskit@users.noreply.github.com> Date: Wed, 13 Aug 2025 20:13:40 -0700 Subject: [PATCH] refactors and more UI --- Data/Database.cs | 102 +++++++++++++++++++++++++++++++++++ Database.cs | 10 ---- MercuryConverter.csproj | 4 +- Program.cs | 6 ++- UI/App.axaml | 6 ++- UI/Dialogs/DataOpen.axaml | 19 +++++++ UI/Dialogs/DataOpen.axaml.cs | 40 ++++++++++++++ UI/Dialogs/Welcome.axaml | 21 ++++++++ UI/Dialogs/Welcome.axaml.cs | 19 +++++++ UI/MainWindow.axaml | 61 +++++++++++---------- UI/MainWindow.axaml.cs | 23 +++++++- 11 files changed, 268 insertions(+), 43 deletions(-) create mode 100644 Data/Database.cs delete mode 100644 Database.cs create mode 100644 UI/Dialogs/DataOpen.axaml create mode 100644 UI/Dialogs/DataOpen.axaml.cs create mode 100644 UI/Dialogs/Welcome.axaml create mode 100644 UI/Dialogs/Welcome.axaml.cs diff --git a/Data/Database.cs b/Data/Database.cs new file mode 100644 index 0000000..a5b47e1 --- /dev/null +++ b/Data/Database.cs @@ -0,0 +1,102 @@ +using System; +using System.IO; +using System.Linq; +using System.Text.Json; + +namespace MercuryConverter.Data; + +public static class Database +{ + public static void Setup(string dataDirPath) + { + // Check that path exists + if (!Directory.Exists(dataDirPath)) + { + Console.WriteLine($"Folder {dataDirPath} doesn't exist!"); + return; + } + + // Get metadata.json + var jPath = Path.Combine(dataDirPath, "metadata.json"); + string jStr; + JsonElement mdObj; + try + { + jStr = File.ReadAllText(jPath); + } + catch (Exception e) + { + Console.WriteLine($"Couldn't read {jPath}: {e}"); + return; + } + try + { + mdObj = JsonDocument.Parse(jStr).RootElement.GetProperty("Exports")[0].GetProperty("Table").GetProperty("Data"); + } + catch (Exception e) + { + Console.WriteLine($"Couldn't parse JSON object: {e}"); + return; + } + + // TODO: Clear existing structures + + // Parse metadata.json + foreach (var mdSong in mdObj.EnumerateArray()) + { + var id = ""; + var title = ""; + var rubi = ""; + var artist = ""; + var genre = -1; + var copyright = ""; + var bpm = ""; + var version = -1; + var previewTime = -1; + var previewLength = -1; + var jacketPath = ""; + + var level = new string?[] { null, null, null, null }; + var levelBGA = new string?[] { null, null, null, null}; + var levelAudio = new string?[] { null, null, null, null }; + var levelDesigner = new string?[] { null, null, null, null }; + var levelClearRequirements = new string?[] { null, null, null, null }; + + foreach (var prop in mdSong.GetProperty("Value").EnumerateArray()) + { + var value = prop.GetProperty("Value"); + // Console.WriteLine($"{prop.GetProperty("Name")}={prop.GetProperty("Value")}"); + switch (prop.GetProperty("Name").GetString()!) + { + case "AssetDirectory": + id = value.GetString()!; + break; + case "ScoreGenre": + genre = value.GetInt16(); + break; + case "MusicMessage": + title = value.GetString(); + break; + case "ArtistMessage": + artist = value.GetString(); + break; + case "Rubi": + rubi = value.GetString(); + break; + case "Bpm": + bpm = value.GetString(); + break; + case "CopyrightMessage": + var c = value.GetString(); + if (!new string?[] { "", "-", null }.Contains(c)) + { + copyright = c; + } + break; + } + } + + Console.WriteLine($"[{id}] {artist} - {title}"); + } + } +} \ No newline at end of file diff --git a/Database.cs b/Database.cs deleted file mode 100644 index 1f3303c..0000000 --- a/Database.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace MercuryConverter; - -using System; -using System.Collections.ObjectModel; -using System.Collections.Specialized; - -public static class Database -{ - public static readonly ObservableCollection Songs = new(); -} \ No newline at end of file diff --git a/MercuryConverter.csproj b/MercuryConverter.csproj index 5d4913f..32632d8 100644 --- a/MercuryConverter.csproj +++ b/MercuryConverter.csproj @@ -19,9 +19,11 @@ None All + + - + diff --git a/Program.cs b/Program.cs index dbacdf2..f6f402b 100644 --- a/Program.cs +++ b/Program.cs @@ -11,8 +11,10 @@ class Program // SynchronizationContext-reliant code before AppMain is called: things aren't initialized // yet and stuff might break. [STAThread] - public static void Main(string[] args) => BuildAvaloniaApp() - .StartWithClassicDesktopLifetime(args); + public static void Main(string[] args) + { + BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); + } // Avalonia configuration, don't remove; also used by visual designer. public static AppBuilder BuildAvaloniaApp() diff --git a/UI/App.axaml b/UI/App.axaml index f0d2d3c..3f08616 100644 --- a/UI/App.axaml +++ b/UI/App.axaml @@ -1,6 +1,7 @@ @@ -15,6 +16,8 @@ + + @@ -28,7 +31,8 @@ #20000000 - #20000000 + #ff000000 + #222244 /Assets/imgs/banner_dark.png diff --git a/UI/Dialogs/DataOpen.axaml b/UI/Dialogs/DataOpen.axaml new file mode 100644 index 0000000..5a806aa --- /dev/null +++ b/UI/Dialogs/DataOpen.axaml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/UI/Dialogs/DataOpen.axaml.cs b/UI/Dialogs/DataOpen.axaml.cs new file mode 100644 index 0000000..b1cfcde --- /dev/null +++ b/UI/Dialogs/DataOpen.axaml.cs @@ -0,0 +1,40 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Avalonia.Controls; +using Avalonia.Platform.Storage; +using Avalonia.Threading; + +namespace MercuryConverter.UI.Dialogs; + +public partial class DataOpen : Window +{ + public DataOpen() + { + InitializeComponent(); + BeginDirSelection(); + } + + private void BeginDirSelection() + { + Dispatcher.UIThread.Invoke(async () => + { + await Task.Delay(200); + var dirSelection = await GetTopLevel(this)!.StorageProvider.OpenFolderPickerAsync + ( + new FolderPickerOpenOptions + { + Title = "Open Data Folder", + AllowMultiple = false, + } + ); + + if (dirSelection.Count <= 0) + { + return; + } + + var d = dirSelection!.First().TryGetLocalPath()!; + }); + } +} \ No newline at end of file diff --git a/UI/Dialogs/Welcome.axaml b/UI/Dialogs/Welcome.axaml new file mode 100644 index 0000000..70f578a --- /dev/null +++ b/UI/Dialogs/Welcome.axaml @@ -0,0 +1,21 @@ + + + + Welcome to MercuryConverter! + + + + + + + before proceeding. + +