diff --git a/Design.md b/Design.md index b48da22..28cd7ae 100644 --- a/Design.md +++ b/Design.md @@ -38,8 +38,11 @@ Multiplayer - [x] Optics - [x] All optics implementing a fn/trait that gives a specific gun offset to use the optic correctly - [ ] TODO: Find some way to implement a shader for the optics (AFTER IMPLEMENTING NEW BULLET SYSTEM) + - [ ] Optic glass material + - [ ] Reticle render + - [ ] Parallax effect on reticle - [ ] Weapon Clipping - - [ ] Make the player's collider bigger towards the front + - [x] Make the player's collider bigger towards the front - [ ] Make the weapon's collider cover the firing point - [ ] If possible, create a new gun pose, like pushed back - [ ] Bobbing @@ -53,6 +56,7 @@ Multiplayer - [x] Gun dropping does not apply impulse for some reason... - [x] Gun colliding with ground and going into low ready - [x] With introduction of floor collision groups now bullets go through floors +- [x] TODO: Huge bug all attachments get despawned and spawned when gun shoots # Design diff --git a/assets/attachments/aimpoint_t1.glb b/assets/attachments/aimpoint_t1.glb index 404dbf9..4e3173e 100644 Binary files a/assets/attachments/aimpoint_t1.glb and b/assets/attachments/aimpoint_t1.glb differ diff --git a/src/comps/core/markers/proxy/plugin.rs b/src/comps/core/markers/proxy/plugin.rs index 7efc47d..501a220 100644 --- a/src/comps/core/markers/proxy/plugin.rs +++ b/src/comps/core/markers/proxy/plugin.rs @@ -2,7 +2,7 @@ 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, 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}, weapons::{firearm::insert_firearm_state_to_firearms, gun_colliders::{GunFirearmCollider, update_gun_collider}, sight_placement::{SightPlacementStart, SightPlacementEnd}}}; +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, gun_colliders::{GunFirearmCollider, update_gun_collider}, sight_placement::{SightPlacementStart, SightPlacementEnd}, optic_sight_glass::{OpticSightGlass, replace_optic_sight_material}}}; @@ -36,6 +36,8 @@ impl Plugin for ProxyComponentsPlugin { app.register_type::(); app.register_type::(); + app.register_type::(); + // Parts app.register_type::(); app.register_type::(); @@ -54,10 +56,12 @@ impl Plugin for ProxyComponentsPlugin { app.register_type::(); app.register_type::(); app.register_type::(); + 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); app.add_systems(Update, update_gun_collider); + app.add_systems(Update, replace_optic_sight_material); } } \ No newline at end of file diff --git a/src/comps/core/markers/proxy/weapons/firearm.rs b/src/comps/core/markers/proxy/weapons/firearm.rs index a55a478..9f5f9f9 100644 --- a/src/comps/core/markers/proxy/weapons/firearm.rs +++ b/src/comps/core/markers/proxy/weapons/firearm.rs @@ -11,7 +11,8 @@ pub struct InsertFirearmStateIntoFirearmsParams<'w, 's> { firearm_scene_bundle: Query<'w, 's, (Entity, Option<&'static ItemState>, Option<&'static InitialAttachments>, &'static Children), With>, firearm_query: Query<'w, 's, (Entity, &'static Firearm, &'static Parent, Option<&'static mut FirearmState>), Or<(Without, Changed)>>, slots_query: Query<'w, 's, (Entity, &'static WeaponSlot, &'static Parent, &'static mut Transform)>, - attachments_query: Query<'w, 's, (Entity, &'static WeaponAttachment, &'static Parent)>, + attachments_query: Query<'w, 's, (&'static WeaponAttachment, &'static Parent)>, + scenes_query: Query<'w, 's, (&'static Children, &'static Parent), With>>, //sight_placement_start_query: Query<'w, 's, (&'static Parent, &'static Transform), (With, Without)>, //sight_placement_end_query: Query<'w, 's, (&'static Parent, &'static Transform), (With, Without)>, in_player_hands_query: Query<'w, 's, &'static ItemId, With>, @@ -36,7 +37,7 @@ pub fn insert_firearm_state_to_firearms( #[allow(irrefutable_let_patterns)] if let ItemState::Weapon(mut firearm_state) = item_state.clone() { commands.entity(firearm_scene_entity).remove::(); - spawn_attachments_in_firearm(&mut commands, firearm_entity, &mut firearm_state, &queries.slots_query, &assets_gltf, &loaded_gltf_assets); + spawn_attachments_in_firearm(&mut commands, firearm_entity, &mut firearm_state, &queries.slots_query, &queries.attachments_query, &queries.scenes_query, &assets_gltf, &loaded_gltf_assets); adjust_sight_slot_position(&mut queries.slots_query, firearm_state.optic_pos); commands .entity(firearm_entity) @@ -48,7 +49,7 @@ pub fn insert_firearm_state_to_firearms( match firearm_state_opt { Some(mut firearm_state) => { // Change the Slots - spawn_attachments_in_firearm(&mut commands, firearm_entity, &mut firearm_state, &queries.slots_query, &assets_gltf, &loaded_gltf_assets); + spawn_attachments_in_firearm(&mut commands, firearm_entity, &mut firearm_state, &queries.slots_query, &queries.attachments_query, &queries.scenes_query, &assets_gltf, &loaded_gltf_assets); adjust_sight_slot_position(&mut queries.slots_query, firearm_state.optic_pos); for in_player_hands_item_id in queries.in_player_hands_query.iter() { for player_inventory in queries.player_inventories_query.iter() { @@ -67,7 +68,7 @@ pub fn insert_firearm_state_to_firearms( 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() { + for (weapon_attachment, attachment_parent) in queries.attachments_query.iter() { if slot_entity == attachment_parent.get() { attachment = Some(weapon_attachment.clone()) } @@ -102,6 +103,8 @@ fn spawn_attachments_in_firearm( firearm_entity: Entity, firearm_state: &mut FirearmState, slots_query: &Query<(Entity, &WeaponSlot, &Parent, &mut Transform)>, + attachments_query: &Query<(&'static WeaponAttachment, &'static Parent)>, + scenes_query: &Query<(&'static Children, &'static Parent), With>>, assets_gltf: &GltfAssets, loaded_gltf_assets: &Assets, ) { @@ -111,9 +114,24 @@ fn spawn_attachments_in_firearm( } for attachment_slot in firearm_state.attachment_slots.iter() { if discriminant(&attachment_slot.slot_type) == discriminant(weapon_slot) { - commands.entity(slot_entity).despawn_descendants(); match &attachment_slot.attachment { Some(attachment) => + { + // Check for existing attachment in slot, if it matches then don't despawn it. + let mut skip = false; + for (scene_children, scene_parent) in scenes_query.iter() { + for (weapon_attachment, attachment_parent) in attachments_query.iter() { + if scene_parent.get() == slot_entity { + for scene_child in scene_children { + if scene_child == &attachment_parent.get() && weapon_attachment == attachment{ + skip = true; + } + } + } + } + } + if skip { continue; } + commands.entity(slot_entity).despawn_descendants(); if let Some(asset_handle) = assets_gltf.assets.iter().find(|asset| { asset.asset_type == GltfAssetType::Attachment(attachment.clone()) }) { @@ -132,8 +150,11 @@ fn spawn_attachments_in_firearm( firearm_state.magazine_data = Some(magazine.magazine_data()); } } - }}, - None => {}, + }} + }, + None => { + commands.entity(slot_entity).despawn_descendants(); + }, }; } } diff --git a/src/comps/core/markers/proxy/weapons/mod.rs b/src/comps/core/markers/proxy/weapons/mod.rs index 78da5ef..696b9ad 100644 --- a/src/comps/core/markers/proxy/weapons/mod.rs +++ b/src/comps/core/markers/proxy/weapons/mod.rs @@ -1,4 +1,5 @@ pub mod firearm; pub mod initial_attachments; pub mod gun_colliders; -pub mod sight_placement; \ No newline at end of file +pub mod sight_placement; +pub mod optic_sight_glass; \ No newline at end of file diff --git a/src/comps/core/markers/proxy/weapons/optic_sight_glass.rs b/src/comps/core/markers/proxy/weapons/optic_sight_glass.rs new file mode 100644 index 0000000..f942f49 --- /dev/null +++ b/src/comps/core/markers/proxy/weapons/optic_sight_glass.rs @@ -0,0 +1,23 @@ +use bevy::prelude::*; + +#[derive(Default, Component, Reflect, Debug)] +#[reflect(Component)] +pub struct OpticSightGlass; + +pub fn replace_optic_sight_material( + //mut commands: Commands, + marker_query: Query>, + materials_query: Query<(&Parent, &Handle), With>>, + mut materials: ResMut>, +) { + for marker in marker_query.iter() { + println!("One marker once"); + for (material_parent, material_handle) in materials_query.iter() { + if marker == material_parent.get() { + if let Some(mut material) = materials.get_mut(material_handle) { + println!("Changed material"); + } + } + } + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 1b5dc05..e945ae1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,9 @@ fn main() { fn setup_plugins(application: &mut App) { application - .add_plugins(DefaultPlugins.set(AssetPlugin::default())) + .add_plugins(DefaultPlugins.set(AssetPlugin { + ..Default::default() + })) //.add_plugins(DefaultInspectorConfigPlugin) .add_plugins(RapierPhysicsPlugin::::default()) //.add_plugins(RapierDebugRenderPlugin::default())