1use bevy_ecs::relationship::Relationship;
2use moonshine_kind::prelude::*;
3use moonshine_tag::Tags;
4
5use crate::{Object, ObjectRef, ObjectWorldRef};
6
7pub trait ObjectTags {
9 fn tags(&self) -> &Tags;
13}
14
15impl<T: Kind, R: Relationship> ObjectTags for Object<'_, '_, '_, T, R> {
16 fn tags(&self) -> &Tags {
17 self.nametags
18 .get(self.entity())
19 .ok()
20 .and_then(|(_name, tags)| tags)
21 .unwrap_or(Tags::static_empty())
22 }
23}
24
25impl<T: Kind, R: Relationship> ObjectTags for ObjectRef<'_, '_, '_, T, R> {
26 fn tags(&self) -> &Tags {
27 self.1.tags()
28 }
29}
30
31impl<T: Kind, R: Relationship> ObjectTags for ObjectWorldRef<'_, T, R> {
32 fn tags(&self) -> &Tags {
33 self.world
34 .get(self.entity())
35 .unwrap_or(Tags::static_empty())
36 }
37}