Save player team data

This commit is contained in:
TheThomaas 2026-10-04 13:59:28 +02:00
parent ca79aa060c
commit 614e9c934a

View file

@ -2,13 +2,17 @@ extends Node
# Autoload : GameData # Autoload : GameData
var story_progress : int = 0 # 0 = début, 1 = après 1er badge, 2 = après 2e badge, etc. var story_progress : int = 0 # 0 = début, 1 = après 1er badge, 2 = après 2e badge, etc.
var player_team : PokemonTeam = PokemonTeam.new()
func save() -> void: func save() -> void:
var config := ConfigFile.new() var config := ConfigFile.new()
config.set_value("progress", "story_progress", story_progress) config.set_value("progress", "story_progress", story_progress)
config.set_value("team", "data", player_team.to_dict())
config.save("user://save.cfg") config.save("user://save.cfg")
func load_data() -> void: func load_data() -> void:
var config := ConfigFile.new() var config := ConfigFile.new()
if config.load("user://save.cfg") == OK: if config.load("user://save.cfg") == OK:
story_progress = config.get_value("progress", "story_progress", 0) story_progress = config.get_value("progress", "story_progress", 0)
var team_data : Variant = config.get_value("team", "data", {})
player_team = PokemonTeam.from_dict(team_data) if team_data is Dictionary else PokemonTeam.new()