feat: sync visual day-night cycle with simulation clock

DayNightCycle now reads time_of_day from SimulationManager group node, falling back to self-tracked elapsed for lookdev scenes. Simulation starts at 06:00 morning (tick 50) by default. TimeDial reads directly from SimulationManager and displays HH:MM format with a 24-hour dial arc. Removed initial_cycle override from JajceLookdev.
This commit is contained in:
2026-07-08 18:04:04 +02:00
parent 4604dc6d5a
commit cab732a977
5 changed files with 47 additions and 40 deletions
+2 -2
View File
@@ -130,11 +130,11 @@ theme_override_colors/font_color = Color(0.96, 0.91, 0.78, 1)
theme_override_font_sizes/font_size = 15 theme_override_font_sizes/font_size = 15
text = "Villager inspector" text = "Villager inspector"
[node name="TimeDial" type="Control" parent="UI" node_paths=PackedStringArray("day_night_cycle")] [node name="TimeDial" type="Control" parent="UI" node_paths=PackedStringArray("simulation_manager")]
layout_mode = 0 layout_mode = 0
offset_left = 880.0 offset_left = 880.0
offset_top = 6.0 offset_top = 6.0
offset_right = 940.0 offset_right = 940.0
offset_bottom = 66.0 offset_bottom = 66.0
script = ExtResource("12_timedial") script = ExtResource("12_timedial")
day_night_cycle = NodePath("../JajceWorld/DayNightCycle") simulation_manager = NodePath("../SimulationManager")
+1
View File
@@ -44,6 +44,7 @@ func _ready() -> void:
return return
clock = SimulationClock.new(tick_interval) clock = SimulationClock.new(tick_interval)
clock.cycle_duration_seconds = cycle_duration_seconds clock.cycle_duration_seconds = cycle_duration_seconds
clock.elapsed_ticks = int(0.25 * cycle_duration_seconds / tick_interval)
village.debug_logs = debug_logs village.debug_logs = debug_logs
_initialize_storage() _initialize_storage()
village.update_modifiers() village.update_modifiers()
-3
View File
@@ -7,9 +7,6 @@
[node name="JajceWorld" parent="." instance=ExtResource("1_world")] [node name="JajceWorld" parent="." instance=ExtResource("1_world")]
[node name="DayNightCycle" parent="JajceWorld" index="9"]
initial_cycle = 0.38
[node name="BeautyCamera" type="Camera3D" parent="."] [node name="BeautyCamera" type="Camera3D" parent="."]
position = Vector3(44, 34, 44) position = Vector3(44, 34, 44)
current = true current = true
+16 -9
View File
@@ -1,7 +1,7 @@
extends Node extends Node
@export var cycle_duration_seconds := 240.0 @export var cycle_duration_seconds := 240.0
@export_range(0.0, 1.0, 0.01) var initial_cycle := 0.35 @export_range(0.0, 1.0, 0.01) var initial_cycle := 0.25
@export var directional_light: DirectionalLight3D @export var directional_light: DirectionalLight3D
@export var world_environment: WorldEnvironment @export var world_environment: WorldEnvironment
@@ -36,19 +36,26 @@ const SUNRISE_LIGHT_COLOR := Color(1, 0.6, 0.45, 1)
const SUNRISE_SUNSET_ENERGY := 0.8 const SUNRISE_SUNSET_ENERGY := 0.8
var elapsed := 0.0 var elapsed := 0.0
var _simulation_node: Node
func _ready() -> void: func _ready() -> void:
elapsed = cycle_duration_seconds * initial_cycle _simulation_node = get_tree().get_first_node_in_group("simulation_manager")
_apply_light_rotation(initial_cycle) if _simulation_node == null:
_apply_environment(initial_cycle) elapsed = cycle_duration_seconds * initial_cycle
_apply_light_rotation(initial_cycle)
_apply_environment(initial_cycle)
func _process(delta: float) -> void: func _process(_delta: float) -> void:
elapsed += delta var cycle: float
if elapsed >= cycle_duration_seconds: if _simulation_node != null and "clock" in _simulation_node:
elapsed = fmod(elapsed, cycle_duration_seconds) cycle = _simulation_node.clock.time_of_day()
var cycle := elapsed / cycle_duration_seconds else:
elapsed += _delta
if elapsed >= cycle_duration_seconds:
elapsed = fmod(elapsed, cycle_duration_seconds)
cycle = elapsed / cycle_duration_seconds
_apply_light_rotation(cycle) _apply_light_rotation(cycle)
_apply_environment(cycle) _apply_environment(cycle)
+28 -26
View File
@@ -1,6 +1,6 @@
extends Control extends Control
@export var day_night_cycle: Node @export var simulation_manager: Node
const SIZE_DIAL := 60.0 const SIZE_DIAL := 60.0
const RING_RADIUS := 24.0 const RING_RADIUS := 24.0
@@ -14,7 +14,6 @@ const COLOR_DUSK := Color(0.9, 0.35, 0.2, 1)
const COLOR_BG := Color(0.06, 0.06, 0.08, 0.65) const COLOR_BG := Color(0.06, 0.06, 0.08, 0.65)
var _last_fraction := -1.0 var _last_fraction := -1.0
var _last_color := Color.TRANSPARENT
func _process(_delta: float) -> void: func _process(_delta: float) -> void:
@@ -44,29 +43,37 @@ func _draw() -> void:
var tip_pos := center + tip_dir * RING_RADIUS var tip_pos := center + tip_dir * RING_RADIUS
draw_circle(tip_pos, GLOW_RADIUS, time_color.lightened(0.3)) draw_circle(tip_pos, GLOW_RADIUS, time_color.lightened(0.3))
var label := _phase_label(fraction)
var font := ThemeDB.fallback_font var font := ThemeDB.fallback_font
if font == null: if font == null:
return return
var time_label := _time_label(fraction)
var font_size := 11 var font_size := 11
var text_size := font.get_string_size(label, HORIZONTAL_ALIGNMENT_CENTER, -1, font_size) var text_size := font.get_string_size(time_label, HORIZONTAL_ALIGNMENT_CENTER, -1, font_size)
var text_x := (SIZE_DIAL - text_size.x) / 2.0 var text_x := (SIZE_DIAL - text_size.x) / 2.0
var text_y := SIZE_DIAL - text_size.y + 4.0 var text_y := SIZE_DIAL - text_size.y + 4.0
draw_string(font, Vector2(text_x, text_y), label, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color.WHITE) draw_string(font, Vector2(text_x, text_y), time_label, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color.WHITE)
func _cycle_fraction() -> float: func _cycle_fraction() -> float:
if day_night_cycle == null: if simulation_manager != null:
return 0.0 if "clock" in simulation_manager:
var elapsed: float = day_night_cycle.get("elapsed") if "elapsed" in day_night_cycle else 0.0 return simulation_manager.clock.time_of_day()
var duration: float = ( var day_night_cycle := get_node_or_null(day_night_cycle_fallback())
day_night_cycle.get("cycle_duration_seconds") if day_night_cycle != null:
if "cycle_duration_seconds" in day_night_cycle var elapsed: float = day_night_cycle.get("elapsed") if "elapsed" in day_night_cycle else 0.0
else 240.0 var duration: float = (
) day_night_cycle.get("cycle_duration_seconds")
if duration <= 0.0: if "cycle_duration_seconds" in day_night_cycle
return 0.0 else 240.0
return fmod(elapsed / duration, 1.0) )
if duration > 0.0:
return fmod(elapsed / duration, 1.0)
return 0.0
func day_night_cycle_fallback() -> NodePath:
return NodePath("../../JajceWorld/DayNightCycle")
func _time_color(fraction: float) -> Color: func _time_color(fraction: float) -> Color:
@@ -81,13 +88,8 @@ func _time_color(fraction: float) -> Color:
return COLOR_DUSK.lerp(COLOR_NIGHT, smoothstep(0.85, 1.0, fraction)) return COLOR_DUSK.lerp(COLOR_NIGHT, smoothstep(0.85, 1.0, fraction))
func _phase_label(fraction: float) -> String: func _time_label(fraction: float) -> String:
if fraction < 0.1: var total_minutes := int(fraction * 24.0 * 60.0)
return "Night" var hour := total_minutes / 60
if fraction < 0.2: var minute := total_minutes % 60
return "Dawn" return "%02d:%02d" % [hour, minute]
if fraction < 0.65:
return "Day"
if fraction < 0.8:
return "Dusk"
return "Night"