1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! `world.trigger_event` tool - Trigger events in the Bevy world
use std::collections::HashMap;
use bevy_brp_mcp_macros::ParamStruct;
use bevy_brp_mcp_macros::ResultStruct;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
use serde_json::Value;
use crate::brp_tools::Port;
/// Parameters for the `world.trigger_event` tool
#[derive(Clone, Deserialize, Serialize, JsonSchema, ParamStruct)]
pub struct TriggerEventParams {
/// The full type path of the event to trigger (e.g., "`my_game::events::SpawnEnemy`")
pub event: String,
/// The event payload as JSON. Omit for unit events (events with no data).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub value: Option<HashMap<String, Value>>,
/// The BRP port (default: 15702)
#[serde(default)]
pub port: Port,
}
/// Result for the `world.trigger_event` tool
///
/// Note: This follows the `DespawnEntityResult` pattern - the `{event}` placeholder
/// in the message template is resolved from `TriggerEventParams.event` at response-building
/// time, so we don't need an `event` field in this struct.
#[derive(Serialize, ResultStruct)]
#[brp_result]
pub struct TriggerEventResult {
/// The raw BRP response (null on success)
#[serde(skip_serializing_if = "Option::is_none")]
#[to_result(skip_if_none)]
pub result: Option<Value>,
/// Message template for formatting responses
#[to_message(message_template = "Triggered event {event}")]
pub message_template: String,
}