Merge pull request 'add whistle to train' (#38) from whitleandstats into main

Reviewed-on: #38
This commit was merged in pull request #38.
This commit is contained in:
2026-06-29 08:20:37 +00:00
23 changed files with 879 additions and 38 deletions

View File

@@ -1,7 +1,7 @@
extends Path3D
const STEAM_DISTANCE_STAT: String = "stat_distance_km"
const STEAM_DISTANCE_KM_PER_UNIT: float = 1#0.001
const DISTANCE_KM_PER_UNIT: float = 0.001
@export_group("Train")
##train speed
@@ -402,7 +402,7 @@ func _track_steam_distance(distance_units: float) -> void:
if not SteamManager.is_on_steam:
return
_pending_steam_distance_km += distance_units * STEAM_DISTANCE_KM_PER_UNIT
_pending_steam_distance_km += distance_units * DISTANCE_KM_PER_UNIT
var whole_km: int = int(floor(_pending_steam_distance_km))
if whole_km <= 0:
return

View File

@@ -9,10 +9,10 @@ func _ready() -> void:
deselect()
disable()
func set_option_text(text: String) -> void:
func set_option_text(_text: String) -> void:
if label == null:
label = $%Label
label.text = text
label.text = _text
func select() -> void:
if checkbox == null:

View File

@@ -39,7 +39,7 @@ func apply_video_settings() -> void:
get_viewport().use_taa = save_data.anti_aliasing
var msaa_mode = Viewport.MSAA_2X if save_data.anti_aliasing else Viewport.MSAA_DISABLED
get_viewport().msaa_3d = msaa_mode
get_viewport().msaa_2d = msaa_mode
get_viewport().msaa_2d = Viewport.MSAA_DISABLED
func apply_train_colors() -> void:
if not save_data.train_color_1.is_empty():
@@ -64,9 +64,18 @@ func apply_train_colors() -> void:
DisplayServer.window_set_size(Vector2i(save_data.resolution_x, save_data.resolution_y))
# Optional: center the window if resized
var screen_center = DisplayServer.screen_get_position() + DisplayServer.screen_get_size() / 2
var window_size = DisplayServer.window_get_size()
DisplayServer.window_set_position(screen_center - window_size / 2)
var screen_position: Vector2i = DisplayServer.screen_get_position()
var screen_size: Vector2i = DisplayServer.screen_get_size()
var window_size: Vector2i = DisplayServer.window_get_size()
var screen_center := screen_position + Vector2i(
floori(float(screen_size.x) / 2.0),
floori(float(screen_size.y) / 2.0)
)
var window_half_size := Vector2i(
floori(float(window_size.x) / 2.0),
floori(float(window_size.y) / 2.0)
)
DisplayServer.window_set_position(screen_center - window_half_size)
func save_game() -> void:

View File

@@ -1,6 +1,5 @@
extends Control
@onready var game_menu: Control = $%GameMenu
@onready var game_menu_panel: Control = $%GameMenuPanel
@onready var menu_icon_button: Button = $%MenuIconButton
@@ -112,6 +111,8 @@ func _on_weather_row_on_option_changed(data: String) -> void:
pick_random_weather()
_:
pass
AchievementManager.is_unlocked("ACH_CHANGE_METEO")
func pick_random_weather() -> void:
var valid_buttons = []
@@ -189,6 +190,8 @@ func _on_photo_taken_finished() -> void:
await tween.finished
photo_mode_black_screen.hide()
GameState.on_photo_mode_black_screen_disappeared.emit()
StatsManager.add_int("stat_photo_number", 1)
StatsManager.store()
func _on_choo_choo_button_pressed() -> void:
#play sfx

View File

@@ -0,0 +1,70 @@
## Updates total elapsed time and train distance labels.
class_name TotalStatsDisplay
extends Node
const RAILS_SCRIPT = preload("res://core/biome_generator/rails.gd")
const SECONDS_PER_MINUTE: int = 60
const MINUTES_PER_HOUR: int = 60
const HOURS_PER_DAY: int = 24
#DISTANCE_KM_PER_UNIT is taken from rails.gd constant
@export var time_label_path: NodePath
@export var distance_label_path: NodePath
@export var rail_path: NodePath
var _elapsed_seconds: float = 0.0
var _total_distance_km: float = 0.0
var _last_train_progress: float = -1.0
@onready var _time_label: Label = get_node_or_null(time_label_path) as Label
@onready var _distance_label: Label = get_node_or_null(distance_label_path) as Label
@onready var _rail_path: Path3D = get_node_or_null(rail_path) as Path3D
func _ready() -> void:
_update_time_label()
_update_distance_label()
func _process(delta: float) -> void:
_elapsed_seconds += delta
_update_total_distance()
_update_time_label()
_update_distance_label()
func _update_total_distance() -> void:
if _rail_path == null or _rail_path.curve == null:
return
var current_train_progress: float = float(_rail_path.get("train_progress"))
if _last_train_progress < 0.0:
_last_train_progress = current_train_progress
return
var total_length: float = _rail_path.curve.get_baked_length()
if total_length <= 0.0:
return
var progress_delta: float = absf(current_train_progress - _last_train_progress)
var wrapped_progress_delta: float = minf(progress_delta, total_length - progress_delta)
_total_distance_km += wrapped_progress_delta * RAILS_SCRIPT.DISTANCE_KM_PER_UNIT
_last_train_progress = current_train_progress
func _update_time_label() -> void:
if _time_label == null:
return
var total_minutes: int = int(floor(_elapsed_seconds / SECONDS_PER_MINUTE))
var days: int = floori(float(total_minutes) / float(MINUTES_PER_HOUR * HOURS_PER_DAY))
var hours: int = floori(float(total_minutes) / float(MINUTES_PER_HOUR)) % HOURS_PER_DAY
var minutes: int = total_minutes % MINUTES_PER_HOUR
_time_label.text = "Time %dd %02dh %02dm" % [days, hours, minutes]
func _update_distance_label() -> void:
if _distance_label == null:
return
_distance_label.text = "Distance %.1f km" % _total_distance_km

View File

@@ -0,0 +1 @@
uid://c2usnexa5x7pg

View File

@@ -4,23 +4,22 @@ extends Node
#if you have an error setting achievements or stats in debug mode remember to open your steam client
#with jmp games account or another account who bought this game. If error persist try to clos and reopen steam client.
const KNOWN := [
"ACH_DISTANCE_100",
"ACH_DISTANCE_200",
"ACH_10_PHOTOS",
"ACH_CHANGE_METEO",
"ACH_CHANGE_TRAIN_COLOR",
]
#how it works:
#func _on_player_won() -> void:
# Achievements.unlock("ACH_DISTANCE_100") #unlock the achievement at first win
# AchievementManager.unlock("ACH_DISTANCE_100") #unlock the achievement at first win
#func _on_match_finished(coins_collected: int) -> void:
#update stats
#...
#check thresholds and unlock achievements
# if Stats.get_int("stat_distance_km") >= 100:
# Achievements.unlock("ACH_DISTANCE_100")
# if Stats.get_int("stat_distance_km") >= 200:
# Achievements.unlock("ACH_DISTANCE_200")
# if StatsManager.get_int("stat_distance_km") >= 100:
# AchievementManager.unlock("ACH_DISTANCE_100")
# if StatsManager.get_int("stat_distance_km") >= 200:
# AchievementManager.unlock("ACH_DISTANCE_200")
signal unlocked(api_name: String)

View File

@@ -7,7 +7,7 @@ extends Node
#if you have an error setting achievements or stats in debug mode remember to open your steam client
#with jmp games account or another account who bought this game. If error persist try to clos and reopen steam client.
const KNOWN := [
"stat_games_played",
"stat_time_played",
"stat_distance_km",
"stat_stop_number",
"stat_photo_number",
@@ -16,11 +16,11 @@ const KNOWN := [
#how it works:
#func _on_match_finished(score: int) -> void:
# Stats.add_int("stat_games_played", 1)
# Stats.set_int("stat_total_score", Stats.get_int("stat_total_score") + score)
# Stats.store() #only one push at the end of the game
# if Stats.get_int("stat_games_played") >= 10:
# Achievements.unlock("ACH_PLAY_10_GAMES") #it call storeStats()
# StatsManager.add_int("stat_time_played", 1)
# StatsManager.set_int("stat_total_score", StatsManager.get_int("stat_total_score") + score)
# StatsManager.store() #only one push at the end of the game
# if StatsManager.get_int("stat_time_played") >= 10:
# AchievementManager.unlock("ACH_PLAY_10_HOURS") #it call storeStats()
func _ready() -> void:
@@ -64,8 +64,8 @@ func store() -> void:
#Development only: reset stats
func reset_all(include_achievements: bool = false) -> void:
Steam.resetAllStats(include_achievements)
Steam.storeStats()
if !Steam.resetAllStats(include_achievements):
push_error("resetAllStats failed")
func _on_stats_stored(_game: int, result: int) -> void:
if !result:

57
core/transition.gdshader Normal file
View File

@@ -0,0 +1,57 @@
shader_type canvas_item;
uniform vec4 base_color : source_color;
uniform vec2 node_resolution;
uniform float factor : hint_range(0.0, 1.0, 0.01) = 0.54;
uniform float width = 0.4;
group_uniforms gradient;
uniform sampler2D gradient_texture;
uniform bool gradient_fixed = false;
group_uniforms shape;
uniform sampler2D shape_texture;
uniform float shape_tiling = 32.0;
uniform float shape_rotation = 0.0;
uniform vec2 shape_scroll = vec2(0.0);
uniform float shape_feathering : hint_range(0.0, 1.0, 0.01) = 0.00;
uniform float shape_treshold : hint_range(0.0, 2.0, 0.01) = 1.0;
float gradient(vec2 uv, vec2 fixed_uv, bool fixed){
float value = 0.0;
if(fixed){
value = texture(gradient_texture, fixed_uv).r;
} else {
value = texture(gradient_texture, uv).r;
}
return value;
}
vec2 rotate(vec2 uv, vec2 pivot, float angle)
{
mat2 rotation = mat2(vec2(sin(angle), -cos(angle)),
vec2(cos(angle), sin(angle)));
uv -= pivot;
uv = uv * rotation;
uv += pivot;
return uv;
}
void fragment() {
float progress = mix(-width, 1.0, factor);
float aspect = node_resolution.y / node_resolution.x;
vec2 aspect_uv = ((UV-vec2(0.0,0.5)) * vec2(1.0, aspect))+vec2(0.0,0.5);
float value = clamp((gradient(UV, aspect_uv, gradient_fixed) - progress) / (width), 0.0, 1.0);
vec2 tiled_uv = rotate(mod((aspect_uv + vec2(TIME)*shape_scroll) * shape_tiling, 1.0), vec2(0.5), radians(shape_rotation));
float shape_value = 1.0 - texture(shape_texture, tiled_uv).r;
shape_value = mix(shape_feathering * 0.5, 1.0 - shape_feathering * 0.5, shape_value);
float shaped_gradient = smoothstep(value - (shape_feathering * 0.5), value + (shape_feathering * 0.5), shape_treshold - shape_value);
COLOR.rgb = base_color.rgb;
COLOR.a = shaped_gradient;
}

View File

@@ -0,0 +1 @@
uid://ovrd5ydp8p0q

View File

@@ -43,3 +43,7 @@ signal day_time_changed(value: float, time_string: String)
signal time_option_item_changed(index: int)
@warning_ignore("unused_signal")
signal day_time_option_changed(index: int)
#train signals
@warning_ignore("unused_signal")
signal toot_toot()