use super::factions::Factions;
use super::hook::{DefaultFactionHook, FactionHook};
use super::state::FactionState;
use super::system::FactionSystem;
use crate::Plugin;
use std::sync::Arc;
#[derive(Plugin)]
#[plugin(name = "issun:faction")]
pub struct FactionPlugin {
#[plugin(skip)]
hook: Arc<dyn FactionHook>,
#[plugin(resource)]
factions: Factions,
#[plugin(runtime_state)]
#[allow(dead_code)]
state: FactionState,
#[plugin(system)]
system: FactionSystem,
}
impl FactionPlugin {
pub fn new() -> Self {
let hook = Arc::new(DefaultFactionHook);
Self {
hook: hook.clone(),
factions: Factions::new(),
state: FactionState::new(),
system: FactionSystem::new(hook),
}
}
pub fn with_hook(mut self, hook: impl FactionHook + 'static) -> Self {
let hook = Arc::new(hook);
self.hook = hook.clone();
self.system = FactionSystem::new(hook);
self
}
pub fn with_factions(mut self, factions: Factions) -> Self {
self.factions = factions;
self
}
}
impl Default for FactionPlugin {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_plugin_name() {
let _plugin = FactionPlugin::default();
}
#[test]
fn test_plugin_default() {
let _plugin = FactionPlugin::default();
}
#[test]
fn test_plugin_with_hook() {
let _plugin = FactionPlugin::new().with_hook(DefaultFactionHook);
}
#[test]
fn test_plugin_with_factions() {
use super::super::types::Faction;
let mut factions = Factions::new();
factions.add(Faction::new("crimson", "Crimson Syndicate"));
let _plugin = FactionPlugin::new().with_factions(factions);
}
}