pub fn interaction_system(
    items: ResMut<Items>,
    mut result_events: ResMut<Events<TileInteractionResultEvent>>,
    mut state: ResMut<InteractionState>,
    interaction_events: ResMut<Events<InteractionEvent>>,
    world_catalog: Res<
        InteractionCatalog<TileInteraction, TileComponents, Vec<TileInteractionResult>>,
    >,
    item_query: Query<(Entity, &ItemType, &Named)>,
    interactable_query: Query<(
        Entity,
        &InteractableType,
        &ObjectState,
        &TileInteraction,
        &Inventory
    )>,
) {
    for event in state.interaction_events.iter(&interaction_events) {
        match event.interaction_type {
            InteractionType::Collision => {
                if event.source == event.destination {
                    panic!("A entity collided with itself, this should not happen")
                }

                let tile_handle_r =
                    interactable_query.get::<TileInteraction>(event.destination);

                if let Some(tile_interaction) = tile_handle_r.ok() {
                    //println!("{:?} interacted with {:?} name: {:?}", event.source, event.destination, tile_interaction);

                    let ctx = InteractionContext {
                        source: event.source,
                        destination: event.destination,
                        world_catalog: world_catalog.clone(),
                        interaction_query: &interactable_query,
                        item_query: &item_query,
                        items: &items,
                    };
                    for r in tile_interaction.interact(ctx).iter() {
                        result_events.send(TileInteractionResultEvent {
                            _source: event.source,
                            destination: event.destination,
                            result: r.clone(),
                        })
                    }
                }
            }
            _ => {}
        }
    }
}
/// Interaction System
/// This sytem will try and see if there is a registered Interaction handler for a
/// object that has experienced a collision. If there is, it is ran
/// and the result is sent as an event to be processed.
Interaction System
This sytem will try and see if there is a registered Interaction handler for a
object that has experienced a collision. If there is, it is ran
and the result is sent as an event to be processed.
Interaction System This sytem will try and see if there is a registered Interaction handler for a object that has experienced a collision . If there is it is ran and the result is sent as an event to be processed .
pub fn interaction_system(
    items: ResMut<Items>,
    mut result_events: ResMut<Events<TileInteractionResultEvent>>,
    mut state: ResMut<InteractionState>,
    interaction_events: ResMut<Events<InteractionEvent>>,
    world_catalog: Res<
        InteractionCatalog<TileInteraction, TileComponents, Vec<TileInteractionResult>>,
    >,
    item_query: Query<(Entity, &ItemType, &Named)>,
    interactable_query: Query<(
        Entity,
        &InteractableType,
        &ObjectState,
        &TileInteraction,
        &Inventory
    )>,
) {
    for event in state.interaction_events.iter(&interaction_events) {
        match event.interaction_type {
            InteractionType::Collision => {
                if event.source == event.destination {
                    panic!("A entity collided with itself, this should not happen")
                }
                let tile_handle_r =
                    interactable_query.get::<TileInteraction>(event.destination);
                if let Some(tile_interaction) = tile_handle_r.ok() {
                    //println!("{:?} interacted with {:?} name: {:?}", event.source, event.destination, tile_interaction);
                    let ctx = InteractionContext {
                        source: event.source,
                        destination: event.destination,
                        world_catalog: world_catalog.clone(),
                        interaction_query: &interactable_query,
                        item_query: &item_query,
                        items: &items,
                    };
                    for r in tile_interaction.interact(ctx).iter() {
                        result_events.send(TileInteractionResultEvent {
                            _source: event.source,
                            destination: event.destination,
                            result: r.clone(),
                        })
                    }
                }
            }
            _ => {}
        }
    }
}
pub fn interaction_system ( items : ResMut < Items > , mut result_events : ResMut < Events < TileInteractionResultEvent > > , mut state : ResMut < InteractionState > , interaction_events : ResMut < Events < InteractionEvent > > , world_catalog : Res < InteractionCatalog < TileInteraction , TileComponents , Vec < TileInteractionResult > > , > , item_query : Query < ( Entity , & ItemType , & Named ) > , interactable_query : Query < ( Entity , & InteractableType , & ObjectState , & TileInteraction , & Inventory ) > , ) { for event in state . interaction_events . iter ( & interaction_events ) { match event . interaction_type { InteractionType :: Collision => { if event . source == event . destination { panic ! ( " " ) } let tile_handle_r = interactable_query . get :: < TileInteraction > ( event . destination ) ; if let Some ( tile_interaction ) = tile_handle_r . ok ( ) { //println!("{:?} interacted with {:?} name: {:?}", event.source, event.destination, tile_interaction); let ctx = InteractionContext { source : event . source , destination : event . destination , world_catalog : world_catalog . clone ( ) , interaction_query : & interactable_query , item_query : & item_query , items : & items , } ; for r in tile_interaction . interact ( ctx ) . iter ( ) { result_events . send ( TileInteractionResultEvent { _source : event . source , destination : event . destination , result : r . clone ( ) , } ) } } } _ => { } } } }
Interaction System
This sytem will try and see if there is a registered Interaction handler for a
object that has experienced a collision.
Interaction System This sytem will try and see if there is a registered Interaction handler for a object that has experienced a collision .
items
ResMut<Items>
result_events
ResMut<Events<TileInteractionResultEvent>>
state
ResMut<InteractionState>
interaction_events
ResMut<Events<InteractionEvent>>
world_catalog
Res<
        InteractionCatalog<TileInteraction, TileComponents, Vec<TileInteractionResult>>,
    >
item_query
Query<(Entity, &ItemType, &Named)>
interactable_query
Query<(
        Entity,
        &InteractableType,
        &ObjectState,
        &TileInteraction,
        &Inventory
    )>
items
ResMut<Items>
result_events
ResMut<Events<TileInteractionResultEvent>>
state
ResMut<InteractionState>
interaction_events
ResMut<Events<InteractionEvent>>
world_catalog
Res<
        InteractionCatalog<TileInteraction, TileComponents, Vec<TileInteractionResult>>,
    >
item_query
Query<(Entity, &ItemType, &Named)>
interactable_query
Query<(
        Entity,
        &InteractableType,
        &ObjectState,
        &TileInteraction,
        &Inventory
    )>