Skip to content

Commit 34ff11a

Browse files
committed
fix compendium
1 parent d5d050e commit 34ff11a

1 file changed

Lines changed: 59 additions & 37 deletions

File tree

src/simulation/item/compendium.rs

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn spawn_item_compendium(
3737
mut commands: Commands,
3838
items: Res<Assets<ItemDef>>,
3939
item_assets: Res<ItemAssets>,
40+
asset_server: Res<AssetServer>,
4041
) {
4142
let mut items_sorted: Vec<_> = items.iter().map(|(_, a)| a).collect();
4243
items_sorted.sort_by(|a, b| a.name.cmp(&b.name));
@@ -71,44 +72,65 @@ fn spawn_item_compendium(
7172
.id();
7273

7374
for item_def in items_sorted.iter() {
74-
commands.spawn((
75-
Node {
76-
display: Display::Grid,
77-
grid_template_columns: vec![
78-
RepeatedGridTrack::px(1, 64.0),
79-
RepeatedGridTrack::px(1, 256.0),
80-
],
81-
grid_template_rows: vec![RepeatedGridTrack::px(2, 32.0)],
82-
justify_items: JustifyItems::Start,
83-
align_items: AlignItems::Center,
84-
column_gap: Val::Px(16.0),
85-
padding: UiRect::all(Val::Px(4.0)),
75+
let item_box = commands
76+
.spawn((
77+
Node {
78+
display: Display::Grid,
79+
grid_template_columns: vec![
80+
RepeatedGridTrack::px(1, 64.0),
81+
RepeatedGridTrack::px(1, 256.0),
82+
],
83+
grid_template_rows: vec![RepeatedGridTrack::px(2, 32.0)],
84+
justify_items: JustifyItems::Start,
85+
align_items: AlignItems::Center,
86+
column_gap: Val::Px(16.0),
87+
padding: UiRect::all(Val::Px(4.0)),
88+
..default()
89+
},
90+
ChildOf(item_list),
91+
BackgroundColor(Color::BLACK),
92+
))
93+
.id();
94+
95+
let image = commands
96+
.spawn((
97+
Node {
98+
justify_self: JustifySelf::Center,
99+
grid_column: GridPlacement::span(1),
100+
grid_row: GridPlacement::span(2),
101+
width: Val::Px(56.0),
102+
height: Val::Px(56.0),
103+
..default()
104+
},
105+
ChildOf(item_box),
106+
))
107+
.id();
108+
109+
if let Some(sprite) = &item_def.sprite {
110+
commands.entity(image).insert(ImageNode {
111+
image: asset_server.load(sprite.clone()),
86112
..default()
87-
},
88-
ChildOf(item_list),
89-
BackgroundColor(Color::BLACK),
90-
children![
91-
(
92-
Node {
93-
justify_self: JustifySelf::Center,
94-
grid_column: GridPlacement::span(1),
95-
grid_row: GridPlacement::span(2),
96-
width: Val::Px(56.0),
97-
height: Val::Px(56.0),
98-
..default()
99-
},
100-
ImageNode::default(),
101-
AseSlice {
102-
aseprite: item_assets.aseprite.clone(),
103-
name: item_def.id.to_owned(),
104-
}
105-
),
106-
(Text::new(item_def.name.to_owned()), TextColor(Color::WHITE),),
107-
(
108-
Text::new(item_def.stack_size.to_string()),
109-
TextColor(Color::WHITE),
110-
)
111-
],
113+
});
114+
} else {
115+
commands.entity(image).insert((
116+
ImageNode::default(),
117+
AseSlice {
118+
aseprite: item_assets.aseprite.clone(),
119+
name: item_def.id.to_owned(),
120+
},
121+
));
122+
}
123+
124+
commands.spawn((
125+
Text::new(item_def.name.to_owned()),
126+
TextColor(Color::WHITE),
127+
ChildOf(item_box),
128+
));
129+
130+
commands.spawn((
131+
Text::new(item_def.stack_size.to_string()),
132+
TextColor(Color::WHITE),
133+
ChildOf(item_box),
112134
));
113135
}
114136
}

0 commit comments

Comments
 (0)