use super::hook::{DefaultTerritoryHook, TerritoryHook};
use super::state::TerritoryState;
use super::system::TerritorySystem;
use super::territories::Territories;
use crate::Plugin;
use std::sync::Arc;
#[derive(Plugin)]
#[plugin(name = "issun:territory")]
pub struct TerritoryPlugin {
#[plugin(skip)]
hook: Arc<dyn TerritoryHook>,
#[plugin(resource)]
#[allow(dead_code)]
territories: Territories,
#[plugin(runtime_state)]
#[allow(dead_code)]
state: TerritoryState,
#[plugin(system)]
system: TerritorySystem,
}
impl TerritoryPlugin {
pub fn new() -> Self {
let hook = Arc::new(DefaultTerritoryHook);
Self {
hook: hook.clone(),
territories: Territories::new(),
state: TerritoryState::new(),
system: TerritorySystem::new(hook),
}
}
pub fn with_hook(mut self, hook: impl TerritoryHook + 'static) -> Self {
let hook = Arc::new(hook);
self.hook = hook.clone();
self.system = TerritorySystem::new(hook);
self
}
}
impl Default for TerritoryPlugin {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_plugin_name() {
let _plugin = TerritoryPlugin::default();
}
#[test]
fn test_plugin_default() {
let _plugin = TerritoryPlugin::default();
}
#[test]
fn test_plugin_with_hook() {
let _plugin = TerritoryPlugin::new().with_hook(DefaultTerritoryHook);
}
}