use issun::context::ResourceContext;
use issun::engine::ModBridgeSystem;
use issun::event::EventBus;
use issun::plugin::{CombatConfig, InventoryConfig};
#[tokio::test]
async fn test_mod_bridge_with_plugins() {
let mut resources = ResourceContext::new();
resources.insert(EventBus::new());
resources.insert(CombatConfig::default());
resources.insert(InventoryConfig::default());
{
let mut event_bus = resources
.get_mut::<EventBus>()
.await
.expect("EventBus not found");
event_bus.publish(issun::modding::events::PluginEnabledEvent {
plugin_name: "combat".to_string(),
});
event_bus.publish(issun::modding::events::PluginParameterChangedEvent {
plugin_name: "combat".to_string(),
key: "max_hp".to_string(),
value: serde_json::json!(200),
});
event_bus.publish(issun::modding::events::PluginParameterChangedEvent {
plugin_name: "combat".to_string(),
key: "difficulty".to_string(),
value: serde_json::json!(3.0),
});
event_bus.publish(issun::modding::events::PluginDisabledEvent {
plugin_name: "inventory".to_string(),
});
event_bus.dispatch();
}
let mut bridge_system = ModBridgeSystem::new();
bridge_system.update_resources(&mut resources).await;
{
let combat_config = resources
.get::<CombatConfig>()
.await
.expect("Combat config not found");
assert!(combat_config.enabled, "Combat should be enabled");
assert_eq!(
combat_config.default_max_hp, 200,
"Combat max_hp should be 200"
);
assert_eq!(
combat_config.difficulty_multiplier, 3.0,
"Combat difficulty should be 3.0"
);
}
{
let inventory_config = resources
.get::<InventoryConfig>()
.await
.expect("Inventory config not found");
assert!(!inventory_config.enabled, "Inventory should be disabled");
}
}
#[tokio::test]
async fn test_namespaced_plugin_names() {
let mut resources = ResourceContext::new();
resources.insert(EventBus::new());
resources.insert(CombatConfig::default());
{
let mut event_bus = resources
.get_mut::<EventBus>()
.await
.expect("EventBus not found");
event_bus.publish(issun::modding::events::PluginEnabledEvent {
plugin_name: "issun:combat".to_string(), });
event_bus.dispatch();
}
let mut bridge_system = ModBridgeSystem::new();
bridge_system.update_resources(&mut resources).await;
{
let combat_config = resources
.get::<CombatConfig>()
.await
.expect("Combat config not found");
assert!(
combat_config.enabled,
"Combat should be enabled via namespaced name"
);
}
}
#[tokio::test]
async fn test_unknown_plugin_handling() {
let mut resources = ResourceContext::new();
resources.insert(EventBus::new());
{
let mut event_bus = resources
.get_mut::<EventBus>()
.await
.expect("EventBus not found");
event_bus.publish(issun::modding::events::PluginEnabledEvent {
plugin_name: "unknown_plugin".to_string(),
});
event_bus.dispatch();
}
let mut bridge_system = ModBridgeSystem::new();
bridge_system.update_resources(&mut resources).await;
}
#[tokio::test]
async fn test_unknown_parameter_handling() {
let mut resources = ResourceContext::new();
resources.insert(EventBus::new());
resources.insert(CombatConfig::default());
{
let mut event_bus = resources
.get_mut::<EventBus>()
.await
.expect("EventBus not found");
event_bus.publish(issun::modding::events::PluginParameterChangedEvent {
plugin_name: "combat".to_string(),
key: "unknown_param".to_string(),
value: serde_json::json!(999),
});
event_bus.dispatch();
}
let mut bridge_system = ModBridgeSystem::new();
bridge_system.update_resources(&mut resources).await;
{
let combat_config = resources
.get::<CombatConfig>()
.await
.expect("Combat config not found");
assert_eq!(combat_config.default_max_hp, 100); }
}