Browse Source

Adding signals for controlling time

pull/14/head
Ryan Reed 1 month ago
parent
commit
7856b02ae6
1 changed files with 30 additions and 0 deletions
  1. +30
    -0
      scenes/world/day_night_cycle_component.gd

+ 30
- 0
scenes/world/day_night_cycle_component.gd View File

@ -1,8 +1,16 @@
extends Node3D 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 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 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_group("Colors and Intensity")
@export var moon_color: Gradient @export var moon_color: Gradient
@ -24,10 +32,13 @@ extends Node3D
func _process(delta: float) -> void: func _process(delta: float) -> void:
if time_paused: return
time += tick_rate * delta time += tick_rate * delta
if time >= 1.0: if time >= 1.0:
time = 0.0 time = 0.0
end_of_day.emit()
# 90 to fix alignment # 90 to fix alignment
sun.rotation_degrees.x = time * 360 + 90 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("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_bottom_color", ground_bottom_color.sample(time))
environment.environment.sky.sky_material.set("ground_horizon_color", ground_horizon_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

Loading…
Cancel
Save