add steam overlay, achievements and stats managers

This commit is contained in:
2026-06-23 11:17:31 +02:00
parent efb7a78cf1
commit 298e6cd229
54 changed files with 1031 additions and 13 deletions

View File

@@ -0,0 +1,73 @@
extends Node
#Achievement e statistiche devono essere pubblicati live nel backend
#Steamworks anche se il gioco non è ancora uscito altrimenti le chiamate ritornano errore
const KNOWN := [
"ACH_FIRST_WIN",
"ACH_PLAY_10_GAMES",
"ACH_REACH_LEVEL_5",
]
#how it works:
#func _on_player_won() -> void:
# Achievements.unlock("ACH_FIRST_WIN") #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")
signal unlocked(api_name: String)
func _ready() -> void:
if not SteamManager.is_on_steam:
return
Steam.user_achievement_stored.connect(_on_achievement_stored)
Steam.global_achievement_percentages_ready.connect(_on_global_percentages_ready)
Steam.requestGlobalAchievementPercentages() # asincrona
func _on_global_percentages_ready(_game: int, _result: int) -> void:
pass
func unlock(api_name: String) -> void:
if not KNOWN.has(api_name):
push_warning("Achievement unknown: %s" % api_name)
return
if is_unlocked(api_name):
return
if not Steam.setAchievement(api_name):
push_error("setAchievement failed (is published on Steam?): %s" % api_name)
return
Steam.storeStats()
unlocked.emit(api_name)
func is_unlocked(api_name: String) -> bool:
var data: Dictionary = Steam.getAchievement(api_name)
return data.get("achieved", false)
func get_display_name(api_name: String) -> String:
return Steam.getAchievementDisplayAttribute(api_name, "name")
func get_description(api_name: String) -> String:
return Steam.getAchievementDisplayAttribute(api_name, "desc")
#Global percentage of player who have unlocked the achievement
func get_global_percent(api_name: String) -> float:
var data: Dictionary = Steam.getAchievementAchievedPercent(api_name)
if not data.get("ret", false):
return -1.0 #global percentage not yet available
return data.get("percent", 0.0)
#for development only: reset an achievement
func clear(api_name: String) -> void:
Steam.clearAchievement(api_name)
Steam.storeStats()
func _on_achievement_stored(_game: int, _group: bool, api_name: String,
current: int, maximum: int) -> void:
print("Achievement confirmed by server: %s (%d/%d)" % [api_name, current, maximum])