Fixed weapon equip bug where changing firearm while in hands would not persist attachments
This commit is contained in:
parent
45845fcd6c
commit
802a3f5376
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -1918,6 +1918,7 @@ dependencies = [
|
|||||||
"bevy_gltf_components",
|
"bevy_gltf_components",
|
||||||
"bevy_hanabi",
|
"bevy_hanabi",
|
||||||
"bevy_rapier3d",
|
"bevy_rapier3d",
|
||||||
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -3990,11 +3991,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uuid"
|
name = "uuid"
|
||||||
version = "1.4.1"
|
version = "1.6.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d"
|
checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom",
|
"getrandom",
|
||||||
|
"rand",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -22,3 +22,9 @@ bevy_rapier3d = { version = "0.23", features = ["debug-render-3d"] }
|
|||||||
bevy_hanabi = { version = "0.8", default-features = false, features = [ "3d" ] }
|
bevy_hanabi = { version = "0.8", default-features = false, features = [ "3d" ] }
|
||||||
bevy-trait-query = "0.4.0"
|
bevy-trait-query = "0.4.0"
|
||||||
bevy_gltf_components = "0.2.0"
|
bevy_gltf_components = "0.2.0"
|
||||||
|
|
||||||
|
|
||||||
|
uuid = { version = "1.6.1", features = [
|
||||||
|
"v4", # Lets you generate random UUIDs
|
||||||
|
"fast-rng", # Use a faster (but still sufficiently random) RNG
|
||||||
|
] }
|
@ -13,6 +13,7 @@ impl ItemState {
|
|||||||
pub fn as_firearm_state(self) -> FirearmState {
|
pub fn as_firearm_state(self) -> FirearmState {
|
||||||
match self {
|
match self {
|
||||||
ItemState::Weapon(firearm_state) => firearm_state,
|
ItemState::Weapon(firearm_state) => firearm_state,
|
||||||
|
#[allow(unreachable_patterns)]
|
||||||
_ => panic!("Not a weapon ItemState variant...")
|
_ => panic!("Not a weapon ItemState variant...")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,6 @@ impl PlayerInventory {
|
|||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
};
|
};
|
||||||
let Some(firearm) = item.get_firearm() else { return; };
|
let Some(firearm) = item.get_firearm() else { return; };
|
||||||
println!("Pickup item: {:?}", item.get_state());
|
|
||||||
inventory_slot.item = Some(item);
|
inventory_slot.item = Some(item);
|
||||||
}
|
}
|
||||||
pub fn drop_item(&mut self, slot: PlayerInventorySlotType) {
|
pub fn drop_item(&mut self, slot: PlayerInventorySlotType) {
|
||||||
@ -66,7 +65,17 @@ impl PlayerInventory {
|
|||||||
PlayerInventorySlotType::Secondary => self.secondary.item = None,
|
PlayerInventorySlotType::Secondary => self.secondary.item = None,
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn get_current_slot_item(&self) -> Option<Arc<dyn Item>> {
|
||||||
|
match self.current_slot {
|
||||||
|
Some(current_slot) => match current_slot {
|
||||||
|
PlayerInventorySlotType::Primary => self.primary.item.clone(),
|
||||||
|
PlayerInventorySlotType::Secondary => self.secondary.item.clone(),
|
||||||
|
_ => unimplemented!(),
|
||||||
|
},
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Drop item from a specific slot.
|
/// Drop item from a specific slot.
|
||||||
@ -108,7 +117,6 @@ pub fn drop_slot_in_game_world(
|
|||||||
FirearmType::Primary => {
|
FirearmType::Primary => {
|
||||||
// Send equipment_changed_event
|
// Send equipment_changed_event
|
||||||
if let Some(primary_item) = player_inventory.get_primary() {
|
if let Some(primary_item) = player_inventory.get_primary() {
|
||||||
println!("drop_slot_in_game_world {:?}", primary_item.get_state());
|
|
||||||
// Drop this one
|
// Drop this one
|
||||||
primary_item.spawn(
|
primary_item.spawn(
|
||||||
commands,
|
commands,
|
||||||
|
@ -6,13 +6,15 @@ use bevy_rapier3d::{dynamics::{RigidBody, GravityScale, ExternalImpulse}, geomet
|
|||||||
|
|
||||||
use crate::{comps::core::{
|
use crate::{comps::core::{
|
||||||
grid::UGrid,
|
grid::UGrid,
|
||||||
items::item::{Item, ItemType},
|
items::item::{Item, ItemType, ItemId},
|
||||||
markers::{holdable::HoldableObjectType, interactable::Interactable}, inventory::slot::PlayerInventorySlotType, weapons::{firearm::Firearm, firearm_data::FirearmData}, events::pickup_item::ItemState,
|
markers::{holdable::HoldableObjectType, interactable::Interactable}, inventory::slot::PlayerInventorySlotType, weapons::{firearm::Firearm, firearm_data::FirearmData}, events::pickup_item::ItemState,
|
||||||
}, setup::assets::{GltfAssets, GltfAssetType}, utils};
|
}, setup::assets::{GltfAssets, GltfAssetType}, utils};
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component, Clone)]
|
||||||
pub struct Ak105GunItem {
|
pub struct Ak105GunItem {
|
||||||
pub state: Mutex<Option<ItemState>>
|
pub id: ItemId,
|
||||||
|
pub state: Mutex<Option<ItemState>>,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Item for Ak105GunItem {
|
impl Item for Ak105GunItem {
|
||||||
@ -52,6 +54,10 @@ impl Item for Ak105GunItem {
|
|||||||
PlayerInventorySlotType::Primary
|
PlayerInventorySlotType::Primary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn id(&self) -> ItemId {
|
||||||
|
self.id.clone()
|
||||||
|
}
|
||||||
|
|
||||||
fn spawn(
|
fn spawn(
|
||||||
&self,
|
&self,
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
@ -121,7 +127,8 @@ impl Item for Ak105GunItem {
|
|||||||
impulse: with_impulse,
|
impulse: with_impulse,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
Interactable::Item(Arc::new(Ak105GunItem { state: Mutex::new(item_state) })),
|
Interactable::Item(Arc::new(self.clone())),
|
||||||
|
self.id(),
|
||||||
))
|
))
|
||||||
.push_children(&[firearm_asset_entity]);
|
.push_children(&[firearm_asset_entity]);
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,14 @@ use bevy_rapier3d::{geometry::{ColliderMassProperties, Collider}, dynamics::{Rig
|
|||||||
|
|
||||||
use crate::{comps::core::{
|
use crate::{comps::core::{
|
||||||
grid::UGrid,
|
grid::UGrid,
|
||||||
items::item::{Item, ItemType},
|
items::item::{Item, ItemType, ItemId},
|
||||||
markers::{holdable::HoldableObjectType, interactable::Interactable}, inventory::slot::PlayerInventorySlotType, weapons::{firearm::Firearm, firearm_data::FirearmData}, events::pickup_item::ItemState,
|
markers::{holdable::HoldableObjectType, interactable::Interactable}, inventory::slot::PlayerInventorySlotType, weapons::{firearm::Firearm, firearm_data::FirearmData}, events::pickup_item::ItemState,
|
||||||
}, setup::assets::{GltfAssets, GltfAssetType}, utils};
|
}, setup::assets::{GltfAssets, GltfAssetType}, utils};
|
||||||
|
|
||||||
#[derive(Component, Reflect)]
|
#[derive(Component, Reflect, Clone)]
|
||||||
pub struct Glock17GunItem;
|
pub struct Glock17GunItem {
|
||||||
|
pub id: ItemId,
|
||||||
|
}
|
||||||
|
|
||||||
impl Item for Glock17GunItem {
|
impl Item for Glock17GunItem {
|
||||||
fn get_type(&self) -> ItemType {
|
fn get_type(&self) -> ItemType {
|
||||||
@ -118,7 +120,8 @@ impl Item for Glock17GunItem {
|
|||||||
impulse: with_impulse,
|
impulse: with_impulse,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
Interactable::Item(Arc::new(Glock17GunItem) ),
|
Interactable::Item(Arc::new(self.clone()) ),
|
||||||
|
self.id(),
|
||||||
))
|
))
|
||||||
.push_children(&[firearm_asset_entity]);
|
.push_children(&[firearm_asset_entity]);
|
||||||
}
|
}
|
||||||
@ -132,5 +135,9 @@ impl Item for Glock17GunItem {
|
|||||||
fn set_state(&self, state: Option<ItemState>) {
|
fn set_state(&self, state: Option<ItemState>) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn id(&self) -> ItemId {
|
||||||
|
self.id.clone()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use bevy::{gltf::Gltf, prelude::*};
|
use bevy::{gltf::Gltf, prelude::*};
|
||||||
use bevy_rapier3d::prelude::*;
|
use bevy_rapier3d::prelude::*;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub enum ItemType {
|
pub enum ItemType {
|
||||||
@ -16,6 +17,10 @@ pub enum ItemType {
|
|||||||
Consumable,
|
Consumable,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Reflect, Default)]
|
||||||
|
#[reflect(Component)]
|
||||||
|
pub struct ItemId(pub Uuid);
|
||||||
|
|
||||||
#[bevy_trait_query::queryable]
|
#[bevy_trait_query::queryable]
|
||||||
pub trait Item: Sync + Send {
|
pub trait Item: Sync + Send {
|
||||||
fn get_type(&self) -> ItemType;
|
fn get_type(&self) -> ItemType;
|
||||||
@ -28,6 +33,7 @@ pub trait Item: Sync + Send {
|
|||||||
fn inventory_description(&self) -> String;
|
fn inventory_description(&self) -> String;
|
||||||
fn set_state(&self, state: Option<ItemState>);
|
fn set_state(&self, state: Option<ItemState>);
|
||||||
fn get_state(&self) -> Option<ItemState>;
|
fn get_state(&self) -> Option<ItemState>;
|
||||||
|
fn id(&self) -> ItemId;
|
||||||
/// Spawn an item on the game world. Every item should implement this
|
/// Spawn an item on the game world. Every item should implement this
|
||||||
/// The transform passed to this function should be a GlobalTransform.into()
|
/// The transform passed to this function should be a GlobalTransform.into()
|
||||||
///
|
///
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use bevy::{prelude::*, gltf::Gltf, ecs::system::SystemParam, scene::SceneInstance};
|
use bevy::{prelude::*, gltf::Gltf, ecs::system::SystemParam, scene::SceneInstance};
|
||||||
|
|
||||||
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}};
|
use crate::{comps::core::{weapons::{firearm::Firearm, firearm_state::FirearmState, slot::slot::WeaponSlot, attachment_slot::AttachmentSlot, attachments::weapon_attachment::WeaponAttachment}, events::pickup_item::ItemState, markers::holdable::InPlayerHands, inventory::player_inventory::PlayerInventory, items::item::ItemId}, setup::assets::{GltfAssets, GltfAssetType}};
|
||||||
|
|
||||||
#[derive(SystemParam)]
|
#[derive(SystemParam)]
|
||||||
pub struct InsertFirearmStateIntoFirearmsParams<'w, 's> {
|
pub struct InsertFirearmStateIntoFirearmsParams<'w, 's> {
|
||||||
@ -8,6 +8,8 @@ pub struct InsertFirearmStateIntoFirearmsParams<'w, 's> {
|
|||||||
firearm_query: Query<'w, 's, (Entity, &'static Firearm, &'static Parent, Option<&'static FirearmState>), Or<(Without<FirearmState>, Changed<FirearmState>)>>,
|
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)>,
|
slots_query: Query<'w, 's, (Entity, &'static WeaponSlot, &'static Parent)>,
|
||||||
attachments_query: Query<'w, 's, (Entity, &'static WeaponAttachment, &'static Parent)>,
|
attachments_query: Query<'w, 's, (Entity, &'static WeaponAttachment, &'static Parent)>,
|
||||||
|
in_player_hands_query: Query<'w, 's, &'static ItemId, With<InPlayerHands>>,
|
||||||
|
player_inventories_query: Query<'w, 's, &'static PlayerInventory>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This query inserts FirearmState into firearms, updates firearm assets that already have a FirearmState,
|
/// This query inserts FirearmState into firearms, updates firearm assets that already have a FirearmState,
|
||||||
@ -40,6 +42,16 @@ pub fn insert_firearm_state_to_firearms(
|
|||||||
Some(firearm_state) => {
|
Some(firearm_state) => {
|
||||||
// Change the Slots
|
// Change the Slots
|
||||||
spawn_attachments_in_firearm(&mut commands, firearm_entity, firearm_state, &queries.slots_query, &assets_gltf, &loaded_gltf_assets);
|
spawn_attachments_in_firearm(&mut commands, firearm_entity, firearm_state, &queries.slots_query, &assets_gltf, &loaded_gltf_assets);
|
||||||
|
//TODO: Change firearm state inside inventory
|
||||||
|
for in_player_hands_item_id in queries.in_player_hands_query.iter() {
|
||||||
|
for player_inventory in queries.player_inventories_query.iter() {
|
||||||
|
if let Some(current_item) = player_inventory.get_current_slot_item() {
|
||||||
|
if ¤t_item.id() == in_player_hands_item_id {
|
||||||
|
current_item.set_state(Some(ItemState::Weapon(firearm_state.clone())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
// Create the firearm_state
|
// Create the firearm_state
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_inspector_egui::egui::mutex::Mutex;
|
use bevy_inspector_egui::egui::mutex::Mutex;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::comps::core::{
|
use crate::comps::core::{
|
||||||
items::{guns::ak105::Ak105GunItem, item::Item},
|
items::{guns::ak105::Ak105GunItem, item::{Item, ItemId}},
|
||||||
spawners::item::ItemSpawnPoint,
|
spawners::item::ItemSpawnPoint,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -17,6 +18,6 @@ impl ItemSpawnPoint for Ak105SpawnPoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_item(&self) -> Box<dyn Item> {
|
fn get_item(&self) -> Box<dyn Item> {
|
||||||
Box::new(Ak105GunItem { state: Mutex::new(None) })
|
Box::new(Ak105GunItem { state: Mutex::new(None), id: ItemId(Uuid::new_v4()) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::comps::core::{
|
use crate::comps::core::{
|
||||||
items::{guns::glock17::Glock17GunItem, item::Item},
|
items::{guns::glock17::Glock17GunItem, item::{Item, ItemId}},
|
||||||
spawners::item::ItemSpawnPoint,
|
spawners::item::ItemSpawnPoint,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -16,6 +17,6 @@ impl ItemSpawnPoint for Glock17SpawnPoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_item(&self) -> Box<dyn Item> {
|
fn get_item(&self) -> Box<dyn Item> {
|
||||||
Box::new(Glock17GunItem)
|
Box::new(Glock17GunItem { id: ItemId(Uuid::new_v4()) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,7 @@ pub fn player_spawner(
|
|||||||
game_load_state.player_loaded = true;
|
game_load_state.player_loaded = true;
|
||||||
equipment_change_event_writer.send(EquipmentChangeEvent(
|
equipment_change_event_writer.send(EquipmentChangeEvent(
|
||||||
player_spawn_point.player.0.equipment.clone(),
|
player_spawn_point.player.0.equipment.clone(),
|
||||||
|
None
|
||||||
));
|
));
|
||||||
commands.entity(player_spawn_point_entity).despawn();
|
commands.entity(player_spawn_point_entity).despawn();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::sync::{Arc};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_inspector_egui::egui::mutex::Mutex;
|
use bevy_inspector_egui::egui::mutex::Mutex;
|
||||||
@ -153,19 +153,4 @@ impl Firearm {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_item_arc(&self) -> Arc<dyn Item> {
|
|
||||||
match self {
|
|
||||||
//Firearm::M4A1 => Arc::new(M4a1GunItem),
|
|
||||||
Firearm::Glock17 => Arc::new(Glock17GunItem),
|
|
||||||
Firearm::Ak105 => Arc::new(Ak105GunItem { state: Mutex::new(None) }),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn get_item_box(&self) -> Box<dyn Item> {
|
|
||||||
match self {
|
|
||||||
//Firearm::M4A1 => Box::new(M4a1GunItem),
|
|
||||||
Firearm::Glock17 => Box::new(Glock17GunItem),
|
|
||||||
Firearm::Ak105 => Box::new(Ak105GunItem { state: Mutex::new(None) }),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -76,9 +76,8 @@ pub fn capture_hand_usage(
|
|||||||
if Equipment::Firearm(primary_firearm.clone(), primary_item.get_state().expect("No item state in an equipped Item.").as_firearm_state())
|
if Equipment::Firearm(primary_firearm.clone(), primary_item.get_state().expect("No item state in an equipped Item.").as_firearm_state())
|
||||||
!= player.0.equipment
|
!= player.0.equipment
|
||||||
{
|
{
|
||||||
println!("CaptureHandUsage {:?}", primary_item.get_state().expect("No item state in an equipped Item.").as_firearm_state());
|
|
||||||
equipment_change_event_writer
|
equipment_change_event_writer
|
||||||
.send(EquipmentChangeEvent(Equipment::Firearm(primary_firearm, primary_item.get_state().expect("No item state in an equipped Item.").as_firearm_state())));
|
.send(EquipmentChangeEvent(Equipment::Firearm(primary_firearm, primary_item.get_state().expect("No item state in an equipped Item.").as_firearm_state()), Some(primary_item.id())));
|
||||||
player_inventory.current_slot = Some(PlayerInventorySlotType::Primary);
|
player_inventory.current_slot = Some(PlayerInventorySlotType::Primary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,14 +89,14 @@ pub fn capture_hand_usage(
|
|||||||
!= player.0.equipment
|
!= player.0.equipment
|
||||||
{
|
{
|
||||||
equipment_change_event_writer
|
equipment_change_event_writer
|
||||||
.send(EquipmentChangeEvent(Equipment::Firearm(secondary_firearm, secondary_item.get_state().expect("No item state in an equipped Item.").as_firearm_state())));
|
.send(EquipmentChangeEvent(Equipment::Firearm(secondary_firearm, secondary_item.get_state().expect("No item state in an equipped Item.").as_firearm_state()), Some(secondary_item.id())));
|
||||||
player_inventory.current_slot = Some(PlayerInventorySlotType::Secondary);
|
player_inventory.current_slot = Some(PlayerInventorySlotType::Secondary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if resources.keyboard_input.just_pressed(KeyCode::Key3) {
|
} else if resources.keyboard_input.just_pressed(KeyCode::Key3) {
|
||||||
if Equipment::Nothing != player.0.equipment {
|
if Equipment::Nothing != player.0.equipment {
|
||||||
equipment_change_event_writer.send(EquipmentChangeEvent(Equipment::Nothing));
|
equipment_change_event_writer.send(EquipmentChangeEvent(Equipment::Nothing, None));
|
||||||
player_inventory.current_slot = None;
|
player_inventory.current_slot = None;
|
||||||
}
|
}
|
||||||
} else if resources.keyboard_input.just_pressed(KeyCode::G) {
|
} else if resources.keyboard_input.just_pressed(KeyCode::G) {
|
||||||
@ -107,7 +106,7 @@ pub fn capture_hand_usage(
|
|||||||
for (firearm_entity, _, firearm_state, _) in firearms_query.iter() {
|
for (firearm_entity, _, firearm_state, _) in firearms_query.iter() {
|
||||||
if find_child_in_parent_children(&mut commands, in_player_hands_entity, firearm_entity, &children) {
|
if find_child_in_parent_children(&mut commands, in_player_hands_entity, firearm_entity, &children) {
|
||||||
player_inventory::drop_slot_in_game_world(&mut commands, player_transform, &mut inventory_changed_events, &mut player_inventory, &resources.assets_gltf, &resources.loaded_gltf_assets, current_slot, Some(ItemState::Weapon(firearm_state.clone())));
|
player_inventory::drop_slot_in_game_world(&mut commands, player_transform, &mut inventory_changed_events, &mut player_inventory, &resources.assets_gltf, &resources.loaded_gltf_assets, current_slot, Some(ItemState::Weapon(firearm_state.clone())));
|
||||||
equipment_change_event_writer.send(EquipmentChangeEvent(Equipment::Nothing));
|
equipment_change_event_writer.send(EquipmentChangeEvent(Equipment::Nothing, None));
|
||||||
player_inventory.current_slot = None;
|
player_inventory.current_slot = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -352,7 +351,6 @@ pub fn interact_action(
|
|||||||
item_state = Some(ItemState::Weapon(firearm_state.clone()));
|
item_state = Some(ItemState::Weapon(firearm_state.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("Setting item state: {:?}", item_state);
|
|
||||||
item.set_state(item_state);
|
item.set_state(item_state);
|
||||||
|
|
||||||
pickup_item_event_writer.send(PickupItemEvent {
|
pickup_item_event_writer.send(PickupItemEvent {
|
||||||
|
@ -24,7 +24,6 @@ pub fn update_player_inventory_system(
|
|||||||
//player_inventory::drop_slot_in_game_world(&mut commands, player_transform, &mut inventory_changed_events, &mut player_inventory, &assets_gltf, &loaded_gltf_assets, event.item.get_item_slot(), event.item.get_state().clone());
|
//player_inventory::drop_slot_in_game_world(&mut commands, player_transform, &mut inventory_changed_events, &mut player_inventory, &assets_gltf, &loaded_gltf_assets, event.item.get_item_slot(), event.item.get_state().clone());
|
||||||
player_inventory.pickup_item(event.item.clone(), event.item.get_item_slot());
|
player_inventory.pickup_item(event.item.clone(), event.item.get_item_slot());
|
||||||
inventory_changed_events.send(PlayerInventoryChangedEvent { item: Some(event.item.clone()), slot_type: event.item.get_item_slot() });
|
inventory_changed_events.send(PlayerInventoryChangedEvent { item: Some(event.item.clone()), slot_type: event.item.get_item_slot() });
|
||||||
println!("Inventory Changed Event sent");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ use crate::{
|
|||||||
comps::core::{markers::{
|
comps::core::{markers::{
|
||||||
holdable::InPlayerHands,
|
holdable::InPlayerHands,
|
||||||
player::Player, proxy::character::in_player_hands_parent::InPlayerHandsParent,
|
player::Player, proxy::character::in_player_hands_parent::InPlayerHandsParent,
|
||||||
}, weapons::{firearm::Firearm, firearm_data::FirearmData, firearm_state::FirearmState}, events::pickup_item::ItemState},
|
}, weapons::{firearm::Firearm, firearm_data::FirearmData, firearm_state::FirearmState}, events::pickup_item::ItemState, items::item::ItemId},
|
||||||
logic::core::guns::player_firing::PlayerFiringInfo,
|
logic::core::guns::player_firing::PlayerFiringInfo,
|
||||||
utils,
|
utils,
|
||||||
};
|
};
|
||||||
@ -14,7 +14,7 @@ use crate::{
|
|||||||
use super::assets::{GltfAssetType, GltfAssets};
|
use super::assets::{GltfAssetType, GltfAssets};
|
||||||
|
|
||||||
#[derive(Event)]
|
#[derive(Event)]
|
||||||
pub struct EquipmentChangeEvent(pub Equipment);
|
pub struct EquipmentChangeEvent(pub Equipment, pub Option<ItemId>);
|
||||||
/// Foundation for inventory System.
|
/// Foundation for inventory System.
|
||||||
#[derive(Component, Clone, Default, Reflect, PartialEq, PartialOrd)]
|
#[derive(Component, Clone, Default, Reflect, PartialEq, PartialOrd)]
|
||||||
pub enum Equipment {
|
pub enum Equipment {
|
||||||
@ -42,10 +42,8 @@ pub fn change_equipment(
|
|||||||
let player_hands = player_hands_query.single_mut();
|
let player_hands = player_hands_query.single_mut();
|
||||||
|
|
||||||
commands.entity(player_hands).despawn_descendants(); // TODO: Don't do this without keeping the state from the last mag
|
commands.entity(player_hands).despawn_descendants(); // TODO: Don't do this without keeping the state from the last mag
|
||||||
println!("");
|
|
||||||
|
|
||||||
if let Equipment::Firearm(new_firearm, firearm_state) = equipment_change_event.0.clone() {
|
if let Equipment::Firearm(new_firearm, firearm_state) = equipment_change_event.0.clone() {
|
||||||
println!("Equipping: {:?}", firearm_state);
|
|
||||||
spawn_firearm_on_player_hands(
|
spawn_firearm_on_player_hands(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
player_firing_info,
|
player_firing_info,
|
||||||
@ -54,6 +52,7 @@ pub fn change_equipment(
|
|||||||
&loaded_gltf_assets,
|
&loaded_gltf_assets,
|
||||||
new_firearm,
|
new_firearm,
|
||||||
firearm_state,
|
firearm_state,
|
||||||
|
equipment_change_event.1.clone().expect("Spawning firearm on player hands without an ItemId")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +70,7 @@ fn spawn_firearm_on_player_hands(
|
|||||||
loaded_gltf_assets: &Assets<Gltf>,
|
loaded_gltf_assets: &Assets<Gltf>,
|
||||||
firearm: Firearm,
|
firearm: Firearm,
|
||||||
firearm_state: FirearmState,
|
firearm_state: FirearmState,
|
||||||
|
item_id: ItemId,
|
||||||
) {
|
) {
|
||||||
if let Some(asset_handle) = assets_gltf
|
if let Some(asset_handle) = assets_gltf
|
||||||
.assets
|
.assets
|
||||||
@ -103,6 +103,7 @@ fn spawn_firearm_on_player_hands(
|
|||||||
.spawn((
|
.spawn((
|
||||||
firearm.holdable_object_data(),
|
firearm.holdable_object_data(),
|
||||||
InPlayerHands,
|
InPlayerHands,
|
||||||
|
item_id,
|
||||||
Name::new("Firearm"),
|
Name::new("Firearm"),
|
||||||
TransformBundle {
|
TransformBundle {
|
||||||
local: Transform::from_xyz(0.0, 0.0, 0.0),
|
local: Transform::from_xyz(0.0, 0.0, 0.0),
|
||||||
|
Loading…
Reference in New Issue
Block a user