* cleaned up crate code
 * added duplicate named component to testing project to resolve issues with clashing short_names for bevy components
This commit is contained in:
kaosat.dev 2024-04-30 11:58:03 +02:00
parent 9138c81c60
commit 49917e3b17
8 changed files with 105 additions and 84 deletions

View File

@ -10,13 +10,7 @@ pub use process_gltfs::*;
pub mod blender_settings; pub mod blender_settings;
use bevy::{ use bevy::{
app::Startup, ecs::{component::Component, reflect::ReflectComponent, system::Resource},
ecs::{
component::Component,
reflect::ReflectComponent,
system::{Res, Resource},
},
log::warn,
prelude::{App, IntoSystemConfigs, Plugin, SystemSet, Update}, prelude::{App, IntoSystemConfigs, Plugin, SystemSet, Update},
reflect::Reflect, reflect::Reflect,
}; };
@ -68,16 +62,14 @@ pub enum GltfComponentsSet {
#[derive(Clone, Resource)] #[derive(Clone, Resource)]
pub struct GltfComponentsConfig {} pub struct GltfComponentsConfig {}
pub struct ComponentsFromGltfPlugin { pub struct ComponentsFromGltfPlugin {}
}
impl Default for ComponentsFromGltfPlugin { impl Default for ComponentsFromGltfPlugin {
fn default() -> Self { fn default() -> Self {
Self { } Self {}
} }
} }
impl Plugin for ComponentsFromGltfPlugin { impl Plugin for ComponentsFromGltfPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_plugins(blender_settings::plugin) app.add_plugins(blender_settings::plugin)

View File

@ -13,7 +13,7 @@ use bevy::{
utils::HashMap, utils::HashMap,
}; };
use crate::{ronstring_to_reflect_component, GltfComponentsConfig, GltfProcessed}; use crate::{ronstring_to_reflect_component, GltfProcessed};
/// main function: injects components into each entity in gltf files that have `gltf_extras`, using reflection /// main function: injects components into each entity in gltf files that have `gltf_extras`, using reflection
pub fn add_components_from_gltf_extras(world: &mut World) { pub fn add_components_from_gltf_extras(world: &mut World) {
@ -22,7 +22,7 @@ pub fn add_components_from_gltf_extras(world: &mut World) {
let mut entity_components: HashMap<Entity, Vec<(Box<dyn Reflect>, TypeRegistration)>> = let mut entity_components: HashMap<Entity, Vec<(Box<dyn Reflect>, TypeRegistration)>> =
HashMap::new(); HashMap::new();
let gltf_components_config = world.resource::<GltfComponentsConfig>(); // let gltf_components_config = world.resource::<GltfComponentsConfig>();
for (entity, name, extra, parent) in extras.iter(world) { for (entity, name, extra, parent) in extras.iter(world) {
debug!( debug!(
@ -33,10 +33,7 @@ pub fn add_components_from_gltf_extras(world: &mut World) {
let type_registry: &AppTypeRegistry = world.resource(); let type_registry: &AppTypeRegistry = world.resource();
let type_registry = type_registry.read(); let type_registry = type_registry.read();
let reflect_components = ronstring_to_reflect_component( let reflect_components = ronstring_to_reflect_component(&extra.value, &type_registry);
&extra.value,
&type_registry,
);
// we assign the components specified /xxx_components objects to their parent node // we assign the components specified /xxx_components objects to their parent node
let mut target_entity = entity; let mut target_entity = entity;

View File

@ -1,6 +1,6 @@
use bevy::log::{debug, warn}; use bevy::log::{debug, warn};
use bevy::reflect::serde::UntypedReflectDeserializer; use bevy::reflect::serde::UntypedReflectDeserializer;
use bevy::reflect::{Reflect, TypeInfo, TypeRegistration, TypeRegistry}; use bevy::reflect::{Reflect, TypeRegistration, TypeRegistry};
use bevy::utils::HashMap; use bevy::utils::HashMap;
use ron::Value; use ron::Value;
use serde::de::DeserializeSeed; use serde::de::DeserializeSeed;
@ -17,7 +17,7 @@ pub fn ronstring_to_reflect_component(
let type_string = key.replace("component: ", "").trim().to_string(); let type_string = key.replace("component: ", "").trim().to_string();
let capitalized_type_name = capitalize_first_letter(type_string.as_str()); let capitalized_type_name = capitalize_first_letter(type_string.as_str());
let mut parsed_value: String; let parsed_value: String;
match value.clone() { match value.clone() {
Value::String(str) => { Value::String(str) => {
parsed_value = str; parsed_value = str;

View File

@ -2960,6 +2960,22 @@
"type": "object", "type": "object",
"typeInfo": "Struct" "typeInfo": "Struct"
}, },
"bevy_example::dupe_components::EnumTest": {
"isComponent": true,
"isResource": false,
"oneOf": [
"Metal",
"Wood",
"Rock",
"Cloth",
"Squishy",
"None"
],
"short_name": "EnumTest",
"title": "bevy_example::dupe_components::EnumTest",
"type": "string",
"typeInfo": "Enum"
},
"bevy_example::game::animation::Marker1": { "bevy_example::game::animation::Marker1": {
"additionalProperties": false, "additionalProperties": false,
"isComponent": true, "isComponent": true,

View File

@ -0,0 +1,13 @@
use bevy::prelude::*;
#[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)]
pub enum EnumTest {
Metal,
Wood,
Rock,
Cloth,
Squishy,
#[default]
None,
}

View File

@ -7,6 +7,7 @@ use crate::core::*;
mod game; mod game;
use game::*; use game::*;
mod dupe_components;
mod test_components; mod test_components;
use test_components::*; use test_components::*;

View File

@ -1,3 +1,4 @@
use crate::dupe_components;
use bevy::{ use bevy::{
pbr::{ExtendedMaterial, MaterialExtension}, pbr::{ExtendedMaterial, MaterialExtension},
prelude::*, prelude::*,
@ -164,6 +165,7 @@ impl Plugin for ComponentsTestPlugin {
.register_type::<TupleVec2>() .register_type::<TupleVec2>()
.register_type::<TupleVec3>() .register_type::<TupleVec3>()
.register_type::<EnumTest>() .register_type::<EnumTest>()
.register_type::<dupe_components::EnumTest>()
.register_type::<TupleTestColor>() .register_type::<TupleTestColor>()
.register_type::<TupleVec>() .register_type::<TupleVec>()
.register_type::<Vec<String>>() .register_type::<Vec<String>>()