From c55bb81fd7fa31f01c751b9f31fdcff5cd7a3692 Mon Sep 17 00:00:00 2001 From: Franklin Date: Mon, 13 Nov 2023 13:57:24 -0400 Subject: [PATCH] Cargo fmt, readme update and removed warnings --- Readme.md | 10 +++- src/comps/core/events/inventory_changed.rs | 4 +- src/comps/core/events/mod.rs | 2 +- src/comps/core/events/pickup_item.rs | 4 +- src/comps/core/inventory/mod.rs | 2 +- src/comps/core/inventory/player_inventory.rs | 3 +- src/comps/core/inventory/plugin.rs | 7 ++- src/comps/core/items/item.rs | 5 +- src/comps/core/spawners/player.rs | 11 ++-- src/logic/core/guns/firearm.rs | 14 +++-- src/logic/core/player/hands.rs | 43 ++++++++------ src/logic/core/player/inventory.rs | 59 +++++++++++++++----- src/logic/core/player/mod.rs | 2 +- src/scenes/scene1/init.rs | 3 +- src/scenes/scene1/obstacles.rs | 34 +++++------ src/setup/equipment.rs | 2 +- src/ui/game/inventory/menu.rs | 6 +- 17 files changed, 133 insertions(+), 78 deletions(-) diff --git a/Readme.md b/Readme.md index eb57f81..7f82a08 100644 --- a/Readme.md +++ b/Readme.md @@ -3,18 +3,22 @@ ## Things to finish: - [ ] Perfect movement -- [ ] Equipping items (Guns and armor) +- [x] Equipping items +- [x] Replace items in the same slot, drop them +- [ ] When equipping an item that replaces another item because of the slot, throw item towards front of player - [ ] Gun aiming and noscope is not the same position - [ ] Controls being bindable - [ ] Gun moving out of the way on a collision - [ ] Gun moving when walking, when running, aimed in. - [ ] Visual effects for camera +- [ ] Persistent magazine data +- [ ] Perfectly center interact clue text on screen +- [ ] Fix: No Sprinting while aiming - [ ] Fix: Make gun have more priority in rendering. So it doesn't clip through walls -- [ ] Feature: Give a collider to the gun and when it collides with something make it move out of the way. +- [ ] Feature: Give a (sensor) collider to the gun and when it collides with something make it move out of the way. - [ ] Feature: Add bullet holes -- [ ] Fix: No Sprinting while aiming - [ ] Fix: Movement is clunky and very linear. Add some sort of Lerping for acceleration vectors. - [x] Feature: Muzzle flashes for shots - [x] Feature: Bullets (projectile) diff --git a/src/comps/core/events/inventory_changed.rs b/src/comps/core/events/inventory_changed.rs index 18d399c..79b9334 100644 --- a/src/comps/core/events/inventory_changed.rs +++ b/src/comps/core/events/inventory_changed.rs @@ -2,6 +2,4 @@ use bevy::prelude::*; /// This will be what is triggered after picking up an item or dropping an item. #[derive(Event)] -pub struct InventoryChangedEvent { - -} \ No newline at end of file +pub struct InventoryChangedEvent {} diff --git a/src/comps/core/events/mod.rs b/src/comps/core/events/mod.rs index 0591b47..aa3a379 100644 --- a/src/comps/core/events/mod.rs +++ b/src/comps/core/events/mod.rs @@ -1,3 +1,3 @@ //pub mod loot_container; +pub mod inventory_changed; pub mod pickup_item; -pub mod inventory_changed; \ No newline at end of file diff --git a/src/comps/core/events/pickup_item.rs b/src/comps/core/events/pickup_item.rs index 27dedcc..17029e4 100644 --- a/src/comps/core/events/pickup_item.rs +++ b/src/comps/core/events/pickup_item.rs @@ -7,9 +7,9 @@ use crate::comps::core::items::item::Item; /// When an item gets picked up in the game world, this event should handle all the physical properties on the game world. /// Mainly, removing the item from the game world, triggering inventory events, changing the player's equipment, etc... #[derive(Event)] -pub struct PickupItemEvent { +pub struct PickupItemEvent { /// Item entity pub entity: Entity, - pub item: Arc, + pub item: Arc, pub player: Entity, } diff --git a/src/comps/core/inventory/mod.rs b/src/comps/core/inventory/mod.rs index a29a9db..2da8b59 100644 --- a/src/comps/core/inventory/mod.rs +++ b/src/comps/core/inventory/mod.rs @@ -2,4 +2,4 @@ //pub mod inventory_item; pub mod item_inventory; pub mod player_inventory; -pub mod plugin; \ No newline at end of file +pub mod plugin; diff --git a/src/comps/core/inventory/player_inventory.rs b/src/comps/core/inventory/player_inventory.rs index 31588a5..6b5a604 100644 --- a/src/comps/core/inventory/player_inventory.rs +++ b/src/comps/core/inventory/player_inventory.rs @@ -35,5 +35,4 @@ impl PlayerInventory { pub fn get_secondary(&self) -> &Option> { &self.secondary.item } - -} \ No newline at end of file +} diff --git a/src/comps/core/inventory/plugin.rs b/src/comps/core/inventory/plugin.rs index 03b72b9..22a71bd 100644 --- a/src/comps/core/inventory/plugin.rs +++ b/src/comps/core/inventory/plugin.rs @@ -1,6 +1,9 @@ use bevy::prelude::*; -use crate::{comps::core::events::pickup_item::PickupItemEvent, logic::core::player::inventory::update_player_inventory_system}; +use crate::{ + comps::core::events::pickup_item::PickupItemEvent, + logic::core::player::inventory::update_player_inventory_system, +}; pub struct InventoryPlugin; @@ -9,4 +12,4 @@ impl Plugin for InventoryPlugin { app.add_event::(); app.add_systems(Update, update_player_inventory_system); } -} \ No newline at end of file +} diff --git a/src/comps/core/items/item.rs b/src/comps/core/items/item.rs index c017556..310a7ab 100644 --- a/src/comps/core/items/item.rs +++ b/src/comps/core/items/item.rs @@ -3,8 +3,9 @@ use crate::{ grid::UGrid, markers::{firearm::FirearmData, holdable::HoldableObjectType, interactable::Interactable}, }, + logic::core::guns::firearm::Firearm, setup::assets::{GltfAssetType, GltfAssets}, - utils, logic::core::guns::firearm::Firearm, + utils, }; use bevy::{gltf::Gltf, prelude::*}; use bevy_rapier3d::prelude::*; @@ -105,7 +106,7 @@ pub trait Item: Sync + Send { ItemType::Holdable(holdable) => match holdable { HoldableObjectType::Firearm(firearm) => Some(firearm), }, - _ => None + _ => None, } } } diff --git a/src/comps/core/spawners/player.rs b/src/comps/core/spawners/player.rs index 7414dc1..001898f 100644 --- a/src/comps/core/spawners/player.rs +++ b/src/comps/core/spawners/player.rs @@ -2,10 +2,13 @@ use bevy::prelude::*; use bevy_rapier3d::prelude::*; use crate::{ - comps::core::{markers::{ - camera::MainCamera, - player::{Player, PlayerData, PlayerHand}, - }, inventory::player_inventory::PlayerInventory}, + comps::core::{ + inventory::player_inventory::PlayerInventory, + markers::{ + camera::MainCamera, + player::{Player, PlayerData, PlayerHand}, + }, + }, logic::core::{ guns::player_firing::PlayerFiringInfo, player::{ diff --git a/src/logic/core/guns/firearm.rs b/src/logic/core/guns/firearm.rs index c726654..0788fe5 100644 --- a/src/logic/core/guns/firearm.rs +++ b/src/logic/core/guns/firearm.rs @@ -1,9 +1,15 @@ use std::sync::Arc; -use crate::comps::core::{markers::{ - firearm::{FirearmData, FirearmType, FiringPoint}, - holdable::HoldableObjectData, -}, items::{item::Item, guns::{m4a1::M4a1GunItem, glock17::Glock17GunItem}}}; +use crate::comps::core::{ + items::{ + guns::{glock17::Glock17GunItem, m4a1::M4a1GunItem}, + item::Item, + }, + markers::{ + firearm::{FirearmData, FirearmType, FiringPoint}, + holdable::HoldableObjectData, + }, +}; use bevy::prelude::*; use super::{caliber::Caliber, spray_pattern::FirearmSprayPattern}; diff --git a/src/logic/core/player/hands.rs b/src/logic/core/player/hands.rs index 251630f..408e4a5 100644 --- a/src/logic/core/player/hands.rs +++ b/src/logic/core/player/hands.rs @@ -2,13 +2,18 @@ use bevy::{ecs::system::SystemParam, prelude::*}; use bevy_rapier3d::prelude::*; use crate::{ - comps::core::{markers::{ - camera::MainCamera, - firearm::{FirearmData, MagazineData}, - holdable::{InPlayerHands, HoldableObjectType}, - interactable::Interactable, - player::{Player, PlayerHand}, - }, events::pickup_item::PickupItemEvent, inventory::player_inventory::PlayerInventory, items::item::ItemType}, + comps::core::{ + events::pickup_item::PickupItemEvent, + inventory::player_inventory::PlayerInventory, + items::item::ItemType, + markers::{ + camera::MainCamera, + firearm::{FirearmData, MagazineData}, + holdable::{HoldableObjectType, InPlayerHands}, + interactable::Interactable, + player::{Player, PlayerHand}, + }, + }, logic::core::guns::{firearm::Firearm, player_firing::PlayerFiringInfo, shoot::shoot_bullet}, setup::{ animations::AllFirearmAnimations, @@ -70,32 +75,34 @@ pub fn capture_hand_usage( if resources.keyboard_input.just_pressed(KeyCode::Key1) { if let Some(primary_item) = player_query.single().1.get_primary() { if let Some(primary_firearm) = primary_item.get_firearm() { - if Equipment::Firearm(primary_firearm.clone()) != player_query.single().0.0.equipment { + if Equipment::Firearm(primary_firearm.clone()) + != player_query.single().0 .0.equipment + { equipment_change_event_writer - .send(EquipmentChangeEvent(Equipment::Firearm(primary_firearm))); + .send(EquipmentChangeEvent(Equipment::Firearm(primary_firearm))); } } - } } else if resources.keyboard_input.just_pressed(KeyCode::Key2) { if let Some(secondary_item) = player_query.single().1.get_secondary() { if let Some(secondary_firearm) = secondary_item.get_firearm() { - if Equipment::Firearm(secondary_firearm.clone()) != player_query.single().0.0.equipment { + if Equipment::Firearm(secondary_firearm.clone()) + != player_query.single().0 .0.equipment + { equipment_change_event_writer - .send(EquipmentChangeEvent(Equipment::Firearm(secondary_firearm))); + .send(EquipmentChangeEvent(Equipment::Firearm(secondary_firearm))); } } - } } else if resources.keyboard_input.just_pressed(KeyCode::Key3) { - if Equipment::Nothing != player_query.single().0.0.equipment { + if Equipment::Nothing != player_query.single().0 .0.equipment { equipment_change_event_writer.send(EquipmentChangeEvent(Equipment::Nothing)); } } } // Firearm stuff - if let Equipment::Firearm(player_firearm) = player_query.single().0.0.equipment.clone() { + if let Equipment::Firearm(player_firearm) = player_query.single().0 .0.equipment.clone() { for mut player_firing_info in player_firing_info_query.iter_mut() { player_firing_info .full_auto_timer @@ -306,7 +313,11 @@ pub fn interact_action( .send(LootContainerEvent(any_inventory.clone())) }*/ Interactable::Item(item) => { - pickup_item_event_writer.send(PickupItemEvent { entity: interactable_entity, item: item.clone(), player: player_entity }); + pickup_item_event_writer.send(PickupItemEvent { + entity: interactable_entity, + item: item.clone(), + player: player_entity, + }); } } } diff --git a/src/logic/core/player/inventory.rs b/src/logic/core/player/inventory.rs index b4be8aa..2b111ed 100644 --- a/src/logic/core/player/inventory.rs +++ b/src/logic/core/player/inventory.rs @@ -1,6 +1,14 @@ -use bevy::{prelude::*, gltf::Gltf}; +use bevy::{gltf::Gltf, prelude::*}; -use crate::{comps::core::{events::pickup_item::PickupItemEvent, markers::{player::Player, holdable::HoldableObjectType, firearm::FirearmType}, inventory::player_inventory::PlayerInventory, items::item::ItemType}, setup::assets::GltfAssets}; +use crate::{ + comps::core::{ + events::pickup_item::PickupItemEvent, + inventory::player_inventory::PlayerInventory, + items::item::ItemType, + markers::{firearm::FirearmType, holdable::HoldableObjectType, player::Player}, + }, + setup::assets::GltfAssets, +}; pub fn update_player_inventory_system( mut commands: Commands, @@ -17,30 +25,55 @@ pub fn update_player_inventory_system( ItemType::Holdable(holdable_object) => { match holdable_object { HoldableObjectType::Firearm(firearm) => { - commands.entity(event.entity).despawn_descendants().despawn(); + commands + .entity(event.entity) + .despawn_descendants() + .despawn(); match firearm.firearm_data().firearm_type { FirearmType::Primary => { // Send equipment_changed_event if let Some(primary_item) = player_inventory.get_primary() { // Drop this one - primary_item.spawn(&mut commands, Transform::from_translation(player_transform.translation + player_transform.up() * 5.0 + player_transform.forward()), &assets_gltf, &loaded_gltf_assets); - player_inventory.primary.item = Some(firearm.get_item_box()) + primary_item.spawn( + &mut commands, + Transform::from_translation( + player_transform.translation + + player_transform.up() * 5.0 + + player_transform.forward(), + ), + &assets_gltf, + &loaded_gltf_assets, + ); + player_inventory.primary.item = + Some(firearm.get_item_box()) } else { - player_inventory.primary.item = Some(firearm.get_item_box()) + player_inventory.primary.item = + Some(firearm.get_item_box()) } - }, + } FirearmType::Secondary => { if let Some(secondary) = player_inventory.get_secondary() { - secondary.spawn(&mut commands, Transform::from_translation(player_transform.translation + player_transform.up() * 5.0 + player_transform.forward()), &assets_gltf, &loaded_gltf_assets); - player_inventory.secondary.item = Some(firearm.get_item_box()) + secondary.spawn( + &mut commands, + Transform::from_translation( + player_transform.translation + + player_transform.up() * 5.0 + + player_transform.forward(), + ), + &assets_gltf, + &loaded_gltf_assets, + ); + player_inventory.secondary.item = + Some(firearm.get_item_box()) } else { - player_inventory.secondary.item = Some(firearm.get_item_box()) + player_inventory.secondary.item = + Some(firearm.get_item_box()) } - }, + } } - }, + } } - }, + } ItemType::Equippable => todo!(), ItemType::Consumable => todo!(), } diff --git a/src/logic/core/player/mod.rs b/src/logic/core/player/mod.rs index dc25a89..ae04d39 100644 --- a/src/logic/core/player/mod.rs +++ b/src/logic/core/player/mod.rs @@ -1,7 +1,7 @@ pub mod camera_effects; pub mod camera_player_sync; pub mod hands; +pub mod inventory; pub mod player_movement; pub mod player_values_state; pub mod player_vertical_sync; -pub mod inventory; \ No newline at end of file diff --git a/src/scenes/scene1/init.rs b/src/scenes/scene1/init.rs index e15535c..ddf69fd 100644 --- a/src/scenes/scene1/init.rs +++ b/src/scenes/scene1/init.rs @@ -3,7 +3,8 @@ use bevy::prelude::*; use crate::{ comps::core::{ controller::capture_input, - spawners::{player::player_spawner, spawn::SpawnerPlugin}, inventory::plugin::InventoryPlugin, + inventory::plugin::InventoryPlugin, + spawners::{player::player_spawner, spawn::SpawnerPlugin}, }, logic::core::{ guns::despawn_shots::{despawn_muzzle_flashes, despawn_stray_bullets}, diff --git a/src/scenes/scene1/obstacles.rs b/src/scenes/scene1/obstacles.rs index e806088..ddf625d 100644 --- a/src/scenes/scene1/obstacles.rs +++ b/src/scenes/scene1/obstacles.rs @@ -82,22 +82,22 @@ pub fn spawn_obstacles( // CRATE /*commands - .spawn(( - Collider::from_bevy_mesh(&box_5_mesh, &Default::default()).unwrap(), - Name::new("Crate"), - )) - .insert(RigidBody::Fixed) - .insert(PbrBundle { - mesh: meshes.add(box_5_mesh.into()), - material: materials.add(StandardMaterial { - base_color: Color::BLUE, - perceptual_roughness: 0.1, - ..default() - }), - transform: Transform::from_xyz(20.0, 2.0, 20.0), + .spawn(( + Collider::from_bevy_mesh(&box_5_mesh, &Default::default()).unwrap(), + Name::new("Crate"), + )) + .insert(RigidBody::Fixed) + .insert(PbrBundle { + mesh: meshes.add(box_5_mesh.into()), + material: materials.add(StandardMaterial { + base_color: Color::BLUE, + perceptual_roughness: 0.1, ..default() - }) - /*.insert(Interactable::Lootable(AnyInventory::new( - UGrid::new_square(10), - )))*/;*/ + }), + transform: Transform::from_xyz(20.0, 2.0, 20.0), + ..default() + }) + /*.insert(Interactable::Lootable(AnyInventory::new( + UGrid::new_square(10), + )))*/;*/ } diff --git a/src/setup/equipment.rs b/src/setup/equipment.rs index fb71cc7..a932435 100644 --- a/src/setup/equipment.rs +++ b/src/setup/equipment.rs @@ -6,7 +6,7 @@ use crate::{ comps::core::markers::{ firearm::{FirearmData, MagazineData}, holdable::InPlayerHands, - player::{Player, PlayerHand, PlayerData}, + player::{Player, PlayerHand}, }, logic::core::guns::{firearm::Firearm, player_firing::PlayerFiringInfo}, utils, diff --git a/src/ui/game/inventory/menu.rs b/src/ui/game/inventory/menu.rs index 6ee09a6..69174cd 100644 --- a/src/ui/game/inventory/menu.rs +++ b/src/ui/game/inventory/menu.rs @@ -6,8 +6,4 @@ use bevy::prelude::*; /// Should contain player inventory and if player is looting something as well pub fn setup_inventory_screen(mut _commands: Commands) {} -pub fn update_inventory_screen( - mut _commands: Commands, -) { - -} +pub fn update_inventory_screen(mut _commands: Commands) {}