set main manu play event

This commit is contained in:
2026-07-03 11:25:17 +02:00
parent 0f7bb6308a
commit dc76181cc0
6 changed files with 81 additions and 64 deletions

View File

@@ -87,6 +87,8 @@ const RIVER_NEIGHBOUR_OFFSETS: Dictionary = {
@export_range(1, 6, 1) var lamppost_search_radius_cells: int = 3
##max allowed distance between lamppost pairs
@export var lamppost_max_wire_distance: float = 35.0
##minimum horizontal distance between generated wires and the railway centerline
@export var lamppost_rail_clearance_distance: float = 4.0
##if true wire connections blocked by colliders are discarded
@export var lamppost_obstacle_check_enabled: bool = true
@@ -1423,6 +1425,25 @@ func _get_wire_sample_point(p1: Vector3, p2: Vector3, t: float) -> Vector3:
point.y -= gravity
return point
func _is_wire_too_close_to_rail(p1: Vector3, p2: Vector3) -> bool:
if rail_path == null or rail_path.curve == null:
return false
if lamppost_rail_clearance_distance <= 0.0:
return false
var clearance_sq: float = lamppost_rail_clearance_distance * lamppost_rail_clearance_distance
var samples: int = 10
for i in range(samples + 1):
var t: float = float(i) / float(samples)
var wire_point: Vector3 = _get_wire_sample_point(p1, p2, t)
var rail_local_point: Vector3 = rail_path.to_local(wire_point)
var closest_rail_point: Vector3 = rail_path.to_global(rail_path.curve.get_closest_point(rail_local_point))
var horizontal_delta := Vector2(wire_point.x - closest_rail_point.x, wire_point.z - closest_rail_point.z)
if horizontal_delta.length_squared() < clearance_sq:
return true
return false
func _collect_wire_excluded_rids(root: Node, excluded_rids: Array[RID]) -> void:
if root == null:
return
@@ -1441,6 +1462,9 @@ func _get_wire_excluded_rids(excluded_roots: Array) -> Array[RID]:
return excluded_rids
func _is_wire_path_blocked(p1: Vector3, p2: Vector3, excluded_roots: Array = []) -> bool:
if _is_wire_too_close_to_rail(p1, p2):
return true
if not lamppost_obstacle_check_enabled:
return false

View File

@@ -4,6 +4,8 @@ const STEAM_DISTANCE_STAT: String = "stat_distance_km"
const DISTANCE_KM_PER_UNIT: float = 0.01
const STATION_STOP_GROUP: StringName = &"railway_station"
enum TrainStartMode { RANDOM_POSITION, SPECIFIED_STATION, SPECIFIED_POSITION }
@export_group("Train")
##train speed
@export var train_speed: float = 6.0
@@ -32,6 +34,14 @@ const STATION_STOP_GROUP: StringName = &"railway_station"
##swing of the train during the ran
@export_range(0.0, 1.0) var basic_swing: float = 0.1
@export_group("Train Start")
@export_enum("random_position", "specified_station", "specified_position") var train_start_mode: int = TrainStartMode.RANDOM_POSITION
@export_range(0, 64, 1, "or_greater") var train_start_stop_index: int = 1
@export var train_start_position: float = 0.0
@export var train_start_delay_seconds: float = 0.0
@export var train_start_after_delay: bool = true
@export var train_start_acceleration_seconds: float = 4.0
@export_group("Rails Bulding")
##distance between sleepers of the rails
@export var sleepers_distance: float = 1.0
@@ -84,7 +94,6 @@ var next_stop_index: int = 0
var stop_multiply: float = 1.0
var is_restarting: bool = false
var tween_restart: Tween
var environment_config: EnvironmentConfig
var wagon_instances: Array[Node3D] = []
var wagon_progress_offsets: Array[float] = []
var _pending_steam_distance_km: float = 0.0
@@ -96,7 +105,6 @@ func _ready() -> void:
GameState.on_enable_photo_mode_request.connect(func(): _is_photo_mode_active = true)
GameState.on_disable_photo_mode_request.connect(func(): _is_photo_mode_active = false)
_cache_environment_config()
_initial_is_inmotion = is_inmotion
if curve != null and curve.get_baked_length() > 0:
@@ -108,24 +116,6 @@ func _ready() -> void:
else:
print("WARNING: Draw Path3D for rails!")
func _cache_environment_config() -> void:
var parent_node: Node = get_parent()
if parent_node != null:
var day_night_node := parent_node.get_node_or_null("DayNight") as EnvironmentManagerRoot
if day_night_node != null:
environment_config = day_night_node.environment_config
return
var current_scene: Node = get_tree().current_scene
if current_scene == null:
return
for child in current_scene.get_children():
var environment_manager := child as EnvironmentManagerRoot
if environment_manager != null:
environment_config = environment_manager.environment_config
return
func _apply_initial_train_start() -> void:
if train_instance == null or curve == null:
return
@@ -134,25 +124,21 @@ func _apply_initial_train_start() -> void:
if total_length <= 0.0:
return
if environment_config != null:
match environment_config.train_start_from_random_position:
EnvironmentConfig.TrainStartMode.RANDOM_POSITION:
train_progress = randf() * total_length
match train_start_mode:
TrainStartMode.RANDOM_POSITION:
train_progress = randf() * total_length
_update_next_stop_index_from_progress()
TrainStartMode.SPECIFIED_STATION:
if stop_offset.is_empty():
train_progress = wrapf(train_progress, 0.0, total_length)
_update_next_stop_index_from_progress()
EnvironmentConfig.TrainStartMode.SPECIFIED_STATION:
if stop_offset.is_empty():
train_progress = wrapf(train_progress, 0.0, total_length)
_update_next_stop_index_from_progress()
else:
var stop_index: int = clampi(environment_config.train_start_stop_index, 0, stop_offset.size() - 1)
train_progress = stop_offset[stop_index]
_set_next_stop_index_from_current(stop_index)
EnvironmentConfig.TrainStartMode.SPECIFIED_POSITION:
train_progress = wrapf(environment_config.train_start_position, 0.0, total_length)
_update_next_stop_index_from_progress()
else:
train_progress = wrapf(train_progress, 0.0, total_length)
_update_next_stop_index_from_progress()
else:
var stop_index: int = clampi(train_start_stop_index, 0, stop_offset.size() - 1)
train_progress = stop_offset[stop_index]
_set_next_stop_index_from_current(stop_index)
TrainStartMode.SPECIFIED_POSITION:
train_progress = wrapf(train_start_position, 0.0, total_length)
_update_next_stop_index_from_progress()
_snap_train_to_progress()
@@ -160,11 +146,8 @@ func _apply_train_start_delay() -> void:
if not _initial_is_inmotion:
return
var should_start_after_delay: bool = true
var start_delay_seconds: float = 0.0
if environment_config != null:
should_start_after_delay = environment_config.train_start_after_delay
start_delay_seconds = maxf(environment_config.train_start_delay_seconds, 0.0)
var should_start_after_delay: bool = train_start_after_delay
var start_delay_seconds: float = maxf(train_start_delay_seconds, 0.0)
if start_delay_seconds <= 0.0:
if not should_start_after_delay:
is_inmotion = false

View File

@@ -1,8 +1,6 @@
class_name EnvironmentConfig
extends Resource
enum TrainStartMode { RANDOM_POSITION, SPECIFIED_STATION, SPECIFIED_POSITION }
@export_group("Day")
@export var start_time: float = 0.0 #start time of the day
@export var day_duration: float = 300.0 #Duration of a full day cycle in seconds
@@ -157,15 +155,6 @@ enum TrainStartMode { RANDOM_POSITION, SPECIFIED_STATION, SPECIFIED_POSITION }
@export var godray_spawn_height: float = 5.0 #Y world position where god rays spawn
@export var godray_scale: Vector3 = Vector3(2.0, 6.0, 2.0) #Scale of the god ray mesh
#Train start settings
@export_group("Train Start")
@export_enum("random_position", "specified_station", "specified_position") var train_start_from_random_position: int = TrainStartMode.RANDOM_POSITION #Train start mode
@export_range(0, 64, 1, "or_greater") var train_start_stop_index: int = 1 #Stop index used for the train start when random start is disabled
@export var train_start_position: float = 0.0 #Offset on the rail curve used when train_start_from_random_position is specified_position
@export var train_start_delay_seconds: float = 0.0 #Seconds the train waits before starting at game launch
@export var train_start_after_delay: bool = true #When enabled the train starts after train_start_delay_seconds, otherwise it stays stopped
@export var train_start_acceleration_seconds: float = 4.0 #Seconds used to progressively reach normal train speed after launch
#Snow settings
@export_group("Snow")
@export var snow_amount: float = 0.0 #Initial snow coverage amount (0.0 = none, 1.0 = full)

View File

@@ -3,6 +3,7 @@ extends Node3D
@export var play_departure_speed: float = -6.0
@export var play_departure_delay_seconds: float = 1.0
@export var play_move_before_transition_seconds: float = 3.0
@export var menu_train_whistle_volume_db: float = -12.0
var _play_departure_started: bool = false
@@ -11,9 +12,25 @@ var _play_departure_started: bool = false
func _ready() -> void:
_stop_menu_train()
_configure_menu_train_whistle_volume()
_configure_play_transition_delay()
_connect_play_button()
func _configure_menu_train_whistle_volume() -> void:
if _rail_path == null or not "train_instance" in _rail_path:
return
var train_instance := _rail_path.get("train_instance") as Node3D
if train_instance == null:
return
if "whistle_volume_db" in train_instance:
train_instance.set("whistle_volume_db", menu_train_whistle_volume_db)
var whistle_player := train_instance.get_node_or_null("TrainWhistlePlayer") as AudioStreamPlayer3D
if whistle_player != null:
whistle_player.volume_db = menu_train_whistle_volume_db
func _configure_play_transition_delay() -> void:
if _option_menu == null or not "fade_time" in _option_menu:
return

View File

@@ -179,10 +179,10 @@ compositor_effects = Array[CompositorEffect]([SubResource("CompositorEffect_q52t
closed = true
bake_interval = 50.0
_data = {
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 3.5, 0, 0, 0, 0, 0, 0, 0, 0, 3.5, 0, 100),
"tilts": PackedFloat32Array(0, 0)
"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 3.5, 0, 0, 0, 0, 0, 0, 0, 0, 3.5, 0, 100, 0, 0, 0, 0, 0, 0, 2.961661, -0.009097099, -56.07381, 0, 0, 0, 0, 0, 0, 3.4848416, -0.013232231, -117.195526, 0, 0, 0, 0, 0, 0, 3.3488476, 0.0048189163, 176.55922, 0, 0, 0, 0, 0, 0, 1.7582202, 0.0118227005, 270.61703),
"tilts": PackedFloat32Array(0, 0, 0, 0, 0, 0)
}
point_count = 2
point_count = 6
[sub_resource type="PlaneMesh" id="PlaneMesh_00nq7"]
@@ -316,9 +316,14 @@ curve = SubResource("Curve3D_263ax")
script = ExtResource("7_5p27e")
train_model = ExtResource("8_ljvyb")
wagon_pool = ExtResource("9_wcae3")
wagon_count = 5
wagon_gap = 0.8
wagon_random_number = false
wagon_count = 4
wagon_gap = 0.6
wagon_spacing_scale = 0.9
train_start_mode = 2
train_start_stop_index = 0
train_start_position = 540.0
train_start_after_delay = false
sleepers_model = ExtResource("10_00nq7")
fireworks_scene = ExtResource("11_aylkj")
@@ -355,9 +360,10 @@ railway_pool = SubResource("Resource_jrt8d")
biome_list = Array[ExtResource("15_3blen")]([SubResource("Resource_n3osn")])
entity_pool = ExtResource("78_xg6nk")
entity_spawn_probability = 0.0
max_entities_per_chunk = 5
eye_line = 8
max_entities_per_chunk = 0
eye_line = 6
lamppost_max_wire_distance = 0.0
lamppost_rail_clearance_distance = 3.0
[node name="Fuji2" parent="." unique_id=842328745 instance=ExtResource("99_61psf")]
transform = Transform3D(0.09337742, 0, 0.9715159, 0, 0.5685182, 0, -0.3828171, 0, 0.23697394, -236.37123, -4.8100815, 216.00096)

View File

@@ -36,6 +36,7 @@ shader_parameter/sun_color = Color(0.2841828, 0.2023238, 0.27953526, 1)
script = ExtResource("3_vg0pk")
start_time = 0.5
start_day_time_paused = true
show_day_time_debug = false
morning_color = Color(0.93333334, 0.78039217, 0.6039216, 1)
afternoon_color = Color(0.9490196, 0.62352943, 0.38039216, 1)
night_color = Color(0.18431373, 0.18431373, 0.4862745, 1)
@@ -85,9 +86,6 @@ godray_spawn_radius = 100.0
godray_spawn_offset = Vector3(20, 80, 20)
godray_rotation_degrees = Vector3(50, 30, 0)
godray_scale = Vector3(2, 25, 50)
train_start_from_random_position = 2
train_start_position = 98.7
train_start_after_delay = false
snow_amount = 2000.0
wind_amount = 50
cloud_speed = 0.01