start on MusicDB
This commit is contained in:
@@ -1,9 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace WacK.Data.Chart
|
|
||||||
{
|
|
||||||
public enum DifficultyLevel
|
|
||||||
{
|
|
||||||
Normal, Hard, Expert, Inferno
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System;
|
using System;
|
||||||
|
using WacK.MusicDB;
|
||||||
|
|
||||||
namespace WacK.Scenes
|
namespace WacK.Scenes
|
||||||
{
|
{
|
||||||
@@ -8,36 +9,7 @@ namespace WacK.Scenes
|
|||||||
// Called when the node enters the scene tree for the first time.
|
// Called when the node enters the scene tree for the first time.
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
GD.Print($"User directory: {OS.GetUserDataDir()}");
|
Database.Init();
|
||||||
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()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change scenes
|
// Change scenes
|
||||||
GetTree().ChangeSceneToFile("res://Scenes/DebugChartLoader.tscn");
|
GetTree().ChangeSceneToFile("res://Scenes/DebugChartLoader.tscn");
|
||||||
|
|||||||
Reference in New Issue
Block a user