From cc71436187e3301985477772903f1bd94a01dac8 Mon Sep 17 00:00:00 2001 From: DasLixou Date: Wed, 21 Aug 2024 15:05:56 +0200 Subject: [PATCH] The deserialzation hack.. --- crates/blenvy/src/components/fake_entity.rs | 243 +++++++----------- crates/blenvy/src/components/mod.rs | 2 - crates/blenvy/src/components/patch_entity.rs | 30 --- .../src/components/reflect_ext/array_ext.rs | 36 --- .../src/components/reflect_ext/enum_ext.rs | 36 --- .../src/components/reflect_ext/list_ext.rs | 36 --- .../src/components/reflect_ext/map_ext.rs | 34 --- .../blenvy/src/components/reflect_ext/mod.rs | 56 ---- .../src/components/reflect_ext/struct_ext.rs | 36 --- .../src/components/reflect_ext/tuple_ext.rs | 35 --- .../reflect_ext/tuple_struct_ext.rs | 35 --- .../ronstring_to_reflect_component.rs | 6 +- 12 files changed, 102 insertions(+), 483 deletions(-) delete mode 100644 crates/blenvy/src/components/patch_entity.rs delete mode 100644 crates/blenvy/src/components/reflect_ext/array_ext.rs delete mode 100644 crates/blenvy/src/components/reflect_ext/enum_ext.rs delete mode 100644 crates/blenvy/src/components/reflect_ext/list_ext.rs delete mode 100644 crates/blenvy/src/components/reflect_ext/map_ext.rs delete mode 100644 crates/blenvy/src/components/reflect_ext/mod.rs delete mode 100644 crates/blenvy/src/components/reflect_ext/struct_ext.rs delete mode 100644 crates/blenvy/src/components/reflect_ext/tuple_ext.rs delete mode 100644 crates/blenvy/src/components/reflect_ext/tuple_struct_ext.rs diff --git a/crates/blenvy/src/components/fake_entity.rs b/crates/blenvy/src/components/fake_entity.rs index e7d8c6a..93aa070 100644 --- a/crates/blenvy/src/components/fake_entity.rs +++ b/crates/blenvy/src/components/fake_entity.rs @@ -1,7 +1,62 @@ +use std::{alloc::Layout, num::NonZeroU32}; + +use bevy::{ + log::{info, warn}, + reflect::ReflectDeserialize, +}; +use serde::Deserialize; + +const _: () = { + let real = Layout::new::(); + let fake = Layout::new::(); + assert!(real.size() == fake.size()); + assert!(real.align() == fake.align()); +}; + +#[derive(Clone)] +#[repr(C, align(8))] pub(crate) struct Entity { - pub name: Option, + // Do not reorder the fields here. The ordering is equivalent to bevy's `Entity` + #[cfg(target_endian = "little")] + index: u32, + generation: NonZeroU32, + #[cfg(target_endian = "big")] + index: u32, } +impl<'de> Deserialize<'de> for Entity { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + #[derive(Deserialize)] + #[serde(rename = "Entity")] + struct EntityData { + name: Option, + } + + let entity_data = EntityData::deserialize(deserializer)?; + + let entity = if let Some(name) = entity_data.name { + info!("Found name {name}"); + bevy::ecs::entity::Entity::PLACEHOLDER + } else { + warn!("No object was specified for Entity relation, using `Entity::PLACEHOLDER`."); + bevy::ecs::entity::Entity::PLACEHOLDER + }; + + Ok(unsafe { + // SAFETY: both have the same layout + core::mem::transmute(entity) + }) + } +} + +// This is expanded and modified from +// ``` +// #[derive(Clone, Reflect)] +// #[reflect_value(Deserialize)] +// ``` const _: () = { use bevy::reflect as bevy_reflect; @@ -9,9 +64,6 @@ const _: () = { impl bevy_reflect::GetTypeRegistration for Entity where Self: ::core::any::Any + ::core::marker::Send + ::core::marker::Sync, - Option: bevy_reflect::FromReflect - + bevy_reflect::TypePath - + bevy_reflect::__macro_exports::RegisterForReflection, { fn get_type_registration() -> bevy_reflect::TypeRegistration { let mut registration = bevy_reflect::TypeRegistration::of::(); @@ -22,45 +74,16 @@ const _: () = { registration.insert::( bevy_reflect::FromType::::from_type(), ); + registration.insert::(bevy_reflect::FromType::::from_type()); registration } - #[inline(never)] - fn register_type_dependencies(registry: &mut bevy_reflect::TypeRegistry) { - as bevy_reflect::__macro_exports::RegisterForReflection>::__register( - registry, - ); - } - } - impl bevy_reflect::Typed for Entity - where - Self: ::core::any::Any + ::core::marker::Send + ::core::marker::Sync, - Option: bevy_reflect::FromReflect - + bevy_reflect::TypePath - + bevy_reflect::__macro_exports::RegisterForReflection, - { - fn type_info() -> &'static bevy_reflect::TypeInfo { - static CELL: bevy_reflect::utility::NonGenericTypeInfoCell = - bevy_reflect::utility::NonGenericTypeInfoCell::new(); - CELL.get_or_set(|| { - bevy_reflect::TypeInfo::Struct( - bevy_reflect::StructInfo::new::(&[ - // TODO: changed here - bevy_reflect::NamedField::new::>("name") - .with_custom_attributes( - bevy_reflect::attributes::CustomAttributes::default(), - ), - ]) - .with_custom_attributes(bevy_reflect::attributes::CustomAttributes::default()), - ) - }) - } } impl bevy_reflect::TypePath for Entity where Self: ::core::any::Any + ::core::marker::Send + ::core::marker::Sync, { fn type_path() -> &'static str { - "bevy_ecs::entity::Entity" + "bevy_ecs::entity::Entity" // this is changed } fn short_type_path() -> &'static str { "Entity" @@ -69,74 +92,29 @@ const _: () = { ::core::option::Option::Some("Entity") } fn crate_name() -> Option<&'static str> { + // this is changed ::core::option::Option::Some("bevy_ecs::entity".split(':').next().unwrap()) } fn module_path() -> Option<&'static str> { - ::core::option::Option::Some("bevy_ecs::entity") + ::core::option::Option::Some("bevy_ecs::entity") // this is changed } } - impl bevy_reflect::Struct for Entity + impl bevy_reflect::Typed for Entity where Self: ::core::any::Any + ::core::marker::Send + ::core::marker::Sync, - Option: bevy_reflect::FromReflect - + bevy_reflect::TypePath - + bevy_reflect::__macro_exports::RegisterForReflection, { - fn field(&self, name: &str) -> ::core::option::Option<&dyn bevy_reflect::Reflect> { - match name { - "name" => ::core::option::Option::Some(&self.name), - _ => ::core::option::Option::None, - } - } - fn field_mut( - &mut self, - name: &str, - ) -> ::core::option::Option<&mut dyn bevy_reflect::Reflect> { - match name { - "name" => ::core::option::Option::Some(&mut self.name), - _ => ::core::option::Option::None, - } - } - fn field_at(&self, index: usize) -> ::core::option::Option<&dyn bevy_reflect::Reflect> { - match index { - 0usize => ::core::option::Option::Some(&self.name), - _ => ::core::option::Option::None, - } - } - fn field_at_mut( - &mut self, - index: usize, - ) -> ::core::option::Option<&mut dyn bevy_reflect::Reflect> { - match index { - 0usize => ::core::option::Option::Some(&mut self.name), - _ => ::core::option::Option::None, - } - } - fn name_at(&self, index: usize) -> ::core::option::Option<&str> { - match index { - 0usize => ::core::option::Option::Some("name"), - _ => ::core::option::Option::None, - } - } - fn field_len(&self) -> usize { - 1usize - } - fn iter_fields(&self) -> bevy_reflect::FieldIter { - bevy_reflect::FieldIter::new(self) - } - fn clone_dynamic(&self) -> bevy_reflect::DynamicStruct { - let mut dynamic: bevy_reflect::DynamicStruct = ::core::default::Default::default(); - dynamic.set_represented_type(bevy_reflect::Reflect::get_represented_type_info(self)); - dynamic.insert_boxed("name", bevy_reflect::Reflect::clone_value(&self.name)); - dynamic + fn type_info() -> &'static bevy_reflect::TypeInfo { + static CELL: bevy_reflect::utility::NonGenericTypeInfoCell = + bevy_reflect::utility::NonGenericTypeInfoCell::new(); + CELL.get_or_set(|| { + let info = bevy_reflect::ValueInfo::new::(); // this is changed + bevy_reflect::TypeInfo::Value(info) + }) } } impl bevy_reflect::Reflect for Entity where Self: ::core::any::Any + ::core::marker::Send + ::core::marker::Sync, - Option: bevy_reflect::FromReflect - + bevy_reflect::TypePath - + bevy_reflect::__macro_exports::RegisterForReflection, { #[inline] fn get_represented_type_info( @@ -172,7 +150,29 @@ const _: () = { } #[inline] fn clone_value(&self) -> ::std::boxed::Box { - ::std::boxed::Box::new(bevy_reflect::Struct::clone_dynamic(self)) + ::std::boxed::Box::new(::core::clone::Clone::clone(self)) + } + #[inline] + fn try_apply( + &mut self, + value: &dyn bevy_reflect::Reflect, + ) -> ::core::result::Result<(), bevy_reflect::ApplyError> { + let any = bevy_reflect::Reflect::as_any(value); + if let ::core::option::Option::Some(value) = + ::downcast_ref::(any) + { + *self = ::core::clone::Clone::clone(value); + } else { + return ::core::result::Result::Err(bevy_reflect::ApplyError::MismatchedTypes { + from_type: ::core::convert::Into::into( + bevy_reflect::DynamicTypePath::reflect_type_path(value), + ), + to_type: ::core::convert::Into::into( + ::type_path(), + ), + }); + } + ::core::result::Result::Ok(()) } #[inline] fn set( @@ -183,75 +183,32 @@ const _: () = { ::core::result::Result::Ok(()) } #[inline] - fn try_apply( - &mut self, - value: &dyn bevy_reflect::Reflect, - ) -> ::core::result::Result<(), bevy_reflect::ApplyError> { - if let bevy_reflect::ReflectRef::Struct(struct_value) = - bevy_reflect::Reflect::reflect_ref(value) - { - for (i, value) in ::core::iter::Iterator::enumerate( - bevy_reflect::Struct::iter_fields(struct_value), - ) { - let name = bevy_reflect::Struct::name_at(struct_value, i).unwrap(); - if let ::core::option::Option::Some(v) = - bevy_reflect::Struct::field_mut(self, name) - { - bevy_reflect::Reflect::try_apply(v, value)?; - } - } - } else { - return ::core::result::Result::Err(bevy_reflect::ApplyError::MismatchedKinds { - from_kind: bevy_reflect::Reflect::reflect_kind(value), - to_kind: bevy_reflect::ReflectKind::Struct, - }); - } - ::core::result::Result::Ok(()) - } - #[inline] fn reflect_kind(&self) -> bevy_reflect::ReflectKind { - bevy_reflect::ReflectKind::Struct + bevy_reflect::ReflectKind::Value } #[inline] fn reflect_ref(&self) -> bevy_reflect::ReflectRef { - bevy_reflect::ReflectRef::Struct(self) + bevy_reflect::ReflectRef::Value(self) } #[inline] fn reflect_mut(&mut self) -> bevy_reflect::ReflectMut { - bevy_reflect::ReflectMut::Struct(self) + bevy_reflect::ReflectMut::Value(self) } #[inline] fn reflect_owned(self: ::std::boxed::Box) -> bevy_reflect::ReflectOwned { - bevy_reflect::ReflectOwned::Struct(self) - } - fn reflect_partial_eq( - &self, - value: &dyn bevy_reflect::Reflect, - ) -> ::core::option::Option { - bevy_reflect::struct_partial_eq(self, value) + bevy_reflect::ReflectOwned::Value(self) } } impl bevy_reflect::FromReflect for Entity where Self: ::core::any::Any + ::core::marker::Send + ::core::marker::Sync, - Option: bevy_reflect::FromReflect - + bevy_reflect::TypePath - + bevy_reflect::__macro_exports::RegisterForReflection, { fn from_reflect(reflect: &dyn bevy_reflect::Reflect) -> ::core::option::Option { - if let bevy_reflect::ReflectRef::Struct(__ref_struct) = - bevy_reflect::Reflect::reflect_ref(reflect) - { - ::core::option::Option::Some(Self { - name: (|| { - as bevy_reflect::FromReflect>::from_reflect( - bevy_reflect::Struct::field(__ref_struct, "name")?, - ) - })()?, - }) - } else { - ::core::option::Option::None - } + ::core::option::Option::Some(::core::clone::Clone::clone( + ::downcast_ref::( + ::as_any(reflect), + )?, + )) } } }; diff --git a/crates/blenvy/src/components/mod.rs b/crates/blenvy/src/components/mod.rs index 43a69e3..9c499f2 100644 --- a/crates/blenvy/src/components/mod.rs +++ b/crates/blenvy/src/components/mod.rs @@ -8,8 +8,6 @@ pub mod process_gltfs; pub use process_gltfs::*; mod fake_entity; -mod patch_entity; -mod reflect_ext; pub mod blender_settings; diff --git a/crates/blenvy/src/components/patch_entity.rs b/crates/blenvy/src/components/patch_entity.rs deleted file mode 100644 index 5dac92c..0000000 --- a/crates/blenvy/src/components/patch_entity.rs +++ /dev/null @@ -1,30 +0,0 @@ -use bevy::{ - log::{info, warn}, - prelude::Entity, - reflect::{FromReflect, Reflect}, -}; - -use super::{fake_entity, reflect_ext}; - -pub fn patch_reflect_entity(reflect: &mut dyn Reflect) -> Option { - let maybe_fake = fake_entity::Entity::from_reflect(reflect).map(|fake| fake.name.clone()); - - if let Some(reference) = maybe_fake { - let entity = if let Some(name) = reference { - info!("Found name {name}"); - bevy::ecs::entity::Entity::PLACEHOLDER - } else { - warn!("No object was specified for Entity relation, using `Entity::PLACEHOLDER`."); - bevy::ecs::entity::Entity::PLACEHOLDER - }; - Some(entity) - } else { - let reflect_mut = reflect.reflect_mut(); - let iter = reflect_ext::DynamicFieldIterMut::from_reflect_mut(reflect_mut); - // TODO: recursively update - for f in iter { - patch_reflect_entity(f); - } - None - } -} diff --git a/crates/blenvy/src/components/reflect_ext/array_ext.rs b/crates/blenvy/src/components/reflect_ext/array_ext.rs deleted file mode 100644 index e73a35b..0000000 --- a/crates/blenvy/src/components/reflect_ext/array_ext.rs +++ /dev/null @@ -1,36 +0,0 @@ -use bevy::reflect::{Array, Reflect}; - -pub struct ArrayIterMut<'a> { - array: &'a mut dyn Array, - index: usize, -} - -impl<'a> ArrayIterMut<'a> { - /// Creates a new [`ArrayIterMut`]. - #[inline] - pub fn new(array: &'a mut dyn Array) -> ArrayIterMut { - ArrayIterMut { array, index: 0 } - } -} - -impl<'a> Iterator for ArrayIterMut<'a> { - type Item = &'a mut dyn Reflect; - - #[inline] - fn next(&mut self) -> Option { - let value = self.array.get_mut(self.index); - self.index += value.is_some() as usize; - value.map(|v| unsafe { - // SAFETY: index can only correspond to one field - &mut *(v as *mut _) - }) - } - - #[inline] - fn size_hint(&self) -> (usize, Option) { - let size = self.array.len(); - (size, Some(size)) - } -} - -impl<'a> ExactSizeIterator for ArrayIterMut<'a> {} diff --git a/crates/blenvy/src/components/reflect_ext/enum_ext.rs b/crates/blenvy/src/components/reflect_ext/enum_ext.rs deleted file mode 100644 index 5c15b73..0000000 --- a/crates/blenvy/src/components/reflect_ext/enum_ext.rs +++ /dev/null @@ -1,36 +0,0 @@ -use bevy::reflect::{Enum, Reflect}; - -pub struct VariantFieldIterMut<'a> { - container: &'a mut dyn Enum, - index: usize, -} - -impl<'a> VariantFieldIterMut<'a> { - pub fn new(container: &'a mut dyn Enum) -> Self { - Self { - container, - index: 0, - } - } -} - -impl<'a> Iterator for VariantFieldIterMut<'a> { - // TODO: make this work with `VariantFieldMut` again - type Item = &'a mut dyn Reflect; - - fn next(&mut self) -> Option { - let value = self.container.field_at_mut(self.index); - self.index += value.is_some() as usize; - value.map(|v| unsafe { - // SAFETY: index can only correspond to one field - &mut *(v as *mut _) - }) - } - - fn size_hint(&self) -> (usize, Option) { - let size = self.container.field_len(); - (size, Some(size)) - } -} - -impl<'a> ExactSizeIterator for VariantFieldIterMut<'a> {} diff --git a/crates/blenvy/src/components/reflect_ext/list_ext.rs b/crates/blenvy/src/components/reflect_ext/list_ext.rs deleted file mode 100644 index d8d17f6..0000000 --- a/crates/blenvy/src/components/reflect_ext/list_ext.rs +++ /dev/null @@ -1,36 +0,0 @@ -use bevy::reflect::{List, Reflect}; - -pub struct ListIterMut<'a> { - list: &'a mut dyn List, - index: usize, -} - -impl<'a> ListIterMut<'a> { - /// Creates a new [`ListIterMut`]. - #[inline] - pub fn new(list: &'a mut dyn List) -> ListIterMut { - ListIterMut { list, index: 0 } - } -} - -impl<'a> Iterator for ListIterMut<'a> { - type Item = &'a mut dyn Reflect; - - #[inline] - fn next(&mut self) -> Option { - let value = self.list.get_mut(self.index); - self.index += value.is_some() as usize; - value.map(|v| unsafe { - // SAFETY: index can only correspond to one field - &mut *(v as *mut _) - }) - } - - #[inline] - fn size_hint(&self) -> (usize, Option) { - let size = self.list.len(); - (size, Some(size)) - } -} - -impl<'a> ExactSizeIterator for ListIterMut<'a> {} diff --git a/crates/blenvy/src/components/reflect_ext/map_ext.rs b/crates/blenvy/src/components/reflect_ext/map_ext.rs deleted file mode 100644 index d503a57..0000000 --- a/crates/blenvy/src/components/reflect_ext/map_ext.rs +++ /dev/null @@ -1,34 +0,0 @@ -use bevy::reflect::{Map, Reflect}; - -pub struct MapIterMut<'a> { - map: &'a mut dyn Map, - index: usize, -} - -impl<'a> MapIterMut<'a> { - /// Creates a new [`MapIterMut`]. - #[inline] - pub fn new(map: &'a mut dyn Map) -> MapIterMut { - MapIterMut { map, index: 0 } - } -} - -impl<'a> Iterator for MapIterMut<'a> { - type Item = (&'a dyn Reflect, &'a mut dyn Reflect); - - fn next(&mut self) -> Option { - let value = self.map.get_at_mut(self.index); - self.index += value.is_some() as usize; - value.map(|(k, v)| unsafe { - // SAFETY: index can only correspond to one field - (&*(k as *const _), &mut *(v as *mut _)) - }) - } - - fn size_hint(&self) -> (usize, Option) { - let size = self.map.len(); - (size, Some(size)) - } -} - -impl<'a> ExactSizeIterator for MapIterMut<'a> {} diff --git a/crates/blenvy/src/components/reflect_ext/mod.rs b/crates/blenvy/src/components/reflect_ext/mod.rs deleted file mode 100644 index 15a63d5..0000000 --- a/crates/blenvy/src/components/reflect_ext/mod.rs +++ /dev/null @@ -1,56 +0,0 @@ -use bevy::reflect::{Reflect, ReflectMut}; - -pub mod array_ext; -pub mod enum_ext; -pub mod list_ext; -pub mod map_ext; -pub mod struct_ext; -pub mod tuple_ext; -pub mod tuple_struct_ext; - -pub enum DynamicFieldIterMut<'a> { - Struct(struct_ext::FieldIterMut<'a>), - TupleStruct(tuple_struct_ext::TupleStructFieldIterMut<'a>), - Tuple(tuple_ext::TupleFieldIterMut<'a>), - List(list_ext::ListIterMut<'a>), - Array(array_ext::ArrayIterMut<'a>), - Map(map_ext::MapIterMut<'a>), - Enum(enum_ext::VariantFieldIterMut<'a>), - Value, -} - -impl<'a> DynamicFieldIterMut<'a> { - pub fn from_reflect_mut(ref_mut: ReflectMut<'a>) -> Self { - match ref_mut { - ReflectMut::Struct(s) => DynamicFieldIterMut::Struct(struct_ext::FieldIterMut::new(s)), - ReflectMut::TupleStruct(s) => { - DynamicFieldIterMut::TupleStruct(tuple_struct_ext::TupleStructFieldIterMut::new(s)) - } - ReflectMut::Tuple(t) => { - DynamicFieldIterMut::Tuple(tuple_ext::TupleFieldIterMut::new(t)) - } - ReflectMut::List(l) => DynamicFieldIterMut::List(list_ext::ListIterMut::new(l)), - ReflectMut::Array(a) => DynamicFieldIterMut::Array(array_ext::ArrayIterMut::new(a)), - ReflectMut::Map(m) => DynamicFieldIterMut::Map(map_ext::MapIterMut::new(m)), - ReflectMut::Enum(e) => DynamicFieldIterMut::Enum(enum_ext::VariantFieldIterMut::new(e)), - ReflectMut::Value(_) => DynamicFieldIterMut::Value, - } - } -} - -impl<'a> Iterator for DynamicFieldIterMut<'a> { - type Item = &'a mut dyn Reflect; - - fn next(&mut self) -> Option { - match self { - DynamicFieldIterMut::Struct(s) => s.next(), - DynamicFieldIterMut::TupleStruct(s) => s.next(), - DynamicFieldIterMut::Tuple(t) => t.next(), - DynamicFieldIterMut::List(l) => l.next(), - DynamicFieldIterMut::Array(a) => a.next(), - DynamicFieldIterMut::Map(m) => m.next().map(|(_, v)| v), - DynamicFieldIterMut::Enum(e) => e.next(), - DynamicFieldIterMut::Value => None, - } - } -} diff --git a/crates/blenvy/src/components/reflect_ext/struct_ext.rs b/crates/blenvy/src/components/reflect_ext/struct_ext.rs deleted file mode 100644 index d79e62d..0000000 --- a/crates/blenvy/src/components/reflect_ext/struct_ext.rs +++ /dev/null @@ -1,36 +0,0 @@ -use bevy::reflect::{Reflect, Struct}; - -/// An iterator over the field values of a struct. -pub struct FieldIterMut<'a> { - pub(crate) struct_val: &'a mut dyn Struct, - pub(crate) index: usize, -} - -impl<'a> FieldIterMut<'a> { - pub fn new(value: &'a mut dyn Struct) -> Self { - FieldIterMut { - struct_val: value, - index: 0, - } - } -} - -impl<'a> Iterator for FieldIterMut<'a> { - type Item = &'a mut dyn Reflect; - - fn next(&mut self) -> Option { - let value = self.struct_val.field_at_mut(self.index); - self.index += value.is_some() as usize; - value.map(|v| unsafe { - // SAFETY: index can only correspond to one field - &mut *(v as *mut _) - }) - } - - fn size_hint(&self) -> (usize, Option) { - let size = self.struct_val.field_len(); - (size, Some(size)) - } -} - -impl<'a> ExactSizeIterator for FieldIterMut<'a> {} diff --git a/crates/blenvy/src/components/reflect_ext/tuple_ext.rs b/crates/blenvy/src/components/reflect_ext/tuple_ext.rs deleted file mode 100644 index cb67980..0000000 --- a/crates/blenvy/src/components/reflect_ext/tuple_ext.rs +++ /dev/null @@ -1,35 +0,0 @@ -use bevy::reflect::{Reflect, Tuple}; - -pub struct TupleFieldIterMut<'a> { - pub(crate) tuple: &'a mut dyn Tuple, - pub(crate) index: usize, -} - -impl<'a> TupleFieldIterMut<'a> { - pub fn new(value: &'a mut dyn Tuple) -> Self { - TupleFieldIterMut { - tuple: value, - index: 0, - } - } -} - -impl<'a> Iterator for TupleFieldIterMut<'a> { - type Item = &'a mut dyn Reflect; - - fn next(&mut self) -> Option { - let value = self.tuple.field_mut(self.index); - self.index += value.is_some() as usize; - value.map(|v| unsafe { - // SAFETY: index can only correspond to one field - &mut *(v as *mut _) - }) - } - - fn size_hint(&self) -> (usize, Option) { - let size = self.tuple.field_len(); - (size, Some(size)) - } -} - -impl<'a> ExactSizeIterator for TupleFieldIterMut<'a> {} diff --git a/crates/blenvy/src/components/reflect_ext/tuple_struct_ext.rs b/crates/blenvy/src/components/reflect_ext/tuple_struct_ext.rs deleted file mode 100644 index c189ea8..0000000 --- a/crates/blenvy/src/components/reflect_ext/tuple_struct_ext.rs +++ /dev/null @@ -1,35 +0,0 @@ -use bevy::reflect::{Reflect, TupleStruct}; - -pub struct TupleStructFieldIterMut<'a> { - pub(crate) tuple_struct: &'a mut dyn TupleStruct, - pub(crate) index: usize, -} - -impl<'a> TupleStructFieldIterMut<'a> { - pub fn new(value: &'a mut dyn TupleStruct) -> Self { - TupleStructFieldIterMut { - tuple_struct: value, - index: 0, - } - } -} - -impl<'a> Iterator for TupleStructFieldIterMut<'a> { - type Item = &'a mut dyn Reflect; - - fn next(&mut self) -> Option { - let value = self.tuple_struct.field_mut(self.index); - self.index += value.is_some() as usize; - value.map(|v| unsafe { - // SAFETY: index can only correspond to one field - &mut *(v as *mut _) - }) - } - - fn size_hint(&self) -> (usize, Option) { - let size = self.tuple_struct.field_len(); - (size, Some(size)) - } -} - -impl<'a> ExactSizeIterator for TupleStructFieldIterMut<'a> {} diff --git a/crates/blenvy/src/components/ronstring_to_reflect_component.rs b/crates/blenvy/src/components/ronstring_to_reflect_component.rs index aa83af7..ba1a473 100644 --- a/crates/blenvy/src/components/ronstring_to_reflect_component.rs +++ b/crates/blenvy/src/components/ronstring_to_reflect_component.rs @@ -7,7 +7,7 @@ use bevy::utils::HashMap; use ron::Value; use serde::de::DeserializeSeed; -use super::{capitalize_first_letter, fake_entity, patch_entity::patch_reflect_entity}; +use super::{capitalize_first_letter, fake_entity}; pub fn ronstring_to_reflect_component( ron_string: &str, @@ -127,7 +127,7 @@ fn bevy_components_string_to_components( let mut deserializer = ron::Deserializer::from_str(ron_string.as_str()) .expect("deserialzer should have been generated from string"); let reflect_deserializer = ReflectDeserializer::new(type_registry); - let mut component = reflect_deserializer + let component = reflect_deserializer .deserialize(&mut deserializer) .unwrap_or_else(|e| { panic!( @@ -136,8 +136,6 @@ fn bevy_components_string_to_components( ) }); - patch_reflect_entity(component.as_mut()); - debug!("component {:?}", component); debug!("real type {:?}", component.get_represented_type_info()); components.push((component, type_registration.clone()));