use crate::z_ignore_test_common::*;
use flecs_ecs::prelude::*;
use json::WorldToJsonDesc;
#[derive(Debug, Component)]
#[flecs(meta)]
pub struct Position {
pub x: f32,
pub y: f32,
}
#[derive(Debug, Component)]
#[flecs(meta)]
pub struct Velocity {
pub x: f32,
pub y: f32,
}
#[derive(Component)]
pub struct Move;
impl Module for Move {
fn module(world: &World) {
world
.system_named::<(&mut Position, &Velocity)>("Move")
.each_entity(|e, (pos, vel)| {
pos.x += vel.x;
pos.y += vel.y;
println!(
"{} moved to {{x: {}, y: {}}}",
e.path().unwrap_or_default(),
pos.x,
pos.y
);
});
}
}
fn main() {
let world_a = World::new();
world_a.import::<Move>();
world_a
.entity_named("ent_1")
.set(Position { x: 10.0, y: 20.0 })
.set(Velocity { x: 1.0, y: -1.0 });
world_a
.entity_named("ent_2")
.set(Position { x: 30.0, y: 40.0 })
.set(Velocity { x: -1.0, y: 1.0 });
let json = world_a.to_json_world(None);
println!("{json}");
let world_b = World::new();
world_b.import::<Move>();
world_b.from_json_world(json.as_str(), None);
world_a.progress();
println!();
world_b.progress();
}
#[cfg(feature = "flecs_nightly_tests")]
#[test]
fn test() {
let output_capture = OutputCapture::capture().unwrap();
main();
output_capture.test("reflection_world_ser_deser".to_string());
}