From 36c174397993a1d8bba6731b8c87606ac19da177 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 16 Apr 2024 03:56:46 +0200 Subject: [PATCH] Break `Draggable` --- behaviours/draggable.gd | 19 ++-------------- behaviours/draggable.svg | 39 +++++++++++++++++++++++++++++++++ behaviours/draggable.svg.import | 37 +++++++++++++++++++++++++++++++ behaviours/draggable.tscn | 9 +------- behaviours/eat_target.gd | 37 ------------------------------- behaviours/eat_target.tscn | 23 ------------------- 6 files changed, 79 insertions(+), 85 deletions(-) create mode 100644 behaviours/draggable.svg create mode 100644 behaviours/draggable.svg.import delete mode 100644 behaviours/eat_target.gd delete mode 100644 behaviours/eat_target.tscn diff --git a/behaviours/draggable.gd b/behaviours/draggable.gd index c02fd6b..26ad854 100644 --- a/behaviours/draggable.gd +++ b/behaviours/draggable.gd @@ -1,21 +1,13 @@ +@icon("res://behaviours/draggable.svg") extends Area2D class_name Draggable -signal move(movement: Vector2) signal dragged signal dropped -@onready var mover: Node2D = $"MatchMousePosition" - -var being_dragged: bool: - get: - return being_dragged - set(value): - being_dragged = value - mover.set_process(being_dragged) - mover.set_physics_process(being_dragged) +var being_dragged: bool = false func drag(): @@ -25,10 +17,3 @@ func drag(): func drop(): being_dragged = false dropped.emit() - - -func _ready(): - being_dragged = false - -func _on_move(movement: Vector2): - move.emit(movement) diff --git a/behaviours/draggable.svg b/behaviours/draggable.svg new file mode 100644 index 0000000..2462527 --- /dev/null +++ b/behaviours/draggable.svg @@ -0,0 +1,39 @@ + + + + + + + diff --git a/behaviours/draggable.svg.import b/behaviours/draggable.svg.import new file mode 100644 index 0000000..c2672cd --- /dev/null +++ b/behaviours/draggable.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bepjyaq1y3g7w" +path="res://.godot/imported/draggable.svg-7f8260afa88b76990683b55fd9af07eb.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://behaviours/draggable.svg" +dest_files=["res://.godot/imported/draggable.svg-7f8260afa88b76990683b55fd9af07eb.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/behaviours/draggable.tscn b/behaviours/draggable.tscn index 60e1f2c..f8e46d8 100644 --- a/behaviours/draggable.tscn +++ b/behaviours/draggable.tscn @@ -1,15 +1,8 @@ -[gd_scene load_steps=3 format=3 uid="uid://dijcjahkddudv"] +[gd_scene load_steps=2 format=3 uid="uid://dijcjahkddudv"] [ext_resource type="Script" path="res://behaviours/draggable.gd" id="1_hdedq"] -[ext_resource type="PackedScene" uid="uid://bvrxvrjlo5130" path="res://behaviours/move_towards_mouse.tscn" id="2_gi6xd"] [node name="Draggable" type="Area2D"] collision_layer = 0 collision_mask = 0 script = ExtResource("1_hdedq") - -[node name="MatchMousePosition" parent="." instance=ExtResource("2_gi6xd")] -scale = Vector2(10000, 10000) -speed = 3600.0 - -[connection signal="move" from="MatchMousePosition" to="." method="_on_move"] diff --git a/behaviours/eat_target.gd b/behaviours/eat_target.gd deleted file mode 100644 index 3ffd6d2..0000000 --- a/behaviours/eat_target.gd +++ /dev/null @@ -1,37 +0,0 @@ -extends Node2D -class_name EatTarget - - -signal eaten(target: Node2D) -signal move(movement: Vector2) - -@export var tag: StringName: - get: - return tag - set(value): - tag = value - if hunt_target != null: - hunt_target.tag = value - if eater != null: - eater.tag = value - - -@onready var hunt_target: HuntTarget = $"HuntTarget" -@onready var eater: Eater = $"Eater" -@onready var move_towards: MoveTowardsTarget = $"MoveTowardsTarget" - -func _ready(): - hunt_target.tag = tag - eater.tag = tag - -func _on_target_selected(body: Node2D) -> void: - move_towards.target = body - -func _on_target_abandoned(_body: Node2D) -> void: - move_towards.target = null - -func _on_eater_eaten(edible): - eaten.emit(edible) - -func _on_move_towards_target_move(movement): - move.emit(movement) diff --git a/behaviours/eat_target.tscn b/behaviours/eat_target.tscn deleted file mode 100644 index 53ab7a7..0000000 --- a/behaviours/eat_target.tscn +++ /dev/null @@ -1,23 +0,0 @@ -[gd_scene load_steps=5 format=3 uid="uid://b7bdlh5akhi8s"] - -[ext_resource type="Script" path="res://behaviours/eat_target.gd" id="1_tlnlt"] -[ext_resource type="PackedScene" uid="uid://dxmodn8mbvw0i" path="res://behaviours/hunt_target.tscn" id="2_c8wdv"] -[ext_resource type="PackedScene" uid="uid://jg7qkbswgqjc" path="res://behaviours/eater.tscn" id="3_ir2yh"] -[ext_resource type="PackedScene" uid="uid://kceb2v2dm0qn" path="res://behaviours/move_towards_target.tscn" id="4_1qc2q"] - -[node name="EatTarget" type="Node2D"] -script = ExtResource("1_tlnlt") - -[node name="HuntTarget" parent="." instance=ExtResource("2_c8wdv")] -scale = Vector2(16, 16) -give_up_secs = 5.0 - -[node name="Eater" parent="." instance=ExtResource("3_ir2yh")] -scale = Vector2(2.5, 2.5) - -[node name="MoveTowardsTarget" parent="." instance=ExtResource("4_1qc2q")] - -[connection signal="target_abandoned" from="HuntTarget" to="." method="_on_target_abandoned"] -[connection signal="target_selected" from="HuntTarget" to="." method="_on_target_selected"] -[connection signal="eaten" from="Eater" to="." method="_on_eater_eaten"] -[connection signal="move" from="MoveTowardsTarget" to="." method="_on_move_towards_target_move"]