use crate::ecs::world::{LOCAL_TRANSFORM_DIRTY, PARENT, World};

pub fn mark_local_transform_dirty(world: &mut World, entity: freecs::Entity) {
    if world.resources.children_cache.is_empty() && world.query_entities(PARENT).count() > 0 {
        world.validate_and_rebuild_children_cache();
    }

    let mut stack = vec![entity];

    while let Some(current) = stack.pop() {
        world.add_components(current, LOCAL_TRANSFORM_DIRTY);

        if let Some(children) = world.resources.children_cache.get(&current) {
            for &child in children {
                stack.push(child);
            }
        }
    }
}
