@@ -157,195 +157,3 @@ pub fn with_world<F: FnOnce(&mut RhaiScriptContext) -> Result<(), ScriptError>>(
157157 f ( context)
158158 } )
159159}
160- // use crate::{
161- // assets::{RhaiFile, RhaiLoader},
162- // docs::RhaiDocFragment,
163- // };
164- // use bevy::{ecs::schedule::ScheduleLabel, prelude::*};
165- // use bevy_mod_scripting_core::{prelude::*, systems::*};
166- // use rhai::*;
167- // use std::marker::PhantomData;
168-
169- // pub mod assets;
170- // pub mod docs;
171- // pub use rhai;
172- // pub mod prelude {
173- // pub use crate::{
174- // assets::{RhaiFile, RhaiLoader},
175- // docs::RhaiDocFragment,
176- // RhaiContext, RhaiEvent, RhaiScriptHost,
177- // };
178- // pub use rhai;
179- // pub use rhai::{RhaiRuntime, FuncArgs};
180- // }
181-
182- // #[derive(Resource)]
183- // pub struct RhaiScriptHost<A: FuncArgs + Send> {
184- // pub RhaiRuntime: RhaiRuntime,
185- // _ph: PhantomData<A>,
186- // }
187-
188- // #[allow(deprecated)]
189- // impl<A: FuncArgs + Send> Default for RhaiScriptHost<A> {
190- // fn default() -> Self {
191- // let mut e = RhaiRuntime::new();
192- // // prevent shadowing of `state`,`world` and `entity` in variable in scripts
193- // e.on_def_var(|_, info, _| {
194- // Ok(info.name() != "state" && info.name() != "world" && info.name() != "entity")
195- // });
196-
197- // Self {
198- // RhaiRuntime: e,
199- // _ph: Default::default(),
200- // }
201- // }
202- // }
203-
204- // pub struct RhaiContext {
205- // pub ast: AST,
206- // pub scope: Scope<'static>,
207- // }
208-
209- // #[derive(Clone, Event)]
210- // /// A Rhai Hook. The result of creating this event will be
211- // /// a call to the lua script with the hook_name and the given arguments
212- // pub struct RhaiEvent<A: FuncArgs + Clone + 'static> {
213- // pub hook_name: String,
214- // pub args: A,
215- // pub recipients: Recipients,
216- // }
217-
218- // impl<A: FuncArgs + Clone + Send + Sync + 'static> ScriptEvent for RhaiEvent<A> {
219- // fn recipients(&self) -> &crate::Recipients {
220- // &self.recipients
221- // }
222- // }
223-
224- // impl<A: FuncArgs + Send + Clone + Sync + 'static> ScriptHost for RhaiScriptHost<A> {
225- // type ScriptContext = RhaiContext;
226- // type ScriptEvent = RhaiEvent<A>;
227- // type ScriptAsset = RhaiFile;
228- // type APITarget = RhaiRuntime;
229- // type DocTarget = RhaiDocFragment;
230-
231- // fn register_with_app_in_set(
232- // app: &mut bevy::prelude::App,
233- // schedule: impl ScheduleLabel,
234- // set: impl SystemSet,
235- // ) {
236- // app.add_priority_event::<Self::ScriptEvent>()
237- // .init_asset::<RhaiFile>()
238- // .init_asset_loader::<RhaiLoader>()
239- // .init_resource::<CachedScriptState<Self>>()
240- // .init_resource::<ScriptContexts<Self::ScriptContext>>()
241- // .init_resource::<APIProviders<Self>>()
242- // .register_type::<ScriptCollection<Self::ScriptAsset>>()
243- // .register_type::<Script<Self::ScriptAsset>>()
244- // .register_type::<Handle<RhaiFile>>()
245- // .add_systems(
246- // schedule,
247- // (
248- // script_add_synchronizer::<Self>,
249- // script_remove_synchronizer::<Self>,
250- // script_hot_reload_handler::<Self>,
251- // )
252- // .chain()
253- // .in_set(set),
254- // )
255- // // setup RhaiRuntime
256- // .add_systems(
257- // Startup,
258- // |mut providers: ResMut<APIProviders<Self>>, mut host: ResMut<Self>| {
259- // providers
260- // .attach_all(&mut host.RhaiRuntime)
261- // .expect("Error in adding api's for rhai");
262- // },
263- // );
264- // }
265-
266- // fn setup_script(
267- // &mut self,
268- // script_data: &ScriptData,
269- // ctx: &mut Self::ScriptContext,
270- // providers: &mut APIProviders<Self>,
271- // ) -> Result<(), ScriptError> {
272- // providers.setup_all(script_data, ctx)
273- // }
274-
275- // fn load_script(
276- // &mut self,
277- // script: &[u8],
278- // script_data: &ScriptData,
279- // _: &mut APIProviders<Self>,
280- // ) -> Result<Self::ScriptContext, ScriptError> {
281- // let mut scope = Scope::new();
282- // let mut ast = self
283- // .RhaiRuntime
284- // .compile(
285- // std::str::from_utf8(script).map_err(|e| ScriptError::FailedToLoad {
286- // script: script_data.name.to_owned(),
287- // msg: e.to_string(),
288- // })?,
289- // )
290- // .map_err(|e| ScriptError::SyntaxError {
291- // script: script_data.name.to_owned(),
292- // msg: e.to_string(),
293- // })?;
294-
295- // ast.set_source(script_data.name);
296-
297- // // persistent state for scripts
298- // scope.push("state", Map::new());
299-
300- // Ok(RhaiContext { ast, scope })
301- // }
302-
303- // fn handle_events<'a>(
304- // &mut self,
305- // world: &mut World,
306- // events: &[Self::ScriptEvent],
307- // ctxs: impl Iterator<Item = (ScriptData<'a>, &'a mut Self::ScriptContext)>,
308- // _providers: &mut APIProviders<Self>,
309- // ) {
310- // ctxs.for_each(|(fd, ctx)| {
311- // for event in events.iter() {
312- // // check if this script should handle this event
313- // if !event.recipients().is_recipient(&fd) {
314- // continue;
315- // };
316-
317- // match self.RhaiRuntime.call_fn(
318- // &mut ctx.scope,
319- // &ctx.ast,
320- // &event.hook_name,
321- // event.args.clone(),
322- // ) {
323- // Ok(v) => v,
324- // Err(e) => {
325- // let mut state: CachedScriptState<Self> = world.remove_resource().unwrap();
326-
327- // match *e {
328- // EvalAltResult::ErrorFunctionNotFound(..) => {}
329- // _ => {
330- // let (_, mut error_wrt, _) = state.event_state.get_mut(world);
331-
332- // let error = ScriptError::RuntimeError {
333- // script: fd.name.to_string(),
334- // msg: e.to_string(),
335- // };
336- // error!("{}", error);
337- // error_wrt.send(ScriptErrorEvent { error });
338- // }
339- // }
340-
341- // world.insert_resource(state);
342- // }
343- // };
344- // }
345-
346- // // executing this at the end here means we execute global statements exactly once
347- // // all this method call does is set a variable on the AST to NONE so should not affect performance
348- // ctx.ast.clear_statements();
349- // });
350- // }
351- // }
0 commit comments