WIP prefabs loader
This commit is contained in:
52
engine/prefabs/src/tests.rs
Normal file
52
engine/prefabs/src/tests.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use bevy::{
|
||||
ecs::{component::Component, system::EntityCommands},
|
||||
math::{Vec3, VectorSpace},
|
||||
render::view::PostProcessWrite,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::prefab::{ComponentBuilder, PrefabAsset};
|
||||
|
||||
#[derive(Component, Serialize, Deserialize)]
|
||||
struct Name {
|
||||
pub name: String,
|
||||
}
|
||||
#[typetag::serde]
|
||||
impl ComponentBuilder for Name {
|
||||
fn insert(&self, entity: &mut EntityCommands) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Serialize, Deserialize)]
|
||||
struct Position {
|
||||
pub pos: Vec3,
|
||||
}
|
||||
|
||||
#[typetag::serde]
|
||||
impl ComponentBuilder for Position {
|
||||
fn insert(&self, entity: &mut EntityCommands) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_test() {
|
||||
let prefab = PrefabAsset {
|
||||
components: vec![
|
||||
Box::new(Position { pos: Vec3::X }),
|
||||
Box::new(Name {
|
||||
name: "Test".to_string(),
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
||||
let serialized = ron::to_string(&prefab);
|
||||
assert!(serialized.is_ok());
|
||||
|
||||
let deserialize = ron::from_str::<PrefabAsset>(&serialized.unwrap());
|
||||
assert!(deserialize.is_ok());
|
||||
|
||||
let loaded_asset = deserialize.unwrap();
|
||||
assert!(loaded_asset.components.len() == prefab.components.len());
|
||||
}
|
||||
Reference in New Issue
Block a user