test stats anche achievements

This commit is contained in:
2026-06-23 12:45:00 +02:00
parent 298e6cd229
commit aad14ab242
5 changed files with 58 additions and 15 deletions

View File

@@ -1,5 +1,8 @@
extends Path3D
const STEAM_DISTANCE_STAT: String = "stat_distance_km"
const STEAM_DISTANCE_KM_PER_UNIT: float = 1#0.001
@export_group("Train")
##train speed
@export var train_speed: float = 6.0
@@ -79,6 +82,7 @@ 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
func _ready() -> void:
randomize()
@@ -328,6 +332,7 @@ func train_move(delta: float) -> void:
var current_speed = train_speed * stop_multiply
train_progress += current_speed * delta
_track_steam_distance(abs(current_speed) * delta)
if enable_stops and stop_offset.size() > 0:
var target_offset = stop_offset[next_stop_index]
@@ -385,6 +390,29 @@ func train_move(delta: float) -> void:
train_instance.rotation.z += curve_roll
train_instance.rotation.x += curve_pitch
#Calculate train distance for steam stats
func _track_steam_distance(distance_units: float) -> void:
if distance_units <= 0.0 or not SteamManager.is_on_steam:
return
_pending_steam_distance_km += distance_units * STEAM_DISTANCE_KM_PER_UNIT
var whole_km: int = int(floor(_pending_steam_distance_km))
if whole_km <= 0:
return
_pending_steam_distance_km -= float(whole_km)
var total_distance_km: int = StatsManager.get_int(STEAM_DISTANCE_STAT) + whole_km
StatsManager.set_int(STEAM_DISTANCE_STAT, total_distance_km)
_check_distance_achievements(total_distance_km)
StatsManager.store()
#Check achievements
func _check_distance_achievements(total_distance_km: int) -> void:
if total_distance_km >= 100:
AchievementManager.unlock("ACH_DISTANCE_100")
if total_distance_km >= 200:
AchievementManager.unlock("ACH_DISTANCE_200")
func _execute_stop(go_forward: bool = true) -> void:
stop_ongoing = true
stop_multiply = 0.0

View File

@@ -1,25 +1,26 @@
extends Node
#Achievement e statistiche devono essere pubblicati live nel backend
#Steamworks anche se il gioco non è ancora uscito altrimenti le chiamate ritornano errore
#Achievements and stats must be published on Steam even if game is not yet released
#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_FIRST_WIN",
"ACH_PLAY_10_GAMES",
"ACH_REACH_LEVEL_5",
"ACH_DISTANCE_100",
"ACH_DISTANCE_200",
"ACH_10_PHOTOS",
]
#how it works:
#func _on_player_won() -> void:
# Achievements.unlock("ACH_FIRST_WIN") #unlock the achievement at first win
# Achievements.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_games_played") >= 10:
# Achievements.unlock("ACH_PLAY_10_GAMES")
# if Stats.get_int("stat_total_coins") >= 100:
# Achievements.unlock("ACH_COLLECT_100_COINS")
# 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")
signal unlocked(api_name: String)

View File

@@ -1,11 +1,17 @@
extends Node
#Achievement e statistiche devono essere pubblicati live nel backend
#Steamworks anche se il gioco non è ancora uscito altrimenti le chiamate ritornano errore
### SISETMARE SU RAILS IL FATTORE DI CONVERSIONE DA UNITA' A KM!!!
### ORA HO LASCIATO 1:1 PER TEST
#Achievements and stats must be published on Steam even if game is not yet released
#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_total_score",
"stat_distance_km",
"stat_stop_number",
"stat_photo_number",
"stat_toottoot_number",
]
#how it works:
@@ -16,6 +22,7 @@ const KNOWN := [
# if Stats.get_int("stat_games_played") >= 10:
# Achievements.unlock("ACH_PLAY_10_GAMES") #it call storeStats()
func _ready() -> void:
if not SteamManager.is_on_steam:
return
@@ -32,6 +39,7 @@ func set_int(stat: String, value: int) -> void:
if not KNOWN.has(stat):
push_warning("Stat not found: %s" % stat)
return
if not Steam.setStatInt(stat, value):
push_error("setStatInt failed (incremental with value less than current value? is published on steam?): %s" % stat)
@@ -39,6 +47,7 @@ func set_float(stat: String, value: float) -> void:
if not KNOWN.has(stat):
push_warning("Stat not found: %s" % stat)
return
if not Steam.setStatFloat(stat, value):
push_error("setStatFloat failed: %s" % stat)
@@ -59,4 +68,5 @@ func reset_all(include_achievements: bool = false) -> void:
Steam.storeStats()
func _on_stats_stored(_game: int, result: int) -> void:
print("Stats save on server, result=%d" % result)
if !result:
print("stats not ready: (result %d)" % [result])

View File

@@ -1,5 +1,8 @@
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 APP_ID: int = 4809260 #Train Goes Choo Choo
var is_on_steam: bool = false
@@ -21,7 +24,7 @@ func _ready() -> void:
func _process(_delta: float) -> void:
if is_on_steam:
Steam.run_callbacks() # every frame, always
Steam.run_callbacks() #every frame, forever
func _on_overlay_toggled(active: bool, _user_initiated: bool, _app_id: int) -> void:
get_tree().paused = active

View File

@@ -262,6 +262,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -91.191925, 0, 539.03174)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -312.19193, 0, 349.03174)
[node name="Control" type="Control" parent="." unique_id=630650980]
visible = false
layout_mode = 3
anchors_preset = 0
offset_right = 40.0