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

Buttons & Switches interact to all hits #261

Merged
merged 4 commits into from
Oct 13, 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
7 changes: 6 additions & 1 deletion COGITO/CogitoObjects/cogito_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func _ready() -> void:
cooldown = 0 #Enabling button to be pressed right away.
interaction_text = usable_interaction_text
object_state_updated.emit(interaction_text)
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 _physics_process(delta: float) -> void:
if cooldown > 0:
Expand Down Expand Up @@ -85,7 +90,7 @@ func press():
object.interact(player_interaction_component)


func on_damage_received():
func _on_damage_received():
interact(CogitoSceneManager._current_player_node.player_interaction_component)


Expand Down
11 changes: 9 additions & 2 deletions COGITO/CogitoObjects/cogito_switch.gd
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ func _ready():
switch_on()
else:
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
Expand Down Expand Up @@ -123,6 +128,8 @@ func check_for_item() -> bool:
player_interaction_component.send_hint(null,item_hint) # Sends the key hint with the default hint icon.
return false

func _on_damage_received():
interact(CogitoSceneManager._current_player_node.player_interaction_component)

func set_state():
if is_on:
Expand All @@ -144,7 +151,6 @@ func set_state():

object_state_updated.emit(interaction_text)


func save():
var state_dict = {
"node_path" : self.get_path(),
Expand All @@ -158,3 +164,4 @@ func save():

}
return state_dict

14 changes: 6 additions & 8 deletions COGITO/DemoScenes/DemoPrefabs/generic_button.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
[ext_resource type="Script" path="res://COGITO/CogitoObjects/cogito_button.gd" id="1_l32yq"]
[ext_resource type="AudioStream" uid="uid://b6wdy2102jymr" path="res://COGITO/Assets/Audio/Kenney/UiAudio/switch2.ogg" id="2_awyad"]
[ext_resource type="PackedScene" uid="uid://l61jtpfxu5x5" path="res://COGITO/Components/Interactions/BasicInteraction.tscn" id="3_v8dn1"]
[ext_resource type="PackedScene" uid="uid://cqgg1nng0vvbh" path="res://COGITO/Components/Attributes/HealthAttribute.tscn" id="4_26rcl"]
[ext_resource type="PackedScene" uid="uid://k28yrbg3k3pw" path="res://COGITO/Components/HitboxComponent.tscn" id="5_dudfk"]
[ext_resource type="PackedScene" uid="uid://cj0yaeh3yg7tu" path="res://COGITO/Components/Properties/CogitoProperties.tscn" id="6_w5n86"]

[sub_resource type="CylinderMesh" id="CylinderMesh_clo4d"]
top_radius = 0.05
Expand Down Expand Up @@ -43,12 +43,10 @@ shape = SubResource("BoxShape3D_nti18")

[node name="BasicInteraction" parent="." instance=ExtResource("3_v8dn1")]

[node name="HealthAttribute" parent="." instance=ExtResource("4_26rcl")]
value_max = 1.0
value_start = 1.0
is_locked = true
[node name="HitboxComponent" parent="." instance=ExtResource("5_dudfk")]

[node name="HitboxComponent" parent="." node_paths=PackedStringArray("health_attribute") instance=ExtResource("5_dudfk")]
health_attribute = NodePath("../HealthAttribute")
[node name="CogitoProperties" parent="." instance=ExtResource("6_w5n86")]
material_properties = 1
burn_damage_amount = 1.0

[connection signal="damage_taken" from="HealthAttribute" to="." method="on_damage_received"]
[connection signal="damage_received" from="." to="." method="_on_damage_received"]
12 changes: 11 additions & 1 deletion COGITO/DemoScenes/DemoPrefabs/generic_switch.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[gd_scene load_steps=9 format=3 uid="uid://6k5rvlwcpys1"]
[gd_scene load_steps=11 format=3 uid="uid://6k5rvlwcpys1"]

[ext_resource type="Script" path="res://COGITO/CogitoObjects/cogito_switch.gd" id="1_8r8fc"]
[ext_resource type="AudioStream" uid="uid://0himm415mqex" path="res://COGITO/Assets/Audio/Kenney/UiAudio/switch29.ogg" id="2_m3jxc"]
[ext_resource type="PackedScene" uid="uid://l61jtpfxu5x5" path="res://COGITO/Components/Interactions/BasicInteraction.tscn" id="3_v8dn1"]
[ext_resource type="PackedScene" uid="uid://k28yrbg3k3pw" path="res://COGITO/Components/HitboxComponent.tscn" id="4_dkn68"]
[ext_resource type="PackedScene" uid="uid://cj0yaeh3yg7tu" path="res://COGITO/Components/Properties/CogitoProperties.tscn" id="5_mihmv"]

[sub_resource type="CylinderMesh" id="CylinderMesh_clo4d"]
top_radius = 0.05
Expand Down Expand Up @@ -53,3 +55,11 @@ shape = SubResource("BoxShape3D_nti18")
[node name="AudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="."]

[node name="BasicInteraction" parent="." instance=ExtResource("3_v8dn1")]

[node name="HitboxComponent" parent="." instance=ExtResource("4_dkn68")]

[node name="CogitoProperties" parent="." instance=ExtResource("5_mihmv")]
material_properties = 1
burn_damage_amount = 1.0

[connection signal="damage_received" from="." to="." method="_on_damage_received"]