#![doc = include_str!("../README.md")]
use std::borrow::Cow;
pub use bevy::prelude::{BuildChildren, ChildBuilder};
pub use bevy::{core::Name, ecs::system::EntityCommands};
#[doc(hidden)]
pub mod macros;
#[derive(Debug, Clone, Default)]
pub struct BaseDsl {
pub name: Option<Cow<'static, str>>,
}
impl BaseDsl {
pub fn named(&mut self, name: impl Into<Cow<'static, str>>) {
self.name = Some(name.into());
}
}
pub trait DslBundle: Default {
fn insert(&mut self, cmds: &mut EntityCommands);
fn node(&mut self, cmds: &mut EntityCommands, f: impl FnOnce(&mut ChildBuilder)) {
self.insert(cmds);
cmds.with_children(f);
}
}
impl DslBundle for () {
fn insert(&mut self, _: &mut EntityCommands) {}
}
impl DslBundle for BaseDsl {
fn insert(&mut self, cmds: &mut EntityCommands) {
if let Some(name) = self.name.take() {
cmds.insert(Name::new(name));
}
}
}