npc reloading (#28)

This commit is contained in:
extrawurst
2025-04-15 08:30:41 +02:00
committed by GitHub
parent 2e5ec8f3d8
commit 248f92be27
8 changed files with 123 additions and 76 deletions

View File

@@ -1,7 +1,12 @@
use super::AimTarget;
use crate::{
GameState, backpack::UiHeadState, heads::HeadsImages, hitpoints::Hitpoints,
loading_assets::UIAssets, npc::Npc, player::Player,
GameState,
backpack::UiHeadState,
heads::{ActiveHeads, HeadsImages},
hitpoints::Hitpoints,
loading_assets::UIAssets,
npc::Npc,
player::Player,
};
use bevy::prelude::*;
@@ -142,11 +147,12 @@ fn update(
fn sync(
mut target: ResMut<TargetUi>,
player_target: Query<&AimTarget, With<Player>>,
target_data: Query<(&Hitpoints, &Npc)>,
target_data: Query<(&Hitpoints, &ActiveHeads), With<Npc>>,
) {
let mut new_state = None;
if let Some(e) = player_target.iter().next().and_then(|target| target.0) {
if let Ok((hp, head)) = target_data.get(e) {
if let Ok((hp, heads)) = target_data.get(e) {
let head = heads.current().expect("target must have a head on");
new_state = Some(UiHeadState {
head: head.head,
health: hp.health(),