Skip to content

Commit

Permalink
Cogito Tab updates
Browse files Browse the repository at this point in the history
Noticed that the settings in the Cogito tab don't get saved properly. I tried to create a custom resource to save/load these, but currently it doesn't seem to be working as intended. Nothing is majorly broken with this so I'm committing this in the hopes someone can help.
  • Loading branch information
Phazorknight committed Nov 14, 2024
1 parent 3e963a3 commit e421719
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 37 deletions.
6 changes: 3 additions & 3 deletions addons/cogito/CogitoObjects/cogito_pressure_plate.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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))
10 changes: 10 additions & 0 deletions addons/cogito/CogitoSettings.tres
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion addons/cogito/Components/PlayerInteractionComponent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions addons/cogito/DemoScenes/COGITO_4_Laboratory.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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="."]
Expand Down
2 changes: 1 addition & 1 deletion addons/cogito/EasyMenus/Scripts/options_constants.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions addons/cogito/Enemies/cogito_basic_enemy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)


Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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)


Expand Down
3 changes: 2 additions & 1 deletion addons/cogito/SceneManagement/cogito_scene_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
66 changes: 49 additions & 17 deletions addons/cogito/cogito_main.gd
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand Down
6 changes: 1 addition & 5 deletions addons/cogito/cogito_main_panel.tscn
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions addons/cogito/cogito_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
27 changes: 27 additions & 0 deletions addons/cogito/cogito_settings.gd
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit e421719

Please sign in to comment.