diff --git a/editor/src/inspector/editors/script.rs b/editor/src/inspector/editors/script.rs index be4e54bff..dbd79f4f7 100644 --- a/editor/src/inspector/editors/script.rs +++ b/editor/src/inspector/editors/script.rs @@ -272,7 +272,7 @@ fn create_items( ctx[item].user_data = Some(Arc::new(Mutex::new(( *type_uuid, - constructor.source_path.clone(), + Some(constructor.source_path.clone()), )))); item diff --git a/fyrox-animation/src/machine/transition.rs b/fyrox-animation/src/machine/transition.rs index 1900268c6..728a8fad1 100644 --- a/fyrox-animation/src/machine/transition.rs +++ b/fyrox-animation/src/machine/transition.rs @@ -42,6 +42,10 @@ macro_rules! define_two_args_node { } impl Reflect for $name { + fn source_path() -> &'static str { + file!() + } + fn type_name(&self) -> &'static str { type_name::() } @@ -184,6 +188,10 @@ impl Visit for NotNode { } impl Reflect for NotNode { + fn source_path() -> &'static str { + file!() + } + fn type_name(&self) -> &'static str { type_name::() } diff --git a/fyrox-core-derive/src/lib.rs b/fyrox-core-derive/src/lib.rs index 8e74f3cc0..bc1f5d02e 100644 --- a/fyrox-core-derive/src/lib.rs +++ b/fyrox-core-derive/src/lib.rs @@ -1,6 +1,5 @@ mod component; mod reflect; -mod script; mod uuid; mod visit; @@ -56,15 +55,6 @@ pub fn type_uuid(input: TokenStream) -> TokenStream { TokenStream::from(uuid::impl_type_uuid_provider(ast)) } -/// Implements `ScriptSourcePathProvider` trait -/// -/// User has to import `ScriptSourcePathProvider` trait to use this macro. -#[proc_macro_derive(ScriptSourcePathProvider)] -pub fn script_source_path(input: TokenStream) -> TokenStream { - let ast = parse_macro_input!(input as DeriveInput); - TokenStream::from(script::impl_script_source_path_provider(ast)) -} - /// Implements `ComponentProvider` trait /// /// User has to import `ComponentProvider` trait to use this macro. diff --git a/fyrox-core-derive/src/reflect.rs b/fyrox-core-derive/src/reflect.rs index 04f10bb38..08d49bff2 100644 --- a/fyrox-core-derive/src/reflect.rs +++ b/fyrox-core-derive/src/reflect.rs @@ -420,6 +420,10 @@ fn gen_impl( quote! { #[allow(warnings)] impl #impl_generics Reflect for #ty_ident #ty_generics #where_clause { + fn source_path() -> &'static str { + file!() + } + fn type_name(&self) -> &'static str { std::any::type_name::() } diff --git a/fyrox-core-derive/src/script.rs b/fyrox-core-derive/src/script.rs deleted file mode 100644 index a7434d7df..000000000 --- a/fyrox-core-derive/src/script.rs +++ /dev/null @@ -1,23 +0,0 @@ -use darling::*; -use proc_macro2::TokenStream as TokenStream2; -use quote::*; -use syn::*; - -#[derive(FromDeriveInput)] -#[darling(supports(struct_any, enum_any))] -pub struct TypeArgs { - pub ident: Ident, -} - -pub fn impl_script_source_path_provider(ast: DeriveInput) -> TokenStream2 { - let ty_args = TypeArgs::from_derive_input(&ast).unwrap(); - let ty_ident = &ty_args.ident; - - quote! { - impl ScriptSourcePathProvider for #ty_ident { - fn script_source_path() -> &'static str { - file!() - } - } - } -} diff --git a/fyrox-core/src/lib.rs b/fyrox-core/src/lib.rs index 17795f094..04350e725 100644 --- a/fyrox-core/src/lib.rs +++ b/fyrox-core/src/lib.rs @@ -43,7 +43,6 @@ pub mod profiler; pub mod quadtree; pub mod rectpack; pub mod reflect; -pub mod script; pub mod sparse; pub mod sstorage; pub mod task; diff --git a/fyrox-core/src/pool/mod.rs b/fyrox-core/src/pool/mod.rs index 3227aeb5c..be8d20bcb 100644 --- a/fyrox-core/src/pool/mod.rs +++ b/fyrox-core/src/pool/mod.rs @@ -64,6 +64,11 @@ where T: Reflect, P: PayloadContainer + Reflect, { + #[inline] + fn source_path() -> &'static str { + file!() + } + #[inline] fn type_name(&self) -> &'static str { std::any::type_name::() diff --git a/fyrox-core/src/reflect.rs b/fyrox-core/src/reflect.rs index cf0a1d3c2..73bafce70 100644 --- a/fyrox-core/src/reflect.rs +++ b/fyrox-core/src/reflect.rs @@ -161,6 +161,10 @@ impl<'a, 'b> PartialEq for FieldInfo<'a, 'b> { /// for every type that should support `Reflect` trait. It is a good compromise between development speed /// and the quality of the string output. pub trait Reflect: Any + Debug { + fn source_path() -> &'static str + where + Self: Sized; + fn type_name(&self) -> &'static str; fn doc(&self) -> &'static str; @@ -1056,6 +1060,10 @@ impl dyn ReflectList { #[macro_export] macro_rules! blank_reflect { () => { + fn source_path() -> &'static str { + file!() + } + fn type_name(&self) -> &'static str { std::any::type_name::() } @@ -1106,6 +1114,10 @@ macro_rules! blank_reflect { #[macro_export] macro_rules! delegate_reflect { () => { + fn source_path() -> &'static str { + file!() + } + fn type_name(&self) -> &'static str { self.deref().type_name() } diff --git a/fyrox-core/src/reflect/std_impls.rs b/fyrox-core/src/reflect/std_impls.rs index d2b950e53..3f162f44e 100644 --- a/fyrox-core/src/reflect/std_impls.rs +++ b/fyrox-core/src/reflect/std_impls.rs @@ -280,6 +280,10 @@ impl Reflect for Box { macro_rules! impl_reflect_inner_mutability { ($self:ident, $acquire_lock_guard:block, $into_inner:block) => { + fn source_path() -> &'static str { + file!() + } + fn type_name(&$self) -> &'static str { std::any::type_name::() } diff --git a/fyrox-core/src/script.rs b/fyrox-core/src/script.rs deleted file mode 100644 index 999919e49..000000000 --- a/fyrox-core/src/script.rs +++ /dev/null @@ -1,11 +0,0 @@ -pub use fyrox_core_derive::ScriptSourcePathProvider; - -pub mod prelude { - pub use super::ScriptSourcePathProvider; -} - -/// Script source path provider -pub trait ScriptSourcePathProvider: Sized { - /// Script source path to open it from Editor - fn script_source_path() -> &'static str; -} diff --git a/fyrox-core/src/variable.rs b/fyrox-core/src/variable.rs index 8560318f3..fb9aa2737 100644 --- a/fyrox-core/src/variable.rs +++ b/fyrox-core/src/variable.rs @@ -298,6 +298,11 @@ impl Reflect for InheritableVariable where T: Reflect + Clone + PartialEq + Debug, { + #[inline] + fn source_path() -> &'static str { + file!() + } + #[inline] fn type_name(&self) -> &'static str { self.value.type_name() diff --git a/fyrox-ui/src/node/mod.rs b/fyrox-ui/src/node/mod.rs index a82928d40..f0e6bdca5 100644 --- a/fyrox-ui/src/node/mod.rs +++ b/fyrox-ui/src/node/mod.rs @@ -245,6 +245,10 @@ impl Visit for UiNode { } impl Reflect for UiNode { + fn source_path() -> &'static str { + file!() + } + fn type_name(&self) -> &'static str { Reflect::type_name(self.0.deref()) } diff --git a/src/scene/node/mod.rs b/src/scene/node/mod.rs index ed4359377..f21a90e43 100644 --- a/src/scene/node/mod.rs +++ b/src/scene/node/mod.rs @@ -572,6 +572,10 @@ impl Visit for Node { } impl Reflect for Node { + fn source_path() -> &'static str { + file!() + } + fn type_name(&self) -> &'static str { self.0.deref().type_name() } @@ -643,7 +647,6 @@ mod test { futures::executor::block_on, impl_component_provider, reflect::prelude::*, - script::prelude::*, uuid::{uuid, Uuid}, variable::InheritableVariable, visitor::{prelude::*, Visitor}, @@ -666,7 +669,7 @@ mod test { use fyrox_graph::SceneGraph; use std::{fs, path::Path, sync::Arc}; - #[derive(Debug, Clone, Reflect, Visit, Default, ScriptSourcePathProvider)] + #[derive(Debug, Clone, Reflect, Visit, Default)] struct MyScript { some_field: InheritableVariable, some_collection: InheritableVariable>, @@ -746,14 +749,13 @@ mod test { let serialization_context = SerializationContext::new(); serialization_context .script_constructors - .add_with_source_path::("MyScript"); + .add::("MyScript"); assert!(serialization_context .script_constructors .map() .iter() - .find(|s| s.1.source_path == Some(file!().to_string())) - .is_some()); + .any(|s| &s.1.source_path == file!())); engine::initialize_resource_manager_loaders( &resource_manager, diff --git a/src/scene/ragdoll.rs b/src/scene/ragdoll.rs index 5cba59e0c..bdd7cddef 100644 --- a/src/scene/ragdoll.rs +++ b/src/scene/ragdoll.rs @@ -37,6 +37,10 @@ uuid_provider!(Limb = "6d5bc2f7-8acc-4b64-8e4b-65d4551150bf"); // Rust has a compiler bug `overflow evaluating the requirement` that prevents deriving this impl. impl Reflect for Limb { + fn source_path() -> &'static str { + file!() + } + fn type_name(&self) -> &'static str { type_name::() } diff --git a/src/script/constructor.rs b/src/script/constructor.rs index b7b7062f0..5e4ffbcfb 100644 --- a/src/script/constructor.rs +++ b/src/script/constructor.rs @@ -8,7 +8,6 @@ use crate::{ }, script::{Script, ScriptTrait}, }; -use fyrox_core::script::ScriptSourcePathProvider; use std::collections::BTreeMap; /// Script constructor contains all required data and methods to create script instances @@ -21,7 +20,7 @@ pub struct ScriptConstructor { pub name: String, /// Script source path. - pub source_path: Option, + pub source_path: String, } /// A special container that is able to create nodes by their type UUID. @@ -51,31 +50,7 @@ impl ScriptConstructorContainer { ScriptConstructor { constructor: Box::new(|| Script::new(T::default())), name: name.to_owned(), - source_path: None, - }, - ); - - assert!(old.is_none()); - - self - } - - /// Adds new type constructor for a given type. - /// The script should use `ScriptSourcePathProvider` deriver trait to generate the script source path. - /// - /// # Panic - /// - /// The method will panic if there is already a constructor for given type uuid. - pub fn add_with_source_path(&self, name: &str) -> &Self - where - T: TypeUuidProvider + ScriptTrait + Default + ScriptSourcePathProvider, - { - let old = self.map.lock().insert( - T::type_uuid(), - ScriptConstructor { - constructor: Box::new(|| Script::new(T::default())), - name: name.to_owned(), - source_path: Some(T::script_source_path().to_owned()), + source_path: T::source_path().to_owned(), }, ); diff --git a/src/script/mod.rs b/src/script/mod.rs index d821a18f1..ee0486312 100644 --- a/src/script/mod.rs +++ b/src/script/mod.rs @@ -522,6 +522,10 @@ pub struct Script { } impl Reflect for Script { + fn source_path() -> &'static str { + file!() + } + fn type_name(&self) -> &'static str { self.instance.type_name() }