Add signals on save/loads events
This commit is contained in:
parent
5e89c73c31
commit
53e5ca8f7b
|
|
@ -5,6 +5,12 @@ signal selected_pokemon_changed
|
||||||
signal battle_requested(sent : SentPokemon, target : Node) #emis par ThrowState : BattleLauncher s'y branche
|
signal battle_requested(sent : SentPokemon, target : Node) #emis par ThrowState : BattleLauncher s'y branche
|
||||||
signal battle_finished(outcome : int, target : Node) #emis par BattleLauncher (outcome = valeur de Battle.Outcome)
|
signal battle_finished(outcome : int, target : Node) #emis par BattleLauncher (outcome = valeur de Battle.Outcome)
|
||||||
|
|
||||||
|
signal save_started
|
||||||
|
signal save_finished(success : bool)
|
||||||
|
|
||||||
|
signal load_started
|
||||||
|
signal load_finished(success : bool)
|
||||||
|
|
||||||
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()
|
var player_team : PokemonTeam = PokemonTeam.new()
|
||||||
var player_storage : PokemonStorage = PokemonStorage.new()
|
var player_storage : PokemonStorage = PokemonStorage.new()
|
||||||
|
|
@ -50,17 +56,34 @@ func _set_selected(index : int) -> void:
|
||||||
selected_pokemon_changed.emit()
|
selected_pokemon_changed.emit()
|
||||||
|
|
||||||
func save() -> void:
|
func save() -> void:
|
||||||
|
save_started.emit()
|
||||||
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.set_value("team", "data", player_team.to_dict())
|
||||||
config.set_value("storage", "data", player_storage.to_dict())
|
config.set_value("storage", "data", player_storage.to_dict())
|
||||||
config.save("user://save.cfg")
|
|
||||||
|
var err := config.save("user://save.cfg")
|
||||||
|
save_finished.emit(err == OK)
|
||||||
|
|
||||||
|
func has_save() -> bool:
|
||||||
|
return FileAccess.file_exists("user://save.cfg")
|
||||||
|
|
||||||
func load_data() -> void:
|
func load_data() -> void:
|
||||||
|
if not has_save():
|
||||||
|
load_finished.emit(false)
|
||||||
|
return
|
||||||
|
|
||||||
|
load_started.emit()
|
||||||
|
|
||||||
var config := ConfigFile.new()
|
var config := ConfigFile.new()
|
||||||
if config.load("user://save.cfg") == OK:
|
var err : Error = config.load("user://save.cfg")
|
||||||
|
var success := err == OK
|
||||||
|
|
||||||
|
if success:
|
||||||
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", {})
|
var team_data : Variant = config.get_value("team", "data", {})
|
||||||
player_team = PokemonTeam.from_dict(team_data) if team_data is Dictionary else PokemonTeam.new()
|
player_team = PokemonTeam.from_dict(team_data) if team_data is Dictionary else PokemonTeam.new()
|
||||||
var storage_data : Variant = config.get_value("storage", "data", {})
|
var storage_data : Variant = config.get_value("storage", "data", {})
|
||||||
player_storage = PokemonStorage.from_dict(storage_data) if storage_data is Dictionary else PokemonStorage.new()
|
player_storage = PokemonStorage.from_dict(storage_data) if storage_data is Dictionary else PokemonStorage.new()
|
||||||
|
|
||||||
|
load_finished.emit(success)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue