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
46
47
48
49
50
51
52
53
54
55
use crate::{
ecs::Entity,
prefab::{Prefab, PrefabComponent, PrefabError, PrefabProxy},
state::StateToken,
};
use oxygengine_ignite_derive::Ignite;
use serde::{Deserialize, Serialize};
use std::{borrow::Cow, collections::HashMap};
#[derive(Ignite, Debug, Default, Clone, Serialize, Deserialize)]
pub struct Tag(pub Cow<'static, str>);
impl Prefab for Tag {}
impl PrefabComponent for Tag {}
#[derive(Ignite, Debug, Default, Clone, Serialize, Deserialize)]
pub struct Name(pub Cow<'static, str>);
impl Prefab for Name {}
impl PrefabComponent for Name {}
#[derive(Ignite, Debug, Default, Clone, Serialize, Deserialize)]
pub struct NonPersistent(pub StateToken);
impl PrefabProxy<NonPersistentPrefabProxy> for NonPersistent {
fn from_proxy_with_extras(
_: NonPersistentPrefabProxy,
_: &HashMap<String, Entity>,
state_token: StateToken,
) -> Result<Self, PrefabError> {
Ok(NonPersistent(state_token))
}
}
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct NonPersistentPrefabProxy;
impl Prefab for NonPersistentPrefabProxy {}
#[cfg(test)]
mod tests {
use super::*;
use hecs::Component;
#[test]
fn test_component() {
fn foo<T: Component>() {
println!("{} is Component", std::any::type_name::<T>());
}
foo::<Tag>();
foo::<Name>();
foo::<NonPersistent>();
}
}