From 86909e8bcba54e682f911a53797a3454500e90ca Mon Sep 17 00:00:00 2001 From: Franklin Date: Wed, 8 Nov 2023 10:54:22 -0400 Subject: [PATCH] Added debug information with names and reflect types so that everything can be identified and changed in the editor gui --- src/comps/core/markers/firearm.rs | 6 ++--- src/comps/core/markers/holdable.rs | 4 +-- src/comps/core/markers/player.rs | 8 +++--- src/logic/core/guns/caliber.rs | 4 ++- src/logic/core/guns/firearm.rs | 2 +- src/logic/core/guns/spray_pattern.rs | 4 ++- src/logic/core/player/camera_player_sync.rs | 2 +- src/logic/core/player/player_movement.rs | 6 ++--- src/main.rs | 5 +--- src/scenes/scene1/ground.rs | 2 +- src/scenes/scene1/lighting.rs | 4 +-- src/scenes/scene1/obstacles.rs | 8 +++--- src/scenes/scene1/skybox.rs | 2 +- src/setup/animations.rs | 3 ++- src/setup/assets.rs | 5 ++-- src/setup/equipment.rs | 4 +-- src/setup/load_state.rs | 2 +- src/setup/spawn.rs | 2 +- src/setup/spawners/player.rs | 4 +-- src/ui/editor/plugin.rs | 26 ++++++++++++++++++++ src/ui/game/fps_counter.rs | 6 ++--- src/ui/game/settings_screen.rs | 27 +++++++++++---------- 22 files changed, 83 insertions(+), 53 deletions(-) diff --git a/src/comps/core/markers/firearm.rs b/src/comps/core/markers/firearm.rs index a6c2378..b00302a 100644 --- a/src/comps/core/markers/firearm.rs +++ b/src/comps/core/markers/firearm.rs @@ -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, diff --git a/src/comps/core/markers/holdable.rs b/src/comps/core/markers/holdable.rs index c8cbed2..009b3c4 100644 --- a/src/comps/core/markers/holdable.rs +++ b/src/comps/core/markers/holdable.rs @@ -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; diff --git a/src/comps/core/markers/player.rs b/src/comps/core/markers/player.rs index 461d7df..d44c8f7 100644 --- a/src/comps/core/markers/player.rs +++ b/src/comps/core/markers/player.rs @@ -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; \ No newline at end of file diff --git a/src/logic/core/guns/caliber.rs b/src/logic/core/guns/caliber.rs index 9dc6241..9f1ed04 100644 --- a/src/logic/core/guns/caliber.rs +++ b/src/logic/core/guns/caliber.rs @@ -1,5 +1,7 @@ +use bevy::reflect::Reflect; + #[allow(unused)] -#[derive(Clone)] +#[derive(Clone, Reflect)] pub enum Caliber { NATO556, Parabellum9mm, diff --git a/src/logic/core/guns/firearm.rs b/src/logic/core/guns/firearm.rs index f8288f0..d29209c 100644 --- a/src/logic/core/guns/firearm.rs +++ b/src/logic/core/guns/firearm.rs @@ -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, diff --git a/src/logic/core/guns/spray_pattern.rs b/src/logic/core/guns/spray_pattern.rs index 377b3bc..82d5e55 100644 --- a/src/logic/core/guns/spray_pattern.rs +++ b/src/logic/core/guns/spray_pattern.rs @@ -1,6 +1,8 @@ +use bevy::reflect::Reflect; -#[derive(Clone)] + +#[derive(Clone, Reflect)] pub struct FirearmSprayPattern { pub vertical: Vec, pub horizontal: Vec, diff --git a/src/logic/core/player/camera_player_sync.rs b/src/logic/core/player/camera_player_sync.rs index 266cd9d..fd8f48f 100644 --- a/src/logic/core/player/camera_player_sync.rs +++ b/src/logic/core/player/camera_player_sync.rs @@ -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, diff --git a/src/logic/core/player/player_movement.rs b/src/logic/core/player/player_movement.rs index 55c5db8..94d3674 100644 --- a/src/logic/core/player/player_movement.rs +++ b/src/logic/core/player/player_movement.rs @@ -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 diff --git a/src/main.rs b/src/main.rs index e18d5c3..6dbd515 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::() - .register_type::(); + .add_plugins(MainEditorUiPlugin); } fn load(application: &mut App) { diff --git a/src/scenes/scene1/ground.rs b/src/scenes/scene1/ground.rs index dd76881..a1e4f0f 100644 --- a/src/scenes/scene1/ground.rs +++ b/src/scenes/scene1/ground.rs @@ -7,7 +7,7 @@ pub fn spawn_ground( mut materials: ResMut>, ) { 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 { diff --git a/src/scenes/scene1/lighting.rs b/src/scenes/scene1/lighting.rs index 761249e..b9d585f 100644 --- a/src/scenes/scene1/lighting.rs +++ b/src/scenes/scene1/lighting.rs @@ -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"))); } diff --git a/src/scenes/scene1/obstacles.rs b/src/scenes/scene1/obstacles.rs index 83d07e5..a36ca29 100644 --- a/src/scenes/scene1/obstacles.rs +++ b/src/scenes/scene1/obstacles.rs @@ -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()), diff --git a/src/scenes/scene1/skybox.rs b/src/scenes/scene1/skybox.rs index 9fefb92..52ccd95 100644 --- a/src/scenes/scene1/skybox.rs +++ b/src/scenes/scene1/skybox.rs @@ -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, diff --git a/src/setup/animations.rs b/src/setup/animations.rs index 4914886..b1f1a01 100644 --- a/src/setup/animations.rs +++ b/src/setup/animations.rs @@ -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, } +#[derive(Reflect)] pub struct FirearmAnimations { pub firearm: Firearm, pub reload_magazine: Handle, diff --git a/src/setup/assets.rs b/src/setup/assets.rs index f66399f..cc0724e 100644 --- a/src/setup/assets.rs +++ b/src/setup/assets.rs @@ -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 } +#[derive(Reflect)] pub struct GltfAsset { pub asset_type: GltfAssetType, pub asset: Handle, diff --git a/src/setup/equipment.rs b/src/setup/equipment.rs index d295d8d..78f9cfc 100644 --- a/src/setup/equipment.rs +++ b/src/setup/equipment.rs @@ -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, } @@ -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(); diff --git a/src/setup/load_state.rs b/src/setup/load_state.rs index 26a8153..9f2fec1 100644 --- a/src/setup/load_state.rs +++ b/src/setup/load_state.rs @@ -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, diff --git a/src/setup/spawn.rs b/src/setup/spawn.rs index 4c1b552..e04ed9f 100644 --- a/src/setup/spawn.rs +++ b/src/setup/spawn.rs @@ -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 { pub at: Transform, pub what: T diff --git a/src/setup/spawners/player.rs b/src/setup/spawners/player.rs index 0b69aed..a1e8b45 100644 --- a/src/setup/spawners/player.rs +++ b/src/setup/spawners/player.rs @@ -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)) diff --git a/src/ui/editor/plugin.rs b/src/ui/editor/plugin.rs index fafab44..c6a60a0 100644 --- a/src/ui/editor/plugin.rs +++ b/src/ui/editor/plugin.rs @@ -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::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::(); app.insert_resource(EditorUiState::new()); app.add_systems(Update, editor_ui); } diff --git a/src/ui/game/fps_counter.rs b/src/ui/game/fps_counter.rs index f609b1c..436eac0 100644 --- a/src/ui/game/fps_counter.rs +++ b/src/ui/game/fps_counter.rs @@ -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()); } diff --git a/src/ui/game/settings_screen.rs b/src/ui/game/settings_screen.rs index 77f437a..8981a58 100644 --- a/src/ui/game/settings_screen.rs +++ b/src/ui/game/settings_screen.rs @@ -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 });