use bevy_ecs::schedule::DynEq;
use std::any::Any;
use super::*;
#[derive(Component, Debug)]
pub struct HLabelAcc(u64);
fn rec_h_label(acc: &mut HLabelAcc, value: &HLabel) {
acc.0 += value.0;
}
fn compound_h_label((acc, size): (&HLabelAcc, Option<&TreeSize>)) -> HLabel {
HLabel(acc.0 + size.map_or(1, |x| x.value() as u64 + 1))
}
fn add_rec<A: hecs::Component, C: Clone + hecs::Component>(
e: &mut hecs::EntityBuilder,
child: &mut hecs::EntityRef,
f: impl Fn(&mut A, &C),
) {
let c = child.get::<&C>().unwrap();
use std::ops::Deref;
let c = c.deref();
let a: &mut A = e.get_mut().unwrap();
f(a, c)
}
trait CompountMd<Compounds>: Sized {
fn compound(c: Compounds) -> Self;
}
impl<T, Compounds: Data> CompountMd<Compounds> for T
where
T: From<Compounds>,
{
fn compound(c: Compounds) -> Self {
c.into()
}
}
struct CCC();
fn f(e: &mut hecs::EntityBuilder) -> &CCC {
let a = e.get::<&CCC>().unwrap();
a
}
fn g<'a, 'b>(e: &'b mut hecs::EntityRef<'a>) -> hecs::Ref<'a, CCC> {
let a = e.get::<&CCC>().unwrap();
a
}
struct Map;
trait Entry: DynEq {
}
struct Registry(Vec<Box<dyn Entry>>);
trait AAA {
type In;
type Obj;
type Acc;
type Out;
fn pre(id: Self::In, o: Self::Obj) -> Self::Acc;
fn post(o: Self::Obj, acc: Self::Acc);
}
trait Data: 'static {}
impl<T: 'static + Sized> Data for T {}
trait PrimaryData: Data {}
trait DerivedData: Data {}
trait Subtree {
fn _md(&self, id: std::any::TypeId) -> &dyn Any;
}
type Idx = usize;
trait SubtreeExt: Subtree {
type Ty: PrimaryData;
fn ty(&self) -> Self::Ty;
type Label: PrimaryData;
fn label(&self) -> Self::Label;
type I;
fn child(&self, idx: Idx) -> Self::I;
fn md<Md: Data>(&self) -> &Md {
self._md(std::any::TypeId::of::<Md>())
.downcast_ref()
.unwrap()
}
}
struct PrimaryAcc<Ty, L, Cs> {
ty: Ty,
l: L,
cs: Cs,
}
type InFileAcc<Ty, L, I> = PrimaryAcc<Ty, Option<L>, Vec<I>>;
type InDirAcc<Ty, L, I> = PrimaryAcc<Ty, (), (Vec<L>, Vec<I>)>;
trait Acc {}
trait MdAcc {}
use strum_macros::EnumDiscriminants;
#[derive(Component, Debug, EnumDiscriminants)]
#[strum_discriminants(derive(Component))]
#[strum_discriminants(vis(pub))]
#[strum_discriminants(name(TreeSizeDiscriminants))]
pub enum TreeSize {
Leaf(tree_size::Leaf),
Node(tree_size::Node),
}
mod tree_size {
use super::*;
#[derive(Component, Debug)]
pub struct Leaf;
#[derive(Component, Debug)]
pub struct Node(pub usize);
}
pub trait EntityBuilder {
fn add<T: Bundle>(&mut self, component: T) -> &mut Self;
}
impl EntityBuilder for EntityWorldMut<'_> {
fn add<T: Bundle>(&mut self, component: T) -> &mut Self {
self.insert(component)
}
}
trait SelfRecMd {
fn acc(&mut self, from_child: &Self);
}
struct TreeSizeAcc(usize);
impl TreeSize {
fn value(&self) -> usize {
match self {
TreeSize::Leaf(_) => 1,
TreeSize::Node(tree_size::Node(x)) => x + 1,
}
}
}
impl SelfRecMd for TreeSizeAcc {
fn acc(&mut self, from_child: &Self) {
self.0 += from_child.0;
}
}
impl From<TreeSizeAcc> for TreeSize {
fn from(value: TreeSizeAcc) -> Self {
if value.0 == 0 {
TreeSize::Leaf(tree_size::Leaf)
} else {
TreeSize::Node(tree_size::Node(value.0))
}
}
}
impl From<(HLabelAcc, TreeSize)> for HLabel {
fn from(value: (HLabelAcc, TreeSize)) -> Self {
todo!()
}
}