example item
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::entities::item::{Item, ItemBundle, ItemDecorations, ItemType, Material, Quality};
|
||||
use crate::world::VisibleGameEntity;
|
||||
|
||||
// Enum for misc item prefabs
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum MiscPrefab {
|
||||
RawMeat,
|
||||
Coin,
|
||||
}
|
||||
|
||||
// Spawns a misc prefab at a given position.
|
||||
// These are all likely temporary to speed up development but will be replaced by semi-custom items everywhere.
|
||||
pub fn spawn_prefab(
|
||||
commands: &mut Commands,
|
||||
asset_server: &Res<AssetServer>,
|
||||
prefab: MiscPrefab,
|
||||
position: Vec3,
|
||||
) -> Entity {
|
||||
match prefab {
|
||||
MiscPrefab::RawMeat => {
|
||||
let meat = commands
|
||||
.spawn(ItemBundle {
|
||||
item: Item {
|
||||
quality: Quality::Ordinary,
|
||||
..Item::default()
|
||||
},
|
||||
item_type: ItemType::Food(crate::entities::item::FoodType::Meat),
|
||||
base_material: Material::NA,
|
||||
decorations: ItemDecorations::new(),
|
||||
transform: Transform::from_translation(position - Vec3::new(0.0, 0.0, 0.1)),
|
||||
visibility: Visibility::Visible,
|
||||
sprite: Sprite {
|
||||
image: asset_server.load("raw_meat.png"),
|
||||
..Default::default()
|
||||
},
|
||||
})
|
||||
.id();
|
||||
commands.entity(meat).insert(VisibleGameEntity).id()
|
||||
}
|
||||
MiscPrefab::Coin => {
|
||||
let coin = commands
|
||||
.spawn(ItemBundle {
|
||||
item: Item {
|
||||
quality: Quality::Ordinary,
|
||||
..Item::default()
|
||||
},
|
||||
item_type: ItemType::Coin,
|
||||
base_material: Material::Metal(crate::entities::item::MetalType::Copper),
|
||||
decorations: ItemDecorations::new(),
|
||||
transform: Transform::from_translation(position - Vec3::new(0.0, 0.0, 0.1)),
|
||||
visibility: Visibility::Visible,
|
||||
sprite: Sprite {
|
||||
image: asset_server.load("coin.png"),
|
||||
..Default::default()
|
||||
},
|
||||
})
|
||||
.id();
|
||||
commands.entity(coin).insert(VisibleGameEntity).id()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user