@@ -12,7 +12,7 @@ use super::{
12
12
} , function:: {
13
13
namespace:: Namespace ,
14
14
script_function:: { AppScriptFunctionRegistry , DynamicScriptFunction , FunctionCallContext } ,
15
- } , pretty_print:: DisplayWithWorld , schedule:: AppScheduleRegistry , script_value:: ScriptValue , with_global_access, AppReflectAllocator , ReflectBase , ReflectBaseType , ReflectReference , ScriptComponentRegistration , ScriptResourceRegistration , ScriptTypeRegistration
15
+ } , pretty_print:: DisplayWithWorld , schedule:: AppScheduleRegistry , script_value:: ScriptValue , with_global_access, AppReflectAllocator , ReflectBase , ReflectBaseType , ReflectReference , ScriptComponentRegistration , ScriptResourceRegistration , ScriptTypeRegistration , Union
16
16
} ;
17
17
use crate :: {
18
18
bindings:: { function:: { from:: FromScript , from_ref:: FromScriptRef } , with_access_read, with_access_write} ,
@@ -542,6 +542,7 @@ impl<'w> WorldAccessGuard<'w> {
542
542
/// Impl block for higher level world methods
543
543
#[ profiling:: all_functions]
544
544
impl WorldAccessGuard < ' _ > {
545
+
545
546
fn construct_from_script_value (
546
547
& self ,
547
548
descriptor : impl Into < Cow < ' static , str > > ,
@@ -800,7 +801,7 @@ impl WorldAccessGuard<'_> {
800
801
} )
801
802
}
802
803
803
- /// get a type registration for the type
804
+ /// get a type registration for the type, without checking if it's a component or resource
804
805
pub fn get_type_by_name ( & self , type_name : String ) -> Option < ScriptTypeRegistration > {
805
806
let type_registry = self . type_registry ( ) ;
806
807
let type_registry = type_registry. read ( ) ;
@@ -810,6 +811,38 @@ impl WorldAccessGuard<'_> {
810
811
. map ( |registration| ScriptTypeRegistration :: new ( Arc :: new ( registration. clone ( ) ) ) )
811
812
}
812
813
814
+ /// get a type erased type registration for the type including information about whether it's a component or resource
815
+ pub ( crate ) fn get_type_registration ( & self , registration : ScriptTypeRegistration ) -> Result < Union < ScriptTypeRegistration , Union < ScriptComponentRegistration , ScriptResourceRegistration > > , InteropError > {
816
+
817
+ let registration = match self . get_resource_type ( registration) ? {
818
+ Ok ( res) => {
819
+ return Ok ( Union :: new_right ( Union :: new_right ( res) ) ) ;
820
+ }
821
+ Err ( registration) => registration,
822
+ } ;
823
+
824
+ let registration = match self . get_component_type ( registration) ? {
825
+ Ok ( comp) => {
826
+ return Ok ( Union :: new_right ( Union :: new_left ( comp) ) ) ;
827
+ }
828
+ Err ( registration) => registration,
829
+ } ;
830
+
831
+ Ok ( Union :: new_left ( registration) )
832
+ }
833
+
834
+ /// Similar to [`Self::get_type_by_name`] but returns a type erased [`ScriptTypeRegistration`], [`ScriptComponentRegistration`] or [`ScriptResourceRegistration`]
835
+ /// depending on the underlying type and state of the world.
836
+ pub fn get_type_registration_by_name ( & self , type_name : String ) -> Result < Option < Union < ScriptTypeRegistration , Union < ScriptComponentRegistration , ScriptResourceRegistration > > > , InteropError > {
837
+ let val = self . get_type_by_name ( type_name) ;
838
+ Ok ( match val {
839
+ Some ( registration) => {
840
+ Some ( self . get_type_registration ( registration) ?)
841
+ }
842
+ None => None ,
843
+ } )
844
+ }
845
+
813
846
/// get a schedule by name
814
847
pub fn get_schedule_by_name ( & self , schedule_name : String ) -> Option < ReflectSchedule > {
815
848
let schedule_registry = self . schedule_registry ( ) ;
0 commit comments