Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/bevy_mod_scripting_core/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,12 @@ impl<P: IntoScriptPluginParams> RunScriptCallback<P> {
if self.trigger_response {
send_callback_response(
guard.clone(),
ScriptCallbackResponseEvent::new(self.callback, self.id.clone(), result.clone()),
ScriptCallbackResponseEvent::new(
self.entity,
self.callback,
self.id.clone(),
result.clone(),
),
);
}

Expand Down Expand Up @@ -669,6 +674,7 @@ mod test {
assert_response_events(
app.world_mut(),
vec![ScriptCallbackResponseEvent::new(
Entity::from_raw(0),
OnScriptLoaded::into_callback_label(),
"script".into(),
Ok(ScriptValue::Unit),
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_mod_scripting_core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ impl ScriptCallbackEvent {
#[derive(Clone, Event, Debug)]
#[non_exhaustive]
pub struct ScriptCallbackResponseEvent {
/// the entity that the script was invoked on,
pub entity: Entity,
/// the label of the callback
pub label: CallbackLabel,
/// the script that replied
Expand All @@ -190,11 +192,13 @@ pub struct ScriptCallbackResponseEvent {
impl ScriptCallbackResponseEvent {
/// Creates a new callback response event with the given label, script and response
pub fn new<L: Into<CallbackLabel>>(
entity: Entity,
label: L,
script: ScriptId,
response: Result<ScriptValue, ScriptError>,
) -> Self {
Self {
entity,
label: label.into(),
script,
response,
Expand Down
8 changes: 6 additions & 2 deletions crates/bevy_mod_scripting_core/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ pub(crate) fn event_handler_inner<P: IntoScriptPluginParams>(
send_callback_response(
guard.clone(),
ScriptCallbackResponseEvent::new(
*entity,
callback_label.clone(),
script_id.clone(),
call_result.clone(),
Expand Down Expand Up @@ -384,8 +385,10 @@ mod test {
invocations: vec![].into(),
};
let mut app = setup_app::<OnTestCallback>(runtime, scripts);
app.world_mut()
.spawn(ScriptComponent(vec![test_script_id.clone()]));
let entity = app
.world_mut()
.spawn(ScriptComponent(vec![test_script_id.clone()]))
.id();

app.world_mut().send_event(
ScriptCallbackEvent::new(
Expand All @@ -400,6 +403,7 @@ mod test {
assert_response_events(
app.world_mut(),
vec![ScriptCallbackResponseEvent::new(
entity,
OnTestCallback::into_callback_label(),
test_script_id.clone(),
Ok(ScriptValue::Unit),
Expand Down
Loading