update save mode
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user