From 08c283d76aa81072156aaf56fbe67cf3ffae721b Mon Sep 17 00:00:00 2001 From: "m.cirafisi" Date: Thu, 16 Apr 2026 16:11:07 +0200 Subject: [PATCH] replace string with string name for collectible_id --- core/game_state/save_game_data.gd | 10 +++++++--- core/photo_mode/data/collectible_library.tres | 6 +++--- core/photo_mode/data/collectible_resource.gd | 2 +- core/photo_mode/managers/collection_manager.gd | 12 ++++++------ core/photo_mode/ui/collectible_gallery.gd | 4 ++-- docs/museums/photo_mode/museum_photo_mode.tscn | 2 +- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/core/game_state/save_game_data.gd b/core/game_state/save_game_data.gd index 08d6c52..8a1cf10 100644 --- a/core/game_state/save_game_data.gd +++ b/core/game_state/save_game_data.gd @@ -1,13 +1,17 @@ class_name SaveGameData extends Resource -var unlocked_collectibles_ids: Array[String] = [] +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": unlocked_collectibles_ids, + "unlocked_collectibles_ids": serialized_collectible_ids, "saved_photos": saved_photos, "audio_bus_volumes": audio_bus_volumes, } @@ -17,7 +21,7 @@ static func from_dictionary(data: Dictionary) -> SaveGameData: if data.has("unlocked_collectibles_ids"): for collectible_id in data["unlocked_collectibles_ids"]: - save_game_data.unlocked_collectibles_ids.append(str(collectible_id)) + save_game_data.unlocked_collectibles_ids.append(StringName(str(collectible_id))) if data.has("saved_photos"): for photo_path in data["saved_photos"]: diff --git a/core/photo_mode/data/collectible_library.tres b/core/photo_mode/data/collectible_library.tres index b40458b..0ee1fe2 100644 --- a/core/photo_mode/data/collectible_library.tres +++ b/core/photo_mode/data/collectible_library.tres @@ -6,21 +6,21 @@ [sub_resource type="Resource" id="Resource_3cgvf"] script = ExtResource("1_3cgvf") -id = "cane" +id = &"cane" title = "Cane" image = ExtResource("2_pxmdy") metadata/_custom_type_script = "uid://bj34o0org55ei" [sub_resource type="Resource" id="Resource_ggu10"] script = ExtResource("1_3cgvf") -id = "gatto" +id = &"gatto" title = "Gatto" image = ExtResource("2_pxmdy") metadata/_custom_type_script = "uid://bj34o0org55ei" [sub_resource type="Resource" id="Resource_pxmdy"] script = ExtResource("1_3cgvf") -id = "farfalla" +id = &"farfalla" title = "Farfalla" image = ExtResource("2_pxmdy") metadata/_custom_type_script = "uid://bj34o0org55ei" diff --git a/core/photo_mode/data/collectible_resource.gd b/core/photo_mode/data/collectible_resource.gd index a25fe96..90e2d4d 100644 --- a/core/photo_mode/data/collectible_resource.gd +++ b/core/photo_mode/data/collectible_resource.gd @@ -1,6 +1,6 @@ class_name CollectibleResource extends Resource -@export var id: String +@export var id: StringName @export var title: String @export var image: Texture2D diff --git a/core/photo_mode/managers/collection_manager.gd b/core/photo_mode/managers/collection_manager.gd index 6bd4052..193b28a 100644 --- a/core/photo_mode/managers/collection_manager.gd +++ b/core/photo_mode/managers/collection_manager.gd @@ -1,17 +1,17 @@ extends Node -signal on_collectible_unlocked(collectible_id: String) +signal on_collectible_unlocked(collectible_id: StringName) signal on_photo_saved(filePath: String) var collectibles_library: CollectibleLibrary = preload("res://core/photo_mode/data/collectible_library.tres") -var unlocked_collectibles_ids: Array[String] = [] +var unlocked_collectibles_ids: Array[StringName] = [] var saved_photos: Array[String] = [] func _ready() -> void: load_save_data() -func unlock_collectible(collectible_id: String) -> void: +func unlock_collectible(collectible_id: StringName) -> void: if not collectible_id in unlocked_collectibles_ids: var new_collectible = get_collectible_by_id(collectible_id) if new_collectible: @@ -19,7 +19,7 @@ func unlock_collectible(collectible_id: String) -> void: sync_save_data() on_collectible_unlocked.emit(collectible_id) -func get_collectible_by_id(id: String) -> CollectibleResource: +func get_collectible_by_id(id: StringName) -> CollectibleResource: for collectible in collectibles_library.collectibles: if collectible.id == id: return collectible @@ -28,7 +28,7 @@ func get_collectible_by_id(id: String) -> CollectibleResource: func get_all_collectibles() -> Array[CollectibleResource]: return collectibles_library.collectibles -func get_unlocked_collectible_ids() -> Array[String]: +func get_unlocked_collectible_ids() -> Array[StringName]: return unlocked_collectibles_ids func save_photo_to_disk_async() -> void: @@ -55,6 +55,6 @@ func load_save_data() -> void: saved_photos = GameState.save_data.saved_photos.duplicate() if unlocked_collectibles_ids.is_empty() and saved_photos.is_empty(): - unlocked_collectibles_ids.append("cane") + unlocked_collectibles_ids.append(&"cane") sync_save_data() diff --git a/core/photo_mode/ui/collectible_gallery.gd b/core/photo_mode/ui/collectible_gallery.gd index cc1d16a..ea1a87b 100644 --- a/core/photo_mode/ui/collectible_gallery.gd +++ b/core/photo_mode/ui/collectible_gallery.gd @@ -20,7 +20,7 @@ func setup() -> void: if unlocked_collectible_ids.has(collectible.id): _unlock_collectible(collectible.id) -func on_collectible_unlocked(collectible_id: String) -> void: +func on_collectible_unlocked(collectible_id: StringName) -> void: _unlock_collectible(collectible_id) func _add_collectible(collectible: CollectibleResource) -> void: @@ -28,7 +28,7 @@ func _add_collectible(collectible: CollectibleResource) -> void: collectible_ui.setup(collectible) grid_container.add_child(collectible_ui) -func _unlock_collectible(collectible_id: String) -> void: +func _unlock_collectible(collectible_id: StringName) -> void: for collectible_ui in grid_container.get_children(): if collectible_ui.collectible_resource.id == collectible_id: collectible_ui.unlock() diff --git a/docs/museums/photo_mode/museum_photo_mode.tscn b/docs/museums/photo_mode/museum_photo_mode.tscn index aaa55b4..4458ba5 100644 --- a/docs/museums/photo_mode/museum_photo_mode.tscn +++ b/docs/museums/photo_mode/museum_photo_mode.tscn @@ -17,7 +17,7 @@ size = Vector3(1.9942131, 0.09710693, 1.984024) [sub_resource type="Resource" id="Resource_ynvi2"] script = ExtResource("3_hh1ka") -id = "gatto" +id = &"gatto" title = "Gatto" image = ExtResource("4_fan5s") metadata/_custom_type_script = "uid://bj34o0org55ei"