diff --git a/core/game_state/game_state.gd b/core/game_state/game_state.gd index 9118df9..5fb9e27 100644 --- a/core/game_state/game_state.gd +++ b/core/game_state/game_state.gd @@ -22,6 +22,7 @@ signal on_photo_taken_finished signal on_photo_mode_black_screen_disappeared const SAVE_PATH: String = "user://savegame.json" +const SAVE_PASSWORD: String = "jmpgames_megapwd" var save_data: SaveGameData = SaveGameData.new() var is_loaded: bool = false @@ -77,29 +78,55 @@ func apply_train_colors() -> void: ) DisplayServer.window_set_position(screen_center - window_half_size) - -func save_game() -> void: - var save_file = FileAccess.open(SAVE_PATH, FileAccess.WRITE) - var json_string = JSON.stringify(save_data.to_dictionary()) - save_file.store_line(json_string) - +#encrypted file + binary serialization (standard) func load_game() -> void: if not FileAccess.file_exists(SAVE_PATH): save_data = SaveGameData.new() is_loaded = true return - - var file = FileAccess.open(SAVE_PATH, FileAccess.READ) - var json_string = file.get_as_text() - - var json = JSON.new() - var parse_result = json.parse(json_string) - + + var file := FileAccess.open_encrypted_with_pass(SAVE_PATH, FileAccess.READ, SAVE_PASSWORD) save_data = SaveGameData.new() - if parse_result == OK and json.data is Dictionary: - save_data = SaveGameData.from_dictionary(json.data) - + if file != null: + var data = file.get_var() + file.close() + if data is Dictionary: + save_data = SaveGameData.from_dictionary(data) + #if file == null the key or the file is corrupted -> start with new data is_loaded = true + + +func save_game() -> void: + var file := FileAccess.open_encrypted_with_pass(SAVE_PATH, FileAccess.WRITE, SAVE_PASSWORD) + if file == null: + push_error("Salvataggio fallito: %s" % FileAccess.get_open_error()) + return + file.store_var(save_data.to_dictionary()) # binario, non JSON + file.close() + +#JSon Version +#func save_game() -> void: + #var save_file = FileAccess.open(SAVE_PATH, FileAccess.WRITE) + #var json_string = JSON.stringify(save_data.to_dictionary()) + #save_file.store_line(json_string) +# +#func load_game() -> void: + #if not FileAccess.file_exists(SAVE_PATH): + #save_data = SaveGameData.new() + #is_loaded = true + #return + # + #var file = FileAccess.open(SAVE_PATH, FileAccess.READ) + #var json_string = file.get_as_text() + # + #var json = JSON.new() + #var parse_result = json.parse(json_string) + # + #save_data = SaveGameData.new() + #if parse_result == OK and json.data is Dictionary: + #save_data = SaveGameData.from_dictionary(json.data) + # + #is_loaded = true func pause_game() -> void: get_tree().paused = true diff --git a/core/scene_manager/scene_manager.gd b/core/scene_manager/scene_manager.gd index b48a70d..86ff43c 100644 --- a/core/scene_manager/scene_manager.gd +++ b/core/scene_manager/scene_manager.gd @@ -48,8 +48,8 @@ func _build_material() -> void: mat.set_shader_parameter("shape_tiling", 16.0) mat.set_shader_parameter("shape_rotation", 0.0) mat.set_shader_parameter("shape_scroll", Vector2.ZERO) - mat.set_shader_parameter("shape_feathering", 0.0) - mat.set_shader_parameter("shape_treshold", 1.15) # >1 = full at the end of the transation + mat.set_shader_parameter("shape_feathering", 0.05) + mat.set_shader_parameter("shape_treshold", 1.0) # >=1 -> full at the end of the transation mat.set_shader_parameter("width", 0.5) color_rect.material = mat @@ -80,9 +80,15 @@ func change_scene(scene_enum: SceneConfig.SceneName) -> void: var target_scene: PackedScene = config.scenes[scene_enum] color_rect.mouse_filter = Control.MOUSE_FILTER_STOP - + loading_screen.visible = true + await cover(transition_duration) get_tree().change_scene_to_packed(target_scene) await reveal(transition_duration) + loading_screen.visible = false color_rect.mouse_filter = Control.MOUSE_FILTER_IGNORE + +func quit_game() -> void: + get_tree().quit() +