add ai, photo_mode and radio
This commit was merged in pull request #11.
This commit is contained in:
32
core/game_state/game_state.gd
Normal file
32
core/game_state/game_state.gd
Normal file
@@ -0,0 +1,32 @@
|
||||
extends Node
|
||||
|
||||
const SAVE_PATH: String = "user://savegame.json"
|
||||
|
||||
var save_data: SaveGameData = SaveGameData.new()
|
||||
var is_loaded: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
load_game()
|
||||
|
||||
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
|
||||
1
core/game_state/game_state.gd.uid
Normal file
1
core/game_state/game_state.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b17g2w2g101o6
|
||||
34
core/game_state/save_game_data.gd
Normal file
34
core/game_state/save_game_data.gd
Normal file
@@ -0,0 +1,34 @@
|
||||
class_name SaveGameData
|
||||
extends Resource
|
||||
|
||||
var unlocked_collectibles_ids: Array[StringName] = []
|
||||
var saved_photos: Array[String] = []
|
||||
var audio_bus_volumes: Dictionary[String, float] = {}
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
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])
|
||||
|
||||
return save_game_data
|
||||
1
core/game_state/save_game_data.gd.uid
Normal file
1
core/game_state/save_game_data.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bxmvs842r82vl
|
||||
Reference in New Issue
Block a user