Skip to content
Snippets Groups Projects
Verified Commit 1b5a4c32 authored by Louis's avatar Louis :fire:
Browse files

Update to Bevy 0.9

parent 69915f67
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
...@@ -13,7 +13,25 @@ log = "0.4.17" ...@@ -13,7 +13,25 @@ log = "0.4.17"
thiserror = "1.0.37" thiserror = "1.0.37"
serde = "1.0.147" serde = "1.0.147"
serde_json = "1.0.87" serde_json = "1.0.87"
iyes_loopless = "0.8.0" iyes_loopless = "0.9.1"
micro_musicbox = { version = "0.5.0", features = ["mp3"] }
micro_banimate = "0.2.1"
[workspace.dependencies.bevy]
version = "0.9.0"
default-features = false
features = [
"bevy_asset",
"render",
"bevy_winit",
"png",
"hdr",
"x11",
"wayland",
"serialize",
"filesystem_watcher"
]
[profile.release] [profile.release]
debug = 0 debug = 0
......
...@@ -6,6 +6,8 @@ edition = "2021" ...@@ -6,6 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
bevy.workspace = true
fastrand.workspace = true fastrand.workspace = true
anyhow.workspace = true anyhow.workspace = true
log.workspace = true log.workspace = true
...@@ -14,20 +16,10 @@ serde.workspace = true ...@@ -14,20 +16,10 @@ serde.workspace = true
serde_json.workspace = true serde_json.workspace = true
iyes_loopless.workspace = true iyes_loopless.workspace = true
micro_musicbox = "0.4.0" micro_banimate.workspace = true
remote_events = { git = "https://lab.lcr.gr/microhacks/micro-bevy-remote-events.git", rev = "be0c6b43a73e4c5e7ece20797e3d6f59340147b4"} micro_musicbox.workspace = true
micro_banimate = "0.1.1"
#remote_events = { git = "https://lab.lcr.gr/microhacks/micro-bevy-remote-events.git", rev = "be0c6b43a73e4c5e7ece20797e3d6f59340147b4"}
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3.58", features = ["Window"] } web-sys = { version = "0.3.58", features = ["Window"] }
[dependencies.bevy]
version = "0.8.1"
default-features = false
features = [
"render",
"bevy_winit",
"png",
"hdr",
"x11",
]
...@@ -74,6 +74,8 @@ impl<'w, 's> AssetTypeLoader<'w, 's> { ...@@ -74,6 +74,8 @@ impl<'w, 's> AssetTypeLoader<'w, 's> {
Vec2::new(config.tile_width as f32, config.tile_height as f32), Vec2::new(config.tile_width as f32, config.tile_height as f32),
config.columns, config.columns,
config.rows, config.rows,
None,
None,
); );
let atlas_handle = loader.atlas.add(atlas); let atlas_handle = loader.atlas.add(atlas);
...@@ -86,10 +88,10 @@ impl<'w, 's> AssetTypeLoader<'w, 's> { ...@@ -86,10 +88,10 @@ impl<'w, 's> AssetTypeLoader<'w, 's> {
pub fn get_all_load_state(&self) -> Vec<LoadState> { pub fn get_all_load_state(&self) -> Vec<LoadState> {
let image_state = self let image_state = self
.asset_server .asset_server
.get_group_load_state(self.handles.images.values().map(|f| f.id)); .get_group_load_state(self.handles.images.values().map(|f| f.id()));
let atlas_state = self let atlas_state = self
.asset_server .asset_server
.get_group_load_state(self.handles.images.values().map(|f| f.id)); .get_group_load_state(self.handles.images.values().map(|f| f.id()));
vec![image_state, atlas_state] vec![image_state, atlas_state]
} }
......
...@@ -31,7 +31,7 @@ impl SpriteSheetConfig { ...@@ -31,7 +31,7 @@ impl SpriteSheetConfig {
} }
} }
#[derive(Default)] #[derive(Default, Resource)]
pub struct AssetHandles { pub struct AssetHandles {
pub images: HashMap<String, Handle<Image>>, pub images: HashMap<String, Handle<Image>>,
pub atlas: HashMap<String, Handle<TextureAtlas>>, pub atlas: HashMap<String, Handle<TextureAtlas>>,
......
use bevy::prelude::*; use bevy::prelude::*;
use game_core::assets::AssetHandles; use game_core::assets::AssetHandles;
use game_core::system::flow::AppState; use game_core::system::flow::AppState;
use game_core::system::resources::DefaultResourcesPlugin; use game_core::system::resources::InitAppPlugins;
use iyes_loopless::prelude::AppLooplessStateExt; use iyes_loopless::prelude::AppLooplessStateExt;
use micro_musicbox::CombinedAudioPlugins; use micro_musicbox::CombinedAudioPlugins;
use remote_events::RemoteEventPlugin; // use remote_events::RemoteEventPlugin;
fn main() { fn main() {
App::new() App::new()
.add_loopless_state(AppState::Preload) .add_loopless_state(AppState::Preload)
.add_plugin(DefaultResourcesPlugin) .add_plugins(InitAppPlugins)
.add_plugins(DefaultPlugins)
.add_plugin(game_core::assets::AssetsPlugin) .add_plugin(game_core::assets::AssetsPlugin)
.add_plugins(CombinedAudioPlugins::<AssetHandles>::new()) .add_plugins(CombinedAudioPlugins::<AssetHandles>::new())
.add_plugin(game_core::splash_screen::SplashScreenPlugin) .add_plugin(game_core::splash_screen::SplashScreenPlugin)
.add_plugin(game_core::system::camera::CameraManagementPlugin) .add_plugin(game_core::system::camera::CameraManagementPlugin)
.add_plugin(RemoteEventPlugin::< // .add_plugin(RemoteEventPlugin::<
game_core::multiplayer::OutgoingEvent, // game_core::multiplayer::OutgoingEvent,
game_core::multiplayer::IncomingEvent, // game_core::multiplayer::IncomingEvent,
>::new()) // >::new())
.run(); .run();
} }
use remote_events::events::{FromSocketMessage, ToSocketMessage}; // use remote_events::events::{FromSocketMessage, ToSocketMessage};
use serde::{Deserialize, Serialize}; // use serde::{Deserialize, Serialize};
//
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)] // #[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
#[serde(tag = "type")] // #[serde(tag = "type")]
pub enum IncomingEvent { // pub enum IncomingEvent {
#[default] // #[default]
#[serde(rename = "void")] // #[serde(rename = "void")]
Void, // Void,
} // }
//
impl FromSocketMessage for IncomingEvent { // impl FromSocketMessage for IncomingEvent {
fn from_text(value: String) -> Self { // fn from_text(value: String) -> Self {
serde_json::from_str(value.as_str()).unwrap_or_default() // serde_json::from_str(value.as_str()).unwrap_or_default()
} // }
//
fn from_binary(value: Vec<u8>) -> Self { // fn from_binary(value: Vec<u8>) -> Self {
serde_json::from_slice(value.as_slice()).unwrap_or_default() // serde_json::from_slice(value.as_slice()).unwrap_or_default()
} // }
} // }
//
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)] // #[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
#[serde(tag = "type")] // #[serde(tag = "type")]
pub enum OutgoingEvent { // pub enum OutgoingEvent {
#[default] // #[default]
#[serde(rename = "void")] // #[serde(rename = "void")]
Void, // Void,
} // }
//
impl ToSocketMessage for OutgoingEvent { // impl ToSocketMessage for OutgoingEvent {
fn to_text(&self) -> String { // fn to_text(&self) -> String {
serde_json::to_string(&self).unwrap_or(String::from("{}")) // serde_json::to_string(&self).unwrap_or(String::from("{}"))
} // }
} // }
...@@ -58,8 +58,8 @@ pub fn setup_splash_screen( ...@@ -58,8 +58,8 @@ pub fn setup_splash_screen(
image_data.sampler_descriptor = ImageSampler::linear(); image_data.sampler_descriptor = ImageSampler::linear();
music_box.play_sfx("splash_sting"); music_box.play_sfx("splash_sting");
commands commands.spawn((
.spawn_bundle(SpriteBundle { SpriteBundle {
texture: handle.clone_weak(), texture: handle.clone_weak(),
sprite: Sprite { sprite: Sprite {
color: C_TRANS, color: C_TRANS,
...@@ -70,26 +70,25 @@ pub fn setup_splash_screen( ...@@ -70,26 +70,25 @@ pub fn setup_splash_screen(
..Default::default() ..Default::default()
}, },
..Default::default() ..Default::default()
}) },
.insert_bundle(SplashAnimationBundle::from_animation( SplashAnimationBundle::from_animation(SplashAnimation::wait(
SplashAnimation::wait( 1.0,
Some(Box::new(SplashAnimation::fade(
C_TRANS,
C_WHITE,
1.0, 1.0,
Some(Box::new(SplashAnimation::fade( Some(Box::new(SplashAnimation::wait(
C_TRANS,
C_WHITE,
1.0, 1.0,
Some(Box::new(SplashAnimation::wait( Some(Box::new(SplashAnimation::fade(
1.0, C_WHITE,
Some(Box::new(SplashAnimation::fade( C_TRANS,
C_WHITE, 0.75,
C_TRANS, Some(Box::new(SplashAnimation::wait(0.75, None))),
0.75,
Some(Box::new(SplashAnimation::wait(0.75, None))),
))),
))), ))),
))), ))),
), ))),
)); )),
));
} }
pub fn tick_splash_system( pub fn tick_splash_system(
......
...@@ -20,8 +20,8 @@ pub struct GameCamera; ...@@ -20,8 +20,8 @@ pub struct GameCamera;
/// System that creates a default orthographic camera, with correct tags for querying /// System that creates a default orthographic camera, with correct tags for querying
pub fn spawn_orthographic_camera(mut commands: Commands) { pub fn spawn_orthographic_camera(mut commands: Commands) {
let (target_width, target_height) = virtual_size(); let (target_width, target_height) = virtual_size();
commands commands.spawn((
.spawn_bundle(Camera2dBundle { Camera2dBundle {
projection: OrthographicProjection { projection: OrthographicProjection {
left: -(target_width / 2.0), left: -(target_width / 2.0),
right: (target_width / 2.0), right: (target_width / 2.0),
...@@ -34,8 +34,9 @@ pub fn spawn_orthographic_camera(mut commands: Commands) { ...@@ -34,8 +34,9 @@ pub fn spawn_orthographic_camera(mut commands: Commands) {
..Default::default() ..Default::default()
}, },
..Default::default() ..Default::default()
}) },
.insert(GameCamera); GameCamera,
));
} }
/// System that takes the average location of all chase camera entities, and updates the location /// System that takes the average location of all chase camera entities, and updates the location
......
use bevy::asset::AssetServerSettings; use bevy::app::PluginGroupBuilder;
use bevy::log::{Level, LogPlugin};
use bevy::prelude::*; use bevy::prelude::*;
use bevy::render::texture::ImageSettings; use bevy::window::{PresentMode, WindowMode};
use bevy::window::PresentMode;
use crate::system::camera::spawn_orthographic_camera;
use crate::system::load_config::{get_asset_path_string, initial_size}; use crate::system::load_config::{get_asset_path_string, initial_size};
pub struct DefaultResourcesPlugin; pub struct DefaultResourcesPlugin;
impl Plugin for DefaultResourcesPlugin { impl Plugin for DefaultResourcesPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
let (width, height) = initial_size(); app.insert_resource(Msaa { samples: 1 })
.insert_resource(ClearColor(Color::hex("040720").unwrap()));
app.insert_resource(WindowDescriptor { }
width, }
height, pub fn configure_default_plugins() -> PluginGroupBuilder {
resizable: true, let (width, height) = initial_size();
title: String::from("Bevy 2D Template"), DefaultPlugins
present_mode: PresentMode::AutoNoVsync, .set(WindowPlugin {
window: WindowDescriptor {
width,
height,
resizable: true,
mode: WindowMode::Windowed,
title: String::from("Bevy 2D Template"),
present_mode: PresentMode::AutoNoVsync,
..Default::default()
},
..Default::default() ..Default::default()
}) })
.insert_resource(ImageSettings::default_nearest()) .set(AssetPlugin {
.insert_resource(Msaa { samples: 1 })
.insert_resource(ClearColor(Color::hex("040720").unwrap()))
.insert_resource(AssetServerSettings {
asset_folder: get_asset_path_string(), asset_folder: get_asset_path_string(),
watch_for_changes: false, watch_for_changes: true,
}); })
.set(ImagePlugin::default_nearest())
.set(LogPlugin {
filter: String::from(
"info,symphonia_core=warn,symphonia_bundle_mp3=warn,wgpu_core=warn,wgpu_hal=warn",
),
level: Level::DEBUG,
})
}
pub struct InitAppPlugins;
impl PluginGroup for InitAppPlugins {
fn build(self) -> PluginGroupBuilder {
configure_default_plugins().add(DefaultResourcesPlugin)
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment