use bevy::ecs::system::RunSystemOnce; use pomomon_garden::features::grid::components::{Grid, TileState}; use pomomon_garden::features::inventory::components::ItemType; use pomomon_garden::features::notification::components::Notifications; use pomomon_garden::features::pom::actions::InteractionAction; use pomomon_garden::features::pom::components::{GridPosition, InteractionTarget, PathQueue, Pom}; use pomomon_garden::features::pom::perform_interaction; use pomomon_garden::prelude::*; mod common; use common::setup_app; #[test] fn test_prevent_trapping_plant() { let occupied = TileState::Occupied { seed: ItemType::BerrySeed { name: "Wall".into(), }, watered: false, growth_stage: 0, withered: false, dry_counter: 0, }; let mut app = setup_app( 2, 2, &[ (0, 0, TileState::Empty), // Pom (1, 0, TileState::Empty), // Target (0, 1, occupied.clone()), (1, 1, occupied.clone()), ], vec![( ItemType::BerrySeed { name: "Test".into(), }, 10, )], None, ); app.init_resource::(); app.world_mut().spawn(( Pom, GridPosition { x: 0, y: 0 }, InteractionTarget { target: Some((1, 0)), action: Some(InteractionAction::Plant(ItemType::BerrySeed { name: "Test".into(), })), }, PathQueue::default(), )); let _ = app.world_mut().run_system_once(perform_interaction); let grid = app.world().resource::(); let tile_entity = grid.get_tile((1, 0)).unwrap(); let tile_state = app.world().entity(tile_entity).get::().unwrap(); // Should remain Empty because planting was blocked match tile_state { TileState::Empty => (), _ => panic!("Should have prevented planting! State is {:?}", tile_state), } } #[test] fn test_allow_safe_plant() { let mut app = setup_app( 10, 10, &[(0, 0, TileState::Empty), (1, 0, TileState::Empty)], vec![( ItemType::BerrySeed { name: "Test".into(), }, 10, )], None, ); app.init_resource::(); app.world_mut().spawn(( Pom, GridPosition { x: 0, y: 0 }, InteractionTarget { target: Some((1, 0)), action: Some(InteractionAction::Plant(ItemType::BerrySeed { name: "Test".into(), })), }, PathQueue::default(), )); let _ = app.world_mut().run_system_once(perform_interaction); let grid = app.world().resource::(); let tile_entity = grid.get_tile((1, 0)).unwrap(); let tile_state = app.world().entity(tile_entity).get::().unwrap(); // Should be Occupied match tile_state { TileState::Occupied { .. } => (), _ => panic!("Should have allowed planting! State is {:?}", tile_state), } }