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"):
@@ -40,29 +43,33 @@ func _unhandled_input(event: InputEvent) -> void:
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
if movement_bounds.size != Vector3.ZERO:
current_pan.x = clampf(current_pan.x, movement_bounds.position.x, movement_bounds.position.x + movement_bounds.size.x)
current_pan.y = clampf(current_pan.y, movement_bounds.position.y, movement_bounds.position.y + movement_bounds.size.y)
var right_dir = rot_basis.x.normalized()
var up_dir = rot_basis.y.normalized()
var final_pan_offset = (right_dir * current_pan.x) + (up_dir * current_pan.y)
var orbit_pos = rotation_target.global_position + (rot_basis * Vector3(0, 0, orbit_distance))
global_position = orbit_pos + final_pan_offset
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")