extends Node signal on_collectible_unlocked(collectible_id: String) signal on_photo_saved(filePath: String) var collectibles_library: CollectibleLibrary = preload("res://core/photo_mode/collectible_library.tres") var unlocked_collectibles_ids: Array[String] = [] var saved_photos: Array[String] = [] func _ready() -> void: add_to_group("Saveable") load_save_data() func unlock_collectible(collectible_id: String) -> void: if not collectible_id in unlocked_collectibles_ids: var new_collectible = get_collectible_by_id(collectible_id) if new_collectible: unlocked_collectibles_ids.append(collectible_id) on_collectible_unlocked.emit(collectible_id) func get_collectible_by_id(id: String) -> CollectibleResource: for collectible in collectibles_library.collectibles: if collectible.id == id: return collectible return null func get_all_collectibles() -> Array[CollectibleResource]: return collectibles_library.collectibles func get_unlocked_collectible_ids() -> Array[String]: return unlocked_collectibles_ids func save_photo_to_disk_async() -> void: await RenderingServer.frame_post_draw var image = get_viewport().get_texture().get_image() if not DirAccess.dir_exists_absolute("user://photos"): DirAccess.make_dir_absolute("user://photos") var timestamp = str(Time.get_unix_time_from_system()) var file_path = "user://photos/photo_" + timestamp + ".png" image.save_png(file_path) saved_photos.append(file_path) on_photo_saved.emit(file_path) func get_save_data() -> Dictionary: return { "unlocked_collectibles_ids": unlocked_collectibles_ids, "saved_photos": saved_photos } func load_save_data() -> void: var my_path = str(get_path()) if GameState.save_data.has(my_path): var data = GameState.save_data[my_path] if data.has("unlocked_collectibles_ids"): var loaded_ids = data["unlocked_collectibles_ids"] unlocked_collectibles_ids.clear() for id in loaded_ids: unlocked_collectibles_ids.append(str(id)) if data.has("saved_photos"): var loaded_photos = data["saved_photos"] saved_photos.clear() for photo in loaded_photos: saved_photos.append(str(photo)) else: unlocked_collectibles_ids.append("cane")