Skip to content

Commit e99869a

Browse files
food-pleaseNathanLovato
authored andcommitted
Set player controller to search/work with Interactions
1 parent 60f8e83 commit e99869a

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

src/Main2.tscn

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[ext_resource type="Resource" uid="uid://k63mv5dbd1uk" path="res://maps/village/gbprops_village.tres" id="7_7v0vs"]
1313
[ext_resource type="TileSet" uid="uid://cnlvvllr0ici" path="res://src/field/gamepieces/controllers/cursor/tileset_cursor.tres" id="8_vw0ml"]
1414
[ext_resource type="Script" uid="uid://dwq2jtul5j1rc" path="res://src/field/gamepieces/controllers/cursor/field_cursor.gd" id="9_xqwga"]
15-
[ext_resource type="Script" uid="uid://vnofet0hi8mx" path="res://src/field/gamepieces/player_controller.gd" id="10_7v0vs"]
15+
[ext_resource type="PackedScene" uid="uid://d2lj4blu56fte" path="res://src/field/gamepieces/controllers/player_controller.tscn" id="13_dn3vx"]
1616
[ext_resource type="PackedScene" uid="uid://oot0x5n44b2r" path="res://src/field/cutscenes/Interaction.tscn" id="15_l5lio"]
1717

1818
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_u7xvm"]
@@ -81,19 +81,14 @@ animation_scene = ExtResource("3_08ad2")
8181
[node name="Camera2D" type="Camera2D" parent="Gamepieces/Gamepiece"]
8282
metadata/_edit_lock_ = true
8383

84-
[node name="Controller" type="Node2D" parent="Gamepieces/Gamepiece"]
85-
position = Vector2(-7.62939e-06, -7.62939e-06)
86-
script = ExtResource("10_7v0vs")
87-
metadata/_edit_lock_ = true
84+
[node name="PlayerController" parent="Gamepieces/Gamepiece" instance=ExtResource("13_dn3vx")]
8885

8986
[node name="Gamepiece2" parent="Gamepieces" instance=ExtResource("2_nevdf")]
9087
position = Vector2(56, 69.8)
9188
animation_scene = ExtResource("3_08ad2")
9289

9390
[node name="Interaction" parent="." instance=ExtResource("15_l5lio")]
94-
position = Vector2(88, 40)
95-
scale = Vector2(1, 1)
91+
position = Vector2(88, 24)
9692

9793
[node name="Interaction2" parent="." instance=ExtResource("15_l5lio")]
9894
position = Vector2(40, 40)
99-
scale = Vector2(1, 1)

src/field/gamepieces/controllers/player_controller.tscn

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[gd_scene load_steps=4 format=3 uid="uid://d2lj4blu56fte"]
22

3-
[ext_resource type="Script" uid="uid://cqlx3rgg16wkv" path="res://src/field/gamepieces/controllers/player_controller.gd" id="1_i2bab"]
3+
[ext_resource type="Script" uid="uid://vnofet0hi8mx" path="res://src/field/gamepieces/player_controller.gd" id="1_5pjdg"]
44

55
[sub_resource type="CircleShape2D" id="CircleShape2D_3ejyl"]
66
radius = 7.0
@@ -9,8 +9,7 @@ radius = 7.0
99
radius = 6.0
1010

1111
[node name="PlayerController" type="Node2D"]
12-
script = ExtResource("1_i2bab")
13-
gamepiece_mask = 18
12+
script = ExtResource("1_5pjdg")
1413

1514
[node name="PlayerCollision" type="Area2D" parent="."]
1615
collision_layer = 4

src/field/gamepieces/player_controller.gd

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,33 @@ var _target: Interaction = null
1515
# than prefering an arbitrary axis.
1616
var _last_input_direction: = Vector2.ZERO
1717

18+
# The "interaction searcher" area basically activates any Interactions, which means that they'll
19+
# respond to key/button input.
20+
@onready var _interaction_searcher: = $InteractionSearcher as Area2D
21+
22+
# The player collision area activates Triggers whenever the player moves onto their collision
23+
# shape.
24+
@onready var _player_collision: = $PlayerCollision as Area2D
25+
1826

1927
func _ready() -> void:
2028
super._ready()
2129

2230
if not Engine.is_editor_hint():
2331
add_to_group(GROUP)
24-
32+
33+
## Refer the various player collision shapes to their gamepiece (parent of the controller).
34+
## This will allow other objects/systems to quickly find which gamepiece they are working on
35+
## via the collision "owners".
36+
_interaction_searcher.owner = _gamepiece
37+
_player_collision.owner = _gamepiece
38+
39+
_gamepiece.direction_changed.connect(
40+
func _on_gamepiece_direction_changed(new_direction: Directions.Points):
41+
var offset: Vector2 = Directions.MAPPINGS[new_direction] * 16
42+
_interaction_searcher.position = offset
43+
)
44+
2545
FieldEvents.cell_selected.connect(_on_cell_selected)
2646
FieldEvents.interaction_selected.connect(_on_interaction_selected)
2747

src/main.tscn

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,7 @@ script = ExtResource("26_p8jrd")
498498

499499
[node name="Interaction" parent="Field/Terrain/Gamepieces/Town/AdoringFan" instance=ExtResource("19_sa6jd")]
500500
script = ExtResource("29_at3vc")
501-
timeline = Object(Button,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"physics_interpolation_mode":2,"auto_translate_mode":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"clip_contents":false,"custom_minimum_size":Vector2(0, 0),"layout_direction":0,"layout_mode":3,"anchors_preset":0,"anchor_left":0.0,"anchor_top":0.0,"anchor_right":0.0,"anchor_bottom":0.0,"offset_left":-8.0,"offset_top":-8.0,"offset_right":8.0,"offset_bottom":8.0,"grow_horizontal":1,"grow_vertical":1,"rotation":0.0,"scale":Vector2(1, 1),"pivot_offset":Vector2(0, 0),"size_flags_horizontal":1,"size_flags_vertical":1,"size_flags_stretch_ratio":1.0,"localize_numeral_system":true,"tooltip_text":"","tooltip_auto_translate_mode":0,"focus_neighbor_left":NodePath(""),"focus_neighbor_top":NodePath(""),"focus_neighbor_right":NodePath(""),"focus_neighbor_bottom":NodePath(""),"focus_next":NodePath(""),"focus_previous":NodePath(""),"focus_mode":0,"mouse_filter":0,"mouse_force_pass_scroll_events":true,"mouse_default_cursor_shape":0,"shortcut_context":null,"theme":null,"theme_type_variation":&"","disabled":false,"toggle_mode":false,"button_pressed":false,"action_mode":1,"button_mask":1,"keep_pressed_outside":false,"button_group":null,"shortcut":null,"shortcut_feedback":true,"shortcut_in_tooltip":true,"text":"","icon":null,"flat":true,"alignment":1,"text_overrun_behavior":0,"autowrap_mode":0,"clip_text":false,"icon_alignment":0,"vertical_icon_alignment":1,"expand_icon":false,"text_direction":0,"language":"","script":null)
502-
501+
timeline = null
503502

504503
[node name="InteractionPopup" parent="Field/Terrain/Gamepieces/Town/AdoringFan/Interaction" instance=ExtResource("34_qs25x")]
505504
emote = 1
@@ -706,22 +705,16 @@ metadata/_edit_lock_ = true
706705
position = Vector2(856, 40)
707706
spikes_animation = NodePath("../Spikes")
708707
pedestal_requirement = "Green"
709-
timeline = Object(Button,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"physics_interpolation_mode":2,"auto_translate_mode":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"clip_contents":false,"custom_minimum_size":Vector2(0, 0),"layout_direction":0,"layout_mode":3,"anchors_preset":0,"anchor_left":0.0,"anchor_top":0.0,"anchor_right":0.0,"anchor_bottom":0.0,"offset_left":-8.0,"offset_top":-8.0,"offset_right":8.0,"offset_bottom":8.0,"grow_horizontal":1,"grow_vertical":1,"rotation":0.0,"scale":Vector2(1, 1),"pivot_offset":Vector2(0, 0),"size_flags_horizontal":1,"size_flags_vertical":1,"size_flags_stretch_ratio":1.0,"localize_numeral_system":true,"tooltip_text":"","tooltip_auto_translate_mode":0,"focus_neighbor_left":NodePath(""),"focus_neighbor_top":NodePath(""),"focus_neighbor_right":NodePath(""),"focus_neighbor_bottom":NodePath(""),"focus_next":NodePath(""),"focus_previous":NodePath(""),"focus_mode":0,"mouse_filter":0,"mouse_force_pass_scroll_events":true,"mouse_default_cursor_shape":0,"shortcut_context":null,"theme":null,"theme_type_variation":&"","disabled":false,"toggle_mode":false,"button_pressed":false,"action_mode":1,"button_mask":1,"keep_pressed_outside":false,"button_group":null,"shortcut":null,"shortcut_feedback":true,"shortcut_in_tooltip":true,"text":"","icon":null,"flat":true,"alignment":1,"text_overrun_behavior":0,"autowrap_mode":0,"clip_text":false,"icon_alignment":0,"vertical_icon_alignment":1,"expand_icon":false,"text_direction":0,"language":"","script":null)
710-
711708

712709
[node name="BluePedestal" parent="Field/Terrain/Gamepieces/House/PedestalPuzzle" node_paths=PackedStringArray("spikes_animation") instance=ExtResource("38_n1c7a")]
713710
position = Vector2(872, 40)
714711
spikes_animation = NodePath("../Spikes")
715712
pedestal_requirement = "Blue"
716-
timeline = Object(Button,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"physics_interpolation_mode":2,"auto_translate_mode":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"clip_contents":false,"custom_minimum_size":Vector2(0, 0),"layout_direction":0,"layout_mode":3,"anchors_preset":0,"anchor_left":0.0,"anchor_top":0.0,"anchor_right":0.0,"anchor_bottom":0.0,"offset_left":-8.0,"offset_top":-8.0,"offset_right":8.0,"offset_bottom":8.0,"grow_horizontal":1,"grow_vertical":1,"rotation":0.0,"scale":Vector2(1, 1),"pivot_offset":Vector2(0, 0),"size_flags_horizontal":1,"size_flags_vertical":1,"size_flags_stretch_ratio":1.0,"localize_numeral_system":true,"tooltip_text":"","tooltip_auto_translate_mode":0,"focus_neighbor_left":NodePath(""),"focus_neighbor_top":NodePath(""),"focus_neighbor_right":NodePath(""),"focus_neighbor_bottom":NodePath(""),"focus_next":NodePath(""),"focus_previous":NodePath(""),"focus_mode":0,"mouse_filter":0,"mouse_force_pass_scroll_events":true,"mouse_default_cursor_shape":0,"shortcut_context":null,"theme":null,"theme_type_variation":&"","disabled":false,"toggle_mode":false,"button_pressed":false,"action_mode":1,"button_mask":1,"keep_pressed_outside":false,"button_group":null,"shortcut":null,"shortcut_feedback":true,"shortcut_in_tooltip":true,"text":"","icon":null,"flat":true,"alignment":1,"text_overrun_behavior":0,"autowrap_mode":0,"clip_text":false,"icon_alignment":0,"vertical_icon_alignment":1,"expand_icon":false,"text_direction":0,"language":"","script":null)
717-
718713

719714
[node name="RedPedestal" parent="Field/Terrain/Gamepieces/House/PedestalPuzzle" node_paths=PackedStringArray("spikes_animation") instance=ExtResource("38_n1c7a")]
720715
position = Vector2(888, 40)
721716
spikes_animation = NodePath("../Spikes")
722717
pedestal_requirement = "Red"
723-
timeline = Object(Button,"_import_path":NodePath(""),"unique_name_in_owner":false,"process_mode":0,"process_priority":0,"process_physics_priority":0,"process_thread_group":0,"physics_interpolation_mode":2,"auto_translate_mode":0,"editor_description":"","visible":true,"modulate":Color(1, 1, 1, 1),"self_modulate":Color(1, 1, 1, 1),"show_behind_parent":false,"top_level":false,"clip_children":0,"light_mask":1,"visibility_layer":1,"z_index":0,"z_as_relative":true,"y_sort_enabled":false,"texture_filter":0,"texture_repeat":0,"material":null,"use_parent_material":false,"clip_contents":false,"custom_minimum_size":Vector2(0, 0),"layout_direction":0,"layout_mode":3,"anchors_preset":0,"anchor_left":0.0,"anchor_top":0.0,"anchor_right":0.0,"anchor_bottom":0.0,"offset_left":-8.0,"offset_top":-8.0,"offset_right":8.0,"offset_bottom":8.0,"grow_horizontal":1,"grow_vertical":1,"rotation":0.0,"scale":Vector2(1, 1),"pivot_offset":Vector2(0, 0),"size_flags_horizontal":1,"size_flags_vertical":1,"size_flags_stretch_ratio":1.0,"localize_numeral_system":true,"tooltip_text":"","tooltip_auto_translate_mode":0,"focus_neighbor_left":NodePath(""),"focus_neighbor_top":NodePath(""),"focus_neighbor_right":NodePath(""),"focus_neighbor_bottom":NodePath(""),"focus_next":NodePath(""),"focus_previous":NodePath(""),"focus_mode":0,"mouse_filter":0,"mouse_force_pass_scroll_events":true,"mouse_default_cursor_shape":0,"shortcut_context":null,"theme":null,"theme_type_variation":&"","disabled":false,"toggle_mode":false,"button_pressed":false,"action_mode":1,"button_mask":1,"keep_pressed_outside":false,"button_group":null,"shortcut":null,"shortcut_feedback":true,"shortcut_in_tooltip":true,"text":"","icon":null,"flat":true,"alignment":1,"text_overrun_behavior":0,"autowrap_mode":0,"clip_text":false,"icon_alignment":0,"vertical_icon_alignment":1,"expand_icon":false,"text_direction":0,"language":"","script":null)
724-
725718

726719
[node name="Spikes" type="AnimationPlayer" parent="Field/Terrain/Gamepieces/House/PedestalPuzzle"]
727720
libraries = {

0 commit comments

Comments
 (0)