1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// src/components/entity_target.rs
use crate::ecs::Entity;
use crate::ecs::asset_id::AssetId;
/// How a runtime request addresses the entity it acts on. Authored placements
/// are named, so a producer holding no live handle addresses them by asset name
/// and the applying system resolves it. Logic that already holds an entity --
/// one it spawned, one a query yielded -- addresses it directly, which is the
/// only way to reach an entity that never had a name.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EntityTarget {
/// Addressed by the placement's authored name.
Name(AssetId),
/// Addressed by a live entity handle.
Entity(Entity),
}
impl Default for EntityTarget {
fn default() -> Self {
EntityTarget::Name(AssetId::default())
}
}
impl From<AssetId> for EntityTarget {
fn from(name: AssetId) -> Self {
EntityTarget::Name(name)
}
}
impl From<Entity> for EntityTarget {
fn from(entity: Entity) -> Self {
EntityTarget::Entity(entity)
}
}
impl EntityTarget {
/// The asset name this target addresses, if it is name-addressed.
pub fn name(self) -> Option<AssetId> {
match self {
EntityTarget::Name(name) => Some(name),
EntityTarget::Entity(_) => None,
}
}
}