feat: derive resource visuals from state

This commit is contained in:
Rijad Zuzo
2026-07-17 18:39:14 +02:00
parent 04c5371b6b
commit 2719b0398b
21 changed files with 686 additions and 18 deletions
@@ -0,0 +1,41 @@
class_name HarvestableTreePresentation
extends ResourceAmountVisual
const THINNED_CANOPIES := [&"CanopyLeft", &"CanopyRight"]
@onready var standing_tree: Node3D = $StandingTree
@onready var stump: Node3D = $Stump
func _ready() -> void:
super()
func is_standing_visible() -> bool:
return standing_tree.visible
func is_stump_visible() -> bool:
return stump.visible
func get_visible_canopy_count() -> int:
if not standing_tree.visible:
return 0
var visible_count := 0
for child in standing_tree.get_children():
if String(child.name).begins_with("Canopy") and child.visible:
visible_count += 1
return visible_count
func _apply_resource_amount_visual(
_amount_remaining: float, _remaining_ratio: float, tier: AmountTier
) -> void:
var depleted := tier == AmountTier.DEPLETED
standing_tree.visible = not depleted
stump.visible = depleted
for canopy_name in THINNED_CANOPIES:
var canopy := standing_tree.get_node_or_null(NodePath(canopy_name)) as Node3D
if canopy != null:
canopy.visible = tier == AmountTier.FULL