use super::components::{
GrassConfig, GrassInteractor, GrassRegion, GrassSpecies, TerrainHeightmap,
};
use crate::ecs::GRASS_REGION;
use crate::ecs::world::World;
use freecs::Entity;
use nalgebra_glm::Vec3;
use crate::prelude::*;
pub fn spawn_grass_region(world: &mut World, config: GrassConfig) -> Entity {
let entity = spawn_entities(world, GRASS_REGION, 1)[0];
let region = GrassRegion::new().with_config(config);
world.core.set_grass_region(entity, region);
entity
}
pub fn add_grass_species(world: &mut World, entity: Entity, species: GrassSpecies, weight: f32) {
if let Some(region) = world.core.get_grass_region_mut(entity) {
region.add_species(species, weight);
}
}
pub fn update_grass_player_position(world: &mut World, entity: Entity, position: Vec3) {
if let Some(region) = world.core.get_grass_region_mut(entity) {
region.set_player_position(position);
}
}
pub fn enable_grass(world: &mut World, entity: Entity, enabled: bool) {
if let Some(region) = world.core.get_grass_region_mut(entity) {
region.enabled = enabled;
}
}
pub fn enable_grass_interactors(world: &mut World, entity: Entity, enabled: bool) {
if let Some(region) = world.core.get_grass_region_mut(entity) {
region.config.interactors_enabled = enabled;
}
}
pub fn set_grass_heightmap(world: &mut World, entity: Entity, heightmap: TerrainHeightmap) {
if let Some(region) = world.core.get_grass_region_mut(entity) {
region.set_heightmap(heightmap);
}
}
pub fn attach_grass_interactor(world: &mut World, entity: Entity, radius: f32, strength: f32) {
world
.core
.set_grass_interactor(entity, GrassInteractor::new(radius, strength));
}