use bevy::prelude::*;
pub mod plugins;
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
pub enum IssunSet {
Input,
Logic,
PostLogic,
Visual,
}
#[derive(Resource)]
pub struct IssunCorePluginMarker;
pub struct IssunCorePlugin;
impl Plugin for IssunCorePlugin {
fn build(&self, app: &mut App) {
app.insert_resource(IssunCorePluginMarker);
app.configure_sets(
Update,
(
IssunSet::Input,
IssunSet::Logic,
IssunSet::PostLogic,
IssunSet::Visual,
)
.chain(),
);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_issun_core_plugin() {
let mut app = App::new();
app.add_plugins(MinimalPlugins);
app.add_plugins(IssunCorePlugin);
app.update();
}
#[test]
fn test_system_set_ordering() {
use std::sync::{Arc, Mutex};
let execution_order = Arc::new(Mutex::new(Vec::new()));
let mut app = App::new();
app.add_plugins(MinimalPlugins);
app.add_plugins(IssunCorePlugin);
let order1 = execution_order.clone();
app.add_systems(
Update,
(move || {
order1.lock().unwrap().push("Input");
})
.in_set(IssunSet::Input),
);
let order2 = execution_order.clone();
app.add_systems(
Update,
(move || {
order2.lock().unwrap().push("Logic");
})
.in_set(IssunSet::Logic),
);
let order3 = execution_order.clone();
app.add_systems(
Update,
(move || {
order3.lock().unwrap().push("PostLogic");
})
.in_set(IssunSet::PostLogic),
);
let order4 = execution_order.clone();
app.add_systems(
Update,
(move || {
order4.lock().unwrap().push("Visual");
})
.in_set(IssunSet::Visual),
);
app.update();
let order = execution_order.lock().unwrap();
assert_eq!(
*order,
vec!["Input", "Logic", "PostLogic", "Visual"],
"SystemSet execution order is incorrect"
);
}
}