Modular weapons
This commit is contained in:
parent
d262378352
commit
be895b0021
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -347,7 +347,6 @@ version = "0.12.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "329e344f835f5a9a4c46a6d1d57371f726aa2c482d1bd669b2b9c4eb1ee91fd7"
|
checksum = "329e344f835f5a9a4c46a6d1d57371f726aa2c482d1bd669b2b9c4eb1ee91fd7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bevy_dylib",
|
|
||||||
"bevy_internal",
|
"bevy_internal",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -587,15 +586,6 @@ dependencies = [
|
|||||||
"sysinfo",
|
"sysinfo",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bevy_dylib"
|
|
||||||
version = "0.12.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "766980812401453563a7490a351dab88e8f53e62ff37e27a5236e6893deedc5a"
|
|
||||||
dependencies = [
|
|
||||||
"bevy_internal",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bevy_ecs"
|
name = "bevy_ecs"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
|
@ -15,7 +15,7 @@ opt-level = 3
|
|||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = { version = "0.12", features = ["dynamic_linking"]}
|
bevy = { version = "0.12", features = []}
|
||||||
bevy-inspector-egui = "0.21.0"
|
bevy-inspector-egui = "0.21.0"
|
||||||
bevy_editor_pls = "0.6"
|
bevy_editor_pls = "0.6"
|
||||||
bevy_rapier3d = { version = "0.23", features = ["debug-render-3d"] }
|
bevy_rapier3d = { version = "0.23", features = ["debug-render-3d"] }
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,7 +2,12 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::comps::core::items::item::Item;
|
use crate::comps::core::{items::item::Item, weapons::firearm_state::FirearmState};
|
||||||
|
|
||||||
|
#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Debug, Clone)]
|
||||||
|
pub enum ItemState {
|
||||||
|
Weapon(FirearmState),
|
||||||
|
}
|
||||||
|
|
||||||
/// When an item gets picked up in the game world, this event should handle all the physical properties on the game world.
|
/// 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...
|
/// Mainly, removing the item from the game world, triggering inventory events, changing the player's equipment, etc...
|
||||||
@ -12,4 +17,5 @@ pub struct PickupItemEvent {
|
|||||||
pub entity: Entity,
|
pub entity: Entity,
|
||||||
pub item: Arc<dyn Item>,
|
pub item: Arc<dyn Item>,
|
||||||
pub player: Entity,
|
pub player: Entity,
|
||||||
|
pub state: Option<ItemState>
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,7 @@ pub fn drop_slot_in_game_world(
|
|||||||
&assets_gltf,
|
&assets_gltf,
|
||||||
&loaded_gltf_assets,
|
&loaded_gltf_assets,
|
||||||
drop_impulse,
|
drop_impulse,
|
||||||
|
None
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
player_inventory.drop_item(PlayerInventorySlotType::Primary);
|
player_inventory.drop_item(PlayerInventorySlotType::Primary);
|
||||||
@ -124,6 +125,7 @@ pub fn drop_slot_in_game_world(
|
|||||||
&assets_gltf,
|
&assets_gltf,
|
||||||
&loaded_gltf_assets,
|
&loaded_gltf_assets,
|
||||||
drop_impulse,
|
drop_impulse,
|
||||||
|
None
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
player_inventory.drop_item(PlayerInventorySlotType::Secondary);
|
player_inventory.drop_item(PlayerInventorySlotType::Secondary);
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::{prelude::*, gltf::Gltf};
|
||||||
|
use bevy_rapier3d::{dynamics::{RigidBody, GravityScale, ExternalImpulse}, geometry::{ColliderMassProperties, Collider}};
|
||||||
|
|
||||||
use crate::comps::core::{
|
use crate::{comps::core::{
|
||||||
grid::UGrid,
|
grid::UGrid,
|
||||||
items::item::{Item, ItemType},
|
items::item::{Item, ItemType},
|
||||||
markers::holdable::HoldableObjectType, inventory::slot::PlayerInventorySlotType, weapons::firearm::Firearm,
|
markers::{holdable::HoldableObjectType, interactable::Interactable}, inventory::slot::PlayerInventorySlotType, weapons::{firearm::Firearm, firearm_data::FirearmData}, events::pickup_item::ItemState,
|
||||||
};
|
}, setup::assets::{GltfAssets, GltfAssetType}, utils};
|
||||||
|
|
||||||
#[derive(Component, Reflect)]
|
#[derive(Component, Reflect)]
|
||||||
pub struct Ak105GunItem;
|
pub struct Ak105GunItem;
|
||||||
|
|
||||||
impl Item for Ak105GunItem {
|
impl Item for Ak105GunItem {
|
||||||
fn get_type(&self) -> ItemType {
|
fn get_type(&self) -> ItemType {
|
||||||
ItemType::Holdable(HoldableObjectType::Firearm(Firearm::Glock17))
|
ItemType::Holdable(HoldableObjectType::Firearm(Firearm::Ak105))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn asset_path(&self) -> &str {
|
fn asset_path(&self) -> &str {
|
||||||
@ -45,4 +46,80 @@ impl Item for Ak105GunItem {
|
|||||||
fn get_item_slot(&self) -> PlayerInventorySlotType {
|
fn get_item_slot(&self) -> PlayerInventorySlotType {
|
||||||
PlayerInventorySlotType::Primary
|
PlayerInventorySlotType::Primary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn spawn(
|
||||||
|
&self,
|
||||||
|
commands: &mut Commands,
|
||||||
|
transform: Transform,
|
||||||
|
assets_gltf: &GltfAssets,
|
||||||
|
loaded_gltf_assets: &Assets<Gltf>,
|
||||||
|
with_impulse: Vec3,
|
||||||
|
item_state: Option<ItemState>,
|
||||||
|
) {
|
||||||
|
let firearm = Firearm::Ak105;
|
||||||
|
if let Some(asset_handle) = assets_gltf.assets.iter().find(|asset| {
|
||||||
|
asset.asset_type == GltfAssetType::Firearm(firearm.clone())
|
||||||
|
}) {
|
||||||
|
if let Some(gltf) = loaded_gltf_assets.get(&asset_handle.asset) {
|
||||||
|
let firearm_data: FirearmData = firearm.firearm_data();
|
||||||
|
let mut firearm_transform = Transform::from_xyz(0.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
firearm_transform.rotate_local_y(
|
||||||
|
utils::rad_deg::radians_from_degrees(
|
||||||
|
firearm.holdable_object_data().y_rot,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
firearm_transform.scale =
|
||||||
|
firearm_transform.scale * firearm_data.scale_factor;
|
||||||
|
|
||||||
|
let scene = gltf.scenes[0].clone();
|
||||||
|
let firearm_asset_entity = commands
|
||||||
|
.spawn((
|
||||||
|
SceneBundle {
|
||||||
|
scene,
|
||||||
|
visibility: Visibility::Inherited,
|
||||||
|
transform: firearm_transform,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
Name::new(format!(
|
||||||
|
"{} Item Gltf Asset",
|
||||||
|
self.inventory_title()
|
||||||
|
)),
|
||||||
|
))
|
||||||
|
.id();
|
||||||
|
match item_state {
|
||||||
|
Some(state) => { commands.entity(firearm_asset_entity).insert(state); },
|
||||||
|
None => {},
|
||||||
|
};
|
||||||
|
let firearm_size = firearm.get_size();
|
||||||
|
commands
|
||||||
|
.spawn((
|
||||||
|
firearm.holdable_object_data(),
|
||||||
|
Name::new(format!("{} Item", self.inventory_title())),
|
||||||
|
TransformBundle {
|
||||||
|
local: transform,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
VisibilityBundle {
|
||||||
|
visibility: Visibility::Visible,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
RigidBody::Dynamic,
|
||||||
|
ColliderMassProperties::Mass(5.0),
|
||||||
|
GravityScale(4.0),
|
||||||
|
Collider::cuboid(
|
||||||
|
firearm_size.x,
|
||||||
|
firearm_size.y,
|
||||||
|
firearm_size.z,
|
||||||
|
),
|
||||||
|
ExternalImpulse {
|
||||||
|
impulse: with_impulse,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
Interactable::Item(firearm.get_item_arc()),
|
||||||
|
))
|
||||||
|
.push_children(&[firearm_asset_entity]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::{prelude::*, gltf::Gltf};
|
||||||
|
use bevy_rapier3d::{geometry::{ColliderMassProperties, Collider}, dynamics::{RigidBody, GravityScale, ExternalImpulse}};
|
||||||
|
|
||||||
use crate::comps::core::{
|
use crate::{comps::core::{
|
||||||
grid::UGrid,
|
grid::UGrid,
|
||||||
items::item::{Item, ItemType},
|
items::item::{Item, ItemType},
|
||||||
markers::holdable::HoldableObjectType, inventory::slot::PlayerInventorySlotType, weapons::firearm::Firearm,
|
markers::{holdable::HoldableObjectType, interactable::Interactable}, inventory::slot::PlayerInventorySlotType, weapons::{firearm::Firearm, firearm_data::FirearmData}, events::pickup_item::ItemState,
|
||||||
};
|
}, setup::assets::{GltfAssets, GltfAssetType}, utils};
|
||||||
|
|
||||||
#[derive(Component, Reflect)]
|
#[derive(Component, Reflect)]
|
||||||
pub struct Glock17GunItem;
|
pub struct Glock17GunItem;
|
||||||
@ -45,4 +46,80 @@ impl Item for Glock17GunItem {
|
|||||||
fn get_item_slot(&self) -> PlayerInventorySlotType {
|
fn get_item_slot(&self) -> PlayerInventorySlotType {
|
||||||
PlayerInventorySlotType::Secondary
|
PlayerInventorySlotType::Secondary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn spawn(
|
||||||
|
&self,
|
||||||
|
commands: &mut Commands,
|
||||||
|
transform: Transform,
|
||||||
|
assets_gltf: &GltfAssets,
|
||||||
|
loaded_gltf_assets: &Assets<Gltf>,
|
||||||
|
with_impulse: Vec3,
|
||||||
|
item_state: Option<ItemState>,
|
||||||
|
) {
|
||||||
|
let firearm = Firearm::Glock17;
|
||||||
|
if let Some(asset_handle) = assets_gltf.assets.iter().find(|asset| {
|
||||||
|
asset.asset_type == GltfAssetType::Firearm(firearm.clone())
|
||||||
|
}) {
|
||||||
|
if let Some(gltf) = loaded_gltf_assets.get(&asset_handle.asset) {
|
||||||
|
let firearm_data: FirearmData = firearm.firearm_data();
|
||||||
|
let mut firearm_transform = Transform::from_xyz(0.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
firearm_transform.rotate_local_y(
|
||||||
|
utils::rad_deg::radians_from_degrees(
|
||||||
|
firearm.holdable_object_data().y_rot,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
firearm_transform.scale =
|
||||||
|
firearm_transform.scale * firearm_data.scale_factor;
|
||||||
|
|
||||||
|
let scene = gltf.scenes[0].clone();
|
||||||
|
let firearm_asset_entity = commands
|
||||||
|
.spawn((
|
||||||
|
SceneBundle {
|
||||||
|
scene,
|
||||||
|
visibility: Visibility::Inherited,
|
||||||
|
transform: firearm_transform,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
Name::new(format!(
|
||||||
|
"{} Item Gltf Asset",
|
||||||
|
self.inventory_title()
|
||||||
|
)),
|
||||||
|
))
|
||||||
|
.id();
|
||||||
|
match item_state {
|
||||||
|
Some(state) => { commands.entity(firearm_asset_entity).insert(state); },
|
||||||
|
None => {},
|
||||||
|
};
|
||||||
|
let firearm_size = firearm.get_size();
|
||||||
|
commands
|
||||||
|
.spawn((
|
||||||
|
firearm.holdable_object_data(),
|
||||||
|
Name::new(format!("{} Item", self.inventory_title())),
|
||||||
|
TransformBundle {
|
||||||
|
local: transform,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
VisibilityBundle {
|
||||||
|
visibility: Visibility::Visible,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
RigidBody::Dynamic,
|
||||||
|
ColliderMassProperties::Mass(5.0),
|
||||||
|
GravityScale(4.0),
|
||||||
|
Collider::cuboid(
|
||||||
|
firearm_size.x,
|
||||||
|
firearm_size.y,
|
||||||
|
firearm_size.z,
|
||||||
|
),
|
||||||
|
ExternalImpulse {
|
||||||
|
impulse: with_impulse,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
Interactable::Item(firearm.get_item_arc()),
|
||||||
|
))
|
||||||
|
.push_children(&[firearm_asset_entity]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comps::core::{
|
comps::core::{
|
||||||
grid::UGrid,
|
grid::UGrid,
|
||||||
markers::{holdable::HoldableObjectType, interactable::Interactable}, inventory::slot::PlayerInventorySlotType, weapons::{firearm_data::FirearmData, firearm::Firearm},
|
markers::{holdable::HoldableObjectType, interactable::Interactable}, inventory::slot::PlayerInventorySlotType, weapons::{firearm_data::FirearmData, firearm::Firearm}, events::pickup_item::ItemState,
|
||||||
},
|
},
|
||||||
setup::assets::{GltfAssetType, GltfAssets},
|
setup::assets::{GltfAssetType, GltfAssets},
|
||||||
utils,
|
utils,
|
||||||
@ -26,6 +26,8 @@ pub trait Item: Sync + Send + Reflect {
|
|||||||
fn inventory_rotatable(&self) -> bool;
|
fn inventory_rotatable(&self) -> bool;
|
||||||
fn inventory_title(&self) -> String;
|
fn inventory_title(&self) -> String;
|
||||||
fn inventory_description(&self) -> String;
|
fn inventory_description(&self) -> String;
|
||||||
|
/// Spawn an item on the game world. Every item should implement this
|
||||||
|
/// The transform passed to this function should be a GlobalTransform.into()
|
||||||
fn spawn(
|
fn spawn(
|
||||||
&self,
|
&self,
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
@ -33,6 +35,7 @@ pub trait Item: Sync + Send + Reflect {
|
|||||||
assets_gltf: &GltfAssets,
|
assets_gltf: &GltfAssets,
|
||||||
loaded_gltf_assets: &Assets<Gltf>,
|
loaded_gltf_assets: &Assets<Gltf>,
|
||||||
with_impulse: Vec3,
|
with_impulse: Vec3,
|
||||||
|
item_state: Option<ItemState>,
|
||||||
) {
|
) {
|
||||||
match self.get_type() {
|
match self.get_type() {
|
||||||
ItemType::Holdable(object_type) => {
|
ItemType::Holdable(object_type) => {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use bevy::app::{Plugin, Update};
|
use bevy::app::{Plugin, Update};
|
||||||
|
|
||||||
use crate::{setup::load_state::update_game_load_state, comps::core::weapons::{firearm::Firearm, attachments::{weapon_attachment::WeaponAttachment, optic::Optic, stock::Stock, compensator::Compensator, magazine::Magazine, foregrip::ForeGrip}, parts::{charging_handle::ChargingHandle, fire_selector::FireSelector, firing_point::FiringPoint, trigger::Trigger}, slot::{compensator_slot::CompensatorSlot, fore_grip_slot::ForeGripSlot, magazine_slot::MagazineSlot, sight_placement_start_slot::SightPlacementStartSlot, sight_placement_end_slot::SightPlacementEndSlot, stock_slot::StockSlot, utility_slot::UtilitySlot}}};
|
use crate::{setup::load_state::update_game_load_state, comps::core::weapons::{firearm::Firearm, attachments::{weapon_attachment::WeaponAttachment, optic::Optic, stock::Stock, compensator::Compensator, magazine::Magazine, foregrip::ForeGrip}, parts::{charging_handle::ChargingHandle, fire_selector::FireSelector, firing_point::FiringPoint, trigger::Trigger}, slot::{compensator_slot::CompensatorSlot, fore_grip_slot::ForeGripSlot, magazine_slot::MagazineSlot, sight_placement_start_slot::SightPlacementStartSlot, sight_placement_end_slot::SightPlacementEndSlot, stock_slot::StockSlot, utility_slot::UtilitySlot, slot::WeaponSlot}}};
|
||||||
|
|
||||||
use super::{character::{player_hitbox::PlayerHitBox, player_character::PlayerCharacter, player_eye::{PlayerEye, insert_components_into_spawned_player}, in_player_hands_parent::{InPlayerHandsParent, insert_components_into_player_hand}, third_person_camera::ThirdPersonCameraProxy}, physics::{rapier::{AutoAABBCollider, physics_replace_proxies}, self}};
|
use super::{character::{player_hitbox::PlayerHitBox, player_character::PlayerCharacter, player_eye::{PlayerEye, insert_components_into_spawned_player}, in_player_hands_parent::{InPlayerHandsParent, insert_components_into_player_hand}, third_person_camera::ThirdPersonCameraProxy}, physics::{rapier::{AutoAABBCollider, physics_replace_proxies}, self}, weapons::firearm::insert_firearm_state_to_firearms};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -25,6 +25,7 @@ impl Plugin for ProxyComponentsPlugin {
|
|||||||
|
|
||||||
// Attachments
|
// Attachments
|
||||||
app.register_type::<WeaponAttachment>();
|
app.register_type::<WeaponAttachment>();
|
||||||
|
app.register_type::<WeaponSlot>();
|
||||||
app.register_type::<Optic>();
|
app.register_type::<Optic>();
|
||||||
app.register_type::<Stock>();
|
app.register_type::<Stock>();
|
||||||
app.register_type::<Compensator>();
|
app.register_type::<Compensator>();
|
||||||
@ -54,5 +55,6 @@ impl Plugin for ProxyComponentsPlugin {
|
|||||||
app.add_systems(Update, (physics_replace_proxies, update_game_load_state));
|
app.add_systems(Update, (physics_replace_proxies, update_game_load_state));
|
||||||
app.add_systems(Update, insert_components_into_spawned_player);
|
app.add_systems(Update, insert_components_into_spawned_player);
|
||||||
app.add_systems(Update, insert_components_into_player_hand);
|
app.add_systems(Update, insert_components_into_player_hand);
|
||||||
|
app.add_systems(Update, insert_firearm_state_to_firearms);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,8 +1,109 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::{prelude::*, gltf::Gltf, ecs::system::SystemParam};
|
||||||
|
|
||||||
|
use crate::{comps::core::{weapons::{firearm::Firearm, firearm_state::FirearmState, slot::slot::WeaponSlot, attachment_slot::AttachmentSlot, attachments::weapon_attachment::WeaponAttachment}, events::pickup_item::ItemState}, setup::assets::{GltfAssets, GltfAssetType}};
|
||||||
|
|
||||||
#[derive(Component, Reflect, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(SystemParam)]
|
||||||
pub enum Firearm {
|
pub struct InsertFirearmStateIntoFirearmsParams<'w, 's> {
|
||||||
Ak105,
|
firearm_scene_bundle: Query<'w, 's, (Entity, Option<&'static ItemState>, &'static Children)>,
|
||||||
Glock17
|
firearm_query: Query<'w, 's, (Entity, &'static Firearm, &'static Parent, Option<&'static FirearmState>), Or<(Without<FirearmState>, Changed<FirearmState>)>>,
|
||||||
|
slots_query: Query<'w, 's, (Entity, &'static WeaponSlot, &'static Parent)>,
|
||||||
|
attachments_query: Query<'w, 's, (Entity, &'static WeaponAttachment, &'static Parent)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This query inserts FirearmState into firearms, updates firearm assets that already have a FirearmState,
|
||||||
|
/// And Re-inserts FirearmState into spawned Firearms that have a passed in ItemState at the root of the SceneBundle
|
||||||
|
pub fn insert_firearm_state_to_firearms(
|
||||||
|
// needed for tri meshes
|
||||||
|
queries: InsertFirearmStateIntoFirearmsParams,
|
||||||
|
assets_gltf: Res<GltfAssets>,
|
||||||
|
loaded_gltf_assets: Res<Assets<Gltf>>,
|
||||||
|
mut commands: Commands,
|
||||||
|
) {
|
||||||
|
for (firearm_scene_entity, item_state_opt, scene_bundle_children) in queries.firearm_scene_bundle.iter() {
|
||||||
|
for scene_bundle_child in scene_bundle_children.iter() {
|
||||||
|
for (firearm_entity, _, firearm_parent, firearm_state_opt) in queries.firearm_query.iter() {
|
||||||
|
if &firearm_parent.get() == scene_bundle_child {
|
||||||
|
if let Some(item_state) = item_state_opt {
|
||||||
|
// Firearm State is already created and item is being spawned again into world
|
||||||
|
#[allow(irrefutable_let_patterns)]
|
||||||
|
if let ItemState::Weapon(firearm_state) = item_state {
|
||||||
|
commands.entity(firearm_scene_entity).remove::<ItemState>();
|
||||||
|
commands
|
||||||
|
.entity(firearm_entity)
|
||||||
|
.insert(firearm_state.clone());
|
||||||
|
//TODO: spawn in attachments
|
||||||
|
println!("Reused firearm_state");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match firearm_state_opt {
|
||||||
|
Some(firearm_state) => {
|
||||||
|
// Change the Slots
|
||||||
|
spawn_attachments_in_firearm(&mut commands, firearm_entity, firearm_state, &queries.slots_query, &assets_gltf, &loaded_gltf_assets)
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
// Create the firearm_state
|
||||||
|
let mut firearm_slots = Vec::new();
|
||||||
|
for (slot_entity, slot, parent_entity) in queries.slots_query.iter() {
|
||||||
|
if firearm_entity == parent_entity.get() {
|
||||||
|
let mut attachment = None;
|
||||||
|
for (_, weapon_attachment, attachment_parent) in queries.attachments_query.iter() {
|
||||||
|
if slot_entity == attachment_parent.get() {
|
||||||
|
attachment = Some(weapon_attachment.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
firearm_slots.push(AttachmentSlot {
|
||||||
|
attachment,
|
||||||
|
slot_type: slot.clone(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
commands
|
||||||
|
.entity(firearm_entity)
|
||||||
|
.insert(FirearmState::new(firearm_slots));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spawn_attachments_in_firearm(
|
||||||
|
commands: &mut Commands,
|
||||||
|
firearm_entity: Entity,
|
||||||
|
firearm_state: &FirearmState,
|
||||||
|
slots_query: &Query<(Entity, &WeaponSlot, &Parent)>,
|
||||||
|
assets_gltf: &GltfAssets,
|
||||||
|
loaded_gltf_assets: &Assets<Gltf>,
|
||||||
|
) {
|
||||||
|
for (slot_entity, weapon_slot, slot_parent) in slots_query.iter() {
|
||||||
|
if slot_parent.get() != firearm_entity {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for attachment_slot in firearm_state.attachment_slots.iter() {
|
||||||
|
if &attachment_slot.slot_type == weapon_slot {
|
||||||
|
commands.entity(slot_entity).despawn_descendants();
|
||||||
|
match &attachment_slot.attachment {
|
||||||
|
Some(attachment) =>
|
||||||
|
if let Some(asset_handle) = assets_gltf.assets.iter().find(|asset| {
|
||||||
|
asset.asset_type == GltfAssetType::Attachment(attachment.clone())
|
||||||
|
}) {
|
||||||
|
if let Some(gltf) = loaded_gltf_assets.get(&asset_handle.asset) {
|
||||||
|
let scene_bundle = commands.spawn(
|
||||||
|
SceneBundle {
|
||||||
|
scene: gltf.scenes[0].clone(),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
).id();
|
||||||
|
commands.entity(slot_entity).add_child(
|
||||||
|
scene_bundle
|
||||||
|
);
|
||||||
|
}},
|
||||||
|
None => {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -31,6 +31,7 @@ pub fn item_spawner(
|
|||||||
&assets_gltf,
|
&assets_gltf,
|
||||||
&loaded_gltf_assets,
|
&loaded_gltf_assets,
|
||||||
Vec3::ZERO,
|
Vec3::ZERO,
|
||||||
|
None
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
//m4.spawn(&mut commands, item_sp.at, &assets_gltf, &loaded_gltf_assets);
|
//m4.spawn(&mut commands, item_sp.at, &assets_gltf, &loaded_gltf_assets);
|
||||||
|
9
src/comps/core/weapons/attachment_slot.rs
Normal file
9
src/comps/core/weapons/attachment_slot.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
use super::{attachments::weapon_attachment::WeaponAttachment, slot::slot::WeaponSlot};
|
||||||
|
|
||||||
|
#[derive(Reflect, PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Default)]
|
||||||
|
pub struct AttachmentSlot {
|
||||||
|
pub attachment: Option<WeaponAttachment>,
|
||||||
|
pub slot_type: WeaponSlot,
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
use bevy::{reflect::Reflect, ecs::{component::Component, reflect::ReflectComponent}};
|
use bevy::{reflect::{Reflect, std_traits::ReflectDefault}, ecs::{component::Component, reflect::ReflectComponent}};
|
||||||
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)]
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component, Default)]
|
||||||
pub enum Compensator {
|
pub enum Compensator {
|
||||||
#[default]
|
#[default]
|
||||||
FirstCompensator,
|
FirstCompensator,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use bevy::{reflect::Reflect, ecs::{component::Component, reflect::ReflectComponent}};
|
use bevy::{reflect::{Reflect, std_traits::ReflectDefault}, ecs::{component::Component, reflect::ReflectComponent}};
|
||||||
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)]
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component, Default)]
|
||||||
pub enum ForeGrip {
|
pub enum ForeGrip {
|
||||||
#[default]
|
#[default]
|
||||||
Pk5,
|
Pk5,
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
use bevy::{reflect::Reflect, ecs::{component::Component, reflect::ReflectComponent}};
|
use bevy::{reflect::{Reflect, std_traits::ReflectDefault}, ecs::{component::Component, reflect::ReflectComponent}};
|
||||||
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)]
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component, Default)]
|
||||||
pub enum Magazine {
|
pub enum Magazine {
|
||||||
#[default]
|
#[default]
|
||||||
Ak105,
|
Ak105,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Magazine {
|
||||||
|
pub fn capacity(&self) -> u32 {
|
||||||
|
match self {
|
||||||
|
Magazine::Ak105 => 30,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
use bevy::{reflect::Reflect, ecs::{component::Component, reflect::ReflectComponent}};
|
use bevy::{reflect::{Reflect, std_traits::ReflectDefault}, ecs::{component::Component, reflect::ReflectComponent}};
|
||||||
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)]
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component, Default)]
|
||||||
pub enum Optic {
|
pub enum Optic {
|
||||||
#[default]
|
#[default]
|
||||||
AimpointT1,
|
AimpointT1,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use bevy::{reflect::Reflect, ecs::{component::Component, reflect::ReflectComponent}};
|
use bevy::{reflect::{Reflect, std_traits::ReflectDefault}, ecs::{component::Component, reflect::ReflectComponent}};
|
||||||
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)]
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Component, Debug, Default)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component, Default)]
|
||||||
pub enum Stock {
|
pub enum Stock {
|
||||||
#[default]
|
#[default]
|
||||||
MagpullTan,
|
MagpullTan,
|
||||||
|
@ -3,7 +3,7 @@ use bevy::prelude::*;
|
|||||||
use super::{compensator::Compensator, magazine::Magazine, stock::Stock, foregrip::ForeGrip, optic::Optic};
|
use super::{compensator::Compensator, magazine::Magazine, stock::Stock, foregrip::ForeGrip, optic::Optic};
|
||||||
|
|
||||||
#[derive(Component, PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Debug)]
|
#[derive(Component, PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Debug)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component, Default)]
|
||||||
pub enum WeaponAttachment {
|
pub enum WeaponAttachment {
|
||||||
Compensator(Compensator),
|
Compensator(Compensator),
|
||||||
Magazine(Magazine),
|
Magazine(Magazine),
|
||||||
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::comps::core::{markers::holdable::HoldableObjectData, items::{item::Item, guns::glock17::Glock17GunItem}};
|
use crate::comps::core::{markers::holdable::HoldableObjectData, items::{item::Item, guns::{glock17::Glock17GunItem, ak105::Ak105GunItem}}};
|
||||||
|
|
||||||
use super::{firearm_data::{FirearmData, FirearmType}, caliber::Caliber, spray_pattern::FirearmSprayPattern};
|
use super::{firearm_data::{FirearmData, FirearmType}, caliber::Caliber, spray_pattern::FirearmSprayPattern};
|
||||||
|
|
||||||
@ -157,14 +157,14 @@ impl Firearm {
|
|||||||
match self {
|
match self {
|
||||||
//Firearm::M4A1 => Arc::new(M4a1GunItem),
|
//Firearm::M4A1 => Arc::new(M4a1GunItem),
|
||||||
Firearm::Glock17 => Arc::new(Glock17GunItem),
|
Firearm::Glock17 => Arc::new(Glock17GunItem),
|
||||||
Firearm::Ak105 => todo!(),
|
Firearm::Ak105 => Arc::new(Ak105GunItem),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn get_item_box(&self) -> Box<dyn Item> {
|
pub fn get_item_box(&self) -> Box<dyn Item> {
|
||||||
match self {
|
match self {
|
||||||
//Firearm::M4A1 => Box::new(M4a1GunItem),
|
//Firearm::M4A1 => Box::new(M4a1GunItem),
|
||||||
Firearm::Glock17 => Box::new(Glock17GunItem),
|
Firearm::Glock17 => Box::new(Glock17GunItem),
|
||||||
Firearm::Ak105 => todo!(),
|
Firearm::Ak105 => Box::new(Ak105GunItem),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
15
src/comps/core/weapons/firearm_state.rs
Normal file
15
src/comps/core/weapons/firearm_state.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
use super::{attachment_slot::AttachmentSlot, slot::slot::WeaponSlot};
|
||||||
|
|
||||||
|
#[derive(Component, Reflect, PartialEq, Eq, PartialOrd, Ord, Debug, Clone)]
|
||||||
|
pub struct FirearmState {
|
||||||
|
pub attachment_slots: Vec<AttachmentSlot>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FirearmState {
|
||||||
|
pub fn new(attachment_slots: Vec<AttachmentSlot>) -> Self {
|
||||||
|
Self { attachment_slots }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -5,4 +5,6 @@ pub mod caliber;
|
|||||||
pub mod spray_pattern;
|
pub mod spray_pattern;
|
||||||
pub mod magazine_data;
|
pub mod magazine_data;
|
||||||
pub mod slot;
|
pub mod slot;
|
||||||
pub mod parts;
|
pub mod parts;
|
||||||
|
pub mod firearm_state;
|
||||||
|
pub mod attachment_slot;
|
@ -4,4 +4,5 @@ pub mod stock_slot;
|
|||||||
pub mod fore_grip_slot;
|
pub mod fore_grip_slot;
|
||||||
pub mod utility_slot;
|
pub mod utility_slot;
|
||||||
pub mod sight_placement_start_slot;
|
pub mod sight_placement_start_slot;
|
||||||
pub mod sight_placement_end_slot;
|
pub mod sight_placement_end_slot;
|
||||||
|
pub mod slot;
|
14
src/comps/core/weapons/slot/slot.rs
Normal file
14
src/comps/core/weapons/slot/slot.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
use bevy::{reflect::Reflect, ecs::{reflect::ReflectComponent, component::Component}};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Reflect, Default, Component)]
|
||||||
|
#[reflect(Component)]
|
||||||
|
pub enum WeaponSlot {
|
||||||
|
ForeGripSlot,
|
||||||
|
MagazineSlot,
|
||||||
|
CompensatorSlot,
|
||||||
|
SightPlacementEndSlot,
|
||||||
|
SightPlacementStartSlot,
|
||||||
|
#[default]
|
||||||
|
StockSlot,
|
||||||
|
UtilitySlot,
|
||||||
|
}
|
@ -336,6 +336,7 @@ pub fn interact_action(
|
|||||||
entity: interactable_entity,
|
entity: interactable_entity,
|
||||||
item: item.clone(),
|
item: item.clone(),
|
||||||
player: player_entity,
|
player: player_entity,
|
||||||
|
state: None
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use crate::{
|
|||||||
comps::core::{
|
comps::core::{
|
||||||
markers::player::{Player, PlayerData},
|
markers::player::{Player, PlayerData},
|
||||||
spawners::{
|
spawners::{
|
||||||
guns::glock17_spawner::Glock17SpawnPoint,
|
guns::{glock17_spawner::Glock17SpawnPoint, ak105_spawner::Ak105SpawnPoint},
|
||||||
player::PlayerSpawnPoint,
|
player::PlayerSpawnPoint,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -30,13 +30,13 @@ pub fn set_spawn_points(mut commands: Commands) {
|
|||||||
transform
|
transform
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
/*commands.spawn(M4a1SpawnPoint {
|
commands.spawn(Ak105SpawnPoint {
|
||||||
transform: {
|
transform: {
|
||||||
let mut transform = Transform::from_xyz(18.0, 10.0, 18.0);
|
let mut transform = Transform::from_xyz(18.0, 10.0, 18.0);
|
||||||
transform.rotate_z(utils::rad_deg::radians_from_degrees(-90.0));
|
transform.rotate_z(utils::rad_deg::radians_from_degrees(-90.0));
|
||||||
transform
|
transform
|
||||||
},
|
},
|
||||||
});*/
|
});
|
||||||
commands.spawn(Glock17SpawnPoint {
|
commands.spawn(Glock17SpawnPoint {
|
||||||
transform: {
|
transform: {
|
||||||
let mut transform = Transform::from_xyz(20.0, 10.0, 20.0);
|
let mut transform = Transform::from_xyz(20.0, 10.0, 20.0);
|
||||||
|
@ -6,7 +6,7 @@ use crate::{
|
|||||||
comps::core::{markers::{
|
comps::core::{markers::{
|
||||||
holdable::{HoldableObjectData, InPlayerHands},
|
holdable::{HoldableObjectData, InPlayerHands},
|
||||||
player::{Player, PlayerData, PlayerHand},
|
player::{Player, PlayerData, PlayerHand},
|
||||||
}, weapons::{firearm_data::FirearmData, magazine_data::MagazineData, caliber::Caliber, firearm::Firearm, spray_pattern::FirearmSprayPattern}},
|
}, weapons::{firearm_data::FirearmData, magazine_data::MagazineData, caliber::Caliber, firearm::Firearm, spray_pattern::FirearmSprayPattern, firearm_state::FirearmState}},
|
||||||
logic::core::{
|
logic::core::{
|
||||||
guns::player_firing::PlayerFiringInfo,
|
guns::player_firing::PlayerFiringInfo,
|
||||||
player::{
|
player::{
|
||||||
@ -51,6 +51,7 @@ impl Plugin for MainEditorUiPlugin {
|
|||||||
.register_type::<PlayerLinearXZState>()
|
.register_type::<PlayerLinearXZState>()
|
||||||
.register_type::<PlayerMovementInput>()
|
.register_type::<PlayerMovementInput>()
|
||||||
.register_type::<Cubemap>()
|
.register_type::<Cubemap>()
|
||||||
|
.register_type::<FirearmState>()
|
||||||
//.register_type::<AllAnimations>()
|
//.register_type::<AllAnimations>()
|
||||||
//.register_type::<FirearmAnimations>()
|
//.register_type::<FirearmAnimations>()
|
||||||
.register_type::<GltfAssetType>()
|
.register_type::<GltfAssetType>()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub fn find_child_in_parent_children(
|
pub fn find_child_in_parent_children(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
parent_entity: Entity,
|
parent_entity: Entity,
|
||||||
@ -10,6 +11,7 @@ pub fn find_child_in_parent_children(
|
|||||||
all_children.contains(&descendant_entity)
|
all_children.contains(&descendant_entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
fn flatten_if_possible_inf_levels(
|
fn flatten_if_possible_inf_levels(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
parent_entity: Entity,
|
parent_entity: Entity,
|
||||||
|
Loading…
Reference in New Issue
Block a user