mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-22 08:04:23 +00:00
32 lines
669 B
GDScript3
32 lines
669 B
GDScript3
|
extends Area2D
|
||
|
class_name Tracker
|
||
|
|
||
|
## Abstract base class for [Area2D]s tracking a certain subset of [Node2D]s.
|
||
|
|
||
|
|
||
|
signal tracked(body: Node2D)
|
||
|
signal untracked(body: Node2D)
|
||
|
|
||
|
var tracking: Array = []
|
||
|
|
||
|
|
||
|
func track(body: Node2D) -> bool:
|
||
|
var act: bool = not body in tracking
|
||
|
if act:
|
||
|
tracking.push_back(body)
|
||
|
tracked.emit(body)
|
||
|
return act
|
||
|
|
||
|
func untrack(body: Node2D) -> bool:
|
||
|
var act: bool = body in tracking
|
||
|
if act:
|
||
|
tracking.erase(body)
|
||
|
untracked.emit(body)
|
||
|
return act
|
||
|
|
||
|
func log_tracked(body: Node2D) -> void:
|
||
|
Log.p(self, "Tracking a new target: %s" % body)
|
||
|
|
||
|
func log_untracked(body: Node2D) -> void:
|
||
|
Log.p(self, "Not tracking anymore target: %s" % body)
|