Skip to content

feat: Include Entity in ScriptCallbackResponseEvent #425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions crates/bevy_mod_scripting_core/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ impl<P: IntoScriptPluginParams> Command for RunScriptCallback<P> {
send_callback_response(
guard.clone(),
ScriptCallbackResponseEvent::new(
self.entity,
self.callback,
self.id.clone(),
result.clone(),
Expand Down Expand Up @@ -569,6 +570,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 @@ -173,6 +173,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 @@ -184,11 +186,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