Skip to content

Commit f564116

Browse files
feat: Include Entity in ScriptCallbackResponseEvent (#425)
Co-authored-by: Maksymilian Mozolewski <makspl17@gmail.com>
1 parent 2a81626 commit f564116

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

crates/bevy_mod_scripting_core/src/commands.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,12 @@ impl<P: IntoScriptPluginParams> RunScriptCallback<P> {
392392
if self.trigger_response {
393393
send_callback_response(
394394
guard.clone(),
395-
ScriptCallbackResponseEvent::new(self.callback, self.id.clone(), result.clone()),
395+
ScriptCallbackResponseEvent::new(
396+
self.entity,
397+
self.callback,
398+
self.id.clone(),
399+
result.clone(),
400+
),
396401
);
397402
}
398403

@@ -669,6 +674,7 @@ mod test {
669674
assert_response_events(
670675
app.world_mut(),
671676
vec![ScriptCallbackResponseEvent::new(
677+
Entity::from_raw(0),
672678
OnScriptLoaded::into_callback_label(),
673679
"script".into(),
674680
Ok(ScriptValue::Unit),

crates/bevy_mod_scripting_core/src/event.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ impl ScriptCallbackEvent {
179179
#[derive(Clone, Event, Debug)]
180180
#[non_exhaustive]
181181
pub struct ScriptCallbackResponseEvent {
182+
/// the entity that the script was invoked on,
183+
pub entity: Entity,
182184
/// the label of the callback
183185
pub label: CallbackLabel,
184186
/// the script that replied
@@ -190,11 +192,13 @@ pub struct ScriptCallbackResponseEvent {
190192
impl ScriptCallbackResponseEvent {
191193
/// Creates a new callback response event with the given label, script and response
192194
pub fn new<L: Into<CallbackLabel>>(
195+
entity: Entity,
193196
label: L,
194197
script: ScriptId,
195198
response: Result<ScriptValue, ScriptError>,
196199
) -> Self {
197200
Self {
201+
entity,
198202
label: label.into(),
199203
script,
200204
response,

crates/bevy_mod_scripting_core/src/handler.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ pub(crate) fn event_handler_inner<P: IntoScriptPluginParams>(
207207
send_callback_response(
208208
guard.clone(),
209209
ScriptCallbackResponseEvent::new(
210+
*entity,
210211
callback_label.clone(),
211212
script_id.clone(),
212213
call_result.clone(),
@@ -384,8 +385,10 @@ mod test {
384385
invocations: vec![].into(),
385386
};
386387
let mut app = setup_app::<OnTestCallback>(runtime, scripts);
387-
app.world_mut()
388-
.spawn(ScriptComponent(vec![test_script_id.clone()]));
388+
let entity = app
389+
.world_mut()
390+
.spawn(ScriptComponent(vec![test_script_id.clone()]))
391+
.id();
389392

390393
app.world_mut().send_event(
391394
ScriptCallbackEvent::new(
@@ -400,6 +403,7 @@ mod test {
400403
assert_response_events(
401404
app.world_mut(),
402405
vec![ScriptCallbackResponseEvent::new(
406+
entity,
403407
OnTestCallback::into_callback_label(),
404408
test_script_id.clone(),
405409
Ok(ScriptValue::Unit),

0 commit comments

Comments
 (0)