Task fix attempt
This commit is contained in:
@@ -49,6 +49,9 @@ pub struct Cargo {
|
||||
pub size: u8,
|
||||
/// Sprite handle for rendering when on the ground.
|
||||
pub ground_sprite: Handle<Image>,
|
||||
/// True once this cargo has been hauled to its destination.
|
||||
/// Used to prevent re-hauling logs that have already been delivered.
|
||||
pub delivered: bool,
|
||||
}
|
||||
|
||||
/// Marks a Cargo entity as haulable by entities with a HaulSlot.
|
||||
|
||||
@@ -93,6 +93,7 @@ pub fn spawn_log_cargo(
|
||||
weight: LOG_WEIGHT_KG,
|
||||
size: SIZE_LARGE,
|
||||
ground_sprite: log_sprite.clone(),
|
||||
delivered: false,
|
||||
},
|
||||
Haulable,
|
||||
Sprite {
|
||||
|
||||
@@ -5,6 +5,8 @@ pub mod systems;
|
||||
pub use crate::world::tiles::tilemap::CargoPlaceError;
|
||||
pub use components::{Cargo, CarryVisualState, HaulSlot, Haulable};
|
||||
pub use log::spawn_log_cargo;
|
||||
pub use systems::{any_hauling, carry_visual_system, haul_encumbrance_system};
|
||||
pub use systems::{
|
||||
any_hauling, cargo_position_sync_system, carry_visual_system, haul_encumbrance_system,
|
||||
};
|
||||
|
||||
pub use crate::plugins::cargo::CargoPlugin;
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user