mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-21 15:44:23 +00:00
Refactor Hunter
into EdibleTracker
This commit is contained in:
parent
db1805eec5
commit
fa502ba267
7 changed files with 122 additions and 48 deletions
34
behaviours/edible_tracker.gd
Normal file
34
behaviours/edible_tracker.gd
Normal file
|
@ -0,0 +1,34 @@
|
|||
@icon("res://behaviours/edible_tracker.svg")
|
||||
extends Area2D
|
||||
class_name EdibleTracker
|
||||
|
||||
## Keeps track of what [Edible]s are inside the area.
|
||||
|
||||
|
||||
signal tracked(body: Node2D)
|
||||
signal untracked(body: Node2D)
|
||||
|
||||
|
||||
@export var acceptable_diets: Array[StringName] = []
|
||||
|
||||
var tracking: Array = []
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
var edibles: Array = body.find_children("Edible", "Edible", false, false)
|
||||
for edible in edibles:
|
||||
if edible.tag in acceptable_diets:
|
||||
tracking.push_back(body)
|
||||
tracked.emit(body)
|
||||
|
||||
func _on_body_exited(body: Node2D) -> void:
|
||||
if body in tracking:
|
||||
tracking.erase(body)
|
||||
untracked.emit(body)
|
||||
|
||||
|
||||
func _on_tracked(body: Node2D) -> void:
|
||||
Log.p(self, "Tracking a new target: %s" % body)
|
||||
|
||||
func _on_untracked(body:Node2D) -> void:
|
||||
Log.p(self, "Not tracking anymore target: %s" % body)
|
39
behaviours/edible_tracker.svg
Normal file
39
behaviours/edible_tracker.svg
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
viewBox="0 0 512 512"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
sodipodi:docname="bowl-rice.svg"
|
||||
inkscape:version="1.3.2 (091e20ef0f, 2023-11-25, custom)"
|
||||
width="16"
|
||||
height="16"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<defs
|
||||
id="defs1" />
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:zoom="1.6464844"
|
||||
inkscape:cx="256"
|
||||
inkscape:cy="256"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1020"
|
||||
inkscape:window-x="1280"
|
||||
inkscape:window-y="32"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg1" />
|
||||
<!--! Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2024 Fonticons, Inc. -->
|
||||
<path
|
||||
d="m 176,56 c 0,-13.3 10.7,-24 24,-24 h 16 c 13.3,0 24,10.7 24,24 0,13.3 -10.7,24 -24,24 H 200 C 186.7,80 176,69.3 176,56 Z m 24,48 h 16 c 13.3,0 24,10.7 24,24 0,13.3 -10.7,24 -24,24 h -16 c -13.3,0 -24,-10.7 -24,-24 0,-13.3 10.7,-24 24,-24 z M 56,176 h 16 c 13.3,0 24,10.7 24,24 0,13.3 -10.7,24 -24,24 H 56 C 42.7,224 32,213.3 32,200 32,186.7 42.7,176 56,176 Z M 0,283.4 C 0,268.3 12.3,256 27.4,256 h 457.2 c 15.1,0 27.4,12.3 27.4,27.4 0,70.5 -44.4,130.7 -106.7,154.1 l -1.8,14.5 c -2,16 -15.6,28 -31.8,28 H 140.2 c -16.1,0 -29.8,-12 -31.8,-28 l -1.8,-14.4 C 44.4,414.1 0,353.9 0,283.4 Z M 224,200 c 0,-13.3 10.7,-24 24,-24 h 16 c 13.3,0 24,10.7 24,24 0,13.3 -10.7,24 -24,24 h -16 c -13.3,0 -24,-10.7 -24,-24 z m -96,0 c 0,-13.3 10.7,-24 24,-24 h 16 c 13.3,0 24,10.7 24,24 0,13.3 -10.7,24 -24,24 h -16 c -13.3,0 -24,-10.7 -24,-24 z m -24,-96 h 16 c 13.3,0 24,10.7 24,24 0,13.3 -10.7,24 -24,24 h -16 c -13.3,0 -24,-10.7 -24,-24 0,-13.3 10.7,-24 24,-24 z m 216,96 c 0,-13.3 10.7,-24 24,-24 h 16 c 13.3,0 24,10.7 24,24 0,13.3 -10.7,24 -24,24 h -16 c -13.3,0 -24,-10.7 -24,-24 z m -24,-96 h 16 c 13.3,0 24,10.7 24,24 0,13.3 -10.7,24 -24,24 h -16 c -13.3,0 -24,-10.7 -24,-24 0,-13.3 10.7,-24 24,-24 z m 120,96 c 0,-13.3 10.7,-24 24,-24 h 16 c 13.3,0 24,10.7 24,24 0,13.3 -10.7,24 -24,24 h -16 c -13.3,0 -24,-10.7 -24,-24 z m -24,-96 h 16 c 13.3,0 24,10.7 24,24 0,13.3 -10.7,24 -24,24 h -16 c -13.3,0 -24,-10.7 -24,-24 0,-13.3 10.7,-24 24,-24 z M 296,32 h 16 c 13.3,0 24,10.7 24,24 0,13.3 -10.7,24 -24,24 h -16 c -13.3,0 -24,-10.7 -24,-24 0,-13.3 10.7,-24 24,-24 z"
|
||||
id="path1"
|
||||
style="fill:#8da5f3" />
|
||||
</svg>
|
After Width: | Height: | Size: 2.8 KiB |
37
behaviours/edible_tracker.svg.import
Normal file
37
behaviours/edible_tracker.svg.import
Normal file
|
@ -0,0 +1,37 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://8443tt517pkv"
|
||||
path="res://.godot/imported/edible_tracker.svg-9169f9c07be35f707b3c167799ba3a76.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://behaviours/edible_tracker.svg"
|
||||
dest_files=["res://.godot/imported/edible_tracker.svg-9169f9c07be35f707b3c167799ba3a76.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
|
11
behaviours/edible_tracker.tscn
Normal file
11
behaviours/edible_tracker.tscn
Normal file
|
@ -0,0 +1,11 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://ctpn4hvkhxoi3"]
|
||||
|
||||
[ext_resource type="Script" path="res://behaviours/edible_tracker.gd" id="1_vo18u"]
|
||||
|
||||
[node name="EdibleTracker" type="Area2D"]
|
||||
script = ExtResource("1_vo18u")
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
[connection signal="body_exited" from="." to="." method="_on_body_exited"]
|
||||
[connection signal="tracked" from="." to="." method="_on_tracked"]
|
||||
[connection signal="untracked" from="." to="." method="_on_untracked"]
|
|
@ -1,7 +1,7 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://dxmodn8mbvw0i"]
|
||||
|
||||
[ext_resource type="Script" path="res://behaviours/hunt_target.gd" id="1_1ex7u"]
|
||||
[ext_resource type="PackedScene" uid="uid://ctpn4hvkhxoi3" path="res://behaviours/hunter.tscn" id="2_vjdtc"]
|
||||
[ext_resource type="PackedScene" uid="uid://ctpn4hvkhxoi3" path="res://behaviours/edible_tracker.tscn" id="2_vjdtc"]
|
||||
|
||||
[node name="HuntTarget" type="Node2D"]
|
||||
script = ExtResource("1_1ex7u")
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
extends Node2D
|
||||
class_name Hunter
|
||||
|
||||
|
||||
signal tracked(body: Node2D)
|
||||
signal untracked(body: Node2D)
|
||||
|
||||
|
||||
@export var tag: StringName
|
||||
|
||||
var possible_targets: Array = []
|
||||
|
||||
|
||||
func _on_detection_area_body_entered(body: Node2D) -> void:
|
||||
var edibles: Array = body.find_children("Edible", "Edible", false, false)
|
||||
for edible in edibles:
|
||||
if edible.tag == tag:
|
||||
possible_targets.push_back(body)
|
||||
tracked.emit(body)
|
||||
|
||||
func _on_detection_area_body_exited(body: Node2D) -> void:
|
||||
if body in possible_targets:
|
||||
possible_targets.erase(body)
|
||||
untracked.emit(body)
|
||||
|
||||
|
||||
func _on_tracked(body: Node2D) -> void:
|
||||
Log.p(self, "Tracking a new target: %s" % body)
|
||||
|
||||
func _on_untracked(body:Node2D) -> void:
|
||||
Log.p(self, "Not tracking anymore target: %s" % body)
|
|
@ -1,16 +0,0 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://ctpn4hvkhxoi3"]
|
||||
|
||||
[ext_resource type="Script" path="res://behaviours/hunter.gd" id="1_3bmd5"]
|
||||
|
||||
[node name="Hunter" type="Node2D"]
|
||||
script = ExtResource("1_3bmd5")
|
||||
|
||||
[node name="DetectionArea" type="Area2D" parent="."]
|
||||
collision_layer = 0
|
||||
collision_mask = 24
|
||||
monitorable = false
|
||||
|
||||
[connection signal="tracked" from="." to="." method="_on_tracked"]
|
||||
[connection signal="untracked" from="." to="." method="_on_untracked"]
|
||||
[connection signal="body_entered" from="DetectionArea" to="." method="_on_detection_area_body_entered"]
|
||||
[connection signal="body_exited" from="DetectionArea" to="." method="_on_detection_area_body_exited"]
|
Loading…
Reference in a new issue