Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity Inspector | First Iteration #81

Closed
wants to merge 56 commits into from
Closed

Conversation

LiamGallagher737
Copy link
Owner

@LiamGallagher737 LiamGallagher737 commented Jul 17, 2024

Things to keep in mind

  • Search
  • Pagination if there are too many entities, keep rendering fast
  • Use name component if possible, fallback to Entity (3v1) or similar
  • This is a first iteration - keep it simple - read only values for now

@LiamGallagher737 LiamGallagher737 linked an issue Jul 17, 2024 that may be closed by this pull request
@LiamGallagher737 LiamGallagher737 changed the title Entity Inspector Entity Inspector | First Iteration Jul 17, 2024
Copy link

cloudflare-workers-and-pages bot commented Jul 17, 2024

Deploying learnbevy with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9e5c637
Status:🚫  Build failed.

View logs

@LiamGallagher737
Copy link
Owner Author

Could use bevyengine/bevy#13563. Likely not in its current state as it uses a http server but I could build off of it or recreate something similar but for JS export values.

@LiamGallagher737
Copy link
Owner Author

LiamGallagher737 commented Sep 28, 2024

Useful playground code

use bevy::prelude::*;
use bevy::log::LogPlugin;

fn main() {
    App::new()
        .insert_resource(ClearColor(Color::srgb(1.0, 0.0, 0.0)))
        .add_plugins(DefaultPlugins.set(LogPlugin {
            filter: "info,wgpu_core=warn,wgpu_hal=warn,mygame=debug,extra_app_code=info".into(),
            ..default()
        }))
        .add_systems(Startup, setup)
        .add_systems(Update, change_clear_color)
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn((Camera2dBundle::default(), Name::new("Cool Camera")));
    info!("Here is some info");
    warn!("Here is a warning");
    error!("Here is an error");
}

fn change_clear_color(input: Res<ButtonInput<KeyCode>>, mut clear_color: ResMut<ClearColor>, mut state: Local<bool>) {
    if input.just_pressed(KeyCode::Space) {
        info!("Changing color");
        *state = !*state;
        if *state {
            clear_color.0 = Color::srgb(0.0, 1.0, 0.0);
        } else {
            clear_color.0 = Color::srgb(0.0, 0.0, 1.0);
        }
    }
}

@LiamGallagher737
Copy link
Owner Author

LiamGallagher737 commented Sep 29, 2024

Another code snippet for testing

use bevy::prelude::*;

fn main() {
    App::new()
        .insert_resource(ClearColor(Color::srgb(1.0, 0.0, 0.0)))
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .add_systems(Update, change_clear_color)
        .register_type::<MyComp>()
        .register_type::<MyObj>()
        .run();
}

#[derive(Component, Reflect)]
#[reflect(Component)]
struct MyComp {
    string: String,
    number: i32,
    boolean: bool,
    obj: MyObj,
    arr: Vec<i32>,
}

#[derive(Reflect)]
struct MyObj {
    str2: String,
    num2: f32,
}

fn setup(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());
    commands.spawn(MyComp {
        string: "Hello".to_string(),
        number: 123,
        boolean: true,
        obj: MyObj {
            str2: "World".to_string(),
            num2: 321.0,
        },
        arr: vec![5, 10, 20, 40, 80, 160],
    });
    info!("Here is some info");
    warn!("Here is a warning");
    error!("Here is an error");
}

fn change_clear_color(input: Res<ButtonInput<KeyCode>>, mut clear_color: ResMut<ClearColor>, mut state: Local<bool>) {
    if input.just_pressed(KeyCode::Space) {
        info!("Changing color");
        *state = !*state;
        if *state {
            clear_color.0 = Color::srgb(0.0, 1.0, 0.0);
        } else {
            clear_color.0 = Color::srgb(0.0, 0.0, 1.0);
        }
    }
}

@LiamGallagher737
Copy link
Owner Author

Anotha one

//! A Bevy app that you can connect to with the BRP and edit.

use bevy::{
    input::common_conditions::input_just_pressed,
    prelude::*,
    time::common_conditions::on_timer,
};
use std::time::Duration;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .add_systems(Update, remove.run_if(input_just_pressed(KeyCode::Space)))
        .add_systems(Update, move_cube.run_if(on_timer(Duration::from_secs(1))))
        .register_type::<Cube>()
        .run();
}

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    // circular base
    commands.spawn((
        Mesh3d(meshes.add(Circle::new(4.0))),
        MeshMaterial3d(materials.add(Color::WHITE)),
        Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
    ));

    // cube
    commands.spawn((
        Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
        MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
        Transform::from_xyz(0.0, 0.5, 0.0),
        Cube(1.0),
    ));

    // light
    commands.spawn((
        PointLight {
            shadows_enabled: true,
            ..default()
        },
        Transform::from_xyz(4.0, 8.0, 4.0),
    ));

    // camera
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
        ..default()
    });
}

fn move_cube(mut query: Query<&mut Transform, With<Cube>>) {
    for mut transform in &mut query {
        if transform.translation.y < 1.0 {
            transform.translation.y = 1.5;
        } else {
            transform.translation.y = 0.5;
        };
    }
}

fn remove(mut commands: Commands, query: Query<Entity, With<Cube>>) {
    commands.entity(query.single()).remove::<Cube>();
}

#[derive(Component, Reflect)]
#[reflect(Component)]
struct Cube(f32);

@LiamGallagher737
Copy link
Owner Author

LiamGallagher737 commented Oct 4, 2024

For testing perf

use bevy::{
    input::common_conditions::input_just_pressed,
    prelude::*,
};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .add_systems(Update, remove.run_if(input_just_pressed(KeyCode::Space)))
        .add_systems(Update, move_cube)
        .register_type::<Cube>()
        .run();
}

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    // circular base
    commands.spawn((
        Mesh3d(meshes.add(Circle::new(4.0))),
        MeshMaterial3d(materials.add(Color::WHITE)),
        Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
    ));

    // cube
    commands.spawn((
        Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
        MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
        Transform::from_xyz(0.0, 0.5, 0.0),
        Cube(1.0),
    ));

    // light
    commands.spawn((
        PointLight {
            shadows_enabled: true,
            ..default()
        },
        Transform::from_xyz(4.0, 8.0, 4.0),
    ));

    // camera
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
        ..default()
    });
}

fn move_cube(mut query: Query<&mut Transform, With<Cube>>, time: Res<Time>) {
    for mut transform in &mut query {
        transform.translation.y = -time.elapsed_seconds().cos() + 1.5;
    }
}

fn remove(mut commands: Commands, query: Query<Entity, With<Cube>>) {
    commands.entity(query.single()).remove::<Cube>();
}

#[derive(Component, Reflect)]
#[reflect(Component)]
struct Cube(f32);

@LiamGallagher737
Copy link
Owner Author

Going to split this out in to multiple PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Entity Inspector
1 participant