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"
|
||||
checksum = "329e344f835f5a9a4c46a6d1d57371f726aa2c482d1bd669b2b9c4eb1ee91fd7"
|
||||
dependencies = [
|
||||
"bevy_dylib",
|
||||
"bevy_internal",
|
||||
]
|
||||
|
||||
@ -587,15 +586,6 @@ dependencies = [
|
||||
"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]]
|
||||
name = "bevy_ecs"
|
||||
version = "0.12.0"
|
||||
|
@ -15,7 +15,7 @@ opt-level = 3
|
||||
opt-level = 3
|
||||
|
||||
[dependencies]
|
||||
bevy = { version = "0.12", features = ["dynamic_linking"]}
|
||||
bevy = { version = "0.12", features = []}
|
||||
bevy-inspector-egui = "0.21.0"
|
||||
bevy_editor_pls = "0.6"
|
||||
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 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.
|
||||
/// 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 item: Arc<dyn Item>,
|
||||
pub player: Entity,
|
||||
pub state: Option<ItemState>
|
||||
}
|
||||
|
@ -111,6 +111,7 @@ pub fn drop_slot_in_game_world(
|
||||
&assets_gltf,
|
||||
&loaded_gltf_assets,
|
||||
drop_impulse,
|
||||
None
|
||||
);
|
||||
}
|
||||
player_inventory.drop_item(PlayerInventorySlotType::Primary);
|
||||
@ -124,6 +125,7 @@ pub fn drop_slot_in_game_world(
|
||||
&assets_gltf,
|
||||
&loaded_gltf_assets,
|
||||
drop_impulse,
|
||||
None
|
||||
);
|
||||
}
|
||||
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,
|
||||
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)]
|
||||
pub struct Ak105GunItem;
|
||||
|
||||
impl Item for Ak105GunItem {
|
||||
fn get_type(&self) -> ItemType {
|
||||
ItemType::Holdable(HoldableObjectType::Firearm(Firearm::Glock17))
|
||||
ItemType::Holdable(HoldableObjectType::Firearm(Firearm::Ak105))
|
||||
}
|
||||
|
||||
fn asset_path(&self) -> &str {
|
||||
@ -45,4 +46,80 @@ impl Item for Ak105GunItem {
|
||||
fn get_item_slot(&self) -> PlayerInventorySlotType {
|
||||
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,
|
||||
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)]
|
||||
pub struct Glock17GunItem;
|
||||
@ -45,4 +46,80 @@ impl Item for Glock17GunItem {
|
||||
fn get_item_slot(&self) -> PlayerInventorySlotType {
|
||||
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::{
|
||||
comps::core::{
|
||||
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},
|
||||
utils,
|
||||
@ -26,6 +26,8 @@ pub trait Item: Sync + Send + Reflect {
|
||||
fn inventory_rotatable(&self) -> bool;
|
||||
fn inventory_title(&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(
|
||||
&self,
|
||||
commands: &mut Commands,
|
||||
@ -33,6 +35,7 @@ pub trait Item: Sync + Send + Reflect {
|
||||
assets_gltf: &GltfAssets,
|
||||
loaded_gltf_assets: &Assets<Gltf>,
|
||||
with_impulse: Vec3,
|
||||
item_state: Option<ItemState>,
|
||||
) {
|
||||
match self.get_type() {
|
||||
ItemType::Holdable(object_type) => {
|
||||
|
@ -1,8 +1,8 @@
|
||||
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
|
||||
app.register_type::<WeaponAttachment>();
|
||||
app.register_type::<WeaponSlot>();
|
||||
app.register_type::<Optic>();
|
||||
app.register_type::<Stock>();
|
||||
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, insert_components_into_spawned_player);
|
||||
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)]
|
||||
pub enum Firearm {
|
||||
Ak105,
|
||||
Glock17
|
||||
#[derive(SystemParam)]
|
||||
pub struct InsertFirearmStateIntoFirearmsParams<'w, 's> {
|
||||
firearm_scene_bundle: Query<'w, 's, (Entity, Option<&'static ItemState>, &'static Children)>,
|
||||
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,
|
||||
&loaded_gltf_assets,
|
||||
Vec3::ZERO,
|
||||
None
|
||||
)
|
||||
}
|
||||
//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)]
|
||||
#[reflect(Component)]
|
||||
#[reflect(Component, Default)]
|
||||
pub enum Compensator {
|
||||
#[default]
|
||||
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)]
|
||||
#[reflect(Component)]
|
||||
#[reflect(Component, Default)]
|
||||
pub enum ForeGrip {
|
||||
#[default]
|
||||
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)]
|
||||
#[reflect(Component)]
|
||||
#[reflect(Component, Default)]
|
||||
pub enum Magazine {
|
||||
#[default]
|
||||
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)]
|
||||
#[reflect(Component)]
|
||||
#[reflect(Component, Default)]
|
||||
pub enum Optic {
|
||||
#[default]
|
||||
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)]
|
||||
#[reflect(Component)]
|
||||
#[reflect(Component, Default)]
|
||||
pub enum Stock {
|
||||
#[default]
|
||||
MagpullTan,
|
||||
|
@ -3,7 +3,7 @@ use bevy::prelude::*;
|
||||
use super::{compensator::Compensator, magazine::Magazine, stock::Stock, foregrip::ForeGrip, optic::Optic};
|
||||
|
||||
#[derive(Component, PartialEq, Eq, PartialOrd, Ord, Clone, Reflect, Debug)]
|
||||
#[reflect(Component)]
|
||||
#[reflect(Component, Default)]
|
||||
pub enum WeaponAttachment {
|
||||
Compensator(Compensator),
|
||||
Magazine(Magazine),
|
||||
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||
|
||||
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};
|
||||
|
||||
@ -157,14 +157,14 @@ impl Firearm {
|
||||
match self {
|
||||
//Firearm::M4A1 => Arc::new(M4a1GunItem),
|
||||
Firearm::Glock17 => Arc::new(Glock17GunItem),
|
||||
Firearm::Ak105 => todo!(),
|
||||
Firearm::Ak105 => Arc::new(Ak105GunItem),
|
||||
}
|
||||
}
|
||||
pub fn get_item_box(&self) -> Box<dyn Item> {
|
||||
match self {
|
||||
//Firearm::M4A1 => Box::new(M4a1GunItem),
|
||||
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 }
|
||||
}
|
||||
|
||||
}
|
@ -6,3 +6,5 @@ pub mod spray_pattern;
|
||||
pub mod magazine_data;
|
||||
pub mod slot;
|
||||
pub mod parts;
|
||||
pub mod firearm_state;
|
||||
pub mod attachment_slot;
|
@ -5,3 +5,4 @@ pub mod fore_grip_slot;
|
||||
pub mod utility_slot;
|
||||
pub mod sight_placement_start_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,
|
||||
item: item.clone(),
|
||||
player: player_entity,
|
||||
state: None
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use crate::{
|
||||
comps::core::{
|
||||
markers::player::{Player, PlayerData},
|
||||
spawners::{
|
||||
guns::glock17_spawner::Glock17SpawnPoint,
|
||||
guns::{glock17_spawner::Glock17SpawnPoint, ak105_spawner::Ak105SpawnPoint},
|
||||
player::PlayerSpawnPoint,
|
||||
},
|
||||
},
|
||||
@ -30,13 +30,13 @@ pub fn set_spawn_points(mut commands: Commands) {
|
||||
transform
|
||||
},
|
||||
});
|
||||
/*commands.spawn(M4a1SpawnPoint {
|
||||
commands.spawn(Ak105SpawnPoint {
|
||||
transform: {
|
||||
let mut transform = Transform::from_xyz(18.0, 10.0, 18.0);
|
||||
transform.rotate_z(utils::rad_deg::radians_from_degrees(-90.0));
|
||||
transform
|
||||
},
|
||||
});*/
|
||||
});
|
||||
commands.spawn(Glock17SpawnPoint {
|
||||
transform: {
|
||||
let mut transform = Transform::from_xyz(20.0, 10.0, 20.0);
|
||||
|
@ -6,7 +6,7 @@ use crate::{
|
||||
comps::core::{markers::{
|
||||
holdable::{HoldableObjectData, InPlayerHands},
|
||||
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::{
|
||||
guns::player_firing::PlayerFiringInfo,
|
||||
player::{
|
||||
@ -51,6 +51,7 @@ impl Plugin for MainEditorUiPlugin {
|
||||
.register_type::<PlayerLinearXZState>()
|
||||
.register_type::<PlayerMovementInput>()
|
||||
.register_type::<Cubemap>()
|
||||
.register_type::<FirearmState>()
|
||||
//.register_type::<AllAnimations>()
|
||||
//.register_type::<FirearmAnimations>()
|
||||
.register_type::<GltfAssetType>()
|
||||
|
@ -1,5 +1,6 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn find_child_in_parent_children(
|
||||
commands: &mut Commands,
|
||||
parent_entity: Entity,
|
||||
@ -10,6 +11,7 @@ pub fn find_child_in_parent_children(
|
||||
all_children.contains(&descendant_entity)
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn flatten_if_possible_inf_levels(
|
||||
commands: &mut Commands,
|
||||
parent_entity: Entity,
|
||||
|
Loading…
Reference in New Issue
Block a user