From e6dcffeb3283f2261a234e35a696eaa50ada346f Mon Sep 17 00:00:00 2001 From: aratama <16192627+aratama@users.noreply.github.com> Date: Tue, 19 Nov 2024 00:32:24 +0900 Subject: [PATCH] remove redundant StateScoped --- src/entity/dropped_item.rs | 31 ++++++---------- src/entity/magic_circle.rs | 4 +- src/hud.rs | 75 +++++++++++++++++--------------------- src/ui/floating.rs | 5 +-- src/ui/inventory.rs | 55 +++++++++++++--------------- src/ui/item_information.rs | 4 -- src/ui/range.rs | 30 +++++++-------- src/ui/wand_editor.rs | 25 +++++-------- 8 files changed, 96 insertions(+), 133 deletions(-) diff --git a/src/entity/dropped_item.rs b/src/entity/dropped_item.rs index dc6ba35..8d39d5c 100644 --- a/src/entity/dropped_item.rs +++ b/src/entity/dropped_item.rs @@ -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), diff --git a/src/entity/magic_circle.rs b/src/entity/magic_circle.rs index 7072913..ff7fb76 100644 --- a/src/entity/magic_circle.rs +++ b/src/entity/magic_circle.rs @@ -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::*; @@ -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(), @@ -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 { diff --git a/src/hud.rs b/src/hud.rs index 6c9ddec..72e2faf 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -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); @@ -128,11 +122,11 @@ 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()); @@ -140,22 +134,19 @@ fn setup_hud( 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, diff --git a/src/ui/floating.rs b/src/ui/floating.rs index 1c378c6..544b5d6 100644 --- a/src/ui/floating.rs +++ b/src/ui/floating.rs @@ -42,10 +42,9 @@ impl Floating { } } -pub fn spawn_inventory_floating(commands: &mut Commands, assets: &Res) { - commands.spawn(( +pub fn spawn_inventory_floating(builder: &mut ChildBuilder, assets: &Res) { + builder.spawn(( Floating(None), - StateScoped(GameState::InGame), Interaction::default(), ImageBundle { style: Style { diff --git a/src/ui/inventory.rs b/src/ui/inventory.rs index 116ed7a..dbc673b 100644 --- a/src/ui/inventory.rs +++ b/src/ui/inventory.rs @@ -14,39 +14,35 @@ struct InventoryItemSlot(usize); pub fn spawn_inventory(builder: &mut ChildBuilder, assets: &Res) { 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, @@ -69,7 +65,6 @@ pub fn spawn_inventory(builder: &mut ChildBuilder, assets: &Res) { for i in 0..MAX_ITEMS_IN_INVENTORY { builder.spawn(( InventoryItemSlot(i), - StateScoped(GameState::MainMenu), Interaction::default(), ImageBundle { style: Style { diff --git a/src/ui/item_information.rs b/src/ui/item_information.rs index 50a9db0..374e181 100644 --- a/src/ui/item_information.rs +++ b/src/ui/item_information.rs @@ -31,7 +31,6 @@ pub fn spawn_spell_information(builder: &mut ChildBuilder, assets: &Res( child_builder: &mut ChildBuilder, assets: &Res, @@ -16,22 +15,19 @@ pub fn spawn_range( 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); diff --git a/src/ui/wand_editor.rs b/src/ui/wand_editor.rs index 75cb8ba..6c1eaba 100644 --- a/src/ui/wand_editor.rs +++ b/src/ui/wand_editor.rs @@ -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) { - commands +pub fn spawn_wand_editor(builder: &mut ChildBuilder, assets: &Res) { + builder .spawn(( - StateScoped(GameState::InGame), WandEditorRoot, NodeBundle { style: Style { @@ -54,18 +53,15 @@ pub fn spawn_wand_editor(commands: &mut Commands, assets: &Res) { 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, @@ -82,9 +78,8 @@ pub fn spawn_wand_editor(commands: &mut Commands, assets: &Res) { }); }); - commands + builder .spawn(( - StateScoped(GameState::InGame), WandEditorRoot, NodeBundle { style: Style {