From e02bd1819fb6e980baef07eff09d04d7a73754ea Mon Sep 17 00:00:00 2001 From: "m.cirafisi" Date: Thu, 16 Apr 2026 11:01:04 +0200 Subject: [PATCH] add gamestate, doc and fix --- .idea/.gitignore | 13 ++++ .idea/encodings.xml | 4 ++ .idea/indexLayout.xml | 8 +++ .idea/vcs.xml | 6 ++ core/ai/ai_base/ai_base.gd | 8 +-- core/ai/ai_base/ai_base.tscn | 3 + core/ai/ai_base/state_machine.gd | 2 - core/game_state/game_state.gd | 41 +++++++++++ core/game_state/game_state.gd.uid | 1 + ...n_compendium.gd => collectible_gallery.gd} | 11 ++- ...dium.gd.uid => collectible_gallery.gd.uid} | 0 ...mpendium.tscn => collectible_gallery.tscn} | 15 ++-- core/photo_mode/collectible_ui.gd | 16 +++-- core/photo_mode/collectible_ui.tscn | 6 +- core/photo_mode/collection_manager.gd | 62 +++++++++++++--- core/photo_mode/photo.gd | 11 +++ core/photo_mode/photo.gd.uid | 1 + core/photo_mode/photo.tscn | 38 ++++++++++ core/photo_mode/photo_gallery.gd | 27 +++++++ core/photo_mode/photo_gallery.gd.uid | 1 + core/photo_mode/photo_gallery.tscn | 48 +++++++++++++ core/photo_mode/photo_mode_controller.gd | 15 ++-- core/photo_mode/photo_mode_controller.tscn | 2 + docs/museums/ai/museum_ai.tscn | 38 ++++++++++ docs/museums/photo_mode/museum_photo_mode.gd | 7 +- .../museums/photo_mode/museum_photo_mode.tscn | 71 +++++++++++++++++-- docs/museums/radio/museum_radio.gd | 10 +-- docs/museums/radio/museum_radio.tscn | 71 +++++++++++++------ project.godot | 1 + 29 files changed, 466 insertions(+), 71 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/indexLayout.xml create mode 100644 .idea/vcs.xml create mode 100644 core/game_state/game_state.gd create mode 100644 core/game_state/game_state.gd.uid rename core/photo_mode/{collection_compendium.gd => collectible_gallery.gd} (86%) rename core/photo_mode/{collection_compendium.gd.uid => collectible_gallery.gd.uid} (100%) rename core/photo_mode/{collection_compendium.tscn => collectible_gallery.tscn} (75%) create mode 100644 core/photo_mode/photo.gd create mode 100644 core/photo_mode/photo.gd.uid create mode 100644 core/photo_mode/photo.tscn create mode 100644 core/photo_mode/photo_gallery.gd create mode 100644 core/photo_mode/photo_gallery.gd.uid create mode 100644 core/photo_mode/photo_gallery.tscn diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..d2c0a84 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/modules.xml +/projectSettingsUpdater.xml +/.idea.tgcc.iml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/indexLayout.xml b/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/core/ai/ai_base/ai_base.gd b/core/ai/ai_base/ai_base.gd index 1d31c7a..f75d9d8 100644 --- a/core/ai/ai_base/ai_base.gd +++ b/core/ai/ai_base/ai_base.gd @@ -9,9 +9,9 @@ class_name AIBase toggle_enable_state_machine() -@onready var patrol_radius_shape: CollisionShape3D = $PatrolRadiusShape -@onready var nav_agent: NavigationAgent3D = $NavigationAgent3D -@onready var state_machine: StateMachine = $StateMachine +@onready var patrol_radius_shape: CollisionShape3D = $%PatrolRadiusShape +@onready var nav_agent: NavigationAgent3D = $%NavigationAgent3D +@onready var state_machine: StateMachine = $%StateMachine func _ready() -> void: @@ -19,7 +19,7 @@ func _ready() -> void: toggle_enable_state_machine() func toggle_enable_state_machine() -> void: - $StateMachine.enable = enable_state_machine + state_machine.enable = enable_state_machine func _physics_process(delta: float) -> void: if !enable_state_machine: diff --git a/core/ai/ai_base/ai_base.tscn b/core/ai/ai_base/ai_base.tscn index 74e83b1..810e424 100644 --- a/core/ai/ai_base/ai_base.tscn +++ b/core/ai/ai_base/ai_base.tscn @@ -22,8 +22,10 @@ mesh = SubResource("CapsuleMesh_mh3lg") shape = SubResource("CapsuleShape3D_mh3lg") [node name="NavigationAgent3D" type="NavigationAgent3D" parent="." unique_id=1370024449] +unique_name_in_owner = true [node name="StateMachine" type="Node" parent="." unique_id=1286404264 node_paths=PackedStringArray("initial_state")] +unique_name_in_owner = true script = ExtResource("2_q1hg3") initial_state = NodePath("IdleState") @@ -36,6 +38,7 @@ script = ExtResource("4_lim44") state_id = "patrol" [node name="PatrolRadiusShape" type="CollisionShape3D" parent="." unique_id=1379515938] +unique_name_in_owner = true shape = SubResource("SphereShape3D_lim44") disabled = true debug_color = Color(1, 1, 0, 1) diff --git a/core/ai/ai_base/state_machine.gd b/core/ai/ai_base/state_machine.gd index f76456c..7ae194b 100644 --- a/core/ai/ai_base/state_machine.gd +++ b/core/ai/ai_base/state_machine.gd @@ -44,5 +44,3 @@ func _on_state_transition(state: State, new_state_id: String) -> void: current_state = new_state current_state.enter() - - print("Transizione a: ", current_state.state_id) diff --git a/core/game_state/game_state.gd b/core/game_state/game_state.gd new file mode 100644 index 0000000..2e1be90 --- /dev/null +++ b/core/game_state/game_state.gd @@ -0,0 +1,41 @@ +extends Node + +const SAVE_PATH: String = "user://savegame.json" + +var save_data: Dictionary = {} +var is_loaded: bool = false + +func _ready() -> void: + load_game() + +func save_game() -> void: + var save_file = FileAccess.open(SAVE_PATH, FileAccess.WRITE) + var save_nodes = get_tree().get_nodes_in_group("Saveable") + var new_save_data: Dictionary = {} + + for node in save_nodes: + if not node.has_method("get_save_data"): + continue + + var node_data = node.get_save_data() + var node_path = str(node.get_path()) + new_save_data[node_path] = node_data + + var json_string = JSON.stringify(new_save_data) + save_file.store_line(json_string) + +func load_game() -> void: + if not FileAccess.file_exists(SAVE_PATH): + 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) + + if parse_result == OK: + save_data = json.data + + is_loaded = true diff --git a/core/game_state/game_state.gd.uid b/core/game_state/game_state.gd.uid new file mode 100644 index 0000000..8f8015c --- /dev/null +++ b/core/game_state/game_state.gd.uid @@ -0,0 +1 @@ +uid://b17g2w2g101o6 diff --git a/core/photo_mode/collection_compendium.gd b/core/photo_mode/collectible_gallery.gd similarity index 86% rename from core/photo_mode/collection_compendium.gd rename to core/photo_mode/collectible_gallery.gd index 1b80ba1..c289cc3 100644 --- a/core/photo_mode/collection_compendium.gd +++ b/core/photo_mode/collectible_gallery.gd @@ -1,13 +1,19 @@ extends Control -@onready var grid_container: GridContainer = $PanelContainer/MarginContainer/ScrollContainer/GridContainer +@onready var grid_container: GridContainer = $%CollectibleGrid @onready var collectible_ui_scene = preload("res://core/photo_mode/collectible_ui.tscn") - func _ready() -> void: CollectionManager.on_collectible_unlocked.connect(_unlock_collectible) + setup() + +func setup() -> void: var unlocked_collectible_ids = CollectionManager.get_unlocked_collectible_ids() var collectibles = CollectionManager.get_all_collectibles() + + for child in grid_container.get_children(): + child.queue_free() + for collectible in collectibles: _add_collectible(collectible) if unlocked_collectible_ids.has(collectible.id): @@ -21,7 +27,6 @@ func _add_collectible(collectible: CollectibleResource) -> void: collectible_ui.setup(collectible) grid_container.add_child(collectible_ui) - func _unlock_collectible(collectible_id: String) -> void: for collectible_ui in grid_container.get_children(): if collectible_ui.collectible_resource.id == collectible_id: diff --git a/core/photo_mode/collection_compendium.gd.uid b/core/photo_mode/collectible_gallery.gd.uid similarity index 100% rename from core/photo_mode/collection_compendium.gd.uid rename to core/photo_mode/collectible_gallery.gd.uid diff --git a/core/photo_mode/collection_compendium.tscn b/core/photo_mode/collectible_gallery.tscn similarity index 75% rename from core/photo_mode/collection_compendium.tscn rename to core/photo_mode/collectible_gallery.tscn index 7daa1e5..7767815 100644 --- a/core/photo_mode/collection_compendium.tscn +++ b/core/photo_mode/collectible_gallery.tscn @@ -1,8 +1,8 @@ [gd_scene format=3 uid="uid://bvw086glfpcba"] -[ext_resource type="Script" uid="uid://dq3qtcrdnikl7" path="res://core/photo_mode/collection_compendium.gd" id="1_67tug"] +[ext_resource type="Script" uid="uid://dq3qtcrdnikl7" path="res://core/photo_mode/collectible_gallery.gd" id="1_67tug"] -[node name="CollectionCompendium" type="Control" unique_id=354419843] +[node name="CollectibleGallery" type="Control" unique_id=354419843] layout_mode = 3 anchors_preset = 8 anchor_left = 0.5 @@ -20,10 +20,10 @@ anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -400.0 -offset_top = -400.0 -offset_right = 400.0 -offset_bottom = 400.0 +offset_left = -350.0 +offset_top = -350.0 +offset_right = 350.0 +offset_bottom = 350.0 grow_horizontal = 2 grow_vertical = 2 @@ -38,7 +38,8 @@ theme_override_constants/margin_bottom = 12 layout_mode = 2 draw_focus_border = true -[node name="GridContainer" type="GridContainer" parent="PanelContainer/MarginContainer/ScrollContainer" unique_id=1187865988] +[node name="CollectibleGrid" type="GridContainer" parent="PanelContainer/MarginContainer/ScrollContainer" unique_id=1187865988] +unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 6 size_flags_vertical = 2 diff --git a/core/photo_mode/collectible_ui.gd b/core/photo_mode/collectible_ui.gd index c6e1176..453f528 100644 --- a/core/photo_mode/collectible_ui.gd +++ b/core/photo_mode/collectible_ui.gd @@ -2,15 +2,21 @@ extends Control class_name CollectibleUI -@onready var label: Label = $Panel/MarginContainer/VBoxContainer/Label -@onready var texture_rect: TextureRect = $Panel/MarginContainer/VBoxContainer/TextureRect +@onready var label: Label = $%CollectibleName +@onready var texture_rect: TextureRect = $%CollectibleTexture var collectible_resource: CollectibleResource func setup(collectible: CollectibleResource) -> void: collectible_resource = collectible - $Panel/MarginContainer/VBoxContainer/Label.text = collectible_resource.title + if !label: + label = $%CollectibleName + label.text = collectible_resource.title if collectible.image: - $Panel/MarginContainer/VBoxContainer/TextureRect.texture = collectible_resource.image + if !texture_rect: + texture_rect = $%CollectibleTexture + texture_rect.texture = collectible_resource.image func unlock() -> void: - $Panel/MarginContainer/VBoxContainer/TextureRect.set_modulate(Color(1,1,1,1)) + if !texture_rect: + texture_rect = $%CollectibleTexture + texture_rect.set_modulate(Color(1,1,1,1)) diff --git a/core/photo_mode/collectible_ui.tscn b/core/photo_mode/collectible_ui.tscn index ed2c1db..d26b187 100644 --- a/core/photo_mode/collectible_ui.tscn +++ b/core/photo_mode/collectible_ui.tscn @@ -30,7 +30,8 @@ theme_override_constants/margin_bottom = 12 layout_mode = 2 alignment = 1 -[node name="Label" type="Label" parent="Panel/MarginContainer/VBoxContainer" unique_id=117774359] +[node name="CollectibleName" type="Label" parent="Panel/MarginContainer/VBoxContainer" unique_id=117774359] +unique_name_in_owner = true layout_mode = 2 size_flags_vertical = 0 text = "Collectible" @@ -39,7 +40,8 @@ horizontal_alignment = 1 [node name="HSeparator" type="HSeparator" parent="Panel/MarginContainer/VBoxContainer" unique_id=1345822244] layout_mode = 2 -[node name="TextureRect" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer" unique_id=506844785] +[node name="CollectibleTexture" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer" unique_id=506844785] +unique_name_in_owner = true modulate = Color(0.16206557, 0.1620656, 0.16206557, 1) layout_mode = 2 size_flags_vertical = 3 diff --git a/core/photo_mode/collection_manager.gd b/core/photo_mode/collection_manager.gd index 8c310a8..3bfdbd5 100644 --- a/core/photo_mode/collection_manager.gd +++ b/core/photo_mode/collection_manager.gd @@ -1,26 +1,70 @@ extends Node signal on_collectible_unlocked(collectible_id: String) +signal on_photo_saved(filePath: String) -#TODO -> assign library resource to game_state -var library: CollectibleLibrary = preload("res://core/photo_mode/collectible_library.tres") -var unlocked_ids: Array[String] = ['cane'] +var collectibles_library: CollectibleLibrary = preload("res://core/photo_mode/collectible_library.tres") -func unlock_photo(collectible_id: String) -> void: - if not collectible_id in unlocked_ids: - unlocked_ids.append(collectible_id) +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 library.collectibles: + for collectible in collectibles_library.collectibles: if collectible.id == id: return collectible return null func get_all_collectibles() -> Array[CollectibleResource]: - return library.collectibles + return collectibles_library.collectibles func get_unlocked_collectible_ids() -> Array[String]: - return unlocked_ids + 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") diff --git a/core/photo_mode/photo.gd b/core/photo_mode/photo.gd new file mode 100644 index 0000000..5740c30 --- /dev/null +++ b/core/photo_mode/photo.gd @@ -0,0 +1,11 @@ +extends Control + +class_name Photo + +@onready var texture_rect: TextureRect = $%PhotoTexture + +func setup(texture: Texture) -> void: + if texture: + if !texture_rect: + texture_rect = $%PhotoTexture + texture_rect.texture = texture diff --git a/core/photo_mode/photo.gd.uid b/core/photo_mode/photo.gd.uid new file mode 100644 index 0000000..37f3929 --- /dev/null +++ b/core/photo_mode/photo.gd.uid @@ -0,0 +1 @@ +uid://dsey5dvc11vpq diff --git a/core/photo_mode/photo.tscn b/core/photo_mode/photo.tscn new file mode 100644 index 0000000..77267d9 --- /dev/null +++ b/core/photo_mode/photo.tscn @@ -0,0 +1,38 @@ +[gd_scene format=3 uid="uid://cvus62qkop3qi"] + +[ext_resource type="Script" uid="uid://dsey5dvc11vpq" path="res://core/photo_mode/photo.gd" id="1_u0arp"] + +[node name="Photo" type="Control" unique_id=201865221] +custom_minimum_size = Vector2(200, 200) +layout_mode = 3 +anchors_preset = 0 +offset_right = 200.0 +offset_bottom = 200.0 +script = ExtResource("1_u0arp") + +[node name="ColorRect" type="ColorRect" parent="." unique_id=1208008621] +layout_mode = 0 +offset_right = 200.0 +offset_bottom = 200.0 + +[node name="MarginContainer" type="MarginContainer" parent="ColorRect" unique_id=1141643525] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 12 +theme_override_constants/margin_top = 12 +theme_override_constants/margin_right = 12 +theme_override_constants/margin_bottom = 12 + +[node name="Panel" type="PanelContainer" parent="ColorRect/MarginContainer" unique_id=1372516531] +layout_mode = 2 + +[node name="PhotoTexture" type="TextureRect" parent="ColorRect/MarginContainer/Panel" unique_id=506844785] +unique_name_in_owner = true +layout_mode = 2 +size_flags_vertical = 3 +expand_mode = 1 +stretch_mode = 6 diff --git a/core/photo_mode/photo_gallery.gd b/core/photo_mode/photo_gallery.gd new file mode 100644 index 0000000..6914248 --- /dev/null +++ b/core/photo_mode/photo_gallery.gd @@ -0,0 +1,27 @@ +extends Control + +@onready var grid_container: GridContainer = $%PhotoGrid + +@onready var photo_scene = preload("res://core/photo_mode/photo.tscn") + +func _ready() -> void: + CollectionManager.on_photo_saved.connect(_create_photo_thumbnail) + load_gallery() + +func load_gallery() -> void: + for child in grid_container.get_children(): + child.queue_free() + + var saved_photos = CollectionManager.saved_photos + + for file_path in saved_photos: + if FileAccess.file_exists(file_path): + _create_photo_thumbnail(file_path) + +func _create_photo_thumbnail(file_path: String) -> void: + var image = Image.load_from_file(file_path) + if image: + var photo: Photo = photo_scene.instantiate() + var texture = ImageTexture.create_from_image(image) + photo.setup(texture) + grid_container.add_child(photo) diff --git a/core/photo_mode/photo_gallery.gd.uid b/core/photo_mode/photo_gallery.gd.uid new file mode 100644 index 0000000..74980db --- /dev/null +++ b/core/photo_mode/photo_gallery.gd.uid @@ -0,0 +1 @@ +uid://k4iqrlkbjppl diff --git a/core/photo_mode/photo_gallery.tscn b/core/photo_mode/photo_gallery.tscn new file mode 100644 index 0000000..b93d767 --- /dev/null +++ b/core/photo_mode/photo_gallery.tscn @@ -0,0 +1,48 @@ +[gd_scene format=3 uid="uid://b6r787sik5yil"] + +[ext_resource type="Script" uid="uid://k4iqrlkbjppl" path="res://core/photo_mode/photo_gallery.gd" id="1_bp5uf"] + +[node name="PhotoGallery" type="Control" unique_id=354419843] +layout_mode = 3 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_bp5uf") + +[node name="PanelContainer" type="PanelContainer" parent="." unique_id=640179265] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -350.0 +offset_top = -350.0 +offset_right = 350.0 +offset_bottom = 350.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="MarginContainer" type="MarginContainer" parent="PanelContainer" unique_id=125147979] +layout_mode = 2 +theme_override_constants/margin_left = 12 +theme_override_constants/margin_top = 12 +theme_override_constants/margin_right = 12 +theme_override_constants/margin_bottom = 12 + +[node name="ScrollContainer" type="ScrollContainer" parent="PanelContainer/MarginContainer" unique_id=348576028] +layout_mode = 2 +draw_focus_border = true + +[node name="PhotoGrid" type="GridContainer" parent="PanelContainer/MarginContainer/ScrollContainer" unique_id=1187865988] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 6 +size_flags_vertical = 2 +theme_override_constants/h_separation = 12 +theme_override_constants/v_separation = 12 +columns = 3 diff --git a/core/photo_mode/photo_mode_controller.gd b/core/photo_mode/photo_mode_controller.gd index 62d2fa6..d28d40d 100644 --- a/core/photo_mode/photo_mode_controller.gd +++ b/core/photo_mode/photo_mode_controller.gd @@ -10,7 +10,7 @@ extends Node3D @export_group("Ref") @export var rotation_target: Node3D -@onready var camera: Camera3D = $Camera3D +@onready var camera: Camera3D = $%Camera3D var total_yaw: float = 0.0 var total_pitch: float = 0.0 @@ -29,6 +29,8 @@ func _unhandled_input(event: InputEvent) -> void: if event.is_action_pressed("toggle_photo_mode"): is_active = !is_active + get_tree().paused = is_active + if !is_active: Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) else: @@ -38,7 +40,7 @@ func _unhandled_input(event: InputEvent) -> void: total_yaw -= event.relative.x * rotation_speed if event.is_action_pressed("take_photo"): - take_photo() + take_photo_async() func _process(delta: float) -> void: if not rotation_target: @@ -66,13 +68,15 @@ func _process(delta: float) -> void: global_position = orbit_pos + final_pan_offset global_basis = rot_basis -func take_photo() -> void: +func take_photo_async() -> void: if !is_active: return var targets = get_tree().get_nodes_in_group("collectible") var space_state = get_world_3d().direct_space_state + await CollectionManager.save_photo_to_disk_async() + for target in targets: if not target.collectible_data: continue @@ -85,5 +89,6 @@ func take_photo() -> void: var result = space_state.intersect_ray(query) if result and result.collider == target: - CollectionManager.unlock_photo(target.collectible_data.id) - print("Foto scattata a: ", target.collectible_data.id) + CollectionManager.unlock_collectible(target.collectible_data.id) + + GameState.save_game() diff --git a/core/photo_mode/photo_mode_controller.tscn b/core/photo_mode/photo_mode_controller.tscn index cb447c6..674a358 100644 --- a/core/photo_mode/photo_mode_controller.tscn +++ b/core/photo_mode/photo_mode_controller.tscn @@ -3,6 +3,8 @@ [ext_resource type="Script" uid="uid://d7ln6iru6mq6" path="res://core/photo_mode/photo_mode_controller.gd" id="1_uhpya"] [node name="PhotoModeController" type="Node3D" unique_id=695158870] +process_mode = 3 script = ExtResource("1_uhpya") [node name="Camera3D" type="Camera3D" parent="." unique_id=1369039645] +unique_name_in_owner = true diff --git a/docs/museums/ai/museum_ai.tscn b/docs/museums/ai/museum_ai.tscn index a22975e..dae15dc 100644 --- a/docs/museums/ai/museum_ai.tscn +++ b/docs/museums/ai/museum_ai.tscn @@ -52,3 +52,41 @@ environment = SubResource("Environment_lmjyn") [node name="DirectionalLight3D" type="DirectionalLight3D" parent="." unique_id=269230449] transform = Transform3D(1, 0, 0, 0, 0.17952333, 0.98375374, 0, -0.98375374, 0.17952333, 0, 18.920979, 0) + +[node name="Control" type="Control" parent="." unique_id=1072240389] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="PanelContainer" type="PanelContainer" parent="Control" unique_id=1647272132] +layout_mode = 0 +offset_left = 50.0 +offset_top = 50.0 +offset_right = 400.0 +offset_bottom = 827.0 + +[node name="Label" type="Label" parent="Control/PanelContainer" unique_id=272421245] +custom_minimum_size = Vector2(1, 1) +layout_mode = 2 +size_flags_vertical = 1 +text = "System Logic: +- The NPC is based on CharacterBody3D and is managed via a Finite State Machine (FSM). +- Movement and navigation are calculated during the _physics_process. + +AI States: +- IdleState: The agent remains stationary for the duration defined by the wait_time variable. +- PatrolState: The agent calculates a valid random point and moves toward it. + +Core Components: +- NavigationAgent3D: Manages pathfinding and detects when the agent reaches its destination. +- PatrolRadiusShape: Defines the radius of the area where the agent can move randomly. +- StateMachine: Coordinates transitions between states, such as the automatic switch from Idle to Patrol. + +Parameters: +- Speed: Movement speed of the agent. +- Wait Time: Delay in seconds within the IdleState node. +- Area Radius: Size of the SphereShape3D inside the PatrolRadiusShape node." +autowrap_mode = 2 diff --git a/docs/museums/photo_mode/museum_photo_mode.gd b/docs/museums/photo_mode/museum_photo_mode.gd index 5c6f30d..e92bfd2 100644 --- a/docs/museums/photo_mode/museum_photo_mode.gd +++ b/docs/museums/photo_mode/museum_photo_mode.gd @@ -1,6 +1,7 @@ extends Node3D -@onready var collection_compendium: Control = $Control/CollectionCompendium +@onready var gallery: Control = $%Gallery -func _on_button_pressed() -> void: - collection_compendium.visible = !collection_compendium.visible + +func _on_button_gallery_pressed() -> void: + gallery.visible = !gallery.visible diff --git a/docs/museums/photo_mode/museum_photo_mode.tscn b/docs/museums/photo_mode/museum_photo_mode.tscn index a4d8ad3..60b9e53 100644 --- a/docs/museums/photo_mode/museum_photo_mode.tscn +++ b/docs/museums/photo_mode/museum_photo_mode.tscn @@ -5,7 +5,8 @@ [ext_resource type="PackedScene" uid="uid://bmkxt6btcx8qr" path="res://core/photo_mode/collectible.tscn" id="2_48mla"] [ext_resource type="Script" uid="uid://bj34o0org55ei" path="res://core/photo_mode/collectible_resource.gd" id="3_hh1ka"] [ext_resource type="Texture2D" uid="uid://c3grftlmap4q5" path="res://docs/museums/daynight/scenes/grain_test/leaf_test.png" id="4_fan5s"] -[ext_resource type="PackedScene" uid="uid://bvw086glfpcba" path="res://core/photo_mode/collection_compendium.tscn" id="5_ws0fy"] +[ext_resource type="PackedScene" uid="uid://bvw086glfpcba" path="res://core/photo_mode/collectible_gallery.tscn" id="5_ws0fy"] +[ext_resource type="PackedScene" uid="uid://b6r787sik5yil" path="res://core/photo_mode/photo_gallery.tscn" id="7_fh4km"] [sub_resource type="Environment" id="Environment_48mla"] @@ -67,14 +68,70 @@ grow_horizontal = 2 grow_vertical = 2 mouse_filter = 2 -[node name="Button" type="Button" parent="Control" unique_id=539195532] +[node name="ButtonGallery" type="Button" parent="Control" unique_id=539195532] layout_mode = 0 -offset_right = 8.0 -offset_bottom = 8.0 -text = "Compendium" +offset_left = 50.0 +offset_top = 50.0 +offset_right = 163.0 +offset_bottom = 81.0 +text = "Menu" -[node name="CollectionCompendium" parent="Control" unique_id=354419843 instance=ExtResource("5_ws0fy")] +[node name="Gallery" type="HSplitContainer" parent="Control" unique_id=1388833682] +unique_name_in_owner = true visible = false layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = 420.0 +grow_horizontal = 2 +grow_vertical = 2 -[connection signal="pressed" from="Control/Button" to="." method="_on_button_pressed"] +[node name="CollectibleGallery" parent="Control/Gallery" unique_id=354419843 instance=ExtResource("5_ws0fy")] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="PhotoGallery" parent="Control/Gallery" unique_id=263414560 instance=ExtResource("7_fh4km")] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="PanelContainer" type="PanelContainer" parent="Control" unique_id=2015953740] +layout_mode = 0 +offset_left = 50.0 +offset_top = 150.0 +offset_right = 400.0 +offset_bottom = 927.0 + +[node name="ScrollContainer" type="ScrollContainer" parent="Control/PanelContainer" unique_id=1474258594] +layout_mode = 2 + +[node name="Label" type="Label" parent="Control/PanelContainer/ScrollContainer" unique_id=1982569320] +custom_minimum_size = Vector2(1, 1) +layout_mode = 2 +size_flags_horizontal = 3 +text = "System Logic: +- The system allows players to toggle a free camera mode to photograph and collect museum items. +- Game Pause: Activating the mode pauses the SceneTree, freezing the world while allowing the camera to remain functional. +- It uses a raycasting check to verify if a collectible is visible and unobstructed before unlocking it. +- The CollectionManager acts as a global singleton to track unlocked IDs and manage the library data. +- Save Collectibles and Photo + +Photo Mode Actions: +- Toggle Mode(P): Switches between normal gameplay and the photo camera, capturing or releasing the mouse, and toggles the global pause state. +- Orbit & Pan(Mouse): The camera rotates around a target and can be panned horizontally or vertically. +- Capture(F): Performs a frustum check and a raycast to identify the target in view. + +Core Components: +- PhotoModeController: Manages camera inputs, movement logic, and the photo-taking process. +- Collectible: An Area3D node placed on objects to make them identifiable by the camera. +- CollectionManager: Handles the logic for unlocking items and provides data to the UI. +- CollectionCompendium: A UI grid that displays all items and visually highlights unlocked ones. + +Parameters: +- Pan & Rotation Speed: Defines how fast the camera moves and rotates. +- Movement Bounds: An AABB that restricts the camera's panning area. +- Collectible Data: Resource files containing the ID, title, and image for each item. +- Library: A central list of all CollectibleResources registered in the game." +autowrap_mode = 2 + +[connection signal="pressed" from="Control/ButtonGallery" to="." method="_on_button_gallery_pressed"] diff --git a/docs/museums/radio/museum_radio.gd b/docs/museums/radio/museum_radio.gd index 4241654..d2a8742 100644 --- a/docs/museums/radio/museum_radio.gd +++ b/docs/museums/radio/museum_radio.gd @@ -1,7 +1,7 @@ extends Node3D -@onready var radio: Radio = $Radio - +@onready var radio: Radio = $%Radio +@onready var button_pause_resume: Button = $%Button_Pause_Resume func _on_button_play_pressed() -> void: if !radio.playing: @@ -10,10 +10,12 @@ func _on_button_play_pressed() -> void: func _on_button_pause_pressed() -> void: radio.toggle_pause() + if !button_pause_resume: + button_pause_resume = $%Button_Pause_Resume if radio.stream_paused: - $Control/MarginContainer/VBoxContainer/Button_Pause_Resume.text = "Resume" + button_pause_resume.text = "Resume" else: - $Control/MarginContainer/VBoxContainer/Button_Pause_Resume.text = "Pause" + button_pause_resume.text = "Pause" func _on_button_stop_pressed() -> void: diff --git a/docs/museums/radio/museum_radio.tscn b/docs/museums/radio/museum_radio.tscn index 89a0379..a54280f 100644 --- a/docs/museums/radio/museum_radio.tscn +++ b/docs/museums/radio/museum_radio.tscn @@ -8,6 +8,7 @@ script = ExtResource("1_h5r8c") [node name="Radio" parent="." unique_id=1234112225 instance=ExtResource("1_8yomj")] +unique_name_in_owner = true playlist = Array[AudioStream]([ExtResource("3_ltpvc")]) [node name="Control" type="Control" parent="." unique_id=1232082176] @@ -18,40 +19,70 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -[node name="MarginContainer" type="MarginContainer" parent="Control" unique_id=2102712226] +[node name="VBoxContainer" type="VBoxContainer" parent="Control" unique_id=2097365775] layout_mode = 0 -offset_right = 40.0 -offset_bottom = 40.0 -theme_override_constants/margin_left = 12 -theme_override_constants/margin_top = 12 -theme_override_constants/margin_right = 12 -theme_override_constants/margin_bottom = 12 +offset_left = 50.0 +offset_top = 50.0 +offset_right = 125.0 +offset_bottom = 221.0 -[node name="VBoxContainer" type="VBoxContainer" parent="Control/MarginContainer" unique_id=2097365775] -layout_mode = 2 - -[node name="Button_Play" type="Button" parent="Control/MarginContainer/VBoxContainer" unique_id=1422696340] +[node name="Button_Play" type="Button" parent="Control/VBoxContainer" unique_id=1422696340] layout_mode = 2 text = "Play" -[node name="Button_Pause_Resume" type="Button" parent="Control/MarginContainer/VBoxContainer" unique_id=2016690081] +[node name="Button_Pause_Resume" type="Button" parent="Control/VBoxContainer" unique_id=2016690081] +unique_name_in_owner = true layout_mode = 2 text = "Pause" -[node name="Button_Stop" type="Button" parent="Control/MarginContainer/VBoxContainer" unique_id=61861870] +[node name="Button_Stop" type="Button" parent="Control/VBoxContainer" unique_id=61861870] layout_mode = 2 text = "Stop" -[node name="Button_Next" type="Button" parent="Control/MarginContainer/VBoxContainer" unique_id=957606385] +[node name="Button_Next" type="Button" parent="Control/VBoxContainer" unique_id=957606385] layout_mode = 2 text = "Next" -[node name="Button_Previous" type="Button" parent="Control/MarginContainer/VBoxContainer" unique_id=929072518] +[node name="Button_Previous" type="Button" parent="Control/VBoxContainer" unique_id=929072518] layout_mode = 2 text = "Previous" -[connection signal="pressed" from="Control/MarginContainer/VBoxContainer/Button_Play" to="." method="_on_button_play_pressed"] -[connection signal="pressed" from="Control/MarginContainer/VBoxContainer/Button_Pause_Resume" to="." method="_on_button_pause_pressed"] -[connection signal="pressed" from="Control/MarginContainer/VBoxContainer/Button_Stop" to="." method="_on_button_stop_pressed"] -[connection signal="pressed" from="Control/MarginContainer/VBoxContainer/Button_Next" to="." method="_on_button_next_pressed"] -[connection signal="pressed" from="Control/MarginContainer/VBoxContainer/Button_Previous" to="." method="_on_button_previous_pressed"] +[node name="PanelContainer" type="PanelContainer" parent="Control" unique_id=1558442050] +layout_mode = 0 +offset_left = 50.0 +offset_top = 250.0 +offset_right = 400.0 +offset_bottom = 1027.0 + +[node name="ScrollContainer" type="ScrollContainer" parent="Control/PanelContainer" unique_id=7789304] +layout_mode = 2 + +[node name="Label" type="Label" parent="Control/PanelContainer/ScrollContainer" unique_id=2043293564] +custom_minimum_size = Vector2(1, 1) +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 1 +text = "System Logic: +- The system is an extension of AudioStreamPlayer designed to manage sequential audio playback. +- It automatically triggers the next track in the sequence when the current one finishes via the finished signal. + +Core Functionality: +- Playlist Management: Stores a list of AudioStream resources and tracks the current song index. +- Track Navigation: Allows cycling forward and backward through the playlist with index wrapping (loops back to start/end). +- Playback Control: Supports jumping to specific tracks, toggling the pause state, and stopping the stream. + +Key Methods: +- play_track: Loads a specific stream from the playlist and begins playback. +- next_track / prev_track: Increments or decrements the index to navigate the playlist. +- toggle_pause: Resumes or pauses the current stream without resetting its position. + +Adjustable Parameters: +- Playlist: An Array in the inspector where you can assign multiple AudioStream resources (e.g., .mp3, .ogg). +- Current Track Index: Determines which song starts playing by default." +autowrap_mode = 2 + +[connection signal="pressed" from="Control/VBoxContainer/Button_Play" to="." method="_on_button_play_pressed"] +[connection signal="pressed" from="Control/VBoxContainer/Button_Pause_Resume" to="." method="_on_button_pause_pressed"] +[connection signal="pressed" from="Control/VBoxContainer/Button_Stop" to="." method="_on_button_stop_pressed"] +[connection signal="pressed" from="Control/VBoxContainer/Button_Next" to="." method="_on_button_next_pressed"] +[connection signal="pressed" from="Control/VBoxContainer/Button_Previous" to="." method="_on_button_previous_pressed"] diff --git a/project.godot b/project.godot index 6a5c15a..a56449f 100644 --- a/project.godot +++ b/project.godot @@ -18,6 +18,7 @@ config/icon="res://icon.svg" [autoload] UIEvents="*uid://dehu28iq27mbn" +GameState="*uid://b17g2w2g101o6" CollectionManager="*uid://c3kq1qddpm8tf" [display]