Skip to content

Commit 8a83fee

Browse files
authored
refactor: remove unused player inventory (#20)
1 parent 6b64812 commit 8a83fee

File tree

4 files changed

+3
-288
lines changed

4 files changed

+3
-288
lines changed

src/simulation/item/inventory.rs

Lines changed: 0 additions & 206 deletions
This file was deleted.

src/simulation/item/mod.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@ use bevy::prelude::*;
22

33
mod assets;
44
mod compendium;
5-
mod inventory;
6-
mod stack;
75

8-
pub use self::{
9-
assets::{ItemAssets, ItemDef},
10-
inventory::Inventory,
11-
stack::Stack,
12-
};
6+
pub use self::assets::{ItemAssets, ItemDef};
137

148
pub fn plugin(app: &mut App) {
159
app.register_type::<Item>();
@@ -19,9 +13,6 @@ pub fn plugin(app: &mut App) {
1913
app.add_systems(Update, mark_full);
2014

2115
app.add_plugins((assets::plugin, compendium::plugin));
22-
23-
app.register_type::<PlayerInventory>()
24-
.add_systems(Startup, spawn_player_inventory);
2516
}
2617

2718
#[derive(Component, Reflect)]
@@ -55,14 +46,3 @@ fn mark_full(
5546
}
5647
}
5748
}
58-
59-
#[derive(Component, Reflect, Deref, DerefMut)]
60-
#[reflect(Component)]
61-
pub struct PlayerInventory(Inventory);
62-
63-
fn spawn_player_inventory(mut commands: Commands) {
64-
commands.spawn((
65-
Name::new("Player Inventory"),
66-
PlayerInventory(Inventory::sized(9)),
67-
));
68-
}

src/simulation/item/stack.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/simulation/world/deposit.rs

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@ use serde::Deserialize;
66
use crate::{
77
assets::{
88
LoadResource,
9-
indexing::IndexMap,
109
manifest::{Id, Manifest, ManifestPlugin},
1110
},
1211
screens::Screen,
13-
simulation::{
14-
item::{ItemDef, PlayerInventory, Stack},
15-
recipe::RecipeDef,
16-
world::{MAP_SIZE, Terrain, WorldSpawnSystems},
17-
},
18-
ui::{Interact, Interactable, YSort},
12+
simulation::world::{MAP_SIZE, Terrain, WorldSpawnSystems},
13+
ui::{Interactable, YSort},
1914
};
2015

2116
pub fn plugin(app: &mut App) {
@@ -27,8 +22,6 @@ pub fn plugin(app: &mut App) {
2722
OnEnter(Screen::Gameplay),
2823
spawn_deposits.in_set(WorldSpawnSystems::SpawnDeposits),
2924
);
30-
31-
app.add_observer(on_mine_deposit);
3225
}
3326

3427
#[derive(Debug, Deserialize, TypePath)]
@@ -103,37 +96,3 @@ fn spawn_deposits(
10396
}
10497
}
10598
}
106-
107-
fn on_mine_deposit(
108-
trigger: Trigger<Interact>,
109-
deposits: Query<&DepositRecipe>,
110-
mut inventory: Single<&mut PlayerInventory>,
111-
recipes: Res<Assets<RecipeDef>>,
112-
recipe_index: Res<IndexMap<RecipeDef>>,
113-
items: Res<Assets<ItemDef>>,
114-
item_index: Res<IndexMap<ItemDef>>,
115-
) {
116-
let Ok(deposit_recipe) = deposits.get(trigger.target()) else {
117-
return;
118-
};
119-
120-
let recipe_def = recipe_index
121-
.get(&deposit_recipe.0)
122-
.and_then(|asset_id| recipes.get(*asset_id))
123-
.expect("Deposit refers to non-existent recipe");
124-
125-
for (item_id, quantity) in recipe_def.output.iter() {
126-
let item_def = item_index
127-
.get(item_id)
128-
.and_then(|asset_id| items.get(*asset_id))
129-
.expect("Recipe refers to invalid item id");
130-
131-
let mut stack = Stack {
132-
item_id: item_def.id.to_owned(),
133-
quantity: *quantity,
134-
max_quantity: item_def.stack_size,
135-
};
136-
137-
let _ = inventory.add_stack(&mut stack);
138-
}
139-
}

0 commit comments

Comments
 (0)