make debugchartloader less painful to use

This commit is contained in:
msk
2023-09-18 02:13:52 -07:00
parent 74520c3e04
commit f61fbcccf3
2 changed files with 86 additions and 16 deletions
+20 -12
View File
@@ -2,7 +2,7 @@
[ext_resource type="Script" path="res://Scripts/Scenes/DebugChartLoader.cs" id="1_hjgpd"]
[node name="DebugChartLoader" type="MarginContainer" node_paths=PackedStringArray("inputField", "soundField", "difficultyButton", "playButton")]
[node name="DebugChartLoader" type="MarginContainer" node_paths=PackedStringArray("pathsLine", "songsButton", "soundButton", "difficultyButton", "playButton")]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
@@ -13,30 +13,38 @@ theme_override_constants/margin_top = 32
theme_override_constants/margin_right = 32
theme_override_constants/margin_bottom = 32
script = ExtResource("1_hjgpd")
inputField = NodePath("VBoxContainer/HBoxContainer/PathLineEdit")
soundField = NodePath("VBoxContainer/HBoxContainer3/SoundLineEdit")
difficultyButton = NodePath("VBoxContainer/HBoxContainer/DifficultyOptionButton")
pathsLine = NodePath("VBoxContainer/HBoxContainer0/User path")
songsButton = NodePath("VBoxContainer/HBoxContainer0/HBoxContainer1/SongsOptionButton")
soundButton = NodePath("VBoxContainer/HBoxContainer3/SoundsOptionButton")
difficultyButton = NodePath("VBoxContainer/HBoxContainer0/HBoxContainer1/DifficultyOptionButton")
playButton = NodePath("VBoxContainer/HBoxContainer2/PlayButton")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 2
theme_override_constants/separation = 8
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
[node name="HBoxContainer0" type="VBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
alignment = 2
[node name="User path" type="LineEdit" parent="VBoxContainer/HBoxContainer0"]
layout_mode = 2
size_flags_horizontal = 3
[node name="HBoxContainer1" type="HBoxContainer" parent="VBoxContainer/HBoxContainer0"]
layout_mode = 2
alignment = 1
[node name="PathLineEdit" type="LineEdit" parent="VBoxContainer/HBoxContainer"]
[node name="SongsOptionButton" type="OptionButton" parent="VBoxContainer/HBoxContainer0/HBoxContainer1"]
custom_minimum_size = Vector2(0, 35)
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 8
size_flags_stretch_ratio = 5.97
text = "Bad Apple!!"
placeholder_text = "Folder path relative to \"user://songs/\""
disabled = true
[node name="DifficultyOptionButton" type="OptionButton" parent="VBoxContainer/HBoxContainer"]
[node name="DifficultyOptionButton" type="OptionButton" parent="VBoxContainer/HBoxContainer0/HBoxContainer1"]
custom_minimum_size = Vector2(0, 35)
layout_mode = 2
size_flags_horizontal = 3
@@ -56,11 +64,10 @@ popup/item_3/id = 3
layout_mode = 2
alignment = 1
[node name="SoundLineEdit" type="LineEdit" parent="VBoxContainer/HBoxContainer3"]
[node name="SoundsOptionButton" type="OptionButton" parent="VBoxContainer/HBoxContainer3"]
custom_minimum_size = Vector2(0, 31)
layout_mode = 2
size_flags_horizontal = 3
text = "music.mp3"
placeholder_text = "Name of audio file in the folder specified above with extension"
[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
@@ -70,4 +77,5 @@ alignment = 1
[node name="PlayButton" type="Button" parent="VBoxContainer/HBoxContainer2"]
layout_mode = 2
size_flags_vertical = 0
disabled = true
text = "Play"
+66 -4
View File
@@ -6,10 +6,13 @@ namespace WacK.Scenes
public partial class DebugChartLoader : Node
{
[Export]
private LineEdit inputField;
private LineEdit pathsLine;
[Export]
private LineEdit soundField;
private OptionButton songsButton;
[Export]
private OptionButton soundButton;
[Export]
private OptionButton difficultyButton;
@@ -17,19 +20,77 @@ namespace WacK.Scenes
[Export]
private Button playButton;
const string SONGS_PATH = $"user://songs";
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
// --- UI SETUP --- //
playButton.Pressed += PlayClicked;
songsButton.ItemSelected += RefreshSounds;
pathsLine.Text = OS.GetUserDataDir();
// --- SONGS ENUMERATION --- //
using var dir = DirAccess.Open(SONGS_PATH);
if (dir == null)
{
GD.PrintErr($"Error occurred opening song folder!\n{DirAccess.GetOpenError()}");
}
else
{
// populate songsButton
foreach (var sd in dir.GetDirectories())
{
var d = DirAccess.Open($"{SONGS_PATH}/{sd}");
if (d == null) continue;
songsButton.AddItem(sd);
}
}
if (songsButton.ItemCount >= 1)
{
songsButton.Disabled = false;
playButton.Disabled = false;
}
else
{
playButton.Text = "No songs found!";
}
RefreshSounds(0);
}
private void RefreshSounds(long _)
{
soundButton.Clear();
var dir = DirAccess.Open($"{SONGS_PATH}/{songsButton.Text}");
foreach (var sf in dir.GetFiles())
{
var l = sf.ToLower();
if (l.EndsWith(".mp3") || l.EndsWith(".wav") || l.EndsWith(".ogg"))
{
soundButton.AddItem(sf);
}
}
if (soundButton.ItemCount < 1)
{
soundButton.Disabled = true;
soundButton.Text = "No audio files found!";
}
else
{
soundButton.Disabled = false;
}
}
private void PlayClicked()
{
// TODO: globally accessible verify song folder and chart/audio function
var songPath = $"user://songs/{inputField.Text}";
var songPath = $"user://songs/{songsButton.Text}";
var chartPath = $"{songPath}/{difficultyButton.Selected}.mer";
var soundPath = $"{songPath}/{soundField.Text}";
var soundPath = $"{songPath}/{soundButton.Text}";
GD.Print($"Song: {songPath}\nChart: {chartPath}\nSound: {soundPath}");
// folder check
@@ -62,6 +123,7 @@ namespace WacK.Scenes
public override void _ExitTree()
{
songsButton.ItemSelected -= RefreshSounds;
playButton.Pressed -= PlayClicked;
}
}