Task fix attempt

This commit is contained in:
2026-03-23 19:31:30 +00:00
parent 3632836016
commit 1f5dfe5182
11 changed files with 203 additions and 48 deletions
+16 -2
View File
@@ -1,8 +1,9 @@
//! Cargo systems: carry visual cycling and haul encumbrance.
//! Cargo systems: carry visual cycling, position sync, and haul encumbrance.
use bevy::prelude::*;
use crate::entities::cargo::components::{CarryVisualState, HaulSlot};
use crate::entities::cargo::components::{Cargo, CarryVisualState, HaulSlot};
use crate::entities::item::constants::ITEM_Z_FIGHTING_OFFSET;
use crate::entities::item::inventory::constants::ENCUMBERED_SPEED_MULTIPLIER;
use crate::entities::item::inventory::InventoryChangedEvent;
use crate::entities::shared_components::Ambulatory;
@@ -60,3 +61,16 @@ pub fn haul_encumbrance_system(
events.write(InventoryChangedEvent { carrier: entity });
}
}
/// Sync cargo visual position when tile_pos changes.
/// When cargo is picked up or dropped, tile_pos updates but Transform doesn't.
/// This system keeps Transform in sync with the logical position.
pub fn cargo_position_sync_system(mut query: Query<(&Cargo, &mut Transform), Changed<Cargo>>) {
for (cargo, mut transform) in query.iter_mut() {
transform.translation = Vec3::new(
cargo.tile_pos.x as f32,
cargo.tile_pos.y as f32,
cargo.tile_pos.z as f32 - ITEM_Z_FIGHTING_OFFSET,
);
}
}