Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing Cogito Editor Tab, instead using globals + custom resource CogitoSettings #332

Merged
merged 4 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/cogito/CogitoObjects/cogito_keypad.gd
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func close(_player_interaction_component):

func _on_button_received(_passed_string:String):
if !is_locked:
print("Already unlocked!")
CogitoGlobals.debug_log(true, "cogito_keypad.gd","Already unlocked!")
return

if !is_open:
Expand Down
37 changes: 15 additions & 22 deletions addons/cogito/CogitoObjects/cogito_player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func _ready():
# Grabs all attached player attributes
for attribute in find_children("","CogitoAttribute",false):
player_attributes[attribute.attribute_name] = attribute
CogitoMain.debug_log(is_logging, "cogito_player.gd", "Cogito Attribute found: " + attribute.attribute_name)
CogitoGlobals.debug_log(is_logging, "cogito_player.gd", "Cogito Attribute found: " + attribute.attribute_name)

# If found, hookup health attribute signal to detect player death
var health_attribute = player_attributes.get("health")
Expand All @@ -242,7 +242,7 @@ func _ready():
### CURRENCY SETUP
for currency in find_children("", "CogitoCurrency", false):
player_currencies[currency.currency_name] = currency
CogitoMain.debug_log(is_logging, "cogito_player.gd", "Cogito Currency found: " + currency.currency_name)
CogitoGlobals.debug_log(is_logging, "cogito_player.gd", "Cogito Currency found: " + currency.currency_name)


# Pause Menu setup
Expand All @@ -251,16 +251,14 @@ func _ready():
pause_menu_node.resume.connect(_on_pause_menu_resume) # Hookup resume signal from Pause Menu
pause_menu_node.close_pause_menu() # Making sure pause menu is closed on player scene load
else:

print("Player has no reference to pause menu.")
printerr("Player has no reference to pause menu.")

#Sittable Signals setup
CogitoSceneManager.connect("sit_requested", Callable(self, "_on_sit_requested"))
CogitoSceneManager.connect("stand_requested", Callable(self, "_on_stand_requested"))
CogitoSceneManager.connect("seat_move_requested", Callable(self, "_on_seat_move_requested"))

CogitoMain.debug_log(is_logging, "cogito_player.gd", "Player has no reference to pause menu.")

CogitoGlobals.debug_log(is_logging, "cogito_player.gd", "Player has no reference to pause menu.")

call_deferred("slide_audio_init")

Expand All @@ -275,7 +273,7 @@ func slide_audio_init():
func increase_attribute(attribute_name: String, value: float, value_type: ConsumableItemPD.ValueType) -> bool:
var attribute = player_attributes.get(attribute_name)
if not attribute:
CogitoMain.debug_log(is_logging, "cogito_player.gd", "Increase attribute: Attribute not found")
CogitoGlobals.debug_log(is_logging, "cogito_player.gd", "Increase attribute: Attribute not found")
return false
if value_type == ConsumableItemPD.ValueType.CURRENT:
if attribute.value_current == attribute.value_max:
Expand All @@ -292,7 +290,7 @@ func increase_attribute(attribute_name: String, value: float, value_type: Consum
func decrease_attribute(attribute_name: String, value: float):
var attribute = player_attributes.get(attribute_name)
if not attribute:
CogitoMain.debug_log(is_logging, "cogito_player.gd", "Decrease attribute: " + attribute_name + " - Attribute not found")
CogitoGlobals.debug_log(is_logging, "cogito_player.gd", "Decrease attribute: " + attribute_name + " - Attribute not found")
return
attribute.subtract(value)

Expand All @@ -301,7 +299,7 @@ func decrease_attribute(attribute_name: String, value: float):
func increase_currency(currency_name: String, value: float) -> bool:
var currency = player_currencies.get(currency_name)
if not currency:
CogitoMain.debug_log(is_logging, "cogito_player.gd", "Increase currency: Currency not found")
CogitoGlobals.debug_log(is_logging, "cogito_player.gd", "Increase currency: Currency not found")
return false
else:
currency.add(value)
Expand All @@ -311,7 +309,7 @@ func increase_currency(currency_name: String, value: float) -> bool:
func decrease_currency(currency_name: String, value: float):
var currency = player_currencies.get(currency_name)
if not currency:
CogitoMain.debug_log(is_logging, "cogito_player.gd", "Decrease currency: " + currency_name + " - Currency not found")
CogitoGlobals.debug_log(is_logging, "cogito_player.gd", "Decrease currency: " + currency_name + " - Currency not found")
return
currency.subtract(value)

Expand Down Expand Up @@ -341,7 +339,7 @@ func _on_resume_movement():
func _reload_options():
var err = config.load(OptionsConstants.config_file_name)
if err == 0:
CogitoMain.debug_log(is_logging, "cogito_player.gd", "Options reloaded.")
CogitoGlobals.debug_log(is_logging, "cogito_player.gd", "Options reloaded.")

HEADBOBBLE = config.get_value(OptionsConstants.section_name, OptionsConstants.head_bobble_key, 1)
MOUSE_SENS = config.get_value(OptionsConstants.section_name, OptionsConstants.mouse_sens_key, 0.25)
Expand Down Expand Up @@ -616,31 +614,26 @@ func _move_to_nearby_location(sittable):
randf_range(-0.1, 0.1), # Degree of Y random actually makes this work better at finding candidates
randf_range(-0.1, 0.1)
).normalized()
#print(random_direction)

var candidate_pos = seat_position + (random_direction * exit_distance)
candidate_pos.y = navmesh_offset_y # to check navmesh at navmesh height

navigation_agent.target_position = candidate_pos
#print("Checking position: ", candidate_pos)

# Check if position is reachable
if navigation_agent.is_navigation_finished():
currently_tweening = true
#print("Found available location, moving there.", candidate_pos, attempts)
var tween = create_tween()
navigation_agent.target_position.y += 1 # To avoid player going through floor
tween.tween_property(self, "global_transform:origin", navigation_agent.target_position, sittable.tween_duration)
tween.tween_property(neck, "global_transform:basis", original_neck_basis, sittable.rotation_tween_duration)
tween.tween_callback(Callable(self, "_stand_up_finished"))
return
else:
#print("Position ", candidate_pos, " is not valid.")
exit_distance += step_increase
attempts += 1

if exit_distance > max_distance:
#print("Exceeded maximum exit distance. Distance has been reset")
exit_distance = 1

# If no valid location found, try leave node
Expand Down Expand Up @@ -833,7 +826,7 @@ func _physics_process(delta):

if stand_after_roll:
if !is_movement_paused or !is_showing_ui:
CogitoMain.debug_log(is_logging, "cogito_player.gd", "523: Standing after roll.")
CogitoGlobals.debug_log(is_logging, "cogito_player.gd", "523: Standing after roll.")
head.position.y = lerp(head.position.y, 0.0, delta * LERP_SPEED)
standing_collision_shape.disabled = true
crouching_collision_shape.disabled = false
Expand Down Expand Up @@ -878,7 +871,7 @@ func _physics_process(delta):
is_crouching = true
else:
if !is_showing_ui or !is_movement_paused:
#CogitoMain.debug_log(is_logging, "cogito_player.gd", "567: Standing up...")
#CogitoGlobals.debug_log(is_logging, "cogito_player.gd", "567: Standing up...")
head.position.y = lerp(head.position.y, 0.0, delta * LERP_SPEED)
if head.position.y < CROUCHING_DEPTH/4:
# still transitioning from state
Expand Down Expand Up @@ -919,7 +912,7 @@ func _physics_process(delta):
else:
# STANDING UP HANDLING
if !is_showing_ui or !is_movement_paused:
CogitoMain.debug_log(is_logging, "cogito_player.gd", "606 standing up...")
CogitoGlobals.debug_log(is_logging, "cogito_player.gd", "606 standing up...")
current_speed = lerp(current_speed, WALKING_SPEED, delta * LERP_SPEED)
wiggle_current_intensity = WIGGLE_ON_WALKING_INTENSITY * HEADBOBBLE
wiggle_index += WIGGLE_ON_WALKING_SPEED * delta
Expand Down Expand Up @@ -982,7 +975,7 @@ func _physics_process(delta):
)
else:
if !is_movement_paused or !is_showing_ui:
#CogitoMain.debug_log(is_logging, "cogito_player.gd", "668 Standing up...")
#CogitoGlobals.debug_log(is_logging, "cogito_player.gd", "668 Standing up...")
eyes.position.y = lerp(eyes.position.y, 0.0, delta * LERP_SPEED)
eyes.position.x = lerp(eyes.position.x, 0.0, delta * LERP_SPEED)
if last_velocity.y <= -7.5:
Expand Down Expand Up @@ -1042,7 +1035,7 @@ func _physics_process(delta):
standing_collision_shape.disabled = false
crouching_collision_shape.disabled = true
elif not doesnt_need_stamina:
CogitoMain.debug_log(is_logging, "cogito_player.gd","Not enough stamina to jump.")
CogitoGlobals.debug_log(is_logging, "cogito_player.gd","Not enough stamina to jump.")

if sliding_timer.is_stopped():
if is_on_floor():
Expand Down Expand Up @@ -1274,7 +1267,7 @@ func _on_animation_player_animation_finished(anim_name):

func apply_external_force(force_vector: Vector3):
if force_vector and force_vector.length() > 0:
CogitoMain.debug_log(is_logging, "cogito_player.gd", "Applying external force " + str(force_vector))
CogitoGlobals.debug_log(is_logging, "cogito_player.gd", "Applying external force " + str(force_vector))
velocity += force_vector
move_and_slide()

Expand Down
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:
CogitoMain.debug_log(true,"cogito_pressure_plate.gd", str(body) + " has exited.")
CogitoGlobals.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:
CogitoMain.debug_log(true,"cogito_pressure_plate.gd","Detected " + body.name)
CogitoGlobals.debug_log(true,"cogito_pressure_plate.gd","Detected " + body.name)
if body.is_in_group("Player"):
CogitoMain.debug_log(true,"cogito_pressure_plate.gd", "Player detected. applying force.")
CogitoGlobals.debug_log(true,"cogito_pressure_plate.gd", "Player detected. applying force.")
plate_node.add_constant_central_force(Vector3(0,-3,0))
10 changes: 5 additions & 5 deletions addons/cogito/CogitoObjects/cogito_projectile.gd
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ func _on_body_entered(collider: Node):

if collider.has_signal("damage_received"):
if( !collider.cogito_properties && !cogito_properties): # Case where neither projectile nor the object hit have properties defined.
print("Projectile: Collider nor projectile have CogitoProperties, damaging as usual.")
CogitoGlobals.debug_log(true, "cogito_projectile.gd", "Collider nor projectile have CogitoProperties, damaging as usual.")
deal_damage(collider)
return

if( collider.cogito_properties && !cogito_properties): # Case were only collider has properties.
print("Projectile: Collider has CogitoProperties, currently ignoring these and damaging as usual.")
CogitoGlobals.debug_log(true, "cogito_projectile.gd", "Collider has CogitoProperties, currently ignoring these and damaging as usual.")
deal_damage(collider)

if( !collider.cogito_properties && cogito_properties): # Case where only the projectile has properties defined.
match cogito_properties.material_properties:
CogitoProperties.MaterialProperties.SOFT:
# Defining what happens if a soft projectile hits an object with no properties.
print("Projectile: Soft projectile does no damage per default.")
CogitoGlobals.debug_log(true, "cogito_projectile.gd", "Soft projectile does no damage per default.")
if destroy_on_impact:
die()
return

if( collider.cogito_properties && cogito_properties): # Case where both projectile and the object hit have properties defined.
if( cogito_properties.material_properties == CogitoProperties.MaterialProperties.SOFT && collider.cogito_properties.material_properties == CogitoProperties.MaterialProperties.SOFT):
# When both objects are soft, damage the hit object.
print("Projectile: Soft object hit, dealing damage.")
CogitoGlobals.debug_log(true, "cogito_projectile.gd", "Soft object hit, dealing damage.")
deal_damage(collider)

# Manually setting the reaction collider and calling reactions on object hit, skipping the reaction threshold time.
Expand All @@ -85,7 +85,7 @@ func stick_to_object(collider: Node):
#self.angular_velocity = Vector3.ZERO

func deal_damage(collider: Node):
print(self.name, ": dealing damage amount ", damage_amount, " on collider ", collider.name)
CogitoGlobals.debug_log(true, "cogito_projectile.gd", self.name + " dealing damage amount " + str(damage_amount) + " on collider " + collider.name)
collider.damage_received.emit(damage_amount)
if destroy_on_impact:
die()
Expand Down
24 changes: 12 additions & 12 deletions addons/cogito/CogitoObjects/cogito_security_camera.gd
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func searching():


func start_detecting():
print("SecuirtyCamera: Starting detection.")
current_state = DetectorState.DETECTING
started_detecting.emit()
update_indicator_mesh()
Expand All @@ -96,7 +95,7 @@ func start_detecting():
func detecting(delta: float):
detected_objects = find_visible_targets_within_detection_area()
if detected_objects.size() <= 0:
print("SecurityCamera DETECTING: No visible targets in detection area. Stopping detection.")
CogitoGlobals.debug_log(true,"cogito_security_camera.gd", "DETECTING: No visible targets in detection area. Stopping detection.")
stop_detecting()

if detection_method == DetectionMethod.LIGHTMETER and lightmeter != null:
Expand All @@ -107,7 +106,7 @@ func detecting(delta: float):

if detection_time >= detection_threshold:
# === THIS IS WHERE THE FULL DETECTION HAPPENS ===
print("SecurityCamera: Detected!")
CogitoGlobals.debug_log(true,"cogito_security_camera.gd", "Detected!")
current_state = DetectorState.DETECTED
start_alarm_light()
if !audio_stream_player_3d.playing:
Expand All @@ -118,7 +117,7 @@ func detecting(delta: float):


func stop_detecting():
print("SecurityCamera: Stopping detection.")
CogitoGlobals.debug_log(true,"cogito_security_camera.gd", "Stopping detection.")
detection_time = 0
current_state = DetectorState.SEARCHING
object_no_longer_detected.emit()
Expand Down Expand Up @@ -152,7 +151,7 @@ func find_visible_targets_within_detection_area() -> Array[Node3D]:

func object_visibile_for_detector(target: Node3D) -> bool:
detection_ray_cast_3d.set_target_position(to_local(target.global_position))
print("Security Camera: Checking if detector can see ", target.name, " at position ", target.global_position, ".")
CogitoGlobals.debug_log(true,"cogito_security_camera.gd", "Checking if detector can see " + target.name + " at position " + str(target.global_position) )
var detected_object = detection_ray_cast_3d.get_collider()

if detected_object == target:
Expand All @@ -163,17 +162,18 @@ func object_visibile_for_detector(target: Node3D) -> bool:

func on_body_entered_detection(body: Node3D):
if only_detect_player and body.is_in_group("Player"):
print("SecurityCamera: Player entered detection area: ", body)
CogitoGlobals.debug_log(true,"cogito_security_camera.gd", "Player entered detection area: " + body.name)
objects_in_detection_area.append(body)

# For non-player objects, check they are in the non_player_detection_list, and not a player
elif !only_detect_player and !body.is_in_group("Player"):
if is_relevant_non_player(body):
print("SecurityCamera: Relevant object entered detection area: ", body)
CogitoGlobals.debug_log(true,"cogito_security_camera.gd", "Relevant object entered detection area: " + body.name)
objects_in_detection_area.append(body)
if detection_method == DetectionMethod.LIGHTMETER:
find_lightmeter(body) # Check for Lightmeter on any entered body, if using Lightmeter detection method


func find_lightmeter(body):
var found_lightmeter: CogitoLightmeter = null
for attribute in body.find_children("", "CogitoLightmeter", false):
Expand All @@ -183,25 +183,25 @@ func find_lightmeter(body):

if found_lightmeter:
lightmeter = found_lightmeter
print("Lightmeter found on entity:", body.name)
CogitoGlobals.debug_log(true,"cogito_security_camera.gd", "Lightmeter found on entity:" + body.name)
else:
print("No lightmeter found on entity:", body.name)
CogitoGlobals.debug_log(true,"cogito_security_camera.gd", "No lightmeter found on entity:" + body.name)


func is_relevant_non_player(body: Node3D) -> bool:
##TODO Better way of defining this than names array
if body.name in non_player_detection_list:
return true
else:
#print("SecurityCamera: Non-relevant object ignored:", body.name)
return false


func on_body_left_detection(body: Node3D):
if only_detect_player and body.is_in_group("Player"):
print("SecurityCamera: Player left detection area: ", body)
CogitoGlobals.debug_log(true,"cogito_security_camera.gd", "Player left detection area: " + body.name)
objects_in_detection_area.erase(body)
elif is_relevant_non_player(body):
print("SecurityCamera:",body," left detection area: ")
CogitoGlobals.debug_log(true,"cogito_security_camera.gd", body.name + " left detection area: ")
objects_in_detection_area.erase(body)


Expand Down
10 changes: 4 additions & 6 deletions addons/cogito/CogitoObjects/cogito_snap_slot.gd
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func _ready() -> void:

if expected_object:
instanced_expected_object = load(expected_object.resource_path).instantiate()
print("Cogito_snap_slot: expected object cogito_name=", instanced_expected_object.cogito_name)
CogitoGlobals.debug_log(true,"cogito_snap_slot.gd", "expected object cogito_name=" + instanced_expected_object.cogito_name)


func interact(interactor: Node3D):
Expand All @@ -90,7 +90,7 @@ func place_carryable(world_carryable: Node3D):
if !world_carryable:
return
if !world_carryable.is_class("RigidBody3D"):
print("Cogito_snap_slot: place_carryable(): body wasn't a RigidBody3D.")
CogitoGlobals.debug_log(true,"cogito_snap_slot.gd", "place_carryable(): body wasn't a RigidBody3D.")
return

Audio.play_sound_3d(object_placement_sound).global_position = self.global_position
Expand All @@ -116,19 +116,17 @@ func _on_body_entered_snap_area(body : Node3D):
if !player_interaction_component:
player_interaction_component = CogitoSceneManager._current_player_node.player_interaction_component

print("Cogito_snap_slot: _on_body_entered = ", body)
if body is CogitoObject:
print("Cogito_snap_slot: body is CogitoObject with cogito_name=", body.cogito_name)
CogitoGlobals.debug_log(true,"cogito_snap_slot.gd", "body is CogitoObject with cogito_name=" + body.cogito_name)
if instanced_expected_object.cogito_name == body.cogito_name:
print("Cogito_snap_slot: Expected object detected: ", body.cogito_name)
CogitoGlobals.debug_log(true,"cogito_snap_slot.gd", "Expected object detected: " + body.cogito_name)
place_carryable(body)
pass


func _on_body_exited_snap_area(body: Node3D):
if !expected_object:
return
print("Cogito_snap_slot: _on_body_exited = ", body)
if body is CogitoObject and instanced_expected_object.cogito_name == body.cogito_name:
remove_object()

Expand Down
2 changes: 1 addition & 1 deletion addons/cogito/CogitoObjects/cogito_switch.gd
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func interact(_player_interaction_component):
var inventory = player_interaction_component.get_parent().inventory_data
inventory.pick_up_slot_data(required_item_slot)

CogitoMain.debug_log(true,"cogito_switch.gd","Item " + required_item_slot.inventory_item.name + " added to player inventory")
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()
Expand Down
2 changes: 1 addition & 1 deletion addons/cogito/CogitoObjects/cogito_turnwheel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func _is_being_turned(_time_remaining:float):
func interact(_player_interaction_component):
audio_stream_player_3d.stop()
has_been_turned = !has_been_turned
print("Turnwheel has been turned: ", has_been_turned)
CogitoGlobals.debug_log(true,"cogito_turnwheel.gd", "Turnwheel has been turned: " + str(has_been_turned) )
for node in nodes_to_trigger:
node.interact(null)

Expand Down
Loading