# GrassController.gd
extends Node3D
class_name FlowerController

@onready var flower_multimesh: MultiMeshInstance3D = $FlowerMultimesh
var parent_node: GroundTile = null
var flower_density: float = 0.5
var flower_instance_range: int = 10

func _ready() -> void:
	parent_node = get_parent() as GroundTile

func spawn_flowers_for_cell(value):
	if value == null:
		return
	
	flower_density = value.vegetation_density
	update_flower_density()
	
	if flower_multimesh and flower_multimesh.has_method("setup_multimesh"):
		flower_multimesh.setup_multimesh()

func update_flower_density() -> void:
	if parent_node == null:
		return

	var rng = parent_node.get_rng()

	if flower_density > 0.8:
			flower_instance_range = rng.randi_range(1, 3)
	elif flower_density > 0.6:
			flower_instance_range = rng.randi_range(3, 4)
	elif flower_density > 0.3:
			flower_instance_range = rng.randi_range(4, 7)
	else:
			flower_instance_range = rng.randi_range(5, 10)
