87 lines
2.9 KiB
GDScript
87 lines
2.9 KiB
GDScript
class_name SaveGameData
|
|
extends Resource
|
|
|
|
var unlocked_collectibles_ids: Array[StringName] = []
|
|
var saved_photos: Array[String] = []
|
|
var audio_bus_volumes: Dictionary[String, float] = {}
|
|
|
|
var anti_aliasing: bool = true
|
|
var window_mode_index: int = 0
|
|
var resolution_x: int = 1920
|
|
var resolution_y: int = 1080
|
|
var train_color_1: String = ""
|
|
var train_color_2: String = ""
|
|
var train_color_1_index: int = 0
|
|
var train_color_2_index: int = 0
|
|
|
|
var total_distance_km: float = 0.0
|
|
var total_time_played_seconds: float = 0.0
|
|
|
|
func to_dictionary() -> Dictionary:
|
|
var serialized_collectible_ids: Array[String] = []
|
|
for collectible_id in unlocked_collectibles_ids:
|
|
serialized_collectible_ids.append(str(collectible_id))
|
|
|
|
return {
|
|
"unlocked_collectibles_ids": serialized_collectible_ids,
|
|
"saved_photos": saved_photos,
|
|
"audio_bus_volumes": audio_bus_volumes,
|
|
"anti_aliasing": anti_aliasing,
|
|
"window_mode_index": window_mode_index,
|
|
"resolution_x": resolution_x,
|
|
"resolution_y": resolution_y,
|
|
"train_color_1": train_color_1,
|
|
"train_color_2": train_color_2,
|
|
"train_color_1_index": train_color_1_index,
|
|
"train_color_2_index": train_color_2_index,
|
|
"total_distance_km": total_distance_km,
|
|
"total_time_played_seconds": total_time_played_seconds,
|
|
}
|
|
|
|
static func from_dictionary(data: Dictionary) -> SaveGameData:
|
|
var save_game_data := SaveGameData.new()
|
|
|
|
if data.has("unlocked_collectibles_ids"):
|
|
for collectible_id in data["unlocked_collectibles_ids"]:
|
|
save_game_data.unlocked_collectibles_ids.append(StringName(str(collectible_id)))
|
|
|
|
if data.has("saved_photos"):
|
|
for photo_path in data["saved_photos"]:
|
|
save_game_data.saved_photos.append(str(photo_path))
|
|
|
|
if data.has("audio_bus_volumes") and data["audio_bus_volumes"] is Dictionary:
|
|
for bus_name in data["audio_bus_volumes"]:
|
|
save_game_data.audio_bus_volumes[str(bus_name)] = float(data["audio_bus_volumes"][bus_name])
|
|
|
|
if data.has("anti_aliasing"):
|
|
save_game_data.anti_aliasing = bool(data["anti_aliasing"])
|
|
|
|
if data.has("window_mode_index"):
|
|
save_game_data.window_mode_index = int(data["window_mode_index"])
|
|
|
|
if data.has("resolution_x"):
|
|
save_game_data.resolution_x = int(data["resolution_x"])
|
|
|
|
if data.has("resolution_y"):
|
|
save_game_data.resolution_y = int(data["resolution_y"])
|
|
|
|
if data.has("train_color_1"):
|
|
save_game_data.train_color_1 = str(data["train_color_1"])
|
|
|
|
if data.has("train_color_2"):
|
|
save_game_data.train_color_2 = str(data["train_color_2"])
|
|
|
|
if data.has("train_color_1_index"):
|
|
save_game_data.train_color_1_index = int(data["train_color_1_index"])
|
|
|
|
if data.has("train_color_2_index"):
|
|
save_game_data.train_color_2_index = int(data["train_color_2_index"])
|
|
|
|
if data.has("total_distance_km"):
|
|
save_game_data.total_distance_km = float(data["total_distance_km"])
|
|
|
|
if data.has("total_time_played_seconds"):
|
|
save_game_data.total_time_played_seconds = float(data["total_time_played_seconds"])
|
|
|
|
return save_game_data
|