start on MusicDB

This commit is contained in:
msk
2023-09-30 15:58:08 -07:00
parent a20ace4e5d
commit c6246131f3
5 changed files with 123 additions and 39 deletions
-9
View File
@@ -1,9 +0,0 @@
using System;
namespace WacK.Data.Chart
{
public enum DifficultyLevel
{
Normal, Hard, Expert, Inferno
}
}
+77
View File
@@ -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<Song> 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()
{
}
}
}
+30
View File
@@ -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;
/// <summary>
/// % of max score required to clear this chart.
/// </summary>
float clearRatio;
/// <summary>
/// Path to audio file for this difficulty.
/// </summary>
string audioFile;
string designer;
float audioPreviewStart, audioPreviewLength;
float audioOffset; // in seconds
}
}
+14
View File
@@ -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;
}
}