86 lines
2.9 KiB
Rust
86 lines
2.9 KiB
Rust
use bevy::prelude::*;
|
|
use pomomon_garden::features::config::components::GameConfig;
|
|
use pomomon_garden::features::core::states::AppState;
|
|
use pomomon_garden::features::grid::components::Grid;
|
|
use pomomon_garden::features::phase::components::{CurrentPhase, Phase, TimerSettings};
|
|
use pomomon_garden::features::wonderevent::{RequestWonderEvent, WonderEventPlugin};
|
|
|
|
#[test]
|
|
fn test_wonder_event_triggers() {
|
|
let mut app = App::new();
|
|
app.add_plugins(MinimalPlugins);
|
|
app.add_plugins(bevy::state::app::StatesPlugin);
|
|
app.add_plugins(WonderEventPlugin);
|
|
|
|
app.insert_resource(GameConfig::default());
|
|
app.insert_resource(TimerSettings {
|
|
focus_duration: 60, // 60 seconds
|
|
short_break_duration: 5,
|
|
long_break_duration: 15,
|
|
long_break_interval: 4,
|
|
});
|
|
|
|
app.insert_resource(Grid {
|
|
width: 10,
|
|
height: 10,
|
|
tiles: vec![],
|
|
});
|
|
|
|
app.init_state::<AppState>();
|
|
let mut next_state = app.world_mut().resource_mut::<NextState<AppState>>();
|
|
next_state.set(AppState::GameScreen);
|
|
|
|
app.insert_resource(CurrentPhase(Phase::Focus { duration: 60.0 }));
|
|
|
|
// 1. Full Duration (60.0). No trigger.
|
|
app.update();
|
|
verify_event_count(&mut app, 0);
|
|
|
|
// 2. Half Duration (30.0). Trigger!
|
|
*app.world_mut().resource_mut::<CurrentPhase>() = CurrentPhase(Phase::Focus { duration: 30.0 });
|
|
app.update();
|
|
verify_event_count(&mut app, 1);
|
|
|
|
// 3. Less than half (29.0). Already triggered. No new trigger.
|
|
*app.world_mut().resource_mut::<CurrentPhase>() = CurrentPhase(Phase::Focus { duration: 29.0 });
|
|
app.update();
|
|
verify_event_count(&mut app, 0); // New events should be 0
|
|
|
|
// 4. Pause (Focus). Logic should NOT reset trigger.
|
|
let prev = Box::new(Phase::Focus { duration: 29.0 });
|
|
*app.world_mut().resource_mut::<CurrentPhase>() = CurrentPhase(Phase::Paused {
|
|
previous_phase: prev,
|
|
});
|
|
app.update();
|
|
verify_event_count(&mut app, 0);
|
|
|
|
// 5. Resume Focus. Logic should remember it was triggered.
|
|
*app.world_mut().resource_mut::<CurrentPhase>() = CurrentPhase(Phase::Focus { duration: 29.0 });
|
|
app.update();
|
|
verify_event_count(&mut app, 0);
|
|
|
|
// 6. Break. Logic should reset trigger.
|
|
*app.world_mut().resource_mut::<CurrentPhase>() = CurrentPhase(Phase::Break { duration: 5.0 });
|
|
app.update();
|
|
verify_event_count(&mut app, 0);
|
|
|
|
// 7. New Focus (Half Duration). Logic should trigger again.
|
|
*app.world_mut().resource_mut::<CurrentPhase>() = CurrentPhase(Phase::Focus { duration: 30.0 });
|
|
app.update();
|
|
verify_event_count(&mut app, 1);
|
|
}
|
|
|
|
fn verify_event_count(app: &mut App, expected: usize) {
|
|
let count = app
|
|
.world_mut()
|
|
.resource_mut::<Messages<RequestWonderEvent>>()
|
|
.drain()
|
|
.count();
|
|
|
|
assert_eq!(
|
|
count, expected,
|
|
"Expected {} events, found {}",
|
|
expected, count
|
|
);
|
|
}
|