use super::config::WorldMapConfig;
use super::hook::{DefaultWorldMapHook, WorldMapHook};
use super::registry::WorldMapRegistry;
use super::service::WorldMapService;
use super::state::WorldMapState;
use super::system::WorldMapSystem;
use crate::Plugin;
use std::sync::Arc;
#[derive(Plugin)]
#[plugin(name = "issun:worldmap")]
pub struct WorldMapPlugin {
#[plugin(skip)]
hook: Arc<dyn WorldMapHook>,
#[plugin(resource)]
config: WorldMapConfig,
#[plugin(resource)]
registry: WorldMapRegistry,
#[plugin(runtime_state)]
state: WorldMapState,
#[plugin(service)]
service: WorldMapService,
#[plugin(system)]
system: WorldMapSystem,
}
impl WorldMapPlugin {
pub fn new() -> Self {
let hook = Arc::new(DefaultWorldMapHook);
Self {
hook: hook.clone(),
config: WorldMapConfig::default(),
registry: WorldMapRegistry::new(),
state: WorldMapState::new(),
service: WorldMapService,
system: WorldMapSystem::new(hook),
}
}
pub fn with_hook<H: WorldMapHook + 'static>(mut self, hook: H) -> Self {
let hook = Arc::new(hook);
self.hook = hook.clone();
self.system = WorldMapSystem::new(hook);
self
}
pub fn with_config(mut self, config: WorldMapConfig) -> Self {
self.config = config;
self
}
}
impl Default for WorldMapPlugin {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::plugin::Plugin;
#[test]
fn test_plugin_creation() {
let plugin = WorldMapPlugin::new();
assert_eq!(plugin.name(), "issun:worldmap");
}
#[test]
fn test_plugin_with_custom_hook() {
struct CustomHook;
#[async_trait::async_trait]
impl WorldMapHook for CustomHook {}
let plugin = WorldMapPlugin::new().with_hook(CustomHook);
assert_eq!(plugin.name(), "issun:worldmap");
}
#[test]
fn test_plugin_with_custom_config() {
let config = WorldMapConfig::default()
.with_travel_speed(20.0)
.with_encounter_rate(0.2)
.with_fog_of_war(true);
let plugin = WorldMapPlugin::new().with_config(config);
assert_eq!(plugin.name(), "issun:worldmap");
}
}