diff --git a/scenes/world/day_night_cycle_component.gd b/scenes/world/day_night_cycle_component.gd index 4defd21..3003ba0 100644 --- a/scenes/world/day_night_cycle_component.gd +++ b/scenes/world/day_night_cycle_component.gd @@ -1,8 +1,16 @@ extends Node3D +signal change_day_length(length_in_seconds: float) +signal end_of_day +signal pause_time +signal resume_time +signal set_time(time: float) ## Time should be between 0 and 1 + + @export var day_length: float = 10.0 ## Day length in seconds @export var start_time: float = 0.3 ## Between 0-1 (0.3 is morning, 0.5 noon) +@export var time_paused: bool = false @export_group("Colors and Intensity") @export var moon_color: Gradient @@ -24,10 +32,13 @@ extends Node3D func _process(delta: float) -> void: + if time_paused: return + time += tick_rate * delta if time >= 1.0: time = 0.0 + end_of_day.emit() # 90 to fix alignment sun.rotation_degrees.x = time * 360 + 90 @@ -48,3 +59,22 @@ func _process(delta: float) -> void: environment.environment.sky.sky_material.set("sky_horizon_color", sky_horizon_color.sample(time)) environment.environment.sky.sky_material.set("ground_bottom_color", ground_bottom_color.sample(time)) environment.environment.sky.sky_material.set("ground_horizon_color", ground_horizon_color.sample(time)) + +func _ready() -> void: + change_day_length.connect(_on_change_day_length) + pause_time.connect(_on_pause_time) + resume_time.connect(_on_resume_time) + + +func _on_change_day_length(seconds: float) -> void: + day_length = seconds + tick_rate = 1.0 / day_length + +func _on_pause_time() -> void: + time_paused = true + +func _on_resume_time() -> void: + time_paused = true + +func _on_set_time(new_time: float) -> void: + time = new_time