Skip to content

Commit

Permalink
Merge fixes and code cleanup.
Browse files Browse the repository at this point in the history
Fixed issues that came with mergin in PR #317 due to just being a bit behind main.

Updated more scripts to use Cogito debug logging.

Minor cleanup.
  • Loading branch information
Phazorknight committed Dec 9, 2024
1 parent 2b0c891 commit bf37854
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 117 deletions.
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![COGITO_banner](docs/Cogito_capsule_202402_jpg.jpg)
# COGITO
[![GodotEngine](https://img.shields.io/badge/Godot_4.3_stable-blue?logo=godotengine&logoColor=white)](https://godotengine.org/) [![COGITO](https://img.shields.io/badge/beta_202411-35A1D7?label=COGITO&labelColor=0E887A)](https://github.com/Phazorknight/Cogito)
beta 202411.03
[![GodotEngine](https://img.shields.io/badge/Godot_4.3_stable-blue?logo=godotengine&logoColor=white)](https://godotengine.org/) [![COGITO](https://img.shields.io/badge/beta_202412-35A1D7?label=COGITO&labelColor=0E887A)](https://github.com/Phazorknight/Cogito)
beta 202412.01

## What is it?
COGITO is a first Person Immersive Sim Template Project for Godot Engine 4.
Expand Down
16 changes: 15 additions & 1 deletion addons/cogito/CogitoObjects/cogito_projectile.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@icon("res://addons/cogito/Graphics/Editor/Icon_CogitoObject.svg")
@icon("res://addons/cogito/Assets/Graphics/Editor/Icon_CogitoObject.svg")
extends CogitoObject
## Derived from CogitoObject, this class handles additional information for projectiles like lifespan, damage, destroy_on_impact. Some of these are inherited from the Wieldable that spawns this projectile.
class_name CogitoProjectile
Expand All @@ -15,6 +15,9 @@ var damage_amount : int = 0
@export var stick_on_impact : bool = false
## Array of Scenes that will get spawned on parent position on death.
@export var spawn_on_death : Array[PackedScene] = []
## This prevents being able to auto pick up projectiles that have just been fired
@export_range(0.1, 3.0, 0.1, "or_greater") var pick_up_delay: float = 0.5
var can_pick_up: bool = false

var Direction

Expand All @@ -26,6 +29,17 @@ func _ready():

if lifespan:
lifespan.timeout.connect(on_timeout)

_pick_up_timer()


func _pick_up_timer() -> void:
if lifespan and (lifespan as Timer).wait_time < pick_up_delay:
# The projectile cannot be picked up before it dies, so don't create the timer
return
await get_tree().create_timer(pick_up_delay).timeout
can_pick_up = true


func on_timeout():
die()
Expand Down
3 changes: 1 addition & 2 deletions addons/cogito/CogitoObjects/cogito_sittable.gd
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func _ready():
# find the look marker node
look_marker_node = get_node_or_null(look_marker_node_path)
if not look_marker_node:
print("Look marker node not found.")
CogitoGlobals.debug_log(true, "cogito_sittable", "Look marker node not found.")

#find optional animation player node
animation_player = get_node_or_null(animation_player_node_path)
Expand Down Expand Up @@ -409,4 +409,3 @@ func find_rigid_body() -> RigidBody3D:
return current as RigidBody3D
current = current.get_parent()
return null

50 changes: 39 additions & 11 deletions addons/cogito/CogitoObjects/cogito_switch.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ signal damage_received(damage_value:float)
## Check this if player needs to have an item in the inventory to switch.
@export var needs_item_to_operate : bool
## The item that the player needs to have in their inventory.
@export var required_item : InventoryItemPD
@export var required_item_slot : InventorySlotPD
## Hint that gets displayed if the switch requires an item that the player currently doesn't have.
@export var item_hint : String
## Nodes that will become visible when switch is ON. These will hide again when switch is OFF.
Expand All @@ -38,6 +38,7 @@ var interaction_nodes : Array[Node]
var cogito_properties : CogitoProperties = null

@onready var audio_stream_player_3d = $AudioStreamPlayer3D
var is_holding_item : bool

#endregion

Expand All @@ -55,31 +56,59 @@ func _ready():
switch_off()

find_cogito_properties()


func find_cogito_properties():
var property_nodes = find_children("","CogitoProperties",true) #Grabs all attached property components
if property_nodes:
cogito_properties = property_nodes[0]


func interact(_player_interaction_component):
player_interaction_component = _player_interaction_component
if !allows_repeated_interaction and is_on:
player_interaction_component.send_hint(null, has_been_used_hint)
return
if needs_item_to_operate:
if check_for_item() == true:
switch()
else:

if !needs_item_to_operate:
switch()
else:
if is_holding_item:
# Logic to for the player to pick up the required item
var inventory = player_interaction_component.get_parent().inventory_data
inventory.pick_up_slot_data(required_item_slot)

CogitoGlobals.debug_log(true,"cogito_switch.gd","Item " + required_item_slot.inventory_item.name + " added to player inventory")
is_holding_item = false

if is_on: switch_off()
else: switch_on()
call_interact_on_objects()

else:
if check_for_item():
Audio.play_sound_3d(switch_sound).global_position = global_position
is_holding_item = true
if is_on: switch_off()
else: switch_on()
call_interact_on_objects()


func switch():
audio_stream_player_3d.play()
if needs_item_to_operate and !is_holding_item:
if !check_for_item():
return

if !is_on:
switch_on()
else:
switch_off()

call_interact_on_objects()


func call_interact_on_objects():
if !objects_call_interact:
return
for nodepath in objects_call_interact:
Expand Down Expand Up @@ -118,17 +147,16 @@ func switch_off():
func check_for_item() -> bool:
var inventory = player_interaction_component.get_parent().inventory_data
for slot_data in inventory.inventory_slots:
if slot_data != null and slot_data.inventory_item == required_item:
player_interaction_component.send_hint(null, required_item.name + " used.") # Sends a hint with the key item name.
if slot_data.inventory_item.discard_after_use:
inventory.remove_item_from_stack(slot_data)
# inventory.remove_slot_data(slot_data) (removed on 20240913, leaving line just in case there's bugs.
if slot_data != null and slot_data.inventory_item == required_item_slot.inventory_item:
player_interaction_component.send_hint(null, required_item_slot.inventory_item.name + " used.") # Sends a hint with the key item name.
inventory.remove_item_from_stack(slot_data)
return true

if item_hint != "":
player_interaction_component.send_hint(null,item_hint) # Sends the key hint with the default hint icon.
return false


func _on_damage_received(_damage,_bullet_direction,_bullet_position):
interact(CogitoSceneManager._current_player_node.player_interaction_component)

Expand Down Expand Up @@ -156,6 +184,7 @@ func save():
var state_dict = {
"node_path" : self.get_path(),
"is_on" : is_on,
"is_holding_item" : is_holding_item,
"pos_x" : position.x,
"pos_y" : position.y,
"pos_z" : position.z,
Expand All @@ -165,4 +194,3 @@ func save():

}
return state_dict

2 changes: 1 addition & 1 deletion addons/cogito/Components/DynamicInputIcon.gd
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func update_icon_kbm(): # Sets the bound action to keyboard and mouse icon
frame = keycode_to_frame_index("Mouse Middle")

else:
print("DynamicInputIcon: Action=", action_name, ". No primary keyboard/mouse input map assigned.")
CogitoGlobals.debug_log(true, "DynamicInputIcon.gd", "Action " + action_name + ": No primary keyboard/mouse input map assigned.")
frame = 0
return

Expand Down
8 changes: 4 additions & 4 deletions addons/cogito/DemoScenes/COGITO_3_Lobby.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ volumetric_fog_temporal_reprojection_amount = 0.85
density = 0.04
albedo = Color(0.694118, 0.694118, 0.694118, 1)

[sub_resource type="Resource" id="Resource_fk5t5"]
[sub_resource type="Resource" id="Resource_w7sh1"]
resource_local_to_scene = true
script = ExtResource("4_0kggm")
grid = true
Expand Down Expand Up @@ -2427,7 +2427,7 @@ shadow_mesh = SubResource("ArrayMesh_3ecdw")
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_upcaa"]
data = PackedVector3Array(0.6928, 0.0903, -1.6, 0, 0.0903, -1.2, 0.6128, 0.0903, -0.88, 0.6128, 0.0903, -0.88, 0.7728, 0.0903, -0.88, 0.6928, 0.0903, -1.6, 0.7728, 0.0903, -0.88, 1.3856, 0.0903, -1.2, 0.6928, 0.0903, -1.6, 0.7728, 0.0903, -0.88, 0.7728, 0.0903, -0.72, 1.3856, 0.0903, -1.2, 0.6128, 0.0903, -0.72, 0.6128, 0.0903, -0.88, 0, 0.0903, -1.2, 0.6928, 0.0903, 0, 0.6128, 0.0903, -0.72, 0, 0.0903, -1.2, 0.6928, 0.0903, 0, 0.7728, 0.0903, -0.72, 0.6128, 0.0903, -0.72, 0, 0.0903, -0.4, 0.6928, 0.0903, 0, 0, 0.0903, -1.2, 0, 0.0903, -1.2, 0, 0.0903, -0.8, 0, 0.0903, -0.4, 0.6928, 0.0903, 0, 1.3856, 0.0903, -0.4, 0.7728, 0.0903, -0.72, 1.3856, 0.0903, -0.4, 1.3856, 0.0903, -1.2, 0.7728, 0.0903, -0.72, 1.3856, 0.0903, -0.4, 1.3856, 0.0903, -0.8, 1.3856, 0.0903, -1.2, 0.6928, 0.1935, 0, 0, 0.1935, -0.4, 0, 0.1935, -1.2, 0, 0.1935, -1.2, 0.6928, 0.1935, -1.6, 0.6928, 0.1935, 0, 0.6928, 0.1935, -1.6, 1.3856, 0.1935, -0.4, 0.6928, 0.1935, 0, 0.6928, 0.1935, -1.6, 1.3856, 0.1935, -1.2, 1.3856, 0.1935, -0.4, 0.6928, 0.1935, -1.6, 0.6928, 0.0903, -1.6, 1.3856, 0.0903, -1.2, 1.3856, 0.0903, -1.2, 1.3856, 0.1935, -1.2, 0.6928, 0.1935, -1.6, 1.3856, 0.0903, -0.8, 1.3856, 0.0903, -0.4, 1.3856, 0.1935, -0.4, 1.3856, 0.1935, -0.4, 1.3856, 0.1935, -1.2, 1.3856, 0.0903, -0.8, 1.3856, 0.1935, -1.2, 1.3856, 0.0903, -1.2, 1.3856, 0.0903, -0.8, 1.3856, 0.1935, -0.4, 1.3856, 0.0903, -0.4, 0.6928, 0.0903, 0, 0.6928, 0.0903, 0, 0.6928, 0.1935, 0, 1.3856, 0.1935, -0.4, 0.6928, 0.1935, 0, 0.6928, 0.0903, 0, 0, 0.0903, -0.4, 0, 0.0903, -0.4, 0, 0.1935, -0.4, 0.6928, 0.1935, 0, 0, 0.1935, -1.2, 0, 0.1935, -0.4, 0, 0.0903, -0.4, 0, 0.0903, -0.4, 0, 0.0903, -0.8, 0, 0.1935, -1.2, 0, 0.0903, -0.8, 0, 0.0903, -1.2, 0, 0.1935, -1.2, 0, 0.1935, -1.2, 0, 0.0903, -1.2, 0.6928, 0.0903, -1.6, 0.6928, 0.0903, -1.6, 0.6928, 0.1935, -1.6, 0, 0.1935, -1.2, 0.7728, 0.0903, -0.72, 0.7728, -0.4, -0.72, 0.6128, -0.4, -0.72, 0.6128, -0.4, -0.72, 0.6128, 0.0903, -0.72, 0.7728, 0.0903, -0.72, 0.6128, 0.0903, -0.88, 0.6128, 0.0903, -0.72, 0.6128, -0.4, -0.72, 0.6128, -0.4, -0.72, 0.6128, -0.4, -0.88, 0.6128, 0.0903, -0.88, 0.6128, 0.0903, -0.88, 0.6128, -0.4, -0.88, 0.7728, -0.4, -0.88, 0.7728, -0.4, -0.88, 0.7728, 0.0903, -0.88, 0.6128, 0.0903, -0.88, 0.7728, -0.4, -0.88, 0.7728, -0.4, -0.72, 0.7728, 0.0903, -0.72, 0.7728, 0.0903, -0.72, 0.7728, 0.0903, -0.88, 0.7728, -0.4, -0.88, 0.8128, -0.4, -0.68, 0.8128, -0.44, -0.68, 0.5728, -0.44, -0.68, 0.5728, -0.44, -0.68, 0.5728, -0.4, -0.68, 0.8128, -0.4, -0.68, 0.5728, -0.4, -0.92, 0.5728, -0.4, -0.68, 0.5728, -0.44, -0.68, 0.5728, -0.44, -0.68, 0.5728, -0.44, -0.92, 0.5728, -0.4, -0.92, 0.8128, -0.44, -0.92, 0.8128, -0.44, -0.68, 0.8128, -0.4, -0.68, 0.8128, -0.4, -0.68, 0.8128, -0.4, -0.92, 0.8128, -0.44, -0.92, 0.5728, -0.4, -0.68, 0.5728, -0.4, -0.92, 0.6128, -0.4, -0.72, 0.6128, -0.4, -0.72, 0.8128, -0.4, -0.68, 0.5728, -0.4, -0.68, 0.6128, -0.4, -0.72, 0.7728, -0.4, -0.72, 0.8128, -0.4, -0.68, 0.7728, -0.4, -0.72, 0.7728, -0.4, -0.88, 0.8128, -0.4, -0.68, 0.6128, -0.4, -0.88, 0.6128, -0.4, -0.72, 0.5728, -0.4, -0.92, 0.5728, -0.4, -0.92, 0.8128, -0.4, -0.92, 0.6128, -0.4, -0.88, 0.8128, -0.4, -0.92, 0.7728, -0.4, -0.88, 0.6128, -0.4, -0.88, 0.8128, -0.4, -0.92, 0.8128, -0.4, -0.68, 0.7728, -0.4, -0.88, 0.4928, -0.44, -1, 0.4928, -0.44, -0.6, 0.4928, -0.5, -0.6, 0.4928, -0.5, -0.6, 0.4928, -0.5, -1, 0.4928, -0.44, -1, 0.4928, -0.44, -1, 0.4928, -0.5, -1, 0.8928, -0.5, -1, 0.8928, -0.5, -1, 0.8928, -0.44, -1, 0.4928, -0.44, -1, 0.8928, -0.44, -0.6, 0.8928, -0.5, -0.6, 0.4928, -0.5, -0.6, 0.4928, -0.5, -0.6, 0.4928, -0.44, -0.6, 0.8928, -0.44, -0.6, 0.8928, -0.5, -1, 0.8928, -0.5, -0.6, 0.8928, -0.44, -0.6, 0.8928, -0.44, -0.6, 0.8928, -0.44, -1, 0.8928, -0.5, -1, 0.4928, -0.44, -0.6, 0.4928, -0.44, -1, 0.5728, -0.44, -0.68, 0.5728, -0.44, -0.68, 0.8928, -0.44, -0.6, 0.4928, -0.44, -0.6, 0.5728, -0.44, -0.68, 0.8128, -0.44, -0.68, 0.8928, -0.44, -0.6, 0.8128, -0.44, -0.68, 0.8128, -0.44, -0.92, 0.8928, -0.44, -0.6, 0.5728, -0.44, -0.92, 0.5728, -0.44, -0.68, 0.4928, -0.44, -1, 0.4928, -0.44, -1, 0.8928, -0.44, -1, 0.5728, -0.44, -0.92, 0.8928, -0.44, -1, 0.8128, -0.44, -0.92, 0.5728, -0.44, -0.92, 0.8928, -0.44, -1, 0.8928, -0.44, -0.6, 0.8128, -0.44, -0.92, 0.9128, -0.54, -1.02, 0.4728, -0.54, -1.02, 0.4728, -0.54, -0.58, 0.4728, -0.54, -0.58, 0.9128, -0.54, -0.58, 0.9128, -0.54, -1.02, 0.4928, -0.5, -1, 0.4728, -0.54, -1.02, 0.9128, -0.54, -1.02, 0.9128, -0.54, -1.02, 0.8928, -0.5, -1, 0.4928, -0.5, -1, 0.9128, -0.54, -1.02, 0.9128, -0.54, -0.58, 0.8928, -0.5, -0.6, 0.8928, -0.5, -0.6, 0.8928, -0.5, -1, 0.9128, -0.54, -1.02, 0.8928, -0.5, -0.6, 0.9128, -0.54, -0.58, 0.4728, -0.54, -0.58, 0.4728, -0.54, -0.58, 0.4928, -0.5, -0.6, 0.8928, -0.5, -0.6, 0.4928, -0.5, -0.6, 0.4728, -0.54, -0.58, 0.4728, -0.54, -1.02, 0.4728, -0.54, -1.02, 0.4928, -0.5, -1, 0.4928, -0.5, -0.6, 0.5728, -0.4, -0.92, 0.5728, -0.44, -0.92, 0.8128, -0.44, -0.92, 0.8128, -0.44, -0.92, 0.8128, -0.4, -0.92, 0.5728, -0.4, -0.92)

[sub_resource type="Resource" id="Resource_x81fl"]
[sub_resource type="Resource" id="Resource_cdsqn"]
resource_local_to_scene = true
script = ExtResource("4_0kggm")
grid = true
Expand Down Expand Up @@ -3169,7 +3169,7 @@ material = SubResource("FogMaterial_4avjx")

[node name="Player" parent="." instance=ExtResource("3_mgle8")]
transform = Transform3D(-1, 0, 7.45058e-07, 0, 1, 0, -7.45058e-07, 0, -1, 3.03073, 0.905039, -17.9321)
inventory_data = SubResource("Resource_fk5t5")
inventory_data = SubResource("Resource_w7sh1")
step_height_camera_lerp = 1.5

[node name="QUESTS" type="Node3D" parent="."]
Expand Down Expand Up @@ -6993,7 +6993,7 @@ shape = SubResource("ConcavePolygonShape3D_upcaa")

[node name="kitchenFridgeContainer2" parent="BREAK_ROOM" instance=ExtResource("57_fdyfl")]
transform = Transform3D(-1, 0, -1.50996e-07, 0, 1, 0, 1.50996e-07, 0, -1, 3.65301, -4.84288e-08, 6.17191)
inventory_data = SubResource("Resource_x81fl")
inventory_data = SubResource("Resource_cdsqn")

[node name="kitchenMicrowave2" parent="BREAK_ROOM" instance=ExtResource("61_1x4um")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 1.98491, 0.84, 6.39503)
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 @@ -88,7 +88,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_sxwli"]
[sub_resource type="Resource" id="Resource_1xmvx"]
resource_local_to_scene = true
script = ExtResource("4_hlewe")
grid = true
Expand Down Expand Up @@ -901,7 +901,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_sxwli")
inventory_data = SubResource("Resource_1xmvx")
[node name="CONNECTOR_TO_LOBBY" type="Node3D" parent="."]
Expand Down
4 changes: 2 additions & 2 deletions addons/cogito/PackedScenes/Pickups/pickup_battery.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ metallic_specular = 0.2
height = 0.3
radius = 0.1

[sub_resource type="Resource" id="Resource_krpoc"]
[sub_resource type="Resource" id="Resource_c0wls"]
resource_local_to_scene = true
script = ExtResource("3_12bow")
inventory_item = ExtResource("2_hmjxw")
Expand Down Expand Up @@ -77,6 +77,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0504714, 0)
shape = SubResource("CylinderShape3D_emdw8")

[node name="PickupComponent" parent="." instance=ExtResource("2_5yg6i")]
slot_data = SubResource("Resource_krpoc")
slot_data = SubResource("Resource_c0wls")

[node name="CarryableComponent" parent="." instance=ExtResource("5_q7tof")]
Loading

0 comments on commit bf37854

Please sign in to comment.