@@ -12,7 +12,7 @@ use ::{
12
12
// },
13
13
bevy_reflect:: Reflect ,
14
14
} ;
15
- use bevy_asset:: AssetServer ;
15
+ use bevy_asset:: { AssetServer , Handle } ;
16
16
use bevy_ecs:: {
17
17
entity:: Entity ,
18
18
event:: { EventReader , EventWriter } ,
@@ -23,11 +23,11 @@ use bevy_ecs::{
23
23
use serde:: { Deserialize , Serialize } ;
24
24
25
25
use crate :: {
26
- IntoScriptPluginParams , LanguageExtensions , ScriptComponent , ScriptingSystemSet , StaticScripts ,
26
+ IntoScriptPluginParams , LanguageExtensions , ScriptComponent , ScriptingSystemSet ,
27
27
commands:: { CreateOrUpdateScript , DeleteScript } ,
28
28
error:: ScriptError ,
29
29
event:: ScriptEvent ,
30
- script:: { ContextKey , DisplayProxy , ScriptAttachment } ,
30
+ script:: { ContextKey , DisplayProxy , ScriptAttachment , ScriptContext } ,
31
31
} ;
32
32
33
33
/// Represents a scripting language. Languages which compile into another language should use the target language as their language.
@@ -215,10 +215,10 @@ fn sync_assets(
215
215
fn handle_script_events < P : IntoScriptPluginParams > (
216
216
mut events : EventReader < ScriptEvent > ,
217
217
script_assets : Res < Assets < ScriptAsset > > ,
218
- static_scripts : Res < StaticScripts > ,
219
218
scripts : Query < ( Entity , & ScriptComponent ) > ,
220
219
asset_server : Res < AssetServer > ,
221
220
mut script_queue : Local < ScriptQueue > ,
221
+ script_contexts : Res < ScriptContext < P > > ,
222
222
mut commands : Commands ,
223
223
world_id : WorldId ,
224
224
) {
@@ -233,6 +233,7 @@ fn handle_script_events<P: IntoScriptPluginParams>(
233
233
// We need to reload the script for any context it's
234
234
// associated with. That could be static scripts, script
235
235
// components.
236
+
236
237
for ( entity, script_component) in & scripts {
237
238
if let Some ( handle) =
238
239
script_component. 0 . iter ( ) . find ( |handle| handle. id ( ) == * id)
@@ -247,13 +248,17 @@ fn handle_script_events<P: IntoScriptPluginParams>(
247
248
}
248
249
}
249
250
250
- if let Some ( handle) = static_scripts. scripts . iter ( ) . find ( |s| s. id ( ) == * id) {
251
- commands. queue (
252
- CreateOrUpdateScript :: < P > :: new ( ScriptAttachment :: StaticScript (
253
- handle. clone ( ) ,
254
- ) )
255
- . with_responses ( P :: readonly_configuration ( world_id) . emit_responses ) ,
256
- ) ;
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
+ {
257
+ // if the script does not have any associated entity it's static.
258
+ commands
259
+ . queue ( CreateOrUpdateScript :: < P > :: new ( resident) . with_responses (
260
+ P :: readonly_configuration ( world_id) . emit_responses ,
261
+ ) ) ;
257
262
}
258
263
}
259
264
}
0 commit comments