Skip to content

Commit

Permalink
Upgrade to Bevy 0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr committed Nov 30, 2024
1 parent 5363840 commit 21734fa
Show file tree
Hide file tree
Showing 18 changed files with 1,536 additions and 1,459 deletions.
1,273 changes: 863 additions & 410 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
anyhow = "1"
bevy = { version = "0.14", default-features = false, features = [
bevy = { version = "0.15", default-features = false, features = [
"animation",
"bevy_asset",
"bevy_gilrs",
Expand All @@ -18,6 +18,7 @@ bevy = { version = "0.14", default-features = false, features = [
"bevy_sprite",
"bevy_text",
"bevy_ui",
"bevy_window",
"jpeg",
"png",
"wayland",
Expand Down
10 changes: 2 additions & 8 deletions src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Plugin for BackgroundPlugin {
.init_resource::<BackgroundAsset>()
.add_event::<UpdateBackgroundTransform>()
.add_systems(Update, resize_background.after(load_level).after(on_resize))
.observe(update_background_transform);
.add_observer(update_background_transform);
}
}

Expand All @@ -37,13 +37,7 @@ fn setup_background(
) {
asset.background = image_assets.add(load_repeating_asset(BACKGROUND_ASSET));

commands.spawn((
Background,
SpriteBundle {
texture: asset.background.clone(),
..Default::default()
},
));
commands.spawn((Background, Sprite::from_image(asset.background.clone())));
}

fn resize_background(
Expand Down
22 changes: 11 additions & 11 deletions src/editor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod button;
mod editor_bundle;
mod editor_button;
mod editor_system;
mod number_input;
mod object_selector_bundle;
Expand Down Expand Up @@ -38,16 +38,16 @@ impl Plugin for EditorPlugin {
.add_event::<SelectObject>()
.add_event::<ToggleEditor>()
.add_event::<ToggleSelection>()
.observe(change_height)
.observe(change_identifier)
.observe(change_level)
.observe(change_width)
.observe(move_all_objects)
.observe(on_activate_selection)
.observe(on_deselect_object)
.observe(on_select_object)
.observe(on_toggle_editor)
.observe(on_toggle_selection);
.add_observer(change_height)
.add_observer(change_identifier)
.add_observer(change_level)
.add_observer(change_width)
.add_observer(move_all_objects)
.add_observer(on_activate_selection)
.add_observer(on_deselect_object)
.add_observer(on_select_object)
.add_observer(on_toggle_editor)
.add_observer(on_toggle_selection);
}
}

Expand Down
65 changes: 0 additions & 65 deletions src/editor/button.rs

This file was deleted.

89 changes: 39 additions & 50 deletions src/editor/editor_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@ use bevy::prelude::*;

use crate::{constants::*, fonts::Fonts, game_object::GameObjectAssets, levels::Dimensions};

use super::{
button::{Button, EditorButtonBundle},
number_input::NumberInputBundle,
ObjectSelectorBundle,
};
use super::{editor_button::EditorButton, number_input::NumberInput, ObjectSelector};

const BORDER_WIDTH: f32 = 2.;

#[derive(Component)]
pub struct Editor;

#[derive(Clone, Component, Copy, Eq, PartialEq)]
pub enum Input {
Width,
Expand All @@ -30,36 +23,32 @@ pub struct LevelInput;
#[derive(Component)]
pub struct SelectionOverlay;

#[derive(Bundle)]
pub struct EditorBundle {
background: NodeBundle,
editor: Editor,
}
#[derive(Component)]
#[require(Node)]
pub struct Editor;

impl EditorBundle {
pub fn new() -> Self {
Self {
background: NodeBundle {
style: Style {
width: Val::Px(EDITOR_WIDTH as f32 - BORDER_WIDTH),
height: Val::Percent(100.),
border: UiRect::left(Val::Px(BORDER_WIDTH)),
padding: UiRect::all(Val::Px(EDITOR_PADDING as f32)),
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
justify_content: JustifyContent::Start,
right: Val::Px(0.),
position_type: PositionType::Absolute,
row_gap: Val::Px(EDITOR_PADDING as f32),
..Default::default()
},
background_color: GRAY_BACKGROUND.into(),
border_color: RED.into(),
z_index: ZIndex::Global(100),
..Default::default()
impl Editor {
#[expect(clippy::new_ret_no_self)]
pub fn new() -> impl Bundle {
(
Editor,
BackgroundColor(GRAY_BACKGROUND),
BorderColor(RED),
GlobalZIndex(100),
Node {
width: Val::Px(EDITOR_WIDTH as f32 - BORDER_WIDTH),
height: Val::Percent(100.),
border: UiRect::left(Val::Px(BORDER_WIDTH)),
padding: UiRect::all(Val::Px(EDITOR_PADDING as f32)),
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
justify_content: JustifyContent::Start,
right: Val::Px(0.),
position_type: PositionType::Absolute,
row_gap: Val::Px(EDITOR_PADDING as f32),
..default()
},
editor: Editor,
}
)
}

pub fn populate(
Expand All @@ -68,29 +57,29 @@ impl EditorBundle {
dimensions: &Dimensions,
fonts: &Fonts,
) {
cb.spawn(NumberInputBundle::new()).with_children(|cb| {
NumberInputBundle::populate(cb, Input::Width, "Width:", dimensions.width, fonts)
cb.spawn(NumberInput::new()).with_children(|cb| {
NumberInput::populate(cb, Input::Width, "Width:", dimensions.width, fonts)
});

cb.spawn(NumberInputBundle::new()).with_children(|cb| {
NumberInputBundle::populate(cb, Input::Height, "Height:", dimensions.height, fonts)
cb.spawn(NumberInput::new()).with_children(|cb| {
NumberInput::populate(cb, Input::Height, "Height:", dimensions.height, fonts)
});

cb.spawn(ObjectSelectorBundle::new())
.with_children(|cb| ObjectSelectorBundle::populate(cb, assets));
cb.spawn(ObjectSelector::new())
.with_children(|cb| ObjectSelector::populate(cb, assets));

cb.spawn(EditorButtonBundle::new(Button::Save))
.with_children(|cb| EditorButtonBundle::populate(cb, Button::Save, "Save", fonts));
cb.spawn(EditorButton::new(EditorButton::Save))
.with_children(|cb| EditorButton::populate(cb, EditorButton::Save, "Save", fonts));

cb.spawn(EditorButtonBundle::new(Button::Select))
.with_children(|cb| EditorButtonBundle::populate(cb, Button::Select, "Select", fonts));
cb.spawn(EditorButton::new(EditorButton::Select))
.with_children(|cb| EditorButton::populate(cb, EditorButton::Select, "Select", fonts));

cb.spawn(NumberInputBundle::hidden(LevelInput))
.with_children(|cb| NumberInputBundle::populate(cb, Input::Level, "Level:", 0, fonts));
cb.spawn(NumberInput::hidden(LevelInput))
.with_children(|cb| NumberInput::populate(cb, Input::Level, "Level:", 0, fonts));

cb.spawn(NumberInputBundle::hidden(IdentifierInput))
cb.spawn(NumberInput::hidden(IdentifierInput))
.with_children(|cb| {
NumberInputBundle::populate(cb, Input::Identifier, "Teleporter:", 0, fonts)
NumberInput::populate(cb, Input::Identifier, "Teleporter:", 0, fonts)
});
}
}
48 changes: 48 additions & 0 deletions src/editor/editor_button.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use bevy::prelude::*;

use crate::{
constants::{DARK_GRAY, *},
fonts::Fonts,
};

#[derive(Clone, Component, Copy, Eq, PartialEq)]
pub enum EditorButton {
Save,
Select,
}

impl EditorButton {
#[expect(clippy::new_ret_no_self)]
pub fn new(marker: impl Bundle) -> impl Bundle {
(
marker,
Button,
BackgroundColor(DARK_GRAY),
BorderRadius::all(Val::Px(4.)),
Node {
height: Val::Px(30.),
width: Val::Px(150.),
align_content: AlignContent::Center,
..Default::default()
},
)
}

pub fn populate(
cb: &mut ChildBuilder,
marker: impl Bundle,
text: impl Into<String>,
fonts: &Fonts,
) {
cb.spawn((
marker,
Text::new(text),
TextColor(WHITE),
TextFont::from_font(fonts.poppins_light.clone()).with_font_size(18.),
Node {
margin: UiRect::all(Val::Auto),
..Default::default()
},
));
}
}
Loading

0 comments on commit 21734fa

Please sign in to comment.