class_name GatherNode extends Node3D ## A spot where the scarecrow gathers one material by day: holding interact for gather_time ## puts yield_amount into the pouch and uses one of max_charges. Its children are the props it ## is made of; they fade grey once it is used up. Used charges come back overnight ## (regen_per_night each, applied by Interactions). The farm state keeps only points below ## full, keyed by this node's name, so names must be unique among gather points. const COLORS := { "wood": Color(0.95, 0.68, 0.4), "scrap": Color(0.72, 0.84, 0.95), "straw": Color(1.0, 0.9, 0.42), ## Alien Goop isn't gathered at a GatherNode (dropped by killed Aliens instead); its color is ## used by the HUD and shed pile label, keyed off ResourceStore.MATERIALS like the others. "alien_goop": Color(0.55, 0.95, 0.35), } @export_enum("wood", "scrap", "straw") var material: String = "wood" @export_range(1, 20) var max_charges: int = 2 @export_range(1, 20) var yield_amount: int = 2 @export_range(1, 20) var regen_per_night: int = 20 ## How close the scarecrow's center has to be to this node's origin to gather. @export var reach: float = 1.8 ## Clip the scarecrow loops while gathering here. @export var clip: StringName = &"PickUp" var _faded := false var _fade: StandardMaterial3D var _label: Label3D var _top: float = 1.5 func _ready() -> void: _fade = StandardMaterial3D.new() _fade.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED _fade.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA _fade.albedo_color = Color(0.45, 0.45, 0.45, 0.6) for vi in find_children("*", "VisualInstance3D", true, false): var box := (vi as VisualInstance3D).global_transform * (vi as VisualInstance3D).get_aabb() _top = maxf(_top, box.end.y - global_position.y) _label = Label3D.new() _label.billboard = BaseMaterial3D.BILLBOARD_ENABLED _label.no_depth_test = true _label.shaded = false _label.font_size = 40 _label.outline_size = 10 _label.pixel_size = 0.0075 _label.modulate = COLORS[material] _label.position = Vector3(0.0, minf(_top, 4.0) + 0.5, 0.0) _label.visible = false add_child(_label) ## Top of the point's props (local), for popups. func top() -> float: return minf(_top, 4.0) ## Updates the faded look and the floating label (hidden when show is false). func show_state(charges: int, show: bool, prompt: String) -> void: var empty := charges <= 0 if empty != _faded: _faded = empty for mi in find_children("*", "MeshInstance3D", true, false): (mi as MeshInstance3D).material_overlay = _fade if empty else null _label.visible = show if show: var text := "%s %d/%d" % [material.capitalize(), charges, max_charges] _label.text = text if prompt == "" else text + "\n" + prompt