mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-21 15:44:23 +00:00
Use inheritance properly (oops, my fault!)
This commit is contained in:
parent
1abd1c1ec3
commit
7b54a55dd5
4 changed files with 13 additions and 13 deletions
|
@ -9,17 +9,13 @@ class_name Sampler
|
|||
## [Array] of [Node]s that can be [func sample]d by this [Sampler].
|
||||
@export var possibilities: Array[Node] = []
|
||||
|
||||
## If true, the [Sampler] will attempt to automatically detect the [field possibilities] on NOTIFICATION_READY.
|
||||
@export var autodetect_possibilities_on_ready: bool = true
|
||||
## If true, the [Sampler] will attempt to automatically [method sample_and_enable] on NOTIFICATION_READY.
|
||||
@export var autoenable_on_ready: bool = true
|
||||
|
||||
|
||||
var selected: Node = null;
|
||||
|
||||
|
||||
## Update [field possibilities] with the most likely subset of nodes.
|
||||
func autodetect_possibilities():
|
||||
possibilities = get_children()
|
||||
|
||||
## Get a reference.
|
||||
func sample() -> Node:
|
||||
Log.e(self, "Not implemented.")
|
||||
|
@ -48,5 +44,5 @@ func get_all_refs() -> Array[Node]:
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
if autodetect_possibilities_on_ready:
|
||||
autodetect_possibilities()
|
||||
if autoenable_on_ready:
|
||||
sample_and_enable.call_deferred()
|
||||
|
|
|
@ -2,13 +2,16 @@ extends Sampler
|
|||
class_name SamplerPriority
|
||||
|
||||
|
||||
## If true, the [Sampler] will attempt to automatically detect the [field possibilities] on NOTIFICATION_READY.
|
||||
@export var autodetect_possibilities_on_ready: bool = true
|
||||
|
||||
## If true, the [SamplerPriority] will attempt to automatically setup the recommended signals for all the [field possibilities] on NOTIFICATION_READY.
|
||||
@export var autosetup_signals_on_ready: bool = true
|
||||
|
||||
|
||||
## Update [field possibilities] with the most likely subset of nodes.
|
||||
func autodetect_possibilities() -> void:
|
||||
possibilities = find_children("*", "Priority", true, false)
|
||||
possibilities = get_parent().find_children("*", "Priority", true, false)
|
||||
|
||||
## Setup the recommended signals for each node in [field possibilities].
|
||||
func autosetup_signals() -> void:
|
||||
|
@ -41,11 +44,14 @@ func get_ref(node: Node) -> Node:
|
|||
return node.get_ref()
|
||||
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
if autodetect_possibilities_on_ready:
|
||||
autodetect_possibilities()
|
||||
if autosetup_signals_on_ready:
|
||||
autosetup_signals()
|
||||
|
||||
func _autosetup_on_possibility_priority_changed(node: Priority, new: int, old: int):
|
||||
func _autosetup_on_possibility_priority_changed(new: int, old: int, node: Priority):
|
||||
if node == selected:
|
||||
if new < old:
|
||||
sample_and_enable()
|
||||
|
|
|
@ -120,7 +120,6 @@ debug_color = Color(1, 0, 0, 0)
|
|||
stream = ExtResource("19_7la6c")
|
||||
|
||||
[connection signal="timeout" from="GoldSpawner/TimerStddev" to="GoldSpawner" method="spawn"]
|
||||
[connection signal="ready" from="MovementSampler" to="MovementSampler" method="enable"]
|
||||
[connection signal="changed_direction" from="MovementWander" to="MovementWander/WanderPriority" method="priority_conditional"]
|
||||
[connection signal="move" from="MovementWander" to="." method="_on_move"]
|
||||
[connection signal="timeout" from="MovementWander/ChangeDirectionTimer" to="MovementWander" method="randomize_direction"]
|
||||
|
|
|
@ -183,7 +183,6 @@ stream = ExtResource("16_nswfl")
|
|||
[node name="FallSound" type="AudioStreamPlayer2D" parent="MovementDrag"]
|
||||
stream = ExtResource("17_8kst2")
|
||||
|
||||
[connection signal="ready" from="MovementSampler" to="MovementSampler" method="enable"]
|
||||
[connection signal="move" from="MovementIdle" to="." method="_on_move"]
|
||||
[connection signal="move_disabled" from="MovementIdle" to="MovementIdle/BoredTimer" method="stop"]
|
||||
[connection signal="move_enabled" from="MovementIdle" to="MovementIdle/BoredTimer" method="start"]
|
||||
|
|
Loading…
Reference in a new issue