Skip to content

Commit

Permalink
remove redundant StateScoped
Browse files Browse the repository at this point in the history
  • Loading branch information
aratama committed Nov 18, 2024
1 parent d4cc411 commit e6dcffe
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 133 deletions.
31 changes: 12 additions & 19 deletions src/entity/dropped_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,29 +112,22 @@ pub fn spawn_dropped_item(
InheritedVisibility::default(),
))
.with_children(|parent| {
parent.spawn((
StateScoped(GameState::InGame),
AsepriteSliceBundle {
aseprite: assets.atlas.clone(),
slice: frame_slice.into(),
transform: Transform::from_xyz(0.0, 0.0, 0.0),
..default()
},
));
parent.spawn((AsepriteSliceBundle {
aseprite: assets.atlas.clone(),
slice: frame_slice.into(),
transform: Transform::from_xyz(0.0, 0.0, 0.0),
..default()
},));

parent.spawn((
StateScoped(GameState::InGame),
AsepriteSliceBundle {
aseprite: assets.atlas.clone(),
slice: icon.into(),
transform: Transform::from_xyz(0.0, 0.0, 0.0001),
..default()
},
));
parent.spawn((AsepriteSliceBundle {
aseprite: assets.atlas.clone(),
slice: icon.into(),
transform: Transform::from_xyz(0.0, 0.0, 0.0001),
..default()
},));

parent.spawn((
InteractionMarker,
StateScoped(GameState::InGame),
AsepriteSliceBundle {
aseprite: assets.atlas.clone(),
transform: Transform::from_xyz(0.0, 14.0, 0.0002),
Expand Down
4 changes: 1 addition & 3 deletions src/entity/magic_circle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
asset::GameAssets, command::GameCommand, config::GameConfig, constant::*,
controller::player::Player, player_state::PlayerState, states::GameState, level::NextLevel,
controller::player::Player, level::NextLevel, player_state::PlayerState, states::GameState,
};
use bevy::prelude::*;
use bevy_aseprite_ultra::prelude::*;
Expand Down Expand Up @@ -72,7 +72,6 @@ pub fn spawn_magic_circle(
.with_children(|parent| {
parent.spawn((
Name::new("magic_circle_star"),
StateScoped(GameState::InGame),
MagicStar,
AsepriteSliceBundle {
aseprite: assets.atlas.clone(),
Expand All @@ -90,7 +89,6 @@ pub fn spawn_magic_circle(
commands.entity(light_entity).insert((
Name::new("magic_circle_light"),
MagicCircleLight,
StateScoped(GameState::InGame),
PointLight2dBundle {
transform: Transform::from_xyz(x, y, 0.0),
point_light: PointLight2d {
Expand Down
75 changes: 33 additions & 42 deletions src/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,38 +67,32 @@ fn setup_hud(

// 下半分
parent
.spawn((
StateScoped(GameState::InGame),
NodeBundle {
z_index: ZIndex::Global(HUD_Z_INDEX),
style: Style {
width: Val::Percent(100.),
display: Display::Flex,
flex_direction: FlexDirection::Row,
align_items: AlignItems::End,
justify_content: JustifyContent::SpaceBetween,
..default()
},
.spawn((NodeBundle {
z_index: ZIndex::Global(HUD_Z_INDEX),
style: Style {
width: Val::Percent(100.),
display: Display::Flex,
flex_direction: FlexDirection::Row,
align_items: AlignItems::End,
justify_content: JustifyContent::SpaceBetween,
..default()
},
))
..default()
},))
.with_children(|parent| {
// 左下
parent
.spawn((
StateScoped(GameState::InGame),
NodeBundle {
z_index: ZIndex::Global(HUD_Z_INDEX),
style: Style {
display: Display::Flex,
flex_direction: FlexDirection::Column,
align_items: AlignItems::Start,
row_gap: Val::Px(4.),
..default()
},
.spawn((NodeBundle {
z_index: ZIndex::Global(HUD_Z_INDEX),
style: Style {
display: Display::Flex,
flex_direction: FlexDirection::Column,
align_items: AlignItems::Start,
row_gap: Val::Px(4.),
..default()
},
))
..default()
},))
.with_children(|mut parent| {
spawn_wand_list(&mut parent, &assets);

Expand Down Expand Up @@ -128,34 +122,31 @@ fn setup_hud(
..default()
});
});
});

spawn_wand_editor(&mut commands, &assets);
spawn_wand_editor(&mut parent, &assets);

spawn_inventory_floating(&mut commands, &assets);
spawn_inventory_floating(&mut parent, &assets);
});

#[cfg(feature = "debug")]
commands.spawn(PerfUiBundle::default());
}

fn spawn_status_bars(parent: &mut ChildBuilder) {
parent
.spawn((
StateScoped(GameState::InGame),
NodeBundle {
style: Style {
display: Display::Flex,
justify_content: JustifyContent::Start,
flex_direction: FlexDirection::Column,
align_items: AlignItems::Start,
row_gap: Val::Px(4.),
height: Val::Percent(100.),
width: Val::Percent(100.),
..default()
},
.spawn((NodeBundle {
style: Style {
display: Display::Flex,
justify_content: JustifyContent::Start,
flex_direction: FlexDirection::Column,
align_items: AlignItems::Start,
row_gap: Val::Px(4.),
height: Val::Percent(100.),
width: Val::Percent(100.),
..default()
},
))
..default()
},))
.with_children(|mut parent| {
spawn_status_bar(
&mut parent,
Expand Down
5 changes: 2 additions & 3 deletions src/ui/floating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ impl Floating {
}
}

pub fn spawn_inventory_floating(commands: &mut Commands, assets: &Res<GameAssets>) {
commands.spawn((
pub fn spawn_inventory_floating(builder: &mut ChildBuilder, assets: &Res<GameAssets>) {
builder.spawn((
Floating(None),
StateScoped(GameState::InGame),
Interaction::default(),
ImageBundle {
style: Style {
Expand Down
55 changes: 25 additions & 30 deletions src/ui/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,35 @@ struct InventoryItemSlot(usize);

pub fn spawn_inventory(builder: &mut ChildBuilder, assets: &Res<GameAssets>) {
builder
.spawn((
StateScoped(GameState::InGame),
NodeBundle {
style: Style {
width: Val::Px(32.0 * 8.0),
height: Val::Px(32.0 * 8.0),
// Make the height of the node fill its parent
// height: Val::Percent(100.0),
// Make the grid have a 1:1 aspect ratio meaning it will scale as an exact square
// As the height is set explicitly, this means the width will adjust to match the height
// aspect_ratio: Some(1.0),
// Use grid layout for this node
// display: Display::Grid,
// Add 24px of padding around the grid
// padding: UiRect::all(Val::Px(0.0)),
// Set the grid to have 4 columns all with sizes minmax(0, 1fr)
// This creates 4 exactly evenly sized columns
// grid_template_columns: RepeatedGridTrack::flex(8, 1.0),
// Set the grid to have 4 rows all with sizes minmax(0, 1fr)
// This creates 4 exactly evenly sized rows
// grid_template_rows: RepeatedGridTrack::flex(8, 1.0),
// Set a 12px gap/gutter between rows and columns
// row_gap: Val::Px(2.0),
// column_gap: Val::Px(2.0),
..default()
},
// background_color: BackgroundColor(Color::hsla(0.0, 0.0, 0.5, 0.2)),
.spawn((NodeBundle {
style: Style {
width: Val::Px(32.0 * 8.0),
height: Val::Px(32.0 * 8.0),
// Make the height of the node fill its parent
// height: Val::Percent(100.0),
// Make the grid have a 1:1 aspect ratio meaning it will scale as an exact square
// As the height is set explicitly, this means the width will adjust to match the height
// aspect_ratio: Some(1.0),
// Use grid layout for this node
// display: Display::Grid,
// Add 24px of padding around the grid
// padding: UiRect::all(Val::Px(0.0)),
// Set the grid to have 4 columns all with sizes minmax(0, 1fr)
// This creates 4 exactly evenly sized columns
// grid_template_columns: RepeatedGridTrack::flex(8, 1.0),
// Set the grid to have 4 rows all with sizes minmax(0, 1fr)
// This creates 4 exactly evenly sized rows
// grid_template_rows: RepeatedGridTrack::flex(8, 1.0),
// Set a 12px gap/gutter between rows and columns
// row_gap: Val::Px(2.0),
// column_gap: Val::Px(2.0),
..default()
},
))
// background_color: BackgroundColor(Color::hsla(0.0, 0.0, 0.5, 0.2)),
..default()
},))
.with_children(|builder| {
builder.spawn((
StateScoped(GameState::MainMenu),
ImageBundle {
style: Style {
position_type: PositionType::Absolute,
Expand All @@ -69,7 +65,6 @@ pub fn spawn_inventory(builder: &mut ChildBuilder, assets: &Res<GameAssets>) {
for i in 0..MAX_ITEMS_IN_INVENTORY {
builder.spawn((
InventoryItemSlot(i),
StateScoped(GameState::MainMenu),
Interaction::default(),
ImageBundle {
style: Style {
Expand Down
4 changes: 0 additions & 4 deletions src/ui/item_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub fn spawn_spell_information(builder: &mut ChildBuilder, assets: &Res<GameAsse
builder
.spawn((
SpellInformation(None),
StateScoped(GameState::InGame),
NodeBundle {
style: Style {
padding: UiRect::all(Val::Px(8.0)),
Expand Down Expand Up @@ -60,7 +59,6 @@ pub fn spawn_spell_information(builder: &mut ChildBuilder, assets: &Res<GameAsse
.with_children(|parent| {
parent.spawn((
SpellIcon,
StateScoped(GameState::MainMenu),
ImageBundle {
style: Style {
width: Val::Px(32.0),
Expand All @@ -77,7 +75,6 @@ pub fn spawn_spell_information(builder: &mut ChildBuilder, assets: &Res<GameAsse
));

parent.spawn((
StateScoped(GameState::MainMenu),
SpellName,
TextBundle::from_section(
"",
Expand All @@ -90,7 +87,6 @@ pub fn spawn_spell_information(builder: &mut ChildBuilder, assets: &Res<GameAsse
});

parent.spawn((
StateScoped(GameState::MainMenu),
SpellDescription,
TextBundle::from_section(
"",
Expand Down
30 changes: 13 additions & 17 deletions src/ui/range.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use super::label::spawn_label;
use crate::asset::GameAssets;
use crate::language::Dict;
use crate::ui::menu_button::menu_button;
use crate::{asset::GameAssets, states::GameState};
use bevy::ecs::system::SystemId;
use bevy::prelude::*;

use super::label::spawn_label;

pub fn spawn_range<T: Component>(
child_builder: &mut ChildBuilder,
assets: &Res<GameAssets>,
Expand All @@ -16,22 +15,19 @@ pub fn spawn_range<T: Component>(
label: Dict,
) {
child_builder
.spawn((
StateScoped(GameState::InGame),
NodeBundle {
style: Style {
display: Display::Flex,
flex_direction: FlexDirection::Row,
align_items: AlignItems::Start,
justify_content: JustifyContent::Start,
border: UiRect::all(Val::Px(2.0)),
width: Val::Percent(100.0),
column_gap: Val::Px(10.0),
..default()
},
.spawn((NodeBundle {
style: Style {
display: Display::Flex,
flex_direction: FlexDirection::Row,
align_items: AlignItems::Start,
justify_content: JustifyContent::Start,
border: UiRect::all(Val::Px(2.0)),
width: Val::Percent(100.0),
column_gap: Val::Px(10.0),
..default()
},
))
..default()
},))
.with_children(|parent| {
spawn_label(parent, assets, label);

Expand Down
25 changes: 10 additions & 15 deletions src/ui/wand_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ struct SortButton;

const MENU_THEME_COLOR: Color = Color::hsla(63.0, 0.12, 0.5, 0.95);

pub fn spawn_wand_editor(commands: &mut Commands, assets: &Res<GameAssets>) {
commands
pub fn spawn_wand_editor(builder: &mut ChildBuilder, assets: &Res<GameAssets>) {
builder
.spawn((
StateScoped(GameState::InGame),
WandEditorRoot,
NodeBundle {
style: Style {
Expand All @@ -54,18 +53,15 @@ pub fn spawn_wand_editor(commands: &mut Commands, assets: &Res<GameAssets>) {
spawn_inventory(&mut parent, &assets);

parent
.spawn((
StateScoped(GameState::InGame),
NodeBundle {
style: Style {
display: Display::Flex,
flex_direction: FlexDirection::Row,
column_gap: Val::Px(8.0),
..default()
},
.spawn((NodeBundle {
style: Style {
display: Display::Flex,
flex_direction: FlexDirection::Row,
column_gap: Val::Px(8.0),
..default()
},
))
..default()
},))
.with_children(|parent| {
command_button(
parent,
Expand All @@ -82,9 +78,8 @@ pub fn spawn_wand_editor(commands: &mut Commands, assets: &Res<GameAssets>) {
});
});

commands
builder
.spawn((
StateScoped(GameState::InGame),
WandEditorRoot,
NodeBundle {
style: Style {
Expand Down

0 comments on commit e6dcffe

Please sign in to comment.