Skip to content

Commit 2098400

Browse files
authored
feat: add recipe list to tome (#80)
1 parent 66c0e28 commit 2098400

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed
Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,52 @@
11
use bevy::prelude::*;
22

3-
use crate::gameplay::hud::tome::{TomeTab, UITomeLeftPageRoot, widgets};
3+
use crate::gameplay::{
4+
hud::tome::{TomeTab, UITomeLeftPageRoot, widgets},
5+
recipe::assets::RecipeDef,
6+
};
47

58
pub(super) fn plugin(app: &mut App) {
69
app.add_systems(OnEnter(TomeTab::Recipes), spawn_recipe_list);
10+
11+
app.add_systems(
12+
Update,
13+
refresh_recipe_plates.run_if(in_state(TomeTab::Recipes)),
14+
);
15+
}
16+
17+
#[derive(Component, Reflect, Debug)]
18+
#[reflect(Component)]
19+
pub struct RecipePlate(pub AssetId<RecipeDef>);
20+
21+
fn recipe_plate(recipe: AssetId<RecipeDef>) -> impl Bundle {
22+
(RecipePlate(recipe), Text::default())
23+
}
24+
25+
fn spawn_recipe_list(
26+
mut commands: Commands,
27+
left_page: Single<Entity, With<UITomeLeftPageRoot>>,
28+
recipe_defs: Res<Assets<RecipeDef>>,
29+
) {
30+
let recipe_list = commands
31+
.spawn((
32+
widgets::list_page(),
33+
ChildOf(*left_page),
34+
DespawnOnExit(TomeTab::Recipes),
35+
))
36+
.id();
37+
38+
for (asset_id, _) in recipe_defs.iter() {
39+
commands.spawn((recipe_plate(asset_id), ChildOf(recipe_list)));
40+
}
741
}
842

9-
fn spawn_recipe_list(mut commands: Commands, left_page: Single<Entity, With<UITomeLeftPageRoot>>) {
10-
commands.spawn((
11-
widgets::list_page(),
12-
ChildOf(*left_page),
13-
DespawnOnExit(TomeTab::Recipes),
14-
children![Text::new("Recipes")],
15-
));
43+
fn refresh_recipe_plates(
44+
plates: Query<(&RecipePlate, &mut Text)>,
45+
recipe_defs: Res<Assets<RecipeDef>>,
46+
) {
47+
for (plate, mut text) in plates {
48+
if let Some(recipe) = recipe_defs.get(plate.0) {
49+
text.0 = recipe.name.clone();
50+
}
51+
}
1652
}

0 commit comments

Comments
 (0)