From 458068fb87ab5e0c97ff0c9d237996ae43bfe2cf Mon Sep 17 00:00:00 2001 From: popertots Date: Sun, 22 Mar 2026 00:03:57 +0000 Subject: [PATCH] run_if --- src/entities/cargo/mod.rs | 2 +- src/entities/cargo/systems.rs | 7 +++++++ src/main.rs | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/entities/cargo/mod.rs b/src/entities/cargo/mod.rs index 5a0021a..1f17ca9 100644 --- a/src/entities/cargo/mod.rs +++ b/src/entities/cargo/mod.rs @@ -3,4 +3,4 @@ pub mod systems; pub use crate::world::tiles::tilemap::CargoPlaceError; pub use components::{Cargo, CarryVisualState, HaulSlot, Haulable}; -pub use systems::{carry_visual_system, haul_encumbrance_system}; +pub use systems::{any_hauling, carry_visual_system, haul_encumbrance_system}; diff --git a/src/entities/cargo/systems.rs b/src/entities/cargo/systems.rs index 3373f49..c5dabd3 100644 --- a/src/entities/cargo/systems.rs +++ b/src/entities/cargo/systems.rs @@ -7,10 +7,17 @@ use crate::entities::item::inventory::constants::ENCUMBERED_SPEED_MULTIPLIER; use crate::entities::item::inventory::InventoryChangedEvent; use crate::entities::shared_components::Ambulatory; +/// Returns true if any entity has an occupied HaulSlot. +/// Used to gate carry_visual_system — skips entire system when no one is hauling. +pub fn any_hauling(query: Query<&HaulSlot>) -> bool { + query.iter().any(|slot| slot.is_occupied()) +} + /// Cycle the carry visual sprite while the entity's HaulSlot is occupied. /// When empty, ensure the normal sprite is restored. /// /// Runs in Update (visual only, no game state change). +/// Only runs when at least one entity has an occupied HaulSlot. pub fn carry_visual_system( time: Res