chore(examples): cleanup

This commit is contained in:
kaosat.dev 2024-07-22 00:29:17 +02:00
parent 382759d71f
commit a951d82330
5 changed files with 22 additions and 36 deletions

View File

@ -1,7 +1,11 @@
use std::time::Duration; use std::time::Duration;
use bevy::prelude::*; use bevy::prelude::*;
use blenvy::{AddToGameWorld, BlenvyPlugin, BluePrintBundle, BlueprintAnimationPlayerLink, BlueprintAnimations, BlueprintInfo, DynamicBlueprintInstance, GameWorldTag, HideUntilReady, SpawnBlueprint}; use blenvy::{
AddToGameWorld, BlenvyPlugin, BluePrintBundle, BlueprintAnimationPlayerLink,
BlueprintAnimations, BlueprintInfo, DynamicBlueprintInstance, GameWorldTag, HideUntilReady,
SpawnBlueprint,
};
use rand::Rng; use rand::Rng;
mod component_examples; mod component_examples;
@ -22,31 +26,24 @@ pub struct Fox;
/// Demo marker component /// Demo marker component
pub struct Robot; pub struct Robot;
fn main() { fn main() {
App::new() App::new()
.add_plugins(( .add_plugins((
DefaultPlugins.set(AssetPlugin::default()), DefaultPlugins.set(AssetPlugin::default()),
// our custom plugins // our custom plugins
ComponentsExamplesPlugin, // Showcases different type of components /structs ComponentsExamplesPlugin, // Showcases different type of components /structs
BlenvyPlugin::default() BlenvyPlugin::default(),
)) ))
.register_type::<Player>() .register_type::<Player>()
.register_type::<Fox>() .register_type::<Fox>()
.register_type::<Robot>() .register_type::<Robot>()
.add_systems(Startup, setup_game) .add_systems(Startup, setup_game)
.add_systems(Update, .add_systems(Update, (animation_control,))
(animation_control,)
)
.run(); .run();
} }
// this is how you setup & spawn a level from a blueprint // this is how you setup & spawn a level from a blueprint
fn setup_game( fn setup_game(mut commands: Commands) {
mut commands: Commands,
) {
// here we actually spawn our game world/level // here we actually spawn our game world/level
commands.spawn(( commands.spawn((
BlueprintInfo::from_path("levels/World.glb"), // all we need is a Blueprint info... BlueprintInfo::from_path("levels/World.glb"), // all we need is a Blueprint info...
@ -56,7 +53,6 @@ fn setup_game(
)); ));
} }
////////////////////////////////// //////////////////////////////////
pub fn animation_control( pub fn animation_control(
@ -94,7 +90,7 @@ pub fn animation_control(
if keycode.just_pressed(KeyCode::KeyW) { if keycode.just_pressed(KeyCode::KeyW) {
for (link, animations) in animated_foxes.iter() { for (link, animations) in animated_foxes.iter() {
let (mut animation_player, mut animation_transitions) = let (mut animation_player, mut animation_transitions) =
animation_players.get_mut(link.0).unwrap(); animation_players.get_mut(link.0).unwrap();
let anim_name = "Walk"; let anim_name = "Walk";
animation_transitions animation_transitions
@ -114,7 +110,7 @@ pub fn animation_control(
if keycode.just_pressed(KeyCode::KeyX) { if keycode.just_pressed(KeyCode::KeyX) {
for (link, animations) in animated_foxes.iter() { for (link, animations) in animated_foxes.iter() {
let (mut animation_player, mut animation_transitions) = let (mut animation_player, mut animation_transitions) =
animation_players.get_mut(link.0).unwrap(); animation_players.get_mut(link.0).unwrap();
let anim_name = "Run"; let anim_name = "Run";
animation_transitions animation_transitions
@ -134,7 +130,7 @@ pub fn animation_control(
if keycode.just_pressed(KeyCode::KeyC) { if keycode.just_pressed(KeyCode::KeyC) {
for (link, animations) in animated_foxes.iter() { for (link, animations) in animated_foxes.iter() {
let (mut animation_player, mut animation_transitions) = let (mut animation_player, mut animation_transitions) =
animation_players.get_mut(link.0).unwrap(); animation_players.get_mut(link.0).unwrap();
let anim_name = "Survey"; let anim_name = "Survey";
animation_transitions animation_transitions

View File

@ -1,5 +1,8 @@
use bevy::prelude::*; use bevy::prelude::*;
use blenvy::{AddToGameWorld, BlenvyPlugin, BluePrintBundle, BlueprintInfo, DynamicBlueprintInstance, GameWorldTag, HideUntilReady, SpawnBlueprint}; use blenvy::{
AddToGameWorld, BlenvyPlugin, BluePrintBundle, BlueprintInfo, DynamicBlueprintInstance,
GameWorldTag, HideUntilReady, SpawnBlueprint,
};
use rand::Rng; use rand::Rng;
mod component_examples; mod component_examples;
@ -11,20 +14,15 @@ fn main() {
DefaultPlugins.set(AssetPlugin::default()), DefaultPlugins.set(AssetPlugin::default()),
// our custom plugins // our custom plugins
ComponentsExamplesPlugin, // Showcases different type of components /structs ComponentsExamplesPlugin, // Showcases different type of components /structs
BlenvyPlugin::default() BlenvyPlugin::default(),
)) ))
.add_systems(Startup, setup_game) .add_systems(Startup, setup_game)
.add_systems(Update, spawn_blueprint_instance) .add_systems(Update, spawn_blueprint_instance)
.run(); .run();
} }
// this is how you setup & spawn a level from a blueprint // this is how you setup & spawn a level from a blueprint
fn setup_game( fn setup_game(mut commands: Commands) {
mut commands: Commands,
) {
// here we spawn our game world/level, which is also a blueprint ! // here we spawn our game world/level, which is also a blueprint !
commands.spawn(( commands.spawn((
BlueprintInfo::from_path("levels/World.glb"), // all we need is a Blueprint info... BlueprintInfo::from_path("levels/World.glb"), // all we need is a Blueprint info...
@ -34,7 +32,6 @@ fn setup_game(
)); ));
} }
// you can also spawn blueprint instances at runtime // you can also spawn blueprint instances at runtime
pub fn spawn_blueprint_instance( pub fn spawn_blueprint_instance(
keycode: Res<ButtonInput<KeyCode>>, keycode: Res<ButtonInput<KeyCode>>,
@ -67,10 +64,8 @@ pub fn spawn_blueprint_instance(
HideUntilReady, HideUntilReady,
AddToGameWorld, AddToGameWorld,
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)), TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)),
)) ))
.id(); .id();
// commands.entity(world).add_child(new_entity); // commands.entity(world).add_child(new_entity);
} }
} }

View File

@ -10,18 +10,13 @@ fn main() {
DefaultPlugins.set(AssetPlugin::default()), DefaultPlugins.set(AssetPlugin::default()),
// our custom plugins // our custom plugins
ComponentsExamplesPlugin, // Showcases different type of components /structs ComponentsExamplesPlugin, // Showcases different type of components /structs
BlenvyPlugin::default() BlenvyPlugin::default(),
)) ))
.add_systems(Startup, setup_game) .add_systems(Startup, setup_game)
.run(); .run();
} }
fn setup_game(mut commands: Commands) {
fn setup_game(
mut commands: Commands,
) {
// here we actually spawn our game world/level // here we actually spawn our game world/level
commands.spawn(( commands.spawn((
BlueprintInfo::from_path("levels/World.glb"), // all we need is a Blueprint info... BlueprintInfo::from_path("levels/World.glb"), // all we need is a Blueprint info...

View File

@ -1,6 +1,6 @@
use bevy::prelude::*; use bevy::prelude::*;
use blenvy::{BluePrintBundle, BlueprintName, GameWorldTag};
use bevy_gltf_worlflow_examples_common_rapier::{assets::GameAssets, GameState, InAppRunning}; use bevy_gltf_worlflow_examples_common_rapier::{assets::GameAssets, GameState, InAppRunning};
use blenvy::{BluePrintBundle, BlueprintName, GameWorldTag};
use bevy_rapier3d::prelude::Velocity; use bevy_rapier3d::prelude::Velocity;
use rand::Rng; use rand::Rng;

View File

@ -1,9 +1,9 @@
use bevy::{gltf::Gltf, prelude::*}; use bevy::{gltf::Gltf, prelude::*};
use blenvy::GameWorldTag;
use bevy_gltf_worlflow_examples_common_rapier::{ use bevy_gltf_worlflow_examples_common_rapier::{
assets::GameAssets, GameState, InAppRunning, Player, assets::GameAssets, GameState, InAppRunning, Player,
}; };
use bevy_rapier3d::prelude::*; use bevy_rapier3d::prelude::*;
use blenvy::GameWorldTag;
#[derive(Component, Reflect, Default, Debug)] #[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)] #[reflect(Component)]