Hello,
I'm developing a card game where I want to retain the location of each card (in deck, in player's hand, ...).
My first solution works but it is not very evolutive, lacks genericity and is quite verbose. That is creating an enum and a component for each enum value :
enum CardLocationEnum {
Deck,
SouthPlayerHand,
SouthPlayerTake,
NorthPlayerHand,
NorthPlayerTake,
}
#[derive(Component, Debug)]
struct InDeck;
#[derive(Component, Debug)]
struct InSouthPlayerHand;
#[derive(Component, Debug)]
struct InSouthPlayerTake;
#[derive(Component, Debug)]
struct InNorthPlayerHand;
#[derive(Component, Debug)]
struct InNorthPlayerTake;
... where often, I have to write such dirty pattern matching :
match target_location {
CardLocationEnum::SouthPlayerHand => { commands.entity(c).insert(InSouthPlayerHand); () },
CardLocationEnum::NorthPlayerHand => { commands.entity(c).insert(InNorthPlayerHand); () },
_ => (),
}
or for systems and queries :
fn center_cards_north_player(
card_query: Query<(Entity, &mut Transform), With<InNorthPlayerHand()>>,
) {}
fn center_cards_south_player(
card_query: Query<(Entity, &mut Transform), With<InSouthPlayerHand()>>,
) {}
How can I improve my code ? Thank you for your help !