harvest/game/scripts/farm_zones.gd
2026-10-03 12:14:28 -04:00

49 lines
1.3 KiB
GDScript

class_name FarmZones
extends Node3D
## The Zones/ node of farm.tscn: every FarmZone (with the props that belong to it), the
## perimeter and its markers, and the crop units, plus lookups by position. The playable map is
## the rectangle inside the perimeter fence; the rest of the farm is out-of-bounds scenery.
@export var playable := Rect2(-13.0, -45.0, 60.0, 60.0)
func zones() -> Array[FarmZone]:
var out: Array[FarmZone] = []
for child in get_children():
if child is FarmZone:
out.append(child)
return out
## The zone containing a world position (zones don't overlap), or null between zones.
func zone_at(point: Vector3) -> FarmZone:
for zone in zones():
if zone.contains(point):
return zone
return null
func zone(kind: FarmZone.Kind) -> FarmZone:
for z in zones():
if z.kind == kind:
return z
return null
func markers(kind: FarmMarker.Kind) -> Array[FarmMarker]:
var out: Array[FarmMarker] = []
for node in find_children("*", "Marker3D", true, false):
if node is FarmMarker and (node as FarmMarker).kind == kind:
out.append(node)
return out
func crop_units() -> Array[CropUnit]:
var out: Array[CropUnit] = []
var field := zone(FarmZone.Kind.CROP_FIELD)
if field == null:
return out
for node in field.find_children("*", "Node3D", true, false):
if node is CropUnit:
out.append(node)
return out