@@ -12,7 +12,7 @@ use crate::{
12
12
} ,
13
13
extractors:: { with_handler_system_state, HandlerContext } ,
14
14
handler:: { handle_script_errors, send_callback_response} ,
15
- script:: { Script , ScriptId , Scripts , StaticScripts } ,
15
+ script:: { Script , ScriptId , Scripts , StaticScripts , DisplayProxy } ,
16
16
IntoScriptPluginParams ,
17
17
} ;
18
18
use bevy:: { asset:: Handle , ecs:: entity:: Entity , log:: debug, prelude:: Command } ;
@@ -41,7 +41,7 @@ impl<P: IntoScriptPluginParams> Command for DeleteScript<P> {
41
41
fn apply ( self , world : & mut bevy:: prelude:: World ) {
42
42
// first apply unload callback
43
43
RunScriptCallback :: < P > :: new (
44
- self . id . clone ( ) ,
44
+ Handle :: Weak ( self . id . clone ( ) ) ,
45
45
Entity :: from_raw ( 0 ) ,
46
46
OnScriptUnloaded :: into_callback_label ( ) ,
47
47
vec ! [ ] ,
@@ -65,7 +65,7 @@ impl<P: IntoScriptPluginParams> Command for DeleteScript<P> {
65
65
///
66
66
/// If script comes from an asset, expects it to be loaded, otherwise this command will fail to process the script.
67
67
pub struct CreateOrUpdateScript < P : IntoScriptPluginParams > {
68
- id : ScriptId ,
68
+ id : Handle < ScriptAsset > ,
69
69
content : Box < [ u8 ] > ,
70
70
asset : Option < Handle < ScriptAsset > > ,
71
71
// Hack to make this Send, C does not need to be Send since it is not stored in the command
@@ -75,7 +75,7 @@ pub struct CreateOrUpdateScript<P: IntoScriptPluginParams> {
75
75
#[ profiling:: all_functions]
76
76
impl < P : IntoScriptPluginParams > CreateOrUpdateScript < P > {
77
77
/// Creates a new CreateOrUpdateScript command with the given ID, content and asset
78
- pub fn new ( id : ScriptId , content : Box < [ u8 ] > , asset : Option < Handle < ScriptAsset > > ) -> Self {
78
+ pub fn new ( id : Handle < ScriptAsset > , content : Box < [ u8 ] > , asset : Option < Handle < ScriptAsset > > ) -> Self {
79
79
Self {
80
80
id,
81
81
content,
@@ -84,16 +84,16 @@ impl<P: IntoScriptPluginParams> CreateOrUpdateScript<P> {
84
84
}
85
85
}
86
86
87
- fn script_name ( & self ) -> String {
88
- self . asset . as_ref ( ) . and_then ( |handle| handle. path ( ) . map ( |p| p. to_string ( ) ) ) . unwrap_or_else ( || self . id . to_string ( ) )
89
- }
87
+ // fn script_name(&self) -> String {
88
+ // self.asset.as_ref().and_then(|handle| handle.path().map(|p| p.to_string())).unwrap_or_else(|| self.id.to_string())
89
+ // }
90
90
91
91
fn reload_context (
92
92
& self ,
93
93
guard : WorldGuard ,
94
94
handler_ctxt : & HandlerContext < P > ,
95
95
) -> Result < ( ) , ScriptError > {
96
- let existing_script = match handler_ctxt. scripts . scripts . get ( & self . id ) {
96
+ let existing_script = match handler_ctxt. scripts . scripts . get ( & self . id . id ( ) ) {
97
97
Some ( script) => script,
98
98
None => {
99
99
return Err (
@@ -108,7 +108,7 @@ impl<P: IntoScriptPluginParams> CreateOrUpdateScript<P> {
108
108
( ContextBuilder :: < P > :: reload) (
109
109
handler_ctxt. context_loading_settings . loader . reload ,
110
110
// &self.id,
111
- & Handle :: Weak ( self . id ) ,
111
+ & self . id ,
112
112
& self . content ,
113
113
& mut context,
114
114
& handler_ctxt. context_loading_settings . context_initializers ,
@@ -130,7 +130,7 @@ impl<P: IntoScriptPluginParams> CreateOrUpdateScript<P> {
130
130
let context = ( ContextBuilder :: < P > :: load) (
131
131
handler_ctxt. context_loading_settings . loader . load ,
132
132
// &self.id,
133
- & Handle :: Weak ( self . id ) ,
133
+ & self . id ,
134
134
& self . content ,
135
135
& handler_ctxt. context_loading_settings . context_initializers ,
136
136
& handler_ctxt
@@ -142,8 +142,7 @@ impl<P: IntoScriptPluginParams> CreateOrUpdateScript<P> {
142
142
143
143
let context = Arc :: new ( Mutex :: new ( context) ) ;
144
144
145
- handler_ctxt. scripts . scripts . insert (
146
- self . id . clone ( ) ,
145
+ handler_ctxt. scripts . insert (
147
146
Script {
148
147
id : self . id . clone ( ) ,
149
148
asset : self . asset . clone ( ) ,
@@ -160,7 +159,7 @@ impl<P: IntoScriptPluginParams> Command for CreateOrUpdateScript<P> {
160
159
let success = with_handler_system_state (
161
160
world,
162
161
|guard, handler_ctxt : & mut HandlerContext < P > | {
163
- let is_new_script = !handler_ctxt. scripts . scripts . contains_key ( & self . id ) ;
162
+ let is_new_script = !handler_ctxt. scripts . scripts . contains_key ( & self . id . id ( ) ) ;
164
163
165
164
let assigned_shared_context =
166
165
match handler_ctxt. context_loading_settings . assignment_strategy {
@@ -181,12 +180,12 @@ impl<P: IntoScriptPluginParams> Command for CreateOrUpdateScript<P> {
181
180
} ;
182
181
183
182
debug ! (
184
- "{}: CreateOrUpdateScript command applying (script_id: {}, new context?: {}, new script?: {})" ,
185
- P :: LANGUAGE ,
186
- self . id,
187
- assigned_shared_context. is_none( ) ,
188
- is_new_script
189
- ) ;
183
+ "{}: CreateOrUpdateScript command applying (script {}, new context?: {}, new script?: {})" ,
184
+ P :: LANGUAGE ,
185
+ self . id. display ( ) ,
186
+ assigned_shared_context. is_none( ) ,
187
+ is_new_script
188
+ ) ;
190
189
191
190
let result = match & assigned_shared_context {
192
191
Some ( assigned_shared_context) => {
@@ -200,13 +199,13 @@ impl<P: IntoScriptPluginParams> Command for CreateOrUpdateScript<P> {
200
199
} ;
201
200
// it can potentially be loaded but without a successful script reload but that
202
201
// leaves us in an okay state
203
- handler_ctxt. scripts . scripts . insert ( self . id . clone ( ) , script) ;
202
+ handler_ctxt. scripts . insert ( script) ;
204
203
}
205
- bevy:: log:: debug!( "{}: reloading script with id: {}" , P :: LANGUAGE , self . id) ;
204
+ bevy:: log:: debug!( "{}: reloading script {}" , P :: LANGUAGE , self . id. display ( ) ) ;
206
205
self . reload_context ( guard. clone ( ) , handler_ctxt)
207
206
}
208
207
None => {
209
- bevy:: log:: debug!( "{}: loading script with id: {}" , P :: LANGUAGE , self . id) ;
208
+ bevy:: log:: debug!( "{}: loading script {}" , P :: LANGUAGE , self . id. display ( ) ) ;
210
209
self . load_context ( guard. clone ( ) , handler_ctxt)
211
210
}
212
211
} ;
@@ -221,7 +220,7 @@ impl<P: IntoScriptPluginParams> Command for CreateOrUpdateScript<P> {
221
220
handle_script_errors (
222
221
guard,
223
222
vec ! [ err
224
- . with_script( self . script_name ( ) )
223
+ . with_script( self . id . display ( ) )
225
224
. with_context( P :: LANGUAGE )
226
225
. with_context( phrase) ]
227
226
. into_iter ( ) ,
@@ -230,9 +229,9 @@ impl<P: IntoScriptPluginParams> Command for CreateOrUpdateScript<P> {
230
229
}
231
230
232
231
bevy:: log:: debug!(
233
- "{}: script with id: {} successfully created or updated" ,
232
+ "{}: script {} successfully created or updated" ,
234
233
P :: LANGUAGE ,
235
- self . id
234
+ self . id. display ( )
236
235
) ;
237
236
238
237
true
@@ -256,7 +255,7 @@ impl<P: IntoScriptPluginParams> Command for CreateOrUpdateScript<P> {
256
255
/// Runs a callback on the script with the given ID if it exists
257
256
pub struct RunScriptCallback < P : IntoScriptPluginParams > {
258
257
/// The ID of the script to run the callback on
259
- pub id : AssetId < ScriptAsset > ,
258
+ pub id : Handle < ScriptAsset > ,
260
259
/// The entity to use for the callback
261
260
pub entity : Entity ,
262
261
/// The callback to run
@@ -274,7 +273,7 @@ pub struct RunScriptCallback<P: IntoScriptPluginParams> {
274
273
impl < P : IntoScriptPluginParams > RunScriptCallback < P > {
275
274
/// Creates a new RunCallbackCommand with the given ID, callback and arguments
276
275
pub fn new (
277
- id : AssetId < ScriptAsset > ,
276
+ id : Handle < ScriptAsset > ,
278
277
entity : Entity ,
279
278
callback : CallbackLabel ,
280
279
args : Vec < ScriptValue > ,
@@ -301,11 +300,11 @@ impl<P: IntoScriptPluginParams> RunScriptCallback<P> {
301
300
impl < P : IntoScriptPluginParams > Command for RunScriptCallback < P > {
302
301
fn apply ( self , world : & mut bevy:: prelude:: World ) {
303
302
with_handler_system_state ( world, |guard, handler_ctxt : & mut HandlerContext < P > | {
304
- if !handler_ctxt. is_script_fully_loaded ( self . id . clone ( ) ) {
303
+ if !handler_ctxt. is_script_fully_loaded ( self . id . id ( ) ) {
305
304
bevy:: log:: error!(
306
- "{}: Cannot apply callback command, as script does not exist: {} . Ignoring." ,
305
+ "{}: Cannot apply callback command, as script {} does not exist. Ignoring." ,
307
306
P :: LANGUAGE ,
308
- self . id
307
+ self . id. display ( )
309
308
) ;
310
309
return ;
311
310
}
@@ -323,14 +322,14 @@ impl<P: IntoScriptPluginParams> Command for RunScriptCallback<P> {
323
322
guard. clone ( ) ,
324
323
ScriptCallbackResponseEvent :: new (
325
324
self . callback ,
326
- self . id . clone ( ) ,
325
+ self . id . id ( ) ,
327
326
result. clone ( ) ,
328
327
) ,
329
328
) ;
330
329
}
331
330
332
331
if let Err ( err) = result {
333
- let mut error_with_context = err. with_script ( self . id ) . with_context ( P :: LANGUAGE ) ;
332
+ let mut error_with_context = err. with_script ( self . id . display ( ) ) . with_context ( P :: LANGUAGE ) ;
334
333
if let Some ( ctxt) = self . context {
335
334
error_with_context = error_with_context. with_context ( ctxt) ;
336
335
}
0 commit comments