add random weather function

This commit is contained in:
2026-04-24 17:44:43 +02:00
parent 72c933ba73
commit e8f2c4db84
5 changed files with 96 additions and 14 deletions

View File

@@ -49,6 +49,7 @@ var current_wind_speed: float = 0.0
var current_wind_strength: float = 0.0
var current_wind_fade: float = 0.0
var max_wind_amount: int = 0
var random_weather_restore_tween: Tween
func _init(wind: GPUParticles3D, snow: GPUParticles3D,
fireflies: GPUParticles3D, rain: GPUParticles3D, ray: PackedScene,
@@ -98,6 +99,7 @@ func _ready() -> void:
UIEvents.toggle_snow.connect(toggle_snow)
UIEvents.toggle_wind.connect(toggle_wind)
UIEvents.wind_change.connect(change_wind_strength)
UIEvents.trigger_random_weather.connect(trigger_random_weather_event)
UIEvents.toggle_fireflies.connect(toggle_fireflies)
UIEvents.toggle_storm.connect(toggle_storm)
UIEvents.toggle_dust.connect(toggle_dust)
@@ -410,6 +412,51 @@ func _update_wind_amount_from_strength(value: float) -> void:
environment_config.wind_amount = roundi(max_wind_amount * amount_ratio)
func trigger_random_weather_event(duration: float = 0.0) -> void:
if random_weather_restore_tween and random_weather_restore_tween.is_valid():
random_weather_restore_tween.kill()
var previous_rain: bool = is_raining
var previous_snow: bool = is_snowing
var previous_wind: bool = is_windy
var previous_storm: bool = is_storm
var random_event_index: int = randi_range(0, 3)
match random_event_index:
0:
_apply_weather_event_state(false, true, false, false)
1:
_apply_weather_event_state(true, false, false, false)
2:
_apply_weather_event_state(false, false, true, false)
_:
_apply_weather_event_state(true, false, false, true)
if duration > 0.0:
random_weather_restore_tween = create_tween()
random_weather_restore_tween.tween_interval(duration)
random_weather_restore_tween.tween_callback(func():
_apply_weather_event_state(previous_rain, previous_snow, previous_wind, previous_storm)
)
func _apply_weather_event_state(rain_enabled: bool, snow_enabled: bool, wind_enabled: bool, storm_enabled: bool = false) -> void:
if is_storm and not storm_enabled:
toggle_storm(false)
if is_raining and not rain_enabled:
toggle_rain(false)
if is_snowing and not snow_enabled:
toggle_snow(false)
if is_windy and not wind_enabled:
toggle_wind(false)
if not is_raining and rain_enabled:
toggle_rain(true)
if not is_snowing and snow_enabled:
toggle_snow(true)
if not is_windy and wind_enabled:
toggle_wind(true)
if not is_storm and storm_enabled:
toggle_storm(true)
func _apply_cloud_config() -> void:
var dir = environment_config.wind_direction
var cloud_scale = environment_config.cloud_scale

View File

@@ -10,6 +10,8 @@ signal toggle_wind(value: bool)
@warning_ignore("unused_signal")
signal wind_change(value: float)
@warning_ignore("unused_signal")
signal trigger_random_weather(duration: float)
@warning_ignore("unused_signal")
signal toggle_fireflies(value: bool)
@warning_ignore("unused_signal")
signal toggle_storm(value: bool)