use bevy_ecs::prelude::*;
use super::category::Category;
use crate::AppState;
pub trait SceneObject: Send + Sync + 'static {
fn label(&self) -> &'static str;
fn icon(&self) -> &'static str;
fn category(&self) -> Category;
fn authored(&self) -> bool {
true
}
fn spawn(&self, app: &mut AppState) -> Entity;
}
#[derive(Component)]
pub struct SceneItem {
pub kind: &'static dyn SceneObject,
pub name: String,
}
impl SceneItem {
pub fn new(kind: &'static dyn SceneObject, name: impl Into<String>) -> Self {
Self {
kind,
name: name.into(),
}
}
pub fn icon(&self) -> &'static str {
self.kind.icon()
}
pub fn category(&self) -> Category {
self.kind.category()
}
}
impl std::fmt::Debug for SceneItem {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SceneItem")
.field("kind", &self.kind.label())
.field("name", &self.name)
.finish()
}
}