Added game seed saving
This commit is contained in:
+3
-1
@@ -24,7 +24,7 @@ func _ready() -> void:
|
|||||||
pause_screen.hide()
|
pause_screen.hide()
|
||||||
game_over_screen.hide()
|
game_over_screen.hide()
|
||||||
|
|
||||||
start_game(SaveManager.game_data)
|
start_game(SaveManager.get_game_data())
|
||||||
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
@@ -93,6 +93,8 @@ func _show_main_menu() -> void:
|
|||||||
if _current_passage_scene: _current_passage_scene.queue_free()
|
if _current_passage_scene: _current_passage_scene.queue_free()
|
||||||
if _current_area_map_scene: _current_area_map_scene.queue_free()
|
if _current_area_map_scene: _current_area_map_scene.queue_free()
|
||||||
|
|
||||||
|
SaveManager.save()
|
||||||
|
|
||||||
get_tree().paused = false
|
get_tree().paused = false
|
||||||
get_tree().change_scene_to_file("res://menu/title_screen.tscn")
|
get_tree().change_scene_to_file("res://menu/title_screen.tscn")
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,62 @@
|
|||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
|
||||||
var game_data : GameData
|
const SAVE_FILE = "user://save.bin"
|
||||||
|
const SAVE_FILE_PASS = "save_file_data"
|
||||||
|
|
||||||
|
const CATEGORY_GAME = "game"
|
||||||
|
const PARAMETER_GAME_SEED = "seed"
|
||||||
|
const PARAMETER_GAME_AREA_INDEX = "current_area_index"
|
||||||
|
const PARAMETER_GAME_STAGE_INDEX = "current_stage_index"
|
||||||
|
const PARAMETER_GAME_SECTOR_INDEX = "current_sector_index"
|
||||||
|
|
||||||
|
|
||||||
|
var _save_file: ConfigFile
|
||||||
|
|
||||||
|
var _game_data : GameData
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
_load()
|
||||||
|
|
||||||
|
|
||||||
|
func save() -> void:
|
||||||
|
_save_file.set_value(CATEGORY_GAME, PARAMETER_GAME_SEED, _game_data.game_seed)
|
||||||
|
_save_file.set_value(CATEGORY_GAME, PARAMETER_GAME_AREA_INDEX, _game_data.current_area_index)
|
||||||
|
_save_file.set_value(CATEGORY_GAME, PARAMETER_GAME_AREA_INDEX, _game_data.current_stage_index)
|
||||||
|
_save_file.set_value(CATEGORY_GAME, PARAMETER_GAME_AREA_INDEX, _game_data.current_sector_index)
|
||||||
|
|
||||||
|
_save_file.save_encrypted_pass(SAVE_FILE, SAVE_FILE_PASS)
|
||||||
|
|
||||||
|
|
||||||
|
func new_game() -> void:
|
||||||
|
_game_data.randomize()
|
||||||
|
|
||||||
|
|
||||||
|
func get_game_data() -> GameData:
|
||||||
|
return _game_data
|
||||||
|
|
||||||
|
|
||||||
|
func _load() -> void:
|
||||||
|
_save_file = ConfigFile.new()
|
||||||
|
_game_data = GameData.new()
|
||||||
|
|
||||||
|
if _save_file.load_encrypted_pass(SAVE_FILE, SAVE_FILE_PASS) == OK:
|
||||||
|
_process_save_file()
|
||||||
|
|
||||||
|
save()
|
||||||
|
|
||||||
|
|
||||||
|
func _process_save_file() -> void:
|
||||||
|
_game_data.game_seed = _save_file.get_value(
|
||||||
|
CATEGORY_GAME, PARAMETER_GAME_SEED, _game_data.game_seed
|
||||||
|
)
|
||||||
|
_game_data.current_area_index = _save_file.get_value(
|
||||||
|
CATEGORY_GAME, PARAMETER_GAME_AREA_INDEX, _game_data.current_area_index
|
||||||
|
)
|
||||||
|
_game_data.current_stage_index = _save_file.get_value(
|
||||||
|
CATEGORY_GAME, PARAMETER_GAME_AREA_INDEX, _game_data.current_stage_index
|
||||||
|
)
|
||||||
|
_game_data.current_sector_index = _save_file.get_value(
|
||||||
|
CATEGORY_GAME, PARAMETER_GAME_AREA_INDEX, _game_data.current_sector_index
|
||||||
|
)
|
||||||
|
|||||||
@@ -15,12 +15,15 @@ signal show_options
|
|||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
_init_focus()
|
_init_focus()
|
||||||
_setup_neighbors()
|
_setup_neighbors()
|
||||||
|
continue_button.disabled = SaveManager.get_game_data().game_seed == ""
|
||||||
|
|
||||||
|
|
||||||
func _on_visibility_changed() -> void:
|
func _on_visibility_changed() -> void:
|
||||||
if not is_node_ready(): return
|
if not is_node_ready(): return
|
||||||
if not visible: return
|
if not visible: return
|
||||||
|
|
||||||
|
continue_button.disabled = SaveManager.get_game_data().game_seed == ""
|
||||||
|
|
||||||
_init_focus()
|
_init_focus()
|
||||||
_setup_neighbors()
|
_setup_neighbors()
|
||||||
|
|
||||||
|
|||||||
@@ -21,14 +21,11 @@ func _show_menu(menu: Control) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _on_main_menu_continue_game() -> void:
|
func _on_main_menu_continue_game() -> void:
|
||||||
print("continue")
|
get_tree().change_scene_to_file("res://game/game.tscn")
|
||||||
|
|
||||||
|
|
||||||
func _on_main_menu_new_game() -> void:
|
func _on_main_menu_new_game() -> void:
|
||||||
var game_data := GameData.new()
|
SaveManager.new_game()
|
||||||
game_data.randomize()
|
|
||||||
SaveManager.game_data = game_data
|
|
||||||
|
|
||||||
get_tree().change_scene_to_file("res://game/game.tscn")
|
get_tree().change_scene_to_file("res://game/game.tscn")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user