From fa4386a1850159f744c6e5a1c98b52629f578072 Mon Sep 17 00:00:00 2001 From: "kaosat.dev" Date: Thu, 14 Mar 2024 08:23:25 +0100 Subject: [PATCH] chore(): cleanups, clippy etc --- crates/bevy_gltf_blueprints/src/materials.rs | 23 ++++++++++--------- .../src/spawn_from_blueprints.rs | 17 ++++++++++---- testing/bevy_example/src/game/in_game.rs | 6 ++--- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/crates/bevy_gltf_blueprints/src/materials.rs b/crates/bevy_gltf_blueprints/src/materials.rs index 1c29dd8..030ee90 100644 --- a/crates/bevy_gltf_blueprints/src/materials.rs +++ b/crates/bevy_gltf_blueprints/src/materials.rs @@ -1,7 +1,7 @@ use std::path::Path; use bevy::{ - asset::{AssetId, AssetServer, Assets, Handle}, + asset::{AssetServer, Assets, Handle}, ecs::{ component::Component, entity::Entity, @@ -11,7 +11,7 @@ use bevy::{ }, gltf::Gltf, hierarchy::{Children, Parent}, - log::{debug, info}, + log::debug, pbr::StandardMaterial, reflect::Reflect, render::mesh::Mesh, @@ -66,20 +66,21 @@ pub(crate) fn materials_inject( } else { let material_file_handle: Handle = asset_server.load(materials_path.clone()); let material_file_id = material_file_handle.id(); - let mut asset_infos: Vec> = vec![]; + let asset_infos: Vec> = vec![ + AssetLoadTracker { + name: material_full_path, + id: material_file_id, + loaded: false, + handle: material_file_handle.clone(), + } + ]; - asset_infos.push(AssetLoadTracker { - name: material_full_path, - id: material_file_id, - loaded: false, - handle: material_file_handle.clone(), - }); commands .entity(entity) .insert(AssetsToLoad { all_loaded: false, - asset_infos: asset_infos, - progress: 0.0, //..Default::default() + asset_infos, + ..Default::default() }) .insert(BlueprintMaterialAssetsNotLoaded); /**/ diff --git a/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs b/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs index 35098d9..cf679b7 100644 --- a/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs +++ b/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs @@ -52,17 +52,24 @@ pub struct BlueprintsList(pub HashMap>); #[derive(Default, Debug)] pub(crate) struct AssetLoadTracker { + #[allow(dead_code)] pub name: String, pub id: AssetId, pub loaded: bool, + #[allow(dead_code)] pub handle: Handle, } -#[derive(Component, Default, Debug)] +#[derive(Component, Debug)] pub(crate) struct AssetsToLoad { pub all_loaded: bool, pub asset_infos: Vec>, pub progress: f32, } +impl Default for AssetsToLoad { + fn default() -> Self { + Self { all_loaded: Default::default(), asset_infos: Default::default(), progress: Default::default() } + } +} /// flag component #[derive(Component)] @@ -118,17 +125,17 @@ pub(crate) fn prepare_blueprints( id: model_id, loaded: false, handle: model_handle.clone(), - }) + }); } } // if not all assets are already loaded, inject a component to signal that we need them to be loaded - if asset_infos.len() > 0 { + if !asset_infos.is_empty() { commands .entity(entity) .insert(AssetsToLoad { all_loaded: false, - asset_infos: asset_infos, - progress: 0.0, //..Default::default() + asset_infos, + ..Default::default() }) .insert(BlueprintAssetsNotLoaded); } else { diff --git a/testing/bevy_example/src/game/in_game.rs b/testing/bevy_example/src/game/in_game.rs index ca9f8d1..4873f4e 100644 --- a/testing/bevy_example/src/game/in_game.rs +++ b/testing/bevy_example/src/game/in_game.rs @@ -1,8 +1,8 @@ -use bevy::{prelude::*, utils::hashbrown::HashMap}; +use bevy::prelude::*; use bevy_gltf_blueprints::{ - BluePrintBundle, BlueprintName, BlueprintsList, GameWorldTag, Library, SpawnHere, + BluePrintBundle, BlueprintName, GameWorldTag, }; -use bevy_gltf_worlflow_examples_common_rapier::{assets::GameAssets, GameState, InAppRunning}; +use bevy_gltf_worlflow_examples_common_rapier::{GameState, InAppRunning}; use bevy_rapier3d::prelude::Velocity; use rand::Rng;