Finished persisting optic pos data

This commit is contained in:
Franklin 2023-11-24 12:59:34 -04:00
parent 223d81d8f7
commit 13dd0e2733
5 changed files with 33 additions and 33 deletions

View File

@ -26,7 +26,7 @@ Multiplayer
- [x] Inspect animation & state (procedural) - [x] Inspect animation & state (procedural)
- [x] Attachment editor system when in inspect mode - [x] Attachment editor system when in inspect mode
- [x] remove Start and End optic from Slots, instead make one slot, and have code that checks for the starter slot and the end slot - [x] remove Start and End optic from Slots, instead make one slot, and have code that checks for the starter slot and the end slot
- [ ] SightSlot not retaining position when dropped or switched. - [x] SightSlot not retaining position when dropped or switched.
- [x] High Ready & Low Ready system with state - [x] High Ready & Low Ready system with state
- [x] High ready animation (procedural) - [x] High ready animation (procedural)
- [x] Low ready animation (procedural) - [x] Low ready animation (procedural)

View File

@ -4,13 +4,13 @@ use bevy::{prelude::*, gltf::Gltf, ecs::system::SystemParam, scene::SceneInstanc
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}}; 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}};
use super::{initial_attachments::InitialAttachments, sight_placement::{SightPlacementStart, SightPlacementEnd}}; use super::initial_attachments::InitialAttachments;
#[derive(SystemParam)] #[derive(SystemParam)]
pub struct InsertFirearmStateIntoFirearmsParams<'w, 's> { pub struct InsertFirearmStateIntoFirearmsParams<'w, 's> {
firearm_scene_bundle: Query<'w, 's, (Entity, Option<&'static ItemState>, Option<&'static InitialAttachments>, &'static Children), With<SceneInstance>>, firearm_scene_bundle: Query<'w, 's, (Entity, Option<&'static ItemState>, Option<&'static InitialAttachments>, &'static Children), With<SceneInstance>>,
firearm_query: Query<'w, 's, (Entity, &'static Firearm, &'static Parent, Option<&'static mut FirearmState>), Or<(Without<FirearmState>, Changed<FirearmState>)>>, firearm_query: Query<'w, 's, (Entity, &'static Firearm, &'static Parent, Option<&'static mut 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, &'static mut Transform)>,
attachments_query: Query<'w, 's, (Entity, &'static WeaponAttachment, &'static Parent)>, attachments_query: Query<'w, 's, (Entity, &'static WeaponAttachment, &'static Parent)>,
//sight_placement_start_query: Query<'w, 's, (&'static Parent, &'static Transform), (With<SightPlacementStart>, Without<SightPlacementEnd>)>, //sight_placement_start_query: Query<'w, 's, (&'static Parent, &'static Transform), (With<SightPlacementStart>, Without<SightPlacementEnd>)>,
//sight_placement_end_query: Query<'w, 's, (&'static Parent, &'static Transform), (With<SightPlacementEnd>, Without<SightPlacementStart>)>, //sight_placement_end_query: Query<'w, 's, (&'static Parent, &'static Transform), (With<SightPlacementEnd>, Without<SightPlacementStart>)>,
@ -37,6 +37,7 @@ pub fn insert_firearm_state_to_firearms(
if let ItemState::Weapon(mut firearm_state) = item_state.clone() { if let ItemState::Weapon(mut firearm_state) = item_state.clone() {
commands.entity(firearm_scene_entity).remove::<ItemState>(); commands.entity(firearm_scene_entity).remove::<ItemState>();
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, &assets_gltf, &loaded_gltf_assets);
adjust_sight_slot_position(&mut queries.slots_query, firearm_state.optic_pos);
commands commands
.entity(firearm_entity) .entity(firearm_entity)
.insert(firearm_state); .insert(firearm_state);
@ -48,6 +49,7 @@ pub fn insert_firearm_state_to_firearms(
Some(mut firearm_state) => { Some(mut firearm_state) => {
// Change the Slots // 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, &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 in_player_hands_item_id in queries.in_player_hands_query.iter() {
for player_inventory in queries.player_inventories_query.iter() { for player_inventory in queries.player_inventories_query.iter() {
if let Some(current_item) = player_inventory.get_current_slot_item() { if let Some(current_item) = player_inventory.get_current_slot_item() {
@ -62,7 +64,7 @@ pub fn insert_firearm_state_to_firearms(
// Create the firearm_state // Create the firearm_state
let mut firearm_slots = Vec::new(); let mut firearm_slots = Vec::new();
let magazine_data = None; let magazine_data = None;
for (slot_entity, slot, parent_entity) in queries.slots_query.iter() { for (slot_entity, slot, parent_entity, _) in queries.slots_query.iter() {
if firearm_entity == parent_entity.get() { if firearm_entity == parent_entity.get() {
let mut attachment = None; let mut attachment = None;
for (_, weapon_attachment, attachment_parent) in queries.attachments_query.iter() { for (_, weapon_attachment, attachment_parent) in queries.attachments_query.iter() {
@ -99,11 +101,11 @@ fn spawn_attachments_in_firearm(
commands: &mut Commands, commands: &mut Commands,
firearm_entity: Entity, firearm_entity: Entity,
firearm_state: &mut FirearmState, firearm_state: &mut FirearmState,
slots_query: &Query<(Entity, &WeaponSlot, &Parent)>, slots_query: &Query<(Entity, &WeaponSlot, &Parent, &mut Transform)>,
assets_gltf: &GltfAssets, assets_gltf: &GltfAssets,
loaded_gltf_assets: &Assets<Gltf>, loaded_gltf_assets: &Assets<Gltf>,
) { ) {
for (slot_entity, weapon_slot, slot_parent) in slots_query.iter() { for (slot_entity, weapon_slot, slot_parent, _) in slots_query.iter() {
if slot_parent.get() != firearm_entity { if slot_parent.get() != firearm_entity {
continue; continue;
} }
@ -137,3 +139,16 @@ fn spawn_attachments_in_firearm(
} }
} }
} }
fn adjust_sight_slot_position(
slots_query: &mut Query<(Entity, &'static WeaponSlot, &'static Parent, &'static mut Transform)>,
optic_pos_opt: Option<Vec3>,
) {
if let Some(optic_pos) = optic_pos_opt {
for (_, slot, _, mut slot_transform) in slots_query.iter_mut() {
if slot == &WeaponSlot::SightSlot {
slot_transform.translation = optic_pos;
}
}
}
}

View File

@ -1,6 +0,0 @@
use bevy::prelude::*;
/// This function takes currently equipped gun real world coordinates and converts them to UI coordinates that match the real world position in the screen.
pub fn map_gun_slots_to_ui_slots() {
}

View File

@ -1,6 +1,6 @@
use bevy::{prelude::*, ui::FocusPolicy}; use bevy::{prelude::*, ui::FocusPolicy};
use crate::{comps::core::{markers::{inspect_screen::{InspectScreenUiMarker, InspectScreenSlotUiMarker}, player::Player, holdable::InPlayerHands, camera::MainCamera}, weapons::{firearm_state::FirearmState, slot::slot::WeaponSlot}}, logic::core::guns::player_firing::PlayerFiringInfo}; use crate::{comps::core::{markers::{inspect_screen::{InspectScreenUiMarker, InspectScreenSlotUiMarker}, camera::MainCamera}, weapons::slot::slot::WeaponSlot}, logic::core::guns::player_firing::PlayerFiringInfo};
pub fn setup_inspect_screen(mut commands: Commands) { pub fn setup_inspect_screen(mut commands: Commands) {
// Background // Background
@ -17,7 +17,7 @@ pub fn setup_inspect_screen(mut commands: Commands) {
flex_direction: FlexDirection::Row, flex_direction: FlexDirection::Row,
..Default::default() ..Default::default()
}, },
visibility: Visibility::Visible, //TODO: switch off visibility: Visibility::Hidden,
background_color: BackgroundColor(Color::NONE), background_color: BackgroundColor(Color::NONE),
focus_policy: FocusPolicy::Block, focus_policy: FocusPolicy::Block,
..Default::default() ..Default::default()
@ -60,32 +60,24 @@ pub fn setup_inspect_screen(mut commands: Commands) {
)).set_parent(node_bg); )).set_parent(node_bg);
} }
// TODO: Create every single slot to be used here (1 per weapon slot)
} }
// TODO: put all queries in one params
// TODO: Add state of this screen to GameUiState
// TODO: Create slots if they aren't there for a specific weapon slot
// TODO: Hide and show slots depending on the weapon.
// TODO: Modify their contents to show what they have
pub fn update_inspect_screen( pub fn update_inspect_screen(
mut commands: Commands, //commands: Commands,
player_firing_info_query: Query<(&Player, &PlayerFiringInfo)>, player_firing_info_query: Query<&PlayerFiringInfo>,
in_player_hands_query: Query<(Entity, &InPlayerHands, &Children), Without<Player>>, slots_query: Query<(&WeaponSlot, &GlobalTransform)>,
mut firearm_query: Query<(Entity, &mut FirearmState), Without<InPlayerHands>>, mut inspect_screen_query: Query<&mut Visibility, With<InspectScreenUiMarker>>,
slots_query: Query<(Entity, &WeaponSlot, &GlobalTransform)>, mut inspect_slots_query: Query<(&mut Visibility, &mut InspectScreenSlotUiMarker, &mut Style, &mut BorderColor), Without<InspectScreenUiMarker>>,
mut inspect_screen_query: Query<(Entity, &mut Visibility), With<InspectScreenUiMarker>>,
mut inspect_slots_query: Query<(Entity, &mut Visibility, &mut InspectScreenSlotUiMarker, &mut Style, &mut BorderColor), Without<InspectScreenUiMarker>>,
camera_query: Query<(&Camera, &GlobalTransform), With<MainCamera>>, camera_query: Query<(&Camera, &GlobalTransform), With<MainCamera>>,
) { ) {
for (inspect_screen_entity, mut inspect_screen_visibility) in inspect_screen_query.iter_mut() { for mut inspect_screen_visibility in inspect_screen_query.iter_mut() {
for (player, player_firing_info) in player_firing_info_query.iter() { for player_firing_info in player_firing_info_query.iter() {
if player_firing_info.is_inspecting { if player_firing_info.is_inspecting {
*inspect_screen_visibility = Visibility::Visible; *inspect_screen_visibility = Visibility::Visible;
// TODO: Build // TODO: Build
for (camera, camera_transform) in camera_query.iter() { for (camera, camera_transform) in camera_query.iter() {
for (inspect_slot_entity, mut inspect_slot_visibility, mut inspect_slot, mut inspect_slot_style, mut inspect_slot_border_color) in inspect_slots_query.iter_mut() { for (mut inspect_slot_visibility, mut inspect_slot, mut inspect_slot_style, mut inspect_slot_border_color) in inspect_slots_query.iter_mut() {
for (slot_entity, slot, slot_transform) in slots_query.iter() { for (slot, slot_transform) in slots_query.iter() {
if &inspect_slot.slot == slot { if &inspect_slot.slot == slot {
//inspect_slot_text.sections.first_mut().expect("No section in an already created text...").value = format!("{}", slot.get_index()); //inspect_slot_text.sections.first_mut().expect("No section in an already created text...").value = format!("{}", slot.get_index());
match camera.world_to_viewport(camera_transform, slot_transform.translation()) { match camera.world_to_viewport(camera_transform, slot_transform.translation()) {
@ -111,7 +103,7 @@ pub fn update_inspect_screen(
} }
} else { } else {
*inspect_screen_visibility = Visibility::Hidden; *inspect_screen_visibility = Visibility::Hidden;
for (_, mut inspect_slot_visibility, _, _, _) in inspect_slots_query.iter_mut() { for (mut inspect_slot_visibility, _, _, _) in inspect_slots_query.iter_mut() {
*inspect_slot_visibility = Visibility::Hidden; *inspect_slot_visibility = Visibility::Hidden;
} }
} }

View File

@ -1,3 +1,2 @@
pub mod plugin; pub mod plugin;
pub mod mapper;
pub mod menu; pub mod menu;