From 03c365890f4c74e17cbea14d07c3dbd13c14755b Mon Sep 17 00:00:00 2001 From: kevadesu Date: Wed, 18 Jun 2025 19:36:23 +0200 Subject: [PATCH] uhhh --- 3rdparty/basic_bars_example.gd | 66 ++++++++++++++++++++++++ 3rdparty/basic_bars_example.gd.uid | 1 + 3rdparty/basic_bars_example.tscn | 10 ++++ default_bus_layout.tres | 26 +--------- show_spectrum.gd | 81 ------------------------------ show_spectrum.gd.uid | 1 - show_spectrum.tscn | 14 ------ start.gd | 9 ++-- start.tscn | 48 ++++++++++++------ 9 files changed, 117 insertions(+), 139 deletions(-) create mode 100644 3rdparty/basic_bars_example.gd create mode 100644 3rdparty/basic_bars_example.gd.uid create mode 100644 3rdparty/basic_bars_example.tscn delete mode 100644 show_spectrum.gd delete mode 100644 show_spectrum.gd.uid delete mode 100644 show_spectrum.tscn diff --git a/3rdparty/basic_bars_example.gd b/3rdparty/basic_bars_example.gd new file mode 100644 index 0000000..3abd3e2 --- /dev/null +++ b/3rdparty/basic_bars_example.gd @@ -0,0 +1,66 @@ +extends Control + +@export var audio_player: AudioStreamPlayer + +var spectrum_instance +const NUM_BARS = 64 # Number of frequency bands to display +const MAX_FREQ = 1000 # Frequency range to analyze +var bars = [] +@export var shuffle_freq = false +@export var flip_y = false + +var color_gradient := Gradient.new() # Dynamic color transitions + + +func _ready(): + position = Vector2(0, get_viewport_rect().size.y - 150) + # Set up color gradient (Blue → Purple → Red) + scale = Vector2(1.5, 1.5) + color_gradient.add_point(0.0, Color(0.2, 1.0, 0.8)) # Cyan + color_gradient.add_point(0.5, Color(0.6, 0.2, 1.0)) # Purple + color_gradient.add_point(1.0, Color(1.0, 0.2, 0.2)) # Red + spectrum_instance = AudioServer.get_bus_effect_instance(1, 0) # Bus 1, Effect 0 + create_bars() + +func create_bars(): + for i in range(NUM_BARS): + var bar = ColorRect.new() + bar.color = Color(0.2, 0.8, 1.0) + + # Set anchors so position/size are relative to top-left + bar.set_anchors_preset(Control.PRESET_BOTTOM_LEFT) + + # Position each bar starting from the bottom left + bar.rect_position = Vector2(i * 10, 0) # X is offset, Y = 0 at bottom + bar.rect_size = Vector2(8, 1) # Start with a minimal height + + add_child(bar) + bars.append(bar) + +func _process(delta): + if not spectrum_instance: + return + var max_freq_amp = bars.reduce(func(m, b): return b if b.rect_size.y > m.rect_size.y else m).rect_size.y + + for i in range(NUM_BARS): + var freq_start = (i * MAX_FREQ) / NUM_BARS + var freq_end = ((i + 1) * MAX_FREQ) / NUM_BARS + var magnitude = spectrum_instance.get_magnitude_for_frequency_range(freq_start, freq_end).length() + var target_height = magnitude * 1000 * 2 + bars[i].rect_size.y = lerp(bars[i].rect_size.y, target_height, 0.2) + bars[i].rect_position.y = -bars[i].rect_size.y # Move bar so it grows upward + # Smooth animation + + var intensity = bars[i].rect_size.y / (max_freq_amp * 1.0) if max_freq_amp > 0 else 0.0 +# intensity *= 1000 + intensity = clamp(intensity, 0.0, 1.0) # Keep within valid range + + # Get dynamic color from gradient + var new_color = color_gradient.sample(intensity) + bars[i].color = new_color + if flip_y: + bars[i].scale.y = -1 + + if shuffle_freq: + bars.shuffle() + diff --git a/3rdparty/basic_bars_example.gd.uid b/3rdparty/basic_bars_example.gd.uid new file mode 100644 index 0000000..c2ee21f --- /dev/null +++ b/3rdparty/basic_bars_example.gd.uid @@ -0,0 +1 @@ +uid://c8lfwkgcpcb3b diff --git a/3rdparty/basic_bars_example.tscn b/3rdparty/basic_bars_example.tscn new file mode 100644 index 0000000..988b6f9 --- /dev/null +++ b/3rdparty/basic_bars_example.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=2 format=3 uid="uid://bq0tfw61wpnlg"] + +[ext_resource type="Script" uid="uid://c8lfwkgcpcb3b" path="res://3rdparty/basic_bars_example.gd" id="1_2famp"] + +[node name="BasicBarsExample" type="Control"] +layout_mode = 3 +anchors_preset = 0 +offset_right = 40.0 +offset_bottom = 40.0 +script = ExtResource("1_2famp") diff --git a/default_bus_layout.tres b/default_bus_layout.tres index d91d6d1..6f2745f 100644 --- a/default_bus_layout.tres +++ b/default_bus_layout.tres @@ -1,27 +1,3 @@ -[gd_resource type="AudioBusLayout" load_steps=4 format=3 uid="uid://cjoxo61mhrs7k"] - -[sub_resource type="AudioEffectCompressor" id="1"] -resource_name = "Compressor" -threshold = -6.0 -ratio = 3.0 - -[sub_resource type="AudioEffectDelay" id="2"] -resource_name = "Delay" - -[sub_resource type="AudioEffectChorus" id="3"] -resource_name = "Chorus" -wet = 0.2 +[gd_resource type="AudioBusLayout" format=3 uid="uid://cjoxo61mhrs7k"] [resource] -bus/1/name = &"Example Bus" -bus/1/solo = false -bus/1/mute = false -bus/1/bypass_fx = false -bus/1/volume_db = 0.0 -bus/1/send = &"Master" -bus/1/effect/0/effect = SubResource("1") -bus/1/effect/0/enabled = true -bus/1/effect/1/effect = SubResource("2") -bus/1/effect/1/enabled = true -bus/1/effect/2/effect = SubResource("3") -bus/1/effect/2/enabled = false diff --git a/show_spectrum.gd b/show_spectrum.gd deleted file mode 100644 index 3283a71..0000000 --- a/show_spectrum.gd +++ /dev/null @@ -1,81 +0,0 @@ -extends Node2D - - -const VU_COUNT = 16 -const FREQ_MAX = 11050.0 - -const WIDTH = 800 -const HEIGHT = 250 -const HEIGHT_SCALE = 8.0 -const MIN_DB = 60 -const ANIMATION_SPEED = 0.1 - -var spectrum -var min_values = [] -var max_values = [] - - -func _draw(): - var w = WIDTH / VU_COUNT - for i in range(VU_COUNT): - var min_height = min_values[i] - var max_height = max_values[i] - var height = lerp(min_height, max_height, ANIMATION_SPEED) - - draw_rect( - Rect2(w * i, HEIGHT - height, w - 2, height), - Color.from_hsv(float(VU_COUNT * 0.6 + i * 0.5) / VU_COUNT, 0.5, 0.6) - ) - draw_line( - Vector2(w * i, HEIGHT - height), - Vector2(w * i + w - 2, HEIGHT - height), - Color.from_hsv(float(VU_COUNT * 0.6 + i * 0.5) / VU_COUNT, 0.5, 1.0), - 2.0, - true - ) - - # Draw a reflection of the bars with lower opacity. - draw_rect( - Rect2(w * i, HEIGHT, w - 2, height), - Color.from_hsv(float(VU_COUNT * 0.6 + i * 0.5) / VU_COUNT, 0.5, 0.6) * Color(1, 1, 1, 0.125) - ) - draw_line( - Vector2(w * i, HEIGHT + height), - Vector2(w * i + w - 2, HEIGHT + height), - Color.from_hsv(float(VU_COUNT * 0.6 + i * 0.5) / VU_COUNT, 0.5, 1.0) * Color(1, 1, 1, 0.125), - 2.0, - true - ) - - -func _process(_delta): - var data = [] - var prev_hz = 0 - - for i in range(1, VU_COUNT + 1): - var hz = i * FREQ_MAX / VU_COUNT - var magnitude = spectrum.get_magnitude_for_frequency_range(prev_hz, hz).length() - var energy = clampf((MIN_DB + linear_to_db(magnitude)) / MIN_DB, 0, 1) - var height = energy * HEIGHT * HEIGHT_SCALE - data.append(height) - prev_hz = hz - - for i in range(VU_COUNT): - if data[i] > max_values[i]: - max_values[i] = data[i] - else: - max_values[i] = lerp(max_values[i], data[i], ANIMATION_SPEED) - - if data[i] <= 0.0: - min_values[i] = lerp(min_values[i], 0.0, ANIMATION_SPEED) - - # Sound plays back continuously, so the graph needs to be updated every frame. - queue_redraw() - - -func _ready(): - spectrum = AudioServer.get_bus_effect_instance(0, 0) - min_values.resize(VU_COUNT) - max_values.resize(VU_COUNT) - min_values.fill(0.0) - max_values.fill(0.0) diff --git a/show_spectrum.gd.uid b/show_spectrum.gd.uid deleted file mode 100644 index 12cc7e2..0000000 --- a/show_spectrum.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://x3hrdg2smx4f diff --git a/show_spectrum.tscn b/show_spectrum.tscn deleted file mode 100644 index a3b0552..0000000 --- a/show_spectrum.tscn +++ /dev/null @@ -1,14 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://dsit517glos2s"] - -[ext_resource type="Script" uid="uid://x3hrdg2smx4f" path="res://show_spectrum.gd" id="1"] - -[node name="ShowSpectrum" type="Node2D"] -position = Vector2(136, 80) -script = ExtResource("1") - -[node name="Player" type="AudioStreamPlayer" parent="."] -autoplay = true - -[node name="Camera2D" type="Camera2D" parent="."] -position = Vector2(0, 144) -offset = Vector2(440, 100) diff --git a/start.gd b/start.gd index e86ed2c..5dad068 100644 --- a/start.gd +++ b/start.gd @@ -1,8 +1,9 @@ extends Control -@onready var start_button = get_node("TextureRect/MarginContainer/HBoxContainer/VBoxContainer/PlayButton") -@onready var quit_button = get_node("TextureRect/MarginContainer/HBoxContainer/VBoxContainer/QuitButton") -@onready var levellist = $TextureRect/MarginContainer/HBoxContainer/LevelList +@onready var start_button = get_node("MarginContainer/HBoxContainer/VBoxContainer/PlayButton") +@onready var quit_button = get_node("MarginContainer/HBoxContainer/VBoxContainer/QuitButton") +@onready var levellist = $MarginContainer/HBoxContainer/LevelList +@onready var bgmusic = get_node("AudioStreamPlayer") var playbutton = false var stringing = "hi" @@ -11,6 +12,8 @@ func main(): func _ready(): print("READY!!! >w<") + bgmusic.stream = load("res://assets/audio/FlyingHomeMain.ogg") + bgmusic.play() levellist.hide() start_button.pressed.connect(_start_button_pressed) quit_button.pressed.connect(_quit_button_pressed) diff --git a/start.tscn b/start.tscn index 09b504e..604953e 100644 --- a/start.tscn +++ b/start.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=14 format=3 uid="uid://bciy4rskxlowb"] +[gd_scene load_steps=15 format=3 uid="uid://bciy4rskxlowb"] [ext_resource type="Script" uid="uid://t2iw8p1c6rq3" path="res://start.gd" id="1_g38d0"] [ext_resource type="Texture2D" uid="uid://cm58nw8150cah" path="res://proluzbg.png" id="2_g38d0"] @@ -9,6 +9,7 @@ [ext_resource type="Texture2D" uid="uid://catqff7wmtny0" path="res://assets/icons/learning.svg" id="7_pob1m"] [ext_resource type="Texture2D" uid="uid://brso5ro5k1tri" path="res://assets/icons/extension.svg" id="8_gophc"] [ext_resource type="Texture2D" uid="uid://clnhbd4dggxmo" path="res://ProjektLuzidLogo.svg" id="8_pob1m"] +[ext_resource type="PackedScene" uid="uid://bq0tfw61wpnlg" path="res://3rdparty/basic_bars_example.tscn" id="10_p0nl4"] [sub_resource type="FontFile" id="FontFile_db7xr"] cache/0/16/0/ascent = 0.0 @@ -104,6 +105,7 @@ grow_vertical = 2 script = ExtResource("1_g38d0") [node name="TextureRect" type="TextureRect" parent="."] +visible = false layout_mode = 1 anchors_preset = -1 anchor_right = 1.0 @@ -131,7 +133,7 @@ stretch_mode = 2 [node name="AnimationPlayer" type="AnimationPlayer" parent="TextureRect/TextureRect2"] script = ExtResource("4_p0nl4") -[node name="MarginContainer" type="MarginContainer" parent="TextureRect"] +[node name="MarginContainer" type="MarginContainer" parent="."] layout_mode = 2 anchor_right = 1.0 anchor_bottom = 1.0 @@ -140,15 +142,15 @@ theme_override_constants/margin_top = 20 theme_override_constants/margin_right = 20 theme_override_constants/margin_bottom = 20 -[node name="HBoxContainer" type="HBoxContainer" parent="TextureRect/MarginContainer"] +[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer"] layout_mode = 2 -[node name="VBoxContainer" type="VBoxContainer" parent="TextureRect/MarginContainer/HBoxContainer"] +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/HBoxContainer"] layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 4 -[node name="Label" type="Label" parent="TextureRect/MarginContainer/HBoxContainer/VBoxContainer"] +[node name="Label" type="Label" parent="MarginContainer/HBoxContainer/VBoxContainer"] visible = false layout_mode = 2 size_flags_horizontal = 0 @@ -156,7 +158,7 @@ text = "projektLuzid" label_settings = SubResource("LabelSettings_kenku") vertical_alignment = 1 -[node name="PlayButton" type="Button" parent="TextureRect/MarginContainer/HBoxContainer/VBoxContainer"] +[node name="PlayButton" type="Button" parent="MarginContainer/HBoxContainer/VBoxContainer"] layout_mode = 2 size_flags_horizontal = 0 size_flags_vertical = 6 @@ -168,7 +170,7 @@ text = "play" flat = true alignment = 0 -[node name="QuitButton" type="Button" parent="TextureRect/MarginContainer/HBoxContainer/VBoxContainer"] +[node name="QuitButton" type="Button" parent="MarginContainer/HBoxContainer/VBoxContainer"] layout_mode = 2 size_flags_horizontal = 0 size_flags_vertical = 6 @@ -180,27 +182,27 @@ text = "quit" flat = true alignment = 0 -[node name="LevelList" type="VBoxContainer" parent="TextureRect/MarginContainer/HBoxContainer"] +[node name="LevelList" type="VBoxContainer" parent="MarginContainer/HBoxContainer"] layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 4 alignment = 1 script = ExtResource("6_g38d0") -[node name="Label" type="Label" parent="TextureRect/MarginContainer/HBoxContainer/LevelList"] +[node name="Label" type="Label" parent="MarginContainer/HBoxContainer/LevelList"] layout_mode = 2 text = "Core layer" label_settings = SubResource("LabelSettings_onc8m") horizontal_alignment = 2 -[node name="Label3" type="Label" parent="TextureRect/MarginContainer/HBoxContainer/LevelList"] +[node name="Label3" type="Label" parent="MarginContainer/HBoxContainer/LevelList"] visible = false layout_mode = 2 text = "- awawa" label_settings = SubResource("LabelSettings_ep3pr") horizontal_alignment = 2 -[node name="bLEVEL1" type="Button" parent="TextureRect/MarginContainer/HBoxContainer/LevelList"] +[node name="bLEVEL1" type="Button" parent="MarginContainer/HBoxContainer/LevelList"] layout_mode = 2 size_flags_vertical = 4 theme_override_fonts/font = ExtResource("5_da165") @@ -210,7 +212,7 @@ alignment = 0 icon_alignment = 2 expand_icon = true -[node name="bLEVEL2" type="Button" parent="TextureRect/MarginContainer/HBoxContainer/LevelList"] +[node name="bLEVEL2" type="Button" parent="MarginContainer/HBoxContainer/LevelList"] layout_mode = 2 size_flags_vertical = 4 theme_override_fonts/font = ExtResource("5_da165") @@ -220,7 +222,7 @@ alignment = 0 icon_alignment = 2 expand_icon = true -[node name="bLEVEL3" type="Button" parent="TextureRect/MarginContainer/HBoxContainer/LevelList"] +[node name="bLEVEL3" type="Button" parent="MarginContainer/HBoxContainer/LevelList"] visible = false layout_mode = 2 size_flags_vertical = 4 @@ -232,7 +234,23 @@ alignment = 0 icon_alignment = 2 expand_icon = true +[node name="BasicBarsExample" parent="." instance=ExtResource("10_p0nl4")] +custom_minimum_size = Vector2(5, 5) +layout_mode = 1 +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = -10.0 +offset_right = 0.0 +offset_bottom = 0.0 +grow_horizontal = 2 +grow_vertical = 0 +script = null + [node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] -[connection signal="pressed" from="TextureRect/MarginContainer/HBoxContainer/VBoxContainer/PlayButton" to="." method="_start_button_pressed"] -[connection signal="pressed" from="TextureRect/MarginContainer/HBoxContainer/VBoxContainer/QuitButton" to="." method="_quit_button_pressed"] +[node name="Node2D" type="Node2D" parent="."] + +[connection signal="pressed" from="MarginContainer/HBoxContainer/VBoxContainer/PlayButton" to="." method="_start_button_pressed"] +[connection signal="pressed" from="MarginContainer/HBoxContainer/VBoxContainer/QuitButton" to="." method="_quit_button_pressed"]