Skip to content

Commit 1ca419b

Browse files
committed
fix some bugs
1 parent d4688ca commit 1ca419b

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ bevy = { workspace = true, features = [
211211
"bevy_asset",
212212
"bevy_core_pipeline",
213213
"bevy_sprite",
214+
"x11",
214215
] }
215216
bevy_platform = { workspace = true }
216217
clap = { workspace = true, features = ["derive"] }

crates/bevy_mod_scripting_core/src/asset.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::{
2727
commands::{CreateOrUpdateScript, DeleteScript},
2828
error::ScriptError,
2929
event::ScriptEvent,
30-
script::{ContextKey, DisplayProxy, ScriptAttachment},
30+
script::{ContextKey, DisplayProxy, ScriptAttachment, ScriptContext},
3131
};
3232

3333
/// Represents a scripting language. Languages which compile into another language should use the target language as their language.
@@ -218,6 +218,7 @@ fn handle_script_events<P: IntoScriptPluginParams>(
218218
scripts: Query<(Entity, &ScriptComponent)>,
219219
asset_server: Res<AssetServer>,
220220
mut script_queue: Local<ScriptQueue>,
221+
script_contexts: Res<ScriptContext<P>>,
221222
mut commands: Commands,
222223
world_id: WorldId,
223224
) {
@@ -233,8 +234,6 @@ fn handle_script_events<P: IntoScriptPluginParams>(
233234
// associated with. That could be static scripts, script
234235
// components.
235236

236-
let mut found_entity = false;
237-
238237
for (entity, script_component) in &scripts {
239238
if let Some(handle) =
240239
script_component.0.iter().find(|handle| handle.id() == *id)
@@ -246,17 +245,20 @@ fn handle_script_events<P: IntoScriptPluginParams>(
246245
))
247246
.with_responses(P::readonly_configuration(world_id).emit_responses),
248247
);
249-
found_entity = true;
250248
}
251249
}
252250

253-
if !found_entity {
254-
let handle = Handle::Weak(*id);
251+
let handle = Handle::Weak(*id);
252+
let attachment = ScriptAttachment::StaticScript(handle.clone());
253+
for (resident, _) in script_contexts
254+
.residents(&attachment)
255+
.filter(|(r, _)| r.script() == handle && r.is_static())
256+
{
255257
// if the script does not have any associated entity it's static.
256-
commands.queue(
257-
CreateOrUpdateScript::<P>::new(ScriptAttachment::StaticScript(handle))
258-
.with_responses(P::readonly_configuration(world_id).emit_responses),
259-
);
258+
commands
259+
.queue(CreateOrUpdateScript::<P>::new(resident).with_responses(
260+
P::readonly_configuration(world_id).emit_responses,
261+
));
260262
}
261263
}
262264
}

crates/bevy_mod_scripting_core/src/script/context_key.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ impl ScriptAttachment {
6060
}
6161
}
6262
}
63+
64+
/// Returns true if the attachment is a static script.
65+
pub fn is_static(&self) -> bool {
66+
matches!(self, ScriptAttachment::StaticScript(_))
67+
}
68+
69+
/// Returns true if the attachment is an entity script.
70+
pub fn is_entity_script(&self) -> bool {
71+
matches!(self, ScriptAttachment::EntityScript(_, _))
72+
}
6373
}
6474

6575
impl From<ScriptAttachment> for ContextKey {

examples/game_of_life.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,8 @@ fn game_of_life_app(app: &mut App) -> &mut App {
116116
send_on_update.after(update_rendered_state),
117117
(
118118
event_handler::<OnUpdate, LuaScriptingPlugin>,
119-
#[cfg(feature = "rhai")]
120119
event_handler::<OnUpdate, RhaiScriptingPlugin>,
121120
event_handler::<OnClick, LuaScriptingPlugin>,
122-
#[cfg(feature = "rhai")]
123121
event_handler::<OnClick, RhaiScriptingPlugin>,
124122
)
125123
.after(send_on_update),

0 commit comments

Comments
 (0)