I'm working on a card game using Bevy and I have a question about the best practices for calling one system (or function) from another system. Below is the situation:
The draw function
This function handles the logic for drawing cards from a deck. It updates the deck, the zone of the drawn card, and increments the player's card count.
// This function draws `cards_to_draw` cards for a specific player.
pub fn draw(
mut deck_pile: &mut ResMut<DeckPileResource>, // The shared deck state
mut query: &mut Query<(&mut Zone, &mut Hidden), With<Card>>, // Query for card components
mut query_number_of_cards_in_hand: &mut Query<&mut NumberOfCardsInHand, With<Player>>, // Query for player hand size
player_who_drawn: Entity, // The player drawing the card
cards_to_draw: u8, // Number of cards to draw
) {
for _ in 0..cards_to_draw {
if deck_pile.number_of_cards != 0 {
// Remove a card from the deck and decrease the count
let card_drawn = deck_pile.deck_order.pop().unwrap();
deck_pile.number_of_cards -= 1;
// Update the drawn card's zone and hidden status
let (mut zone, mut hidden_status) = query.get_mut(card_drawn).unwrap();
*zone = Zone::Hand(player_who_drawn);
*hidden_status = Hidden::ForNotOwners(player_who_drawn);
// Increment the number of cards in the player's hand
let mut number_of_cards_in_hand = query_number_of_cards_in_hand.get_mut(player_who_drawn).unwrap();
number_of_cards_in_hand.0 += 1;
info!("Card drawn!");
} else {
info!("No card in deck!");
}
}
}