Skip to content

Commit

Permalink
refactor: migrate to bevy 15
Browse files Browse the repository at this point in the history
  • Loading branch information
malezjaa committed Nov 12, 2024
1 parent e033012 commit 7fa40a6
Show file tree
Hide file tree
Showing 46 changed files with 84 additions and 108 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bevy = "0.15.0-rc.3"
bevy = { version = "0.15.0-rc.3", features = ["custom_cursor"] }
bevy_rapier2d = "0.27.0"

[profile.dev]
Expand Down
Binary file removed assets/cursor.png
Binary file not shown.
Binary file added assets/cursors/cursor_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cursors/cursor_grab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cursors/cursor_grabbing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cursors/cursor_help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cursors/cursor_move.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cursors/cursor_progress.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cursors/cursor_select.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cursors/cursor_unavailable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cursors/cursor_work.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/tile000.png
Binary file not shown.
Binary file removed assets/tile001.png
Binary file not shown.
Binary file removed assets/tile002.png
Binary file not shown.
Binary file removed assets/tile003.png
Binary file not shown.
Binary file removed assets/tile004.png
Binary file not shown.
Binary file removed assets/tile005.png
Binary file not shown.
Binary file removed assets/tile006.png
Binary file not shown.
Binary file removed assets/tile007.png
Binary file not shown.
Binary file removed assets/tile008.png
Binary file not shown.
Binary file removed assets/tile016.png
Binary file not shown.
Binary file removed assets/tile017.png
Binary file not shown.
Binary file removed assets/tile018.png
Binary file not shown.
Binary file removed assets/tile019.png
Binary file not shown.
Binary file removed assets/tile020.png
Binary file not shown.
Binary file removed assets/tile021.png
Binary file not shown.
Binary file removed assets/tile022.png
Diff not rendered.
Binary file removed assets/tile023.png
Diff not rendered.
Binary file removed assets/tile024.png
Diff not rendered.
Binary file removed assets/tile032.png
Diff not rendered.
Binary file removed assets/tile033.png
Diff not rendered.
Binary file removed assets/tile034.png
Diff not rendered.
Binary file removed assets/tile035.png
Diff not rendered.
Binary file removed assets/tile036.png
Diff not rendered.
Binary file removed assets/tile037.png
Diff not rendered.
Binary file removed assets/tile038.png
Diff not rendered.
Binary file removed assets/tile039.png
Diff not rendered.
Binary file removed assets/tile040.png
Diff not rendered.
Binary file removed assets/tile050.png
Diff not rendered.
Binary file removed assets/tile055.png
Diff not rendered.
Binary file removed assets/tile071.png
Diff not rendered.
62 changes: 0 additions & 62 deletions rustc-ice-2024-11-11T21_20_32-29384.txt

This file was deleted.

57 changes: 48 additions & 9 deletions src/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
use bevy::prelude::*;
use bevy::winit::cursor::CustomCursor;

pub fn setup_cursor(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.insert_resource(CustomCursor::Image {
handle: asset_server.load("cursor.png"),
hotspot: (128, 128),
}.into());
}
// use bevy::prelude::*;
// use bevy::window::SystemCursorIcon;
// use bevy::winit::cursor::{CursorIcon, CustomCursor};
//
// #[derive(Resource)]
// pub struct CursorIcons(Vec<CursorIcon>);
//
// pub fn setup_cursor(mut commands: Commands, asset_server: Res<AssetServer>) {
// commands.insert_resource(CursorIcons(vec![
// CustomCursor::Image {
// handle: asset_server.load("cursors/cursor_default.png"),
// hotspot: (23, 24),
// }
// .into(),
// CustomCursor::Image {
// handle: asset_server.load("cursors/cursor_select.png"),
// hotspot: (23, 24),
// }
// .into(),
// CustomCursor::Image {
// handle: asset_server.load("cursors/cursor_progress.gif"),
// hotspot: (23, 24),
// }
// .into(),
// SystemCursorIcon::Text.into(),
// ]));
// }
//
// pub fn handle_cursor(
// mut commands: Commands,
// window: Single<Entity, With<Window>>,
// input: Res<ButtonInput<MouseButton>>,
// cursor_icons: Res<CursorIcons>,
// ) {
// if input.just_pressed(MouseButton::Left) {
// commands
// .entity(*window)
// .insert(cursor_icons.0[1].clone());
// } else if input.just_released(MouseButton::Left) {
// commands
// .entity(*window)
// .insert(cursor_icons.0[0].clone());
// }
//
// commands
// .entity(*window)
// .insert(cursor_icons.0[0].clone());
// }
42 changes: 23 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
pub mod player;
mod cursor;
pub mod menu;
pub mod player;
mod screen;
mod text;
mod cursor;

use bevy::prelude::*;
use bevy_rapier2d::prelude::*;
use crate::menu::{menu_plugin, setup_camera, GameState};
use bevy::prelude::*;
use bevy::window::{CursorMoved, WindowTheme};
use bevy::winit::cursor::{CursorIcon, CustomCursor};
use crate::cursor::setup_cursor;
use bevy_rapier2d::prelude::*;

pub const GAME_TITLE: &str = "Chronos Game";

fn main() {
std::env::set_var("RUST_BACKTRACE", "1");

App::new()
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()).set(
WindowPlugin {
primary_window: Some(Window {
title: GAME_TITLE.into(),
window_theme: Some(WindowTheme::Dark),
enabled_buttons: bevy::window::EnabledButtons {
maximize: false,
..Default::default()
},
.add_plugins(
DefaultPlugins
.set(ImagePlugin::default_nearest())
.set(WindowPlugin {
primary_window: Some(Window {
title: GAME_TITLE.into(),
window_theme: Some(WindowTheme::Dark),
enabled_buttons: bevy::window::EnabledButtons {
maximize: false,
..Default::default()
},
..default()
}),
..default()
}),
..default()
}
))
)
.init_state::<GameState>()
.add_systems(Startup, (setup_camera, setup_cursor))
.add_systems(Startup, (setup_camera /* * setup_cursor **/))
// .add_systems(Update, handle_cursor)
.add_plugins(menu_plugin)
.run();
}
}
14 changes: 3 additions & 11 deletions src/menu.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::{app::AppExit, color::palettes::css::CRIMSON, prelude::*};
use bevy::color::palettes::css::{BLACK, SLATE_GRAY};
use crate::screen::despawn_screen;
use crate::text::{text_bundle, TEXT_COLOR};
use crate::text::{text_bundle, text_style, TEXT_COLOR};

#[derive(Clone, Copy, Default, Eq, PartialEq, Debug, Hash, States)]
pub enum GameState {
Expand Down Expand Up @@ -117,11 +117,6 @@ fn main_menu_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..default()
};

let button_text_style = TextFont {
font_size: 40.0,
..default()
};

commands
.spawn((
Node {
Expand Down Expand Up @@ -150,10 +145,7 @@ fn main_menu_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
}))
.with_children(|parent| {
parent.spawn(
text_bundle("Main Menu", &asset_server, (TextFont {
font_size: 65.0,
..default()
}, Node {
text_bundle("Main Menu", (text_style(65.0, &asset_server), Node {
margin: UiRect {
bottom: Val::Px(20.0),
..default()
Expand All @@ -180,7 +172,7 @@ fn main_menu_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..default()
}, button_icon_style));
parent.spawn(
text_bundle("Play", &asset_server, button_text_style.clone())
text_bundle("Play", text_style(40.0, &asset_server))
);
});
});
Expand Down
15 changes: 9 additions & 6 deletions src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ use bevy::prelude::*;

pub const TEXT_COLOR: Color = Color::srgb(0.0, 0.0, 0.0);

pub fn text_bundle(text: impl Into<String>, asset_server: &Res<AssetServer>, style: impl Bundle) -> impl Bundle {
(Text::new(
text,
), style, TextFont {
font: asset_server.load("fonts/Roboto-Regular.ttf"),
pub fn text_bundle(text: impl Into<String>, style: impl Bundle) -> impl Bundle {
(Text::new(text), style)
}

pub fn text_style(size: f32, asset_server: &Res<AssetServer>) -> impl Bundle {
(TextFont {
font: asset_server.load("fonts/main-font.ttf"),
font_size: size,
..default()
})
}, TextColor(TEXT_COLOR))
}

0 comments on commit 7fa40a6

Please sign in to comment.