diff --git a/addons/cogito/CogitoObjects/cogito_pressure_plate.gd b/addons/cogito/CogitoObjects/cogito_pressure_plate.gd index c5cbd4db..6ea6919a 100644 --- a/addons/cogito/CogitoObjects/cogito_pressure_plate.gd +++ b/addons/cogito/CogitoObjects/cogito_pressure_plate.gd @@ -89,14 +89,14 @@ func save(): func _on_plate_body_exited(body: Node) -> void: if body is CogitoObject: - print("Pressure plate: ", body, " has exited.") + CogitoMain.debug_log(true,"cogito_pressure_plate.gd", str(body) + " has exited.") weight_lifted() if body is CogitoPlayer: plate_node.constant_force = Vector3(0, 0, 0) func _on_plate_body_entered(body: Node) -> void: - print("Pressure plate: detected ", body.name) + CogitoMain.debug_log(true,"cogito_pressure_plate.gd","Detected " + body.name) if body.is_in_group("Player"): - print("Pressure plate: Player detected. applying force.") + CogitoMain.debug_log(true,"cogito_pressure_plate.gd", "Player detected. applying force.") plate_node.add_constant_central_force(Vector3(0,-3,0)) diff --git a/addons/cogito/CogitoSettings.tres b/addons/cogito/CogitoSettings.tres new file mode 100644 index 00000000..e07aa36d --- /dev/null +++ b/addons/cogito/CogitoSettings.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" script_class="CogitoSettings" load_steps=2 format=3] + +[ext_resource type="Script" path="res://addons/cogito/cogito_settings.gd" id="1_usejk"] + +[resource] +script = ExtResource("1_usejk") +is_logging = false +scene_state_prefix = "COGITO_scene_state_" +player_state_prefix = "COGITO_player_state_" +default_transition_duration = 8.0 diff --git a/addons/cogito/Components/PlayerInteractionComponent.gd b/addons/cogito/Components/PlayerInteractionComponent.gd index 68f1f449..7302bacf 100644 --- a/addons/cogito/Components/PlayerInteractionComponent.gd +++ b/addons/cogito/Components/PlayerInteractionComponent.gd @@ -213,7 +213,7 @@ func attempt_reload(): return if equipped_wieldable_item.get_item_amount_in_inventory(equipped_wieldable_item.ammo_item_name) <= 0: - print("You have no ammo for this wieldable.") + CogitoMain.debug_log(true,"PIC", "You have no ammo for this wieldable.") return if equipped_wieldable_node.animation_player.is_playing(): # Make sure reload isn't interrupting another animation. diff --git a/addons/cogito/DemoScenes/COGITO_4_Laboratory.tscn b/addons/cogito/DemoScenes/COGITO_4_Laboratory.tscn index 786c49b9..861f59f6 100644 --- a/addons/cogito/DemoScenes/COGITO_4_Laboratory.tscn +++ b/addons/cogito/DemoScenes/COGITO_4_Laboratory.tscn @@ -86,7 +86,7 @@ volumetric_fog_ambient_inject = 0.1 volumetric_fog_sky_affect = 0.1 volumetric_fog_temporal_reprojection_amount = 0.85 -[sub_resource type="Resource" id="Resource_jsy0q"] +[sub_resource type="Resource" id="Resource_vuwyl"] resource_local_to_scene = true script = ExtResource("4_hlewe") grid = true @@ -899,7 +899,7 @@ environment = SubResource("Environment_obnk3") [node name="Player" parent="." instance=ExtResource("2_7qwrr")] transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 5.13854, 0.8, -5.43073) -inventory_data = SubResource("Resource_jsy0q") +inventory_data = SubResource("Resource_vuwyl") [node name="CONNECTOR_TO_LOBBY" type="Node3D" parent="."] diff --git a/addons/cogito/EasyMenus/Scripts/options_constants.gd b/addons/cogito/EasyMenus/Scripts/options_constants.gd index bc1e4f1d..d0059569 100644 --- a/addons/cogito/EasyMenus/Scripts/options_constants.gd +++ b/addons/cogito/EasyMenus/Scripts/options_constants.gd @@ -3,7 +3,7 @@ class_name OptionsConstants const sfx_bus_name = "SFX" const music_bus_name = "Music" -const config_file_name = "user://options_test.cfg" +const config_file_name = "user://options.cfg" const section_name = "Options" # Auido options diff --git a/addons/cogito/Enemies/cogito_basic_enemy.gd b/addons/cogito/Enemies/cogito_basic_enemy.gd index 1e4ab1c1..e270b178 100644 --- a/addons/cogito/Enemies/cogito_basic_enemy.gd +++ b/addons/cogito/Enemies/cogito_basic_enemy.gd @@ -136,13 +136,13 @@ func handle_chasing(_delta: float): func handle_patrolling(_delta: float): if !patrol_path: - print("Cogito_basic_enemy: No patrol path found. Switching to idle.") + CogitoMain.debug_log(true,"cogito_basic_enemy.gd","No patrol path found. Switching to idle.") switch_to_idle() return if !is_waiting: if patrol_path.patrol_points.size() <= 0: - print("Cogito_basic_enemy: Patrol points array is empty. Switching to idle.") + CogitoMain.debug_log(true,"cogito_basic_enemy.gd","Patrol points array is empty. Switching to idle.") switch_to_idle() return if global_position.distance_to(patrol_path.patrol_points[patrol_point_index].global_position) < patrol_point_threshold: @@ -187,14 +187,14 @@ func _target_in_range() -> bool: func attack(target: Node3D): attack_cooldown = attack_interval - print("Enemy attacks!") + CogitoMain.debug_log(true,"cogito_basic_enemy.gd","Enemy attacks!") var dir = global_position.direction_to(target.global_position) if attack_sound: Audio.play_sound_3d(attack_sound).global_position = self.global_position if target is CogitoPlayer: target.apply_external_force(dir * attack_stagger) - print("Enemy attack: Applying vector ", dir * attack_stagger, " to target. Target.main_velocity = ", target.main_velocity) + CogitoMain.debug_log(true,"cogito_basic_enemy.gd","Enemy attack: Applying vector " + dir * attack_stagger + " to target. Target.main_velocity = " + target.main_velocity) target.decrease_attribute("health", attack_damage) @@ -216,7 +216,6 @@ func switch_to_chasing(): # Future method to set object state when a scene state file is loaded. func set_state(): - print("Cogito_basic_enemy.gd: set_state()") #TODO: Find a way to possibly save health of health attribute. find_cogito_properties() load_patrol_points() @@ -262,7 +261,7 @@ func _on_interaction_raycast_interactable_seen(interactable): func interact_with_door(door: CogitoDoor): if door.is_locked: - print("Door is locked.") + CogitoMain.debug_log(true,"cogito_basic_enemy.gd","Door is locked.") #TODO on NPC inventory addition, add key check here door.audio_stream_player_3d.stream = door.rattle_sound door.audio_stream_player_3d.play() @@ -275,7 +274,7 @@ func interact_with_door(door: CogitoDoor): func load_patrol_points(): if patrol_path_nodepath: - print("Cogito_basic_enemy.gd: Loading patrol path: ", patrol_path_nodepath) + CogitoMain.debug_log(true,"cogito_basic_enemy.gd","Loading patrol path: " + str(patrol_path_nodepath)) patrol_path = get_node(patrol_path_nodepath) diff --git a/addons/cogito/SceneManagement/cogito_scene_manager.gd b/addons/cogito/SceneManagement/cogito_scene_manager.gd index d3f90d9c..d2c0ed57 100644 --- a/addons/cogito/SceneManagement/cogito_scene_manager.gd +++ b/addons/cogito/SceneManagement/cogito_scene_manager.gd @@ -35,7 +35,8 @@ enum CogitoSceneLoadMode {TEMP, LOAD_SAVE, RESET} var cogito_scene_state_prefix : String = CogitoMain.scene_state_prefix var cogito_player_state_prefix : String = CogitoMain.player_state_prefix -@export var default_fade_duration : float = .4 +#@export var default_fade_duration : float = .4 +@export var default_fade_duration : float = CogitoMain.default_transition_duration @export var fade_panel : Panel = null func _ready() -> void: diff --git a/addons/cogito/cogito_main.gd b/addons/cogito/cogito_main.gd index 7b62274d..5e32f57b 100644 --- a/addons/cogito/cogito_main.gd +++ b/addons/cogito/cogito_main.gd @@ -1,22 +1,50 @@ @tool extends Node -@export var entered_string : String = "This is a test string." -@export var is_logging: bool +var cogito_settings : CogitoSettings +var cogito_settings_file := "res://addons/cogito/CogitoSettings.tres" + +### Cached settings +var is_logging : bool: + set(value): + is_logging = value + cogito_settings.is_logging = is_logging + save_cogito_settings() + +var player_state_prefix : String +var scene_state_prefix : String + +var default_transition_duration : float: + set(value): + default_transition_duration = value + cogito_settings.default_transition_duration = default_transition_duration + save_cogito_settings() + + +func _enter_tree() -> void: + load_cogito_project_settings.call_deferred() + + +func load_cogito_project_settings(): + if ResourceLoader.exists(cogito_settings_file): + cogito_settings = ResourceLoader.load(cogito_settings_file, "", ResourceLoader.CACHE_MODE_IGNORE) + print("COGITO: Existing cogito settings loaded.") + + is_logging = cogito_settings.is_logging + player_state_prefix = cogito_settings.player_state_prefix + scene_state_prefix = cogito_settings.scene_state_prefix + default_transition_duration = cogito_settings.default_transition_duration + + else: + print("COGITO: No cogito settings found.") + -### Save Game Settings -@export var scene_state_prefix : String = "COGITO_scene_state_" -@export var player_state_prefix : String = "COGITO_player_state_" -### Scene Settings -@export var default_transition_duration : float = .5 +func save_cogito_settings(): + if cogito_settings: + if ResourceSaver.save(cogito_settings, cogito_settings_file, ResourceSaver.FLAG_CHANGE_PATH) == OK: + print("Cogito: CogitoSettings saved.") -### Input Settings -@export var input_icons_kbm: Texture2D -@export var input_icons_xbox: Texture2D -@export var input_icons_playstation: Texture2D -@export var input_icons_steamdeck: Texture2D -@export var input_icons_switch: Texture2D func debug_log(log_this: bool, _class: String, _message: String) -> void: if is_logging and log_this: @@ -37,18 +65,22 @@ func _on_lineedit_fade_duration_text_changed(new_text: String) -> void: func _on_lineedit_player_state_text_submitted(new_text: String) -> void: if new_text.is_valid_filename(): - player_state_prefix = new_text + cogito_settings.player_state_prefix = new_text else: push_error("Text must not contain invalid characters") - player_state_prefix = "COGITO_player_state_" + cogito_settings.player_state_prefix = "COGITO_player_state_" + + save_cogito_settings() func _on_lineedit_scene_state_text_submitted(new_text: String) -> void: if new_text.is_valid_filename(): - scene_state_prefix = new_text + cogito_settings.scene_state_prefix = new_text else: push_error("Text must not contain invalid characters") - scene_state_prefix = "COGITO_scene_state_" + cogito_settings.scene_state_prefix = "COGITO_scene_state_" + + save_cogito_settings() func _on_btn_git_hub_pressed() -> void: diff --git a/addons/cogito/cogito_main_panel.tscn b/addons/cogito/cogito_main_panel.tscn index 089aba0d..b6d04fc5 100644 --- a/addons/cogito/cogito_main_panel.tscn +++ b/addons/cogito/cogito_main_panel.tscn @@ -1,8 +1,6 @@ -[gd_scene load_steps=5 format=3 uid="uid://dt2gfg7ng6fw8"] +[gd_scene load_steps=3 format=3 uid="uid://dt2gfg7ng6fw8"] [ext_resource type="Script" path="res://addons/cogito/cogito_main.gd" id="1_og8xv"] -[ext_resource type="Texture2D" uid="uid://cb3ul86n4etxx" path="res://addons/cogito/Assets/Graphics/InputIcons/InputIconSheet_Kenney_KeyboardMouse.png" id="2_dttpu"] -[ext_resource type="Texture2D" uid="uid://bsf8v4qjtudck" path="res://addons/cogito/Assets/Graphics/InputIcons/InputIconSheet_Kenney_Xbox.png" id="3_u7lrp"] [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ph56b"] content_margin_left = 5.0 @@ -20,8 +18,6 @@ grow_vertical = 2 size_flags_horizontal = 3 size_flags_vertical = 3 script = ExtResource("1_og8xv") -input_icons_kbm = ExtResource("2_dttpu") -input_icons_xbox = ExtResource("3_u7lrp") [node name="TabContainer" type="TabContainer" parent="."] layout_mode = 1 diff --git a/addons/cogito/cogito_plugin.gd b/addons/cogito/cogito_plugin.gd index 7abd7b38..5852fc52 100644 --- a/addons/cogito/cogito_plugin.gd +++ b/addons/cogito/cogito_plugin.gd @@ -4,6 +4,7 @@ const cogito_plugin_icon : Texture2D = preload("./Cogito.svg") const MainPanel = preload("./cogito_main_panel.tscn") var main_panel_instance +var cog_settings : CogitoSettings func _enter_tree(): add_autoload_singleton("CogitoMain", "/cogito_main.gd") diff --git a/addons/cogito/cogito_settings.gd b/addons/cogito/cogito_settings.gd new file mode 100644 index 00000000..739b8308 --- /dev/null +++ b/addons/cogito/cogito_settings.gd @@ -0,0 +1,27 @@ +class_name CogitoSettings extends Resource + +const settings_path := "res://addons/cogito/" +const settings_filename := "CogitoSettings" + +@export var is_logging: bool + +@export var scene_state_prefix : String +@export var player_state_prefix : String + +@export var default_transition_duration : float + +#func save_settings(file_path: String) -> void: + #var full_settings_filepath = settings_path + settings_filename + ".tres" + #ResourceSaver.save(self, file_path, ResourceSaver.FLAG_CHANGE_PATH) + #print("CogitoSettingsFile: Cogito Settings saved as ", file_path) + +# +#func settings_exist() -> bool: + ##var player_state_file = str(player_state_dir + state_slot + ".res") + #var full_settings_filepath = settings_path + settings_filename + ".tres" + #return ResourceLoader.exists(full_settings_filepath) + # +# +#func load_settings(state_slot : String) -> Resource: + #var full_settings_filepath = settings_path + settings_filename + ".tres" + #return ResourceLoader.load(full_settings_filepath, "CogitoSettings", ResourceLoader.CACHE_MODE_IGNORE)