Skip to content

Commit f4b4f52

Browse files
authored
feat: add harvesting and rework inputs/outputs (#71)
1 parent 864e633 commit f4b4f52

File tree

25 files changed

+498
-282
lines changed

25 files changed

+498
-282
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,8 @@ codegen-units = 4
7070

7171
[profile.ci.package."*"]
7272
opt-level = 0
73+
74+
[lints.clippy]
75+
too_many_arguments = "allow"
76+
type_complexity = "allow"
77+
nonstandard_macro_braces = "warn"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
id = "fauna_a"
22
name = "Fauna A Deposit"
3-
recipe_id = "fauna_a"
3+
item_id = "fauna_a"
4+
taxonomy = "Fauna"
45
seed = 463724
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
id = "flora_a"
22
name = "Flora A Deposit"
3-
recipe_id = "flora_a"
3+
item_id = "flora_a"
4+
taxonomy = "Flora"
45
seed = 821954
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
id = "harvester"
22
name = "Harvester"
3-
default_recipe = "flora_a"

src/gameplay/hud/inspect/info.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::{
44
assets::indexing::IndexMap,
55
gameplay::{
66
hud::inspect::{InspectedEntity, InspectionMenuState},
7-
recipe::{Inputs, Outputs, assets::RecipeDef, select::SelectedRecipe},
7+
item::inventory::Slots,
8+
recipe::{Input, Output, assets::RecipeDef, select::SelectedRecipe},
89
},
910
widgets::{
1011
self,
@@ -24,16 +25,17 @@ pub fn plugin(app: &mut App) {
2425
#[reflect(Component)]
2526
pub struct HeldRelic(Entity);
2627

27-
#[allow(clippy::too_many_arguments)]
2828
pub fn open_recipe_menu(
2929
mut commands: Commands,
3030
inspected_entity: Res<InspectedEntity>,
31-
structure_query: Query<(&SelectedRecipe, &Inputs, &Outputs)>,
31+
structure_query: Query<(&SelectedRecipe, &Slots)>,
32+
input_query: Query<(), With<Input>>,
33+
output_query: Query<(), With<Output>>,
3234
recipes: Res<Assets<RecipeDef>>,
3335
recipe_index: Res<IndexMap<RecipeDef>>,
3436
held_relics: Query<&HeldRelic>,
3537
) {
36-
let Ok((selected_recipe, inputs, outputs)) = structure_query.get(inspected_entity.0) else {
38+
let Ok((selected_recipe, slots)) = structure_query.get(inspected_entity.0) else {
3739
return;
3840
};
3941

@@ -117,7 +119,7 @@ pub fn open_recipe_menu(
117119
))
118120
.id();
119121

120-
for input in inputs.iter() {
122+
for input in slots.iter().filter(|s| input_query.contains(*s)) {
121123
let slot = commands
122124
.spawn((ChildOf(input_list_id), widgets::slot::slot_container()))
123125
.id();
@@ -190,7 +192,7 @@ pub fn open_recipe_menu(
190192
))
191193
.id();
192194

193-
for output in outputs.iter() {
195+
for output in slots.iter().filter(|s| output_query.contains(*s)) {
194196
let slot = commands
195197
.spawn((ChildOf(output_list_id), widgets::slot::slot_container()))
196198
.id();

src/gameplay/item/assets.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ pub struct ItemDef {
2727
pub transport: Transport,
2828
}
2929

30-
#[derive(Clone, Debug, Deserialize, Reflect)]
30+
#[derive(Component, Clone, Debug, Deserialize, Reflect, PartialEq, Eq)]
31+
#[reflect(Component)]
3132
pub enum Taxonomy {
3233
Fauna,
3334
Flora,

src/gameplay/item/compendium.rs

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

src/gameplay/item/inventory.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use bevy::prelude::*;
2+
3+
pub(super) fn plugin(_app: &mut App) {}
4+
5+
#[derive(Component, Reflect, Debug)]
6+
#[reflect(Component)]
7+
#[relationship_target(relationship = SlotOf, linked_spawn)]
8+
pub struct Slots(Vec<Entity>);
9+
10+
#[derive(Component, Reflect, Debug)]
11+
#[reflect(Component)]
12+
#[relationship(relationship_target = Slots)]
13+
pub struct SlotOf(pub Entity);

src/gameplay/item/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use bevy::prelude::*;
22

33
pub mod assets;
4-
pub mod compendium;
4+
pub mod inventory;
55
pub mod stack;
66

77
pub fn plugin(app: &mut App) {
8-
app.add_plugins((assets::plugin, compendium::plugin, stack::plugin));
8+
app.add_plugins((assets::plugin, inventory::plugin, stack::plugin));
99
}

src/gameplay/item/stack.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use bevy::prelude::*;
22

33
use crate::gameplay::item::assets::ItemDef;
44

5-
pub(super) fn plugin(app: &mut App) {
6-
app.add_systems(Update, mark_full_stacks);
7-
}
5+
pub(super) fn plugin(_app: &mut App) {}
86

97
#[derive(Component, Reflect, Debug, Clone)]
108
#[reflect(Component)]
@@ -24,27 +22,3 @@ impl Stack {
2422
Stack { item, quantity }
2523
}
2624
}
27-
28-
#[derive(Component, Reflect)]
29-
#[reflect(Component)]
30-
#[component(storage = "SparseSet")]
31-
pub struct Full;
32-
33-
fn mark_full_stacks(
34-
query: Query<(Entity, &Stack)>,
35-
item_defs: Res<Assets<ItemDef>>,
36-
mut commands: Commands,
37-
) {
38-
for (entity, stack) in query {
39-
let stack_size = item_defs
40-
.get(&stack.item)
41-
.map(|def| def.stack_size)
42-
.unwrap_or(1);
43-
44-
if stack.quantity >= stack_size {
45-
commands.entity(entity).insert(Full);
46-
} else {
47-
commands.entity(entity).remove::<Full>();
48-
}
49-
}
50-
}

0 commit comments

Comments
 (0)