Added debug information with names and reflect types so that everything can be identified and changed in the editor gui

This commit is contained in:
Franklin 2023-11-08 10:54:22 -04:00
parent 2683d75462
commit 86909e8bcb
22 changed files with 83 additions and 53 deletions

View File

@ -1,8 +1,8 @@
use bevy::prelude::{Component, Quat, Vec3};
use bevy::{prelude::{Component, Quat, Vec3}, reflect::Reflect};
use crate::logic::core::guns::{caliber::Caliber, spray_pattern::FirearmSprayPattern};
#[derive(Component, Clone)]
#[derive(Component, Clone, Reflect)]
pub struct FirearmData {
/// Where the bullets will come out of, and muzzle flash will be spawned out of.
pub firing_point: Vec3,
@ -33,7 +33,7 @@ pub struct FirearmData {
pub scale_factor: f32,
}
#[derive(Component)]
#[derive(Component, Reflect)]
pub struct MagazineData {
pub rounds_shot: usize,
pub max_capacity: usize,

View File

@ -1,7 +1,7 @@
use bevy::prelude::*;
/// Anything that can go in the player's hands.
#[derive(Component, Default, Debug)]
#[derive(Component, Default, Debug, Reflect)]
pub struct HoldableObjectData {
/// Where this object should be placed relative to the hand.
pub held_at: Vec3,
@ -9,5 +9,5 @@ pub struct HoldableObjectData {
pub y_rot: f32,
}
#[derive(Component)]
#[derive(Component, Reflect)]
pub struct InPlayerHands;

View File

@ -1,13 +1,13 @@
use bevy::prelude::Component;
use bevy::{prelude::Component, reflect::Reflect};
use crate::setup::equipment::Equipment;
#[derive(Clone, Default)]
#[derive(Clone, Default, Reflect)]
pub struct PlayerData {
pub equipment: Equipment,
}
#[derive(Component)]
#[derive(Component, Reflect)]
pub struct Player(pub PlayerData);
#[derive(Component)]
#[derive(Component, Reflect)]
pub struct PlayerHand;

View File

@ -1,5 +1,7 @@
use bevy::reflect::Reflect;
#[allow(unused)]
#[derive(Clone)]
#[derive(Clone, Reflect)]
pub enum Caliber {
NATO556,
Parabellum9mm,

View File

@ -4,7 +4,7 @@ use bevy::prelude::*;
use super::{caliber::Caliber, spray_pattern::FirearmSprayPattern};
#[allow(unused)]
#[derive(Component, PartialEq, Eq, PartialOrd, Ord, Clone)]
#[derive(Component, PartialEq, Eq, PartialOrd, Ord, Clone, Reflect)]
pub enum Firearm {
M4A1,
Glock17,

View File

@ -1,6 +1,8 @@
use bevy::reflect::Reflect;
#[derive(Clone)]
#[derive(Clone, Reflect)]
pub struct FirearmSprayPattern {
pub vertical: Vec<f32>,
pub horizontal: Vec<f32>,

View File

@ -9,7 +9,7 @@ use crate::{
use super::{player_movement::PlayerLinearXZState, player_values_state::PlayerValuesState};
/// Mouse sensitivity and movement speed
#[derive(Resource)]
#[derive(Resource, Reflect)]
pub struct MouseMovementSettings {
pub sensitivity: f32,
pub speed: f32,

View File

@ -5,7 +5,7 @@ use crate::comps::core::markers::player::Player;
use super::player_values_state::PlayerValuesState;
#[derive(Component, Debug)]
#[derive(Component, Debug, Reflect)]
pub enum PlayerLinearYState {
Grounded(f64),
Jumping,
@ -34,7 +34,7 @@ impl PlayerLinearYState {
}
}
#[derive(Component, Default, Debug)]
#[derive(Component, Default, Debug, Reflect)]
pub enum PlayerLinearXZState {
Crouched(f32),
Walking,
@ -74,7 +74,7 @@ impl PlayerLinearXZState {
}
/// Holds all the possible ways a player can be attempting to move at any time.
#[derive(Default)]
#[derive(Default, Reflect)]
pub struct PlayerMovementInput {
/// Means the player is pressing the space bar key. (JUMP)
/// ## DOES NOT MEAN the player should gain upwards velocity

View File

@ -1,7 +1,6 @@
use bevy::prelude::*;
use bevy_inspector_egui::{DefaultInspectorConfigPlugin, bevy_egui::{self}};
use bevy_rapier3d::prelude::*;
use logic::core::{guns::player_firing::PlayerFiringInfo, player::player_values_state::PlayerValuesState};
use scenes::scene1;
use ui::{game::plugin::MainGameUIPlugin, editor::plugin::MainEditorUiPlugin};
@ -31,9 +30,7 @@ fn setup_plugins(application: &mut App) {
.add_plugins(bevy_egui::EguiPlugin)
//.add_plugins(WorldInspectorPlugin::new())
.add_plugins(MainGameUIPlugin)
.add_plugins(MainEditorUiPlugin)
.register_type::<PlayerFiringInfo>()
.register_type::<PlayerValuesState>();
.add_plugins(MainEditorUiPlugin);
}
fn load(application: &mut App) {

View File

@ -7,7 +7,7 @@ pub fn spawn_ground(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands
.spawn(Collider::cuboid(50.0, 0.1, 50.0))
.spawn((Collider::cuboid(50.0, 0.1, 50.0), Name::new("Ground")))
.insert(TransformBundle::from(Transform::from_xyz(0.0, -2.0, 0.0)))
.insert(RigidBody::Fixed)
.insert(PbrBundle {

View File

@ -1,7 +1,7 @@
use bevy::prelude::*;
pub fn setup_lighting(mut commands: Commands) {
commands.spawn(SpotLightBundle {
commands.spawn((SpotLightBundle {
spot_light: SpotLight {
color: Color::WHITE,
intensity: 3000.0,
@ -12,5 +12,5 @@ pub fn setup_lighting(mut commands: Commands) {
transform: Transform::from_xyz(20.0, 20.0, 20.0).looking_at(Vec3::ZERO, Vec3::Y),
visibility: Visibility::Visible,
..Default::default()
});
}, Name::new("LightSource")));
}

View File

@ -12,7 +12,7 @@ pub fn spawn_obstacles(
let box_3_mesh = shape::Box::new(3.0, 7.0, 3.0).into();
let box_4_mesh = shape::Box::new(3.0, 7.0, 3.0).into();
commands
.spawn(Collider::from_bevy_mesh(&box_1_mesh, &Default::default()).unwrap())
.spawn((Collider::from_bevy_mesh(&box_1_mesh, &Default::default()).unwrap(), Name::new("Obstacle 1")))
.insert(RigidBody::Fixed)
.insert(PbrBundle {
mesh: meshes.add(box_1_mesh.into()),
@ -26,7 +26,7 @@ pub fn spawn_obstacles(
});
commands
.spawn(Collider::from_bevy_mesh(&box_2_mesh, &Default::default()).unwrap())
.spawn((Collider::from_bevy_mesh(&box_2_mesh, &Default::default()).unwrap(), Name::new("Obstacle 2")))
.insert(RigidBody::Fixed)
.insert(PbrBundle {
mesh: meshes.add(box_2_mesh.into()),
@ -40,7 +40,7 @@ pub fn spawn_obstacles(
});
commands
.spawn(Collider::from_bevy_mesh(&box_3_mesh, &Default::default()).unwrap())
.spawn((Collider::from_bevy_mesh(&box_3_mesh, &Default::default()).unwrap(), Name::new("Obstacle 3")))
.insert(RigidBody::Fixed)
.insert(PbrBundle {
mesh: meshes.add(box_3_mesh.into()),
@ -54,7 +54,7 @@ pub fn spawn_obstacles(
});
commands
.spawn(Collider::from_bevy_mesh(&box_4_mesh, &Default::default()).unwrap())
.spawn((Collider::from_bevy_mesh(&box_4_mesh, &Default::default()).unwrap(), Name::new("Obstacle 4")))
.insert(RigidBody::Fixed)
.insert(PbrBundle {
mesh: meshes.add(box_4_mesh.into()),

View File

@ -13,7 +13,7 @@ use crate::comps::core::markers::camera::MainCamera;
pub const CUBEMAPS: &[(&str, CompressedImageFormats)] =
&[("skybox/skybox.png", CompressedImageFormats::NONE)];
#[derive(Resource)]
#[derive(Resource, Reflect)]
pub struct Cubemap {
pub is_loaded: bool,
pub image_handle: Handle<Image>,

View File

@ -4,11 +4,12 @@ use crate::logic::core::guns::firearm::Firearm;
use super::{assets::GltfAssets, load_state::GameLoadState};
#[derive(Resource, Default)]
#[derive(Resource, Default, Reflect)]
pub struct AllFirearmAnimations {
pub animations: Vec<FirearmAnimations>,
}
#[derive(Reflect)]
pub struct FirearmAnimations {
pub firearm: Firearm,
pub reload_magazine: Handle<AnimationClip>,

View File

@ -4,16 +4,17 @@ use crate::{logic::core::guns::firearm::Firearm, scenes::scene1::skybox::{CUBEMA
use super::load_state::GameLoadState;
#[derive(PartialEq, Eq, PartialOrd, Ord)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Reflect)]
pub enum GltfAssetType {
Firearm(Firearm),
#[allow(unused)]
Enemy,
}
#[derive(Resource)]
#[derive(Resource, Reflect)]
pub struct GltfAssets {
pub assets: Vec<GltfAsset>
}
#[derive(Reflect)]
pub struct GltfAsset {
pub asset_type: GltfAssetType,
pub asset: Handle<Gltf>,

View File

@ -9,7 +9,7 @@ use super::assets::{GltfAssets, GltfAssetType};
#[derive(Event)]
pub struct EquipmentChangeEvent(pub Equipment);
/// Foundation for inventory System.
#[derive(Component, Clone, Default)]
#[derive(Component, Clone, Default, Reflect)]
pub struct Equipment {
pub primary_firearm: Option<Firearm>,
}
@ -75,7 +75,7 @@ fn spawn_firearm_on_player_hands(
firearm.holdable_object_data(),
MagazineData { rounds_shot: 0, max_capacity: firearm_data.max_capacity },
InPlayerHands,
Name::new("Firearm")
))
.id();

View File

@ -1,6 +1,6 @@
use bevy::prelude::*;
#[derive(Resource, Default)]
#[derive(Resource, Default, Reflect)]
pub struct GameLoadState {
pub assets_loaded: bool,
pub animations_loaded: bool,

View File

@ -3,7 +3,7 @@ use bevy::prelude::*;
use super::spawners::{player::player_spawner, firearm::firearm_spawner};
/// Where some Bundle T will replace this.
#[derive(Component)]
#[derive(Component, Reflect)]
pub struct SpawnPoint<T: Bundle> {
pub at: Transform,
pub what: T

View File

@ -27,7 +27,7 @@ pub fn player_spawner(
for (player_spawn_point_entity, player_spawn_point) in player_sp_query.iter() {
// Spawn hand
let player_hand = commands
.spawn(PlayerHand)
.spawn((PlayerHand, Name::new("Player Hand")))
.insert(TransformBundle::from(Transform::from_xyz(0.6, -0.45, -20.0)))
.insert(VisibilityBundle {
visibility: Visibility::Inherited,
@ -52,7 +52,7 @@ pub fn player_spawner(
// Spawn player
commands
.spawn(Player(PlayerData::default()))
.spawn((Player(PlayerData::default()), Name::new("Player")))
// Physics
.insert(RigidBody::Dynamic)
.insert(GravityScale(player_values_state.player_gravity_scale))

View File

@ -1,11 +1,37 @@
use bevy::prelude::*;
use crate::{logic::core::{guns::{player_firing::PlayerFiringInfo, caliber::Caliber, firearm::Firearm, spray_pattern::FirearmSprayPattern}, player::{player_values_state::PlayerValuesState, camera_player_sync::MouseMovementSettings, player_movement::{PlayerLinearYState, PlayerLinearXZState, PlayerMovementInput}}}, comps::core::markers::{firearm::{FirearmData, MagazineData}, holdable::{HoldableObjectData, InPlayerHands}, player::{PlayerData, Player, PlayerHand}}, scenes::scene1::skybox::Cubemap, setup::{animations::{AllFirearmAnimations, FirearmAnimations}, assets::{GltfAssetType, GltfAssets}, equipment::Equipment, load_state::GameLoadState}};
use super::{panels::editor_ui, state::EditorUiState};
pub struct MainEditorUiPlugin;
impl Plugin for MainEditorUiPlugin {
fn build(&self, app: &mut App) {
app
.register_type::<PlayerFiringInfo>()
.register_type::<PlayerValuesState>()
.register_type::<FirearmData>()
.register_type::<MagazineData>()
.register_type::<HoldableObjectData>()
.register_type::<InPlayerHands>()
.register_type::<PlayerData>()
.register_type::<Player>()
.register_type::<PlayerHand>()
.register_type::<Caliber>()
.register_type::<Firearm>()
.register_type::<FirearmSprayPattern>()
.register_type::<MouseMovementSettings>()
.register_type::<PlayerLinearYState>()
.register_type::<PlayerLinearXZState>()
.register_type::<PlayerMovementInput>()
.register_type::<Cubemap>()
.register_type::<AllFirearmAnimations>()
.register_type::<FirearmAnimations>()
.register_type::<GltfAssetType>()
.register_type::<GltfAssets>()
.register_type::<Equipment>()
.register_type::<GameLoadState>();
app.insert_resource(EditorUiState::new());
app.add_systems(Update, editor_ui);
}

View File

@ -2,7 +2,7 @@ use std::time::Duration;
use bevy::prelude::*;
#[derive(Component)]
#[derive(Component, Reflect)]
pub struct FpsCounterMarker {
pub timer: Timer,
pub frames_elapsed: u32,
@ -14,7 +14,7 @@ impl FpsCounterMarker {
}
pub fn setup_fps_counter(mut commands: Commands, ) {
commands.spawn(TextBundle {
commands.spawn((TextBundle {
text: Text::from_section("FPS: 0.0", TextStyle {
font_size: 18.0, ..Default::default()
}).with_alignment(TextAlignment::Center),
@ -25,7 +25,7 @@ pub fn setup_fps_counter(mut commands: Commands, ) {
..Default::default()
},
..Default::default()
})
}, Name::new("Fps Counter")))
.insert(FpsCounterMarker::new());
}

View File

@ -12,7 +12,7 @@ pub enum SettingsScreenActions {
}
pub fn setup_settings_screen(mut commands: Commands) {
commands.spawn(
commands.spawn((
NodeBundle {
style: Style {
display: Display::Flex,
@ -27,30 +27,30 @@ pub fn setup_settings_screen(mut commands: Commands) {
background_color: BackgroundColor(Color::rgba(0.0, 0.0, 0.0, 0.9)),
focus_policy: FocusPolicy::Block,
..Default::default()
}
}, Name::new("Settings Menu"))
)
.insert(SettingsScreenMarker)
.with_children(|parent| {
// RESUME BUTTON
parent.spawn(
parent.spawn((
ButtonBundle {
style: Style {
..Default::default()
},
background_color: BackgroundColor(Color::NONE),
//focus_policy: FocusPolicy::Block,
..Default::default()
}
)
},
Name::new("Resume Button")
))
.insert(SettingsScreenActions::Resume)
.with_children(|parent| {
parent.spawn(TextBundle {
parent.spawn((TextBundle {
text: Text::from_section("Resume", TextStyle { font_size: 32.0, ..Default::default() }),
..Default::default()
});
}, Name::new("Resume Button Text")));
});
// QUIT BUTTON
parent.spawn(
parent.spawn((
ButtonBundle {
style: Style {
..Default::default()
@ -58,14 +58,15 @@ pub fn setup_settings_screen(mut commands: Commands) {
background_color: BackgroundColor(Color::NONE),
//focus_policy: FocusPolicy::Block,
..Default::default()
}
)
},
Name::new("Quit Button")
))
.insert(SettingsScreenActions::Quit)
.with_children(|parent| {
parent.spawn(TextBundle {
parent.spawn((TextBundle {
text: Text::from_section("Quit", TextStyle { font_size: 32.0, ..Default::default() }),
..Default::default()
});
}, Name::new("Quit Button text")));
});
// END BUTTONS
});