add radio

This commit is contained in:
2026-04-13 23:05:52 +02:00
parent adaa9eda98
commit dc0bf0ba37
10 changed files with 158 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ class_name State
@export var state_id: String = ""
@warning_ignore("unused_signal")
signal transitioned(state, new_state_name)
func enter() -> void:

View File

@@ -16,6 +16,7 @@ var total_yaw: float = 0.0
var total_pitch: float = 0.0
var orbit_distance: float = 0.0
var current_pan: Vector2 = Vector2.ZERO
var is_active: bool = false
func _ready() -> void:
total_yaw = global_rotation.y
@@ -26,12 +27,14 @@ func _ready() -> void:
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("toggle_photo_mode"):
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
is_active = !is_active
if !is_active:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
else:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
if event is InputEventMouseMotion and is_active:
total_yaw -= event.relative.x * rotation_speed
if event.is_action_pressed("take_photo"):
@@ -41,10 +44,11 @@ func _process(delta: float) -> void:
if not rotation_target:
return
var pan_input = Input.get_vector("photo_pan_left", "photo_pan_right", "photo_pan_up", "photo_pan_down")
var rot_basis = Basis.from_euler(Vector3(total_pitch, total_yaw, 0))
if pan_input != Vector2.ZERO:
if pan_input != Vector2.ZERO and is_active:
current_pan.x += pan_input.x * pan_speed * delta
current_pan.y += -pan_input.y * pan_speed * delta
@@ -63,6 +67,9 @@ func _process(delta: float) -> void:
global_basis = rot_basis
func take_photo() -> void:
if !is_active:
return
var targets = get_tree().get_nodes_in_group("collectible")
var space_state = get_world_3d().direct_space_state

32
core/radio/radio.gd Normal file
View File

@@ -0,0 +1,32 @@
extends AudioStreamPlayer
class_name Radio
@export var playlist: Array[AudioStream] = []
var current_track_index: int = 0
func _ready():
finished.connect(next_track)
func play_track(index: int = current_track_index):
if playlist.is_empty():
push_warning("Playlist is empty")
return
current_track_index = posmod(index, playlist.size())
stream = playlist[current_track_index]
play()
stream_paused = false
func next_track():
play_track(current_track_index + 1)
func prev_track():
play_track(current_track_index - 1)
func toggle_pause():
stream_paused = !stream_paused
func stop_radio():
stop()
stream_paused = false

1
core/radio/radio.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://bwrgh6xlvhqch

6
core/radio/radio.tscn Normal file
View File

@@ -0,0 +1,6 @@
[gd_scene format=3 uid="uid://cpeyt1dgrtglc"]
[ext_resource type="Script" uid="uid://bwrgh6xlvhqch" path="res://core/radio/radio.gd" id="1_2akjj"]
[node name="Radio" type="AudioStreamPlayer" unique_id=1234112225]
script = ExtResource("1_2akjj")

Binary file not shown.

View File

@@ -0,0 +1,19 @@
[remap]
importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://70cc8she43re"
path="res://.godot/imported/lofi_01.ogg-0676fd488ea21d2d6695955666f7f91f.oggvorbisstr"
[deps]
source_file="res://docs/museums/radio/lofi_01.ogg"
dest_files=["res://.godot/imported/lofi_01.ogg-0676fd488ea21d2d6695955666f7f91f.oggvorbisstr"]
[params]
loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4

View File

@@ -0,0 +1,28 @@
extends Node3D
@onready var radio: Radio = $Radio
func _on_button_play_pressed() -> void:
if !radio.playing:
radio.play_track()
func _on_button_pause_pressed() -> void:
radio.toggle_pause()
if radio.stream_paused:
$Control/MarginContainer/VBoxContainer/Button_Pause_Resume.text = "Resume"
else:
$Control/MarginContainer/VBoxContainer/Button_Pause_Resume.text = "Pause"
func _on_button_stop_pressed() -> void:
radio.stop_radio()
func _on_button_next_pressed() -> void:
radio.next_track()
func _on_button_previous_pressed() -> void:
radio.prev_track()

View File

@@ -0,0 +1 @@
uid://ew4b78u5tkiu

View File

@@ -0,0 +1,57 @@
[gd_scene format=3 uid="uid://bdkdhn1oallke"]
[ext_resource type="PackedScene" uid="uid://cpeyt1dgrtglc" path="res://core/radio/radio.tscn" id="1_8yomj"]
[ext_resource type="Script" uid="uid://ew4b78u5tkiu" path="res://docs/museums/radio/museum_radio.gd" id="1_h5r8c"]
[ext_resource type="AudioStream" uid="uid://70cc8she43re" path="res://docs/museums/radio/lofi_01.ogg" id="3_ltpvc"]
[node name="MuseumRadio" type="Node3D" unique_id=204859062]
script = ExtResource("1_h5r8c")
[node name="Radio" parent="." unique_id=1234112225 instance=ExtResource("1_8yomj")]
playlist = Array[AudioStream]([ExtResource("3_ltpvc")])
[node name="Control" type="Control" parent="." unique_id=1232082176]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="MarginContainer" type="MarginContainer" parent="Control" unique_id=2102712226]
layout_mode = 0
offset_right = 40.0
offset_bottom = 40.0
theme_override_constants/margin_left = 12
theme_override_constants/margin_top = 12
theme_override_constants/margin_right = 12
theme_override_constants/margin_bottom = 12
[node name="VBoxContainer" type="VBoxContainer" parent="Control/MarginContainer" unique_id=2097365775]
layout_mode = 2
[node name="Button_Play" type="Button" parent="Control/MarginContainer/VBoxContainer" unique_id=1422696340]
layout_mode = 2
text = "Play"
[node name="Button_Pause_Resume" type="Button" parent="Control/MarginContainer/VBoxContainer" unique_id=2016690081]
layout_mode = 2
text = "Pause"
[node name="Button_Stop" type="Button" parent="Control/MarginContainer/VBoxContainer" unique_id=61861870]
layout_mode = 2
text = "Stop"
[node name="Button_Next" type="Button" parent="Control/MarginContainer/VBoxContainer" unique_id=957606385]
layout_mode = 2
text = "Next"
[node name="Button_Previous" type="Button" parent="Control/MarginContainer/VBoxContainer" unique_id=929072518]
layout_mode = 2
text = "Previous"
[connection signal="pressed" from="Control/MarginContainer/VBoxContainer/Button_Play" to="." method="_on_button_play_pressed"]
[connection signal="pressed" from="Control/MarginContainer/VBoxContainer/Button_Pause_Resume" to="." method="_on_button_pause_pressed"]
[connection signal="pressed" from="Control/MarginContainer/VBoxContainer/Button_Stop" to="." method="_on_button_stop_pressed"]
[connection signal="pressed" from="Control/MarginContainer/VBoxContainer/Button_Next" to="." method="_on_button_next_pressed"]
[connection signal="pressed" from="Control/MarginContainer/VBoxContainer/Button_Previous" to="." method="_on_button_previous_pressed"]