use std::collections::HashMap;
use fmc::{items::ItemId, prelude::*};
pub mod crafting;
mod dropped_items;
pub mod bread;
pub mod hoes;
pub mod seeds;
pub use dropped_items::DroppedItem;
pub struct ItemPlugin;
impl Plugin for ItemPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(ItemRegistry::default())
.add_plugins(dropped_items::DroppedItemsPlugin)
.add_plugins(crafting::CraftingPlugin)
.add_plugins(hoes::HoePlugin)
.add_plugins(bread::BreadPlugin)
.add_plugins(seeds::SeedPlugin);
}
}
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
pub struct ItemUseSystems;
#[derive(Resource, Deref, DerefMut, Default)]
pub struct ItemRegistry(HashMap<ItemId, Entity>);
impl ItemRegistry {
pub fn insert(&mut self, item_id: ItemId, handler_entity: Entity) {
self.0.insert(item_id, handler_entity);
}
}
#[derive(Component, Default)]
pub struct ItemUses(Vec<Entity>);
impl ItemUses {
pub fn read(&mut self) -> impl Iterator<Item = Entity> + '_ {
self.0.drain(..)
}
pub fn push(&mut self, player_entity: Entity) {
self.0.push(player_entity);
}
}