@tool class_name FarmZone extends Node3D ## One purposeful area of the farm: an axis-aligned rectangle on the ground, centered on this ## node (rotation is ignored). Zones live under Zones/ in farm.tscn, and FarmZones looks them ## up by position. In the editor each zone draws a translucent box so the layout is visible. ## Outside zones are gathering areas beyond the farm's edge (north and east of it through the ## fence's gaps, south of it across open ground): there can be several of a kind, and ## FarmZones.zone(kind) only returns the farm's own. enum Kind { CROP_FIELD, ANIMAL_PEN, SUPPLY_SHED, WORK_AREA, WOOD, SCRAP, STRAW } @export var kind: Kind = Kind.CROP_FIELD ## Name shown on the HUD when the scarecrow walks in. @export var display_name: String = "" ## Footprint in meters along X and Z. @export var size: Vector2 = Vector2(10.0, 10.0): set(value): size = value _update_preview() @export var tint: Color = Color(1.0, 1.0, 1.0): set(value): tint = value _update_preview() ## Beyond the farm's fence (a gathering area outside). @export var outside := false var _preview: MeshInstance3D func _ready() -> void: if Engine.is_editor_hint(): _preview = MeshInstance3D.new() add_child(_preview) _update_preview() func rect() -> Rect2: var p := global_position return Rect2(Vector2(p.x, p.z) - size * 0.5, size) func contains(point: Vector3) -> bool: return rect().has_point(Vector2(point.x, point.z)) func _update_preview() -> void: if _preview == null: return var box := BoxMesh.new() box.size = Vector3(size.x, 0.1, size.y) var mat := StandardMaterial3D.new() mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA mat.albedo_color = Color(tint, 0.25) box.material = mat _preview.mesh = box _preview.position = Vector3(0.0, 0.05, 0.0)