Added indexes saving
This commit is contained in:
+27
-2
@@ -10,6 +10,7 @@ var data : WorldData
|
||||
var current_area : AreaData
|
||||
var current_stage : StageData
|
||||
var current_sector : SectorData
|
||||
var current_passage : PassageData
|
||||
|
||||
var _current_passage_scene : Passage
|
||||
var _current_area_map_scene : AreaMap
|
||||
@@ -24,7 +25,7 @@ func _ready() -> void:
|
||||
pause_screen.hide()
|
||||
game_over_screen.hide()
|
||||
|
||||
start_game(SaveManager.get_game_data())
|
||||
start_game(SaveManager.game_data)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
@@ -70,6 +71,8 @@ func _create_game_map() -> void:
|
||||
|
||||
func _show_map() -> void:
|
||||
if _current_passage_scene != null: _current_passage_scene.queue_free()
|
||||
_current_area_map_scene.current_sector = current_sector
|
||||
_current_area_map_scene.selected_sector = current_sector
|
||||
_current_area_map_scene.show()
|
||||
|
||||
|
||||
@@ -77,11 +80,13 @@ func _create_passage(passage_data: PassageData) -> void:
|
||||
if _current_passage_scene != null: _current_passage_scene.queue_free()
|
||||
_current_area_map_scene.hide()
|
||||
|
||||
current_passage = passage_data
|
||||
|
||||
_current_passage_scene = PASSAGE.instantiate()
|
||||
add_child(_current_passage_scene)
|
||||
|
||||
_current_passage_scene.data = passage_data
|
||||
_current_passage_scene.completed.connect(_show_map)
|
||||
_current_passage_scene.completed.connect(_on_passage_completion)
|
||||
_current_passage_scene.player_died.connect(_on_passage_player_died)
|
||||
|
||||
|
||||
@@ -100,4 +105,24 @@ func _show_main_menu() -> void:
|
||||
|
||||
|
||||
func _on_passage_player_died() -> void:
|
||||
SaveManager.delete_game_data()
|
||||
game_over_screen.show()
|
||||
|
||||
|
||||
func _on_passage_completion() -> void:
|
||||
current_sector = current_passage.next_sector
|
||||
_update_data_indexes()
|
||||
_show_map()
|
||||
|
||||
|
||||
func _update_data_indexes() -> void:
|
||||
for area_index in range(data.areas.size()):
|
||||
var area := data.areas[area_index]
|
||||
for stage_index in range(area.stages.size()):
|
||||
var stage := area.stages[stage_index]
|
||||
for sector_index in range(stage.sectors.size()):
|
||||
if stage.sectors[sector_index] == current_sector:
|
||||
SaveManager.game_data.current_area_index = area_index
|
||||
SaveManager.game_data.current_stage_index = stage_index
|
||||
SaveManager.game_data.current_sector_index = sector_index
|
||||
SaveManager.save()
|
||||
|
||||
+18
-17
@@ -13,7 +13,7 @@ const PARAMETER_GAME_SECTOR_INDEX = "current_sector_index"
|
||||
|
||||
var _save_file: ConfigFile
|
||||
|
||||
var _game_data : GameData
|
||||
var game_data : GameData
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -21,25 +21,26 @@ func _ready() -> void:
|
||||
|
||||
|
||||
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.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()
|
||||
game_data.randomize()
|
||||
|
||||
|
||||
func get_game_data() -> GameData:
|
||||
return _game_data
|
||||
func delete_game_data() -> void:
|
||||
game_data = GameData.new()
|
||||
save()
|
||||
|
||||
|
||||
func _load() -> void:
|
||||
_save_file = ConfigFile.new()
|
||||
_game_data = GameData.new()
|
||||
game_data = GameData.new()
|
||||
|
||||
if _save_file.load_encrypted_pass(SAVE_FILE, SAVE_FILE_PASS) == OK:
|
||||
_process_save_file()
|
||||
@@ -48,15 +49,15 @@ func _load() -> void:
|
||||
|
||||
|
||||
func _process_save_file() -> void:
|
||||
_game_data.game_seed = _save_file.get_value(
|
||||
CATEGORY_GAME, PARAMETER_GAME_SEED, _game_data.game_seed
|
||||
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_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_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
|
||||
game_data.current_sector_index = _save_file.get_value(
|
||||
CATEGORY_GAME, PARAMETER_GAME_AREA_INDEX, game_data.current_sector_index
|
||||
)
|
||||
|
||||
+6
-3
@@ -15,17 +15,20 @@ signal show_options
|
||||
func _ready() -> void:
|
||||
_init_focus()
|
||||
_setup_neighbors()
|
||||
continue_button.disabled = SaveManager.get_game_data().game_seed == ""
|
||||
_update_continue_button()
|
||||
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if not is_node_ready(): return
|
||||
if not visible: return
|
||||
|
||||
continue_button.disabled = SaveManager.get_game_data().game_seed == ""
|
||||
|
||||
_init_focus()
|
||||
_setup_neighbors()
|
||||
_update_continue_button()
|
||||
|
||||
|
||||
func _update_continue_button() -> void:
|
||||
continue_button.disabled = SaveManager.game_data.game_seed.is_empty()
|
||||
|
||||
|
||||
func _init_focus() -> void:
|
||||
|
||||
Reference in New Issue
Block a user