From c6246131f354d111b3e9aad8eb11afe0d8d2c902 Mon Sep 17 00:00:00 2001 From: msk <15199219+muskit@users.noreply.github.com> Date: Sat, 30 Sep 2023 15:58:08 -0700 Subject: [PATCH] start on MusicDB --- Scripts/Data/Chart/Difficulty.cs | 9 ---- Scripts/Data/MusicDB/Database.cs | 77 ++++++++++++++++++++++++++++++ Scripts/Data/MusicDB/Difficulty.cs | 30 ++++++++++++ Scripts/Data/MusicDB/Song.cs | 14 ++++++ Scripts/Scenes/Startup.cs | 32 +------------ 5 files changed, 123 insertions(+), 39 deletions(-) delete mode 100644 Scripts/Data/Chart/Difficulty.cs create mode 100644 Scripts/Data/MusicDB/Database.cs create mode 100644 Scripts/Data/MusicDB/Difficulty.cs create mode 100644 Scripts/Data/MusicDB/Song.cs diff --git a/Scripts/Data/Chart/Difficulty.cs b/Scripts/Data/Chart/Difficulty.cs deleted file mode 100644 index 22294fd..0000000 --- a/Scripts/Data/Chart/Difficulty.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace WacK.Data.Chart -{ - public enum DifficultyLevel - { - Normal, Hard, Expert, Inferno - } -} diff --git a/Scripts/Data/MusicDB/Database.cs b/Scripts/Data/MusicDB/Database.cs new file mode 100644 index 0000000..7eee5a2 --- /dev/null +++ b/Scripts/Data/MusicDB/Database.cs @@ -0,0 +1,77 @@ +using System.Collections.Generic; + +using Godot; + +namespace WacK.MusicDB +{ + public class Database + { + public static readonly string SONGS_DIR = "user://songs"; + public List songs; + + public static Database instance; + + public static void Init() + { + if (instance != null) return; + + instance = new Database(); + } + + public Database() + { + InitSongsDir(); + BuildDatabase(SONGS_DIR); + } + + private void InitSongsDir() + { + GD.Print($"User directory: {OS.GetUserDataDir()}"); + var songDir = DirAccess.Open(SONGS_DIR); + if (songDir != null) + { + GD.Print("Successfully opened songs directory!"); + } + else + { + GD.Print("Could not find songs directory! Creating it..."); + + DirAccess.MakeDirAbsolute(SONGS_DIR); + using var newSongDir = DirAccess.Open(SONGS_DIR); + + if (newSongDir != null) + { + GD.Print("Songs folder created successfully!"); + // create note + var note = "Place song folders here. Nested folders supported for organization.\n"; + using (var f = FileAccess.Open($"{newSongDir.GetCurrentDir()}/note.txt", FileAccess.ModeFlags.Write)) + { + f.StoreString(note); + } + } + else + { + GD.PrintErr($"Could not create the songs directory!\n{DirAccess.GetOpenError()}"); + } + + } + } + + private void BuildDatabase(string path) + { + var d = DirAccess.Open(path); + if (d == null) return; + + } + + public void SaveCache() + { + + } + + public void LoadCache() + { + + } + } +} \ No newline at end of file diff --git a/Scripts/Data/MusicDB/Difficulty.cs b/Scripts/Data/MusicDB/Difficulty.cs new file mode 100644 index 0000000..db815a7 --- /dev/null +++ b/Scripts/Data/MusicDB/Difficulty.cs @@ -0,0 +1,30 @@ +using WacK.Data.Chart; + +namespace WacK.MusicDB +{ + public enum DifficultyLevel + { + Normal, Hard, Expert, Inferno + } + + public struct Difficulty + { + DifficultyLevel diffLevel; + float diffValue; + + /// + /// % of max score required to clear this chart. + /// + float clearRatio; + + /// + /// Path to audio file for this difficulty. + /// + string audioFile; + + string designer; + + float audioPreviewStart, audioPreviewLength; + float audioOffset; // in seconds + } +} diff --git a/Scripts/Data/MusicDB/Song.cs b/Scripts/Data/MusicDB/Song.cs new file mode 100644 index 0000000..f4ee9e0 --- /dev/null +++ b/Scripts/Data/MusicDB/Song.cs @@ -0,0 +1,14 @@ +namespace WacK.MusicDB +{ + public class Song + { + string name, artist, category, copyright; + int tempo; + + // chart path relative to user://songs + string dirPath; + + // should only hold 4 values + Difficulty[] diff; + } +} \ No newline at end of file diff --git a/Scripts/Scenes/Startup.cs b/Scripts/Scenes/Startup.cs index b5281ba..02391f6 100644 --- a/Scripts/Scenes/Startup.cs +++ b/Scripts/Scenes/Startup.cs @@ -1,5 +1,6 @@ using Godot; using System; +using WacK.MusicDB; namespace WacK.Scenes { @@ -8,36 +9,7 @@ namespace WacK.Scenes // Called when the node enters the scene tree for the first time. public override void _Ready() { - GD.Print($"User directory: {OS.GetUserDataDir()}"); - using var songDir = DirAccess.Open("user://songs"); - if (songDir != null) - { - GD.Print("Successfully opened songs directory!"); - // load songs - } - else - { - GD.Print("Could not find songs directory! Creating it..."); - - DirAccess.MakeDirAbsolute("user://songs"); - using var newSongDir = DirAccess.Open("user://songs"); - - if (newSongDir != null) - { - GD.Print("Songs folder created successfully!"); - // create note - var note = "Place song folders here. Nested folders supported for organization.\n"; - using var f = FileAccess.Open($"{newSongDir.GetCurrentDir()}/note.txt", FileAccess.ModeFlags.Write); - f.StoreString(note); - - // TODO: add in-game notice - } - else - { - GD.PrintErr($"Could not create the songs directory!\n{DirAccess.GetOpenError()}"); - } - - } + Database.Init(); // Change scenes GetTree().ChangeSceneToFile("res://Scenes/DebugChartLoader.tscn");