update save mode
This commit is contained in:
@@ -22,6 +22,7 @@ signal on_photo_taken_finished
|
|||||||
signal on_photo_mode_black_screen_disappeared
|
signal on_photo_mode_black_screen_disappeared
|
||||||
|
|
||||||
const SAVE_PATH: String = "user://savegame.json"
|
const SAVE_PATH: String = "user://savegame.json"
|
||||||
|
const SAVE_PASSWORD: String = "jmpgames_megapwd"
|
||||||
|
|
||||||
var save_data: SaveGameData = SaveGameData.new()
|
var save_data: SaveGameData = SaveGameData.new()
|
||||||
var is_loaded: bool = false
|
var is_loaded: bool = false
|
||||||
@@ -77,29 +78,55 @@ func apply_train_colors() -> void:
|
|||||||
)
|
)
|
||||||
DisplayServer.window_set_position(screen_center - window_half_size)
|
DisplayServer.window_set_position(screen_center - window_half_size)
|
||||||
|
|
||||||
|
#encrypted file + binary serialization (standard)
|
||||||
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:
|
func load_game() -> void:
|
||||||
if not FileAccess.file_exists(SAVE_PATH):
|
if not FileAccess.file_exists(SAVE_PATH):
|
||||||
save_data = SaveGameData.new()
|
save_data = SaveGameData.new()
|
||||||
is_loaded = true
|
is_loaded = true
|
||||||
return
|
return
|
||||||
|
|
||||||
var file = FileAccess.open(SAVE_PATH, FileAccess.READ)
|
var file := FileAccess.open_encrypted_with_pass(SAVE_PATH, FileAccess.READ, SAVE_PASSWORD)
|
||||||
var json_string = file.get_as_text()
|
|
||||||
|
|
||||||
var json = JSON.new()
|
|
||||||
var parse_result = json.parse(json_string)
|
|
||||||
|
|
||||||
save_data = SaveGameData.new()
|
save_data = SaveGameData.new()
|
||||||
if parse_result == OK and json.data is Dictionary:
|
if file != null:
|
||||||
save_data = SaveGameData.from_dictionary(json.data)
|
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
|
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:
|
func pause_game() -> void:
|
||||||
get_tree().paused = true
|
get_tree().paused = true
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ func _build_material() -> void:
|
|||||||
mat.set_shader_parameter("shape_tiling", 16.0)
|
mat.set_shader_parameter("shape_tiling", 16.0)
|
||||||
mat.set_shader_parameter("shape_rotation", 0.0)
|
mat.set_shader_parameter("shape_rotation", 0.0)
|
||||||
mat.set_shader_parameter("shape_scroll", Vector2.ZERO)
|
mat.set_shader_parameter("shape_scroll", Vector2.ZERO)
|
||||||
mat.set_shader_parameter("shape_feathering", 0.0)
|
mat.set_shader_parameter("shape_feathering", 0.05)
|
||||||
mat.set_shader_parameter("shape_treshold", 1.15) # >1 = full at the end of the transation
|
mat.set_shader_parameter("shape_treshold", 1.0) # >=1 -> full at the end of the transation
|
||||||
mat.set_shader_parameter("width", 0.5)
|
mat.set_shader_parameter("width", 0.5)
|
||||||
|
|
||||||
color_rect.material = mat
|
color_rect.material = mat
|
||||||
@@ -80,9 +80,15 @@ func change_scene(scene_enum: SceneConfig.SceneName) -> void:
|
|||||||
var target_scene: PackedScene = config.scenes[scene_enum]
|
var target_scene: PackedScene = config.scenes[scene_enum]
|
||||||
|
|
||||||
color_rect.mouse_filter = Control.MOUSE_FILTER_STOP
|
color_rect.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||||
|
loading_screen.visible = true
|
||||||
|
|
||||||
await cover(transition_duration)
|
await cover(transition_duration)
|
||||||
get_tree().change_scene_to_packed(target_scene)
|
get_tree().change_scene_to_packed(target_scene)
|
||||||
await reveal(transition_duration)
|
await reveal(transition_duration)
|
||||||
|
|
||||||
|
loading_screen.visible = false
|
||||||
color_rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
color_rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||||
|
|
||||||
|
func quit_game() -> void:
|
||||||
|
get_tree().quit()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user