use bevy_app::prelude::*; use settled_reach_server::simulation::movement::*; use settled_reach_server::simulation::time::SimulationTime; use settled_reach_server::simulation::SimulationPlugin; #[test] fn movement_validated_within_app() { let mut app = App::new(); app.add_plugins(SimulationPlugin { seed: 0 }); // Insert a walkability map with one blocked tile let mut map = WalkabilityMap::new(10, 10, 1); map.set_walkable(&TilePosition::new(3, 3, 0), false); app.insert_resource(map); // Spawn mover (walkable target) and blocked entity let mover = app .world_mut() .spawn(( TilePosition::new(5, 5, 0), MoveIntent { target: TilePosition::new(5, 4, 0), }, )) .id(); let blocked = app .world_mut() .spawn(( TilePosition::new(3, 4, 0), MoveIntent { target: TilePosition::new(3, 3, 0), }, )) .id(); app.update(); // Mover moved assert_eq!( *app.world().get::(mover).unwrap(), TilePosition::new(5, 4, 0) ); // Blocked stayed assert_eq!( *app.world().get::(blocked).unwrap(), TilePosition::new(3, 4, 0) ); // Tick advanced assert_eq!(app.world().resource::().tick, 1); // Both intents consumed assert!(app.world().get::(mover).is_none()); assert!(app.world().get::(blocked).is_none()); } #[test] fn entity_collision_blocks_movement() { let mut app = App::new(); app.add_plugins(SimulationPlugin { seed: 0 }); app.insert_resource(WalkabilityMap::new(10, 10, 1)); // Stationary entity at (5,4) app.world_mut().spawn(TilePosition::new(5, 4, 0)); // Mover tries to move into occupied tile let mover = app .world_mut() .spawn(( TilePosition::new(5, 5, 0), MoveIntent { target: TilePosition::new(5, 4, 0), }, )) .id(); app.update(); assert_eq!( *app.world().get::(mover).unwrap(), TilePosition::new(5, 5, 0) ); }