Remove some of the feature specific types, simplify the code

This commit is contained in:
Piotr Siuszko 2025-07-07 17:14:53 +02:00
parent 06c4a96c0d
commit bbe9798846
3 changed files with 641 additions and 710 deletions

View File

@ -29,7 +29,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.17.0-dev", features = [
] } ] }
bevy_platform = { path = "../bevy_platform", version = "0.17.0-dev", default-features = false, features = [ bevy_platform = { path = "../bevy_platform", version = "0.17.0-dev", default-features = false, features = [
"std", "std",
"serialize", "serialize"
] } ] }
bevy_asset = { path = "../bevy_asset", version = "0.17.0-dev", optional = true } bevy_asset = { path = "../bevy_asset", version = "0.17.0-dev", optional = true }
bevy_math = { path = "../bevy_math", version = "0.17.0-dev", optional = true } bevy_math = { path = "../bevy_math", version = "0.17.0-dev", optional = true }

View File

@ -12,8 +12,7 @@ use serde_json::Value;
use crate::schemas::{ use crate::schemas::{
reflect_info::{ reflect_info::{
is_non_zero_number_type, SchemaNumber, TypeDefinitionBuilder, TypeReferenceId, OptionalInfoReader, SchemaNumber, TypeDefinitionBuilder, TypeReferenceId, TypeReferencePath,
TypeReferencePath,
}, },
SchemaTypesMetadata, SchemaTypesMetadata,
}; };
@ -269,7 +268,7 @@ impl From<JsonSchemaBevyType> for JsonSchemaVariant {
} }
/// Kind of json schema, maps [`bevy_reflect::TypeInfo`] type /// Kind of json schema, maps [`bevy_reflect::TypeInfo`] type
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Reflect)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Reflect, Copy)]
pub enum SchemaKind { pub enum SchemaKind {
/// Struct /// Struct
#[default] #[default]
@ -299,6 +298,14 @@ pub enum SchemaKind {
impl SchemaKind { impl SchemaKind {
/// Creates a [`SchemaKind`] from a [`TypeRegistration`]. /// Creates a [`SchemaKind`] from a [`TypeRegistration`].
pub fn from_type_reg(type_reg: &TypeRegistration) -> Self { pub fn from_type_reg(type_reg: &TypeRegistration) -> Self {
if let Some(info) =
super::reflect_info::BASE_TYPES_INFO.get(&type_reg.type_info().type_id())
{
return info.schema_kind;
}
if type_reg.try_get_optional().is_some() {
return SchemaKind::Optional;
}
match type_reg.type_info() { match type_reg.type_info() {
TypeInfo::Struct(_) => SchemaKind::Struct, TypeInfo::Struct(_) => SchemaKind::Struct,
TypeInfo::TupleStruct(_) => SchemaKind::TupleStruct, TypeInfo::TupleStruct(_) => SchemaKind::TupleStruct,
@ -315,13 +322,7 @@ impl SchemaKind {
_ => SchemaKind::Value, _ => SchemaKind::Value,
} }
} }
TypeInfo::Enum(enum_info) => { TypeInfo::Enum(_) => SchemaKind::Enum,
if super::reflect_info::try_get_optional_from_info(enum_info).is_some() {
SchemaKind::Optional
} else {
SchemaKind::Enum
}
}
} }
} }
} }
@ -393,37 +394,25 @@ pub enum SchemaType {
impl From<TypeId> for SchemaType { impl From<TypeId> for SchemaType {
fn from(value: TypeId) -> Self { fn from(value: TypeId) -> Self {
if value.eq(&TypeId::of::<bool>()) { if let Some(info) = super::reflect_info::BASE_TYPES_INFO.get(&value) {
Self::Boolean info.schema_type
} else if value.eq(&TypeId::of::<f32>()) || value.eq(&TypeId::of::<f64>()) {
Self::Number
} else if value.eq(&TypeId::of::<u8>())
|| value.eq(&TypeId::of::<u16>())
|| value.eq(&TypeId::of::<u32>())
|| value.eq(&TypeId::of::<u64>())
|| value.eq(&TypeId::of::<u128>())
|| value.eq(&TypeId::of::<usize>())
|| value.eq(&TypeId::of::<i8>())
|| value.eq(&TypeId::of::<i16>())
|| value.eq(&TypeId::of::<i32>())
|| value.eq(&TypeId::of::<i64>())
|| value.eq(&TypeId::of::<i128>())
|| value.eq(&TypeId::of::<isize>())
|| is_non_zero_number_type(value)
{
Self::Integer
} else if value.eq(&TypeId::of::<str>())
|| value.eq(&TypeId::of::<char>())
|| value.eq(&TypeId::of::<String>())
|| value.eq(&TypeId::of::<Cow<str>>())
{
Self::String
} else { } else {
Self::Object Self::Object
} }
} }
} }
impl From<SchemaType> for SchemaTypeVariant {
fn from(value: SchemaType) -> Self {
SchemaTypeVariant::Single(value)
}
}
impl From<SchemaType> for Option<SchemaTypeVariant> {
fn from(value: SchemaType) -> Self {
Some(SchemaTypeVariant::Single(value))
}
}
impl SchemaType { impl SchemaType {
/// Returns the primitive type corresponding to the given type ID, if it exists. /// Returns the primitive type corresponding to the given type ID, if it exists.
pub fn try_get_primitive_type_from_type_id(type_id: TypeId) -> Option<Self> { pub fn try_get_primitive_type_from_type_id(type_id: TypeId) -> Option<Self> {

File diff suppressed because it is too large Load Diff