Skip to content

Commit

Permalink
Merge pull request #95 from thombruce/chore/bevy-0.12
Browse files Browse the repository at this point in the history
Chore/bevy 0.12
  • Loading branch information
thombruce authored Nov 13, 2023
2 parents 7b21a56 + 7cf2bfd commit 0b6d1be
Show file tree
Hide file tree
Showing 17 changed files with 476 additions and 381 deletions.
695 changes: 386 additions & 309 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = "0.11.3"
bevy-inspector-egui = "0.20.0"
bevy-ui-navigation = "0.32.0"
bevy_asset_loader = { version = "0.17.0", features = ["2d"] }
bevy_common_assets = { version = "0.7.0", features = ["ron"] }
bevy_fluent = "0.7.0"
bevy_rapier2d = "0.22.0"
bevy_spatial = "0.6.0"
bevy_tiling_background = { git = "https://github.com/rparrett/bevy_tiling_background.git", branch = "tex-typo" }
bevy = "0.12.0"
bevy-inspector-egui = "0.21.0"
bevy-ui-navigation = "0.33.0"
bevy_asset_loader = { version = "0.18.0", features = ["2d"] }
bevy_common_assets = { version = "0.8.0", features = ["ron"] }
bevy_fluent = "0.8.0"
bevy_rapier2d = "0.23.0"
bevy_spatial = "0.7.0"
fluent_content = "0.0.5"
image = "0.24.7"
leafwing-input-manager = "0.10.0"
leafwing-input-manager = "0.11.1"
rand = "0.8.5"
regex = "1.10.2"
ron = "0.8.1"
serde = "1.0.190"
unic-langid = { version = "0.9.1", features = ["macros"] }
winit = "0.28.7"

# Override dependencies to patched versions
[patch.crates-io]
bevy_fluent = { git = "https://github.com/kgv/bevy_fluent.git", branch = "main" } # Temporary Bevy 0.12 patch; TODO: Update

# Enable a small amount of optimization in debug mode
[profile.dev]
opt-level = 1
Expand Down
4 changes: 2 additions & 2 deletions src/core/effects/blink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ pub struct DrawBlinkTimer(pub Timer);
pub(crate) fn menu_blink_system(
mut commands: Commands,
time: Res<Time>,
mut query: Query<(Entity, &mut DrawBlinkTimer, &ComputedVisibility)>,
mut query: Query<(Entity, &mut DrawBlinkTimer, &InheritedVisibility)>,
) {
for (entity, mut timer, visibility) in query.iter_mut() {
timer.0.tick(time.delta());
if timer.0.finished() {
let new_visibility = if visibility.is_visible() {
let new_visibility = if visibility.get() {
Visibility::Hidden
} else {
Visibility::Visible
Expand Down
3 changes: 0 additions & 3 deletions src/core/resources/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ pub struct SpriteAssets {
#[asset(path = "space/celestials/neptune.png")]
pub neptune: Handle<TextureAtlas>,

#[asset(path = "space/backgrounds/custom.png")]
pub background: Handle<Image>,

#[asset(path = "space/meteors/meteorGrey_med1.png")]
pub meteor: Handle<Image>,
}
Expand Down
15 changes: 7 additions & 8 deletions src/i18n/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::asset::LoadState;
use bevy::asset::{LoadState, LoadedFolder};
use bevy::prelude::*;
use bevy_fluent::prelude::*;
use bevy_fluent::{AssetServerExt, BundleAsset, LocalizationBuilder};
use bevy_fluent::LocalizationBuilder;

use crate::systems::states::GameState;

Expand All @@ -25,16 +25,15 @@ pub struct I18n(pub Localization);
pub(crate) fn load_translations(
localization_builder: LocalizationBuilder,
asset_server: Res<AssetServer>,
mut handles: Local<Option<Vec<Handle<BundleAsset>>>>,
mut handle: Local<Option<Handle<LoadedFolder>>>,
mut i18n: ResMut<I18n>,
mut next_state: ResMut<NextState<GameState>>,
) {
let handles =
handles.get_or_insert_with(|| asset_server.load_glob("locales/**/main.ftl.ron").unwrap());
let handle = &*handle.get_or_insert_with(|| asset_server.load_folder("locales"));

let load_state = asset_server.get_group_load_state(handles.iter().map(Handle::id));
if let LoadState::Loaded = load_state {
i18n.0 = localization_builder.build(&*handles);
let load_state = asset_server.get_load_state(handle);
if let Some(LoadState::Loaded) = load_state {
i18n.0 = localization_builder.build(handle);
next_state.set(GameState::StartMenu);
}
}
4 changes: 2 additions & 2 deletions src/shaders/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod chromatic_aberration;
pub mod pixelate;
// pub mod chromatic_aberration;
// pub mod pixelate;
2 changes: 1 addition & 1 deletion src/ships/bullet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(crate) fn spawn_bullet(
handles: Res<SpriteAssets>,
audios: Res<AudioAssets>,
) {
for spawn_event in bullet_spawn_events.iter() {
for spawn_event in bullet_spawn_events.read() {
// Change this random factor to alter accuracy (larger is less accurate).
const SPREAD: f32 = 0.05;
let random_factor: f32 = rand::thread_rng().gen_range(-SPREAD..SPREAD);
Expand Down
2 changes: 1 addition & 1 deletion src/ships/ship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub(crate) fn ship_damage(
mut bullet_ship_contact_events: EventReader<BulletShipContactEvent>,
mut ship_health: Query<&mut Health, With<Ship>>,
) {
for event in bullet_ship_contact_events.iter() {
for event in bullet_ship_contact_events.read() {
commands.entity(event.bullet).despawn();

if let Ok(mut health) = ship_health.get_mut(event.ship) {
Expand Down
2 changes: 1 addition & 1 deletion src/systems/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub(crate) fn contact_system(
query: Query<(Has<Ship>, Has<Bullet>)>,
bullet_spawner: Query<&SpawnedBy, With<Bullet>>,
) {
for event in collision_events.iter() {
for event in collision_events.read() {
if let CollisionEvent::Started(e1, e2, _flags) = event {
let (e1_is_ship, e1_is_bullet) = query.get(*e1).unwrap();
let (e2_is_ship, e2_is_bullet) = query.get(*e2).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/systems/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ impl Plugin for SystemsPlugin {

// OnEnter
// - Any
for state in GameState::variants() {
for state in GameState::IN_ANY_STATE {
app.add_systems(
OnEnter(state),
OnEnter(*state),
states::transitions::state_enter_despawn::<GameState>,
);
}
Expand Down
9 changes: 9 additions & 0 deletions src/systems/states/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ pub enum GameState {
Paused,
}
impl GameState {
pub const IN_ANY_STATE: &[GameState; 7] = &[
GameState::Loading,
GameState::LoadingTranslations,
GameState::StartMenu,
GameState::Credits,
GameState::GameCreate,
GameState::Active,
GameState::Paused,
];
pub const IN_MENU_STATE: &[GameState; 2] = &[GameState::StartMenu, GameState::Credits];
pub const IN_GAME_STATE: &[GameState; 3] =
&[GameState::GameCreate, GameState::Active, GameState::Paused];
Expand Down
26 changes: 13 additions & 13 deletions src/ui/camera.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use bevy::prelude::*;

#[allow(unused_imports)]
use crate::shaders::{
chromatic_aberration::{ChromaticAberrationPlugin, ChromaticAberrationSettings},
pixelate::{PixelatePlugin, PixelateSettings},
};
// #[allow(unused_imports)]
// use crate::shaders::{
// chromatic_aberration::{ChromaticAberrationPlugin, ChromaticAberrationSettings},
// pixelate::{PixelatePlugin, PixelateSettings},
// };

use crate::ships::player::Player;

Expand Down Expand Up @@ -32,14 +32,14 @@ pub(crate) fn spawn_camera(mut commands: Commands) {
},
..default()
},
PixelateSettings {
block_size: 3.25,
..default()
},
ChromaticAberrationSettings {
intensity: 0.001,
..default()
},
// PixelateSettings {
// block_size: 3.25,
// ..default()
// },
// ChromaticAberrationSettings {
// intensity: 0.001,
// ..default()
// },
Name::new("Main Camera"),
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/damage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) fn ui_spawn_damage(
camera_query: Query<(&Camera, &GlobalTransform)>,
ui: Res<UiAssets>,
) {
for event in bullet_ship_contact_events.iter() {
for event in bullet_ship_contact_events.read() {
if let Ok(transform) = ship_transform.get(event.ship) {
// Use camera.world_to_viewport() and camera GlobalTransform to translate
// a world position into UI coordinates
Expand Down
6 changes: 3 additions & 3 deletions src/ui/hud/indicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub(crate) fn spawn_indicators(
pub(crate) fn indicators_system(
mut query: Query<(&mut Transform, &mut Style, &Indicator, &mut BackgroundColor)>,
player_query: Query<&Transform, (With<Player>, Without<Indicator>)>,
entity_query: Query<(&Transform, &ComputedVisibility, &Indicated), Without<Indicator>>,
entity_query: Query<(&Transform, &ViewVisibility, &Indicated), Without<Indicator>>,
bounds_query: Query<&Node, (With<Bounds>, Without<Indicator>)>,
) {
if let Ok(player_transform) = player_query.get_single() {
Expand All @@ -69,7 +69,7 @@ pub(crate) fn indicators_system(
if let Ok((entity_transform, entity_visibility, indicated)) =
entity_query.get(indicator.entity)
{
if entity_visibility.is_visible() {
if entity_visibility.get() {
indicator_style.display = Display::None;
continue;
}
Expand Down Expand Up @@ -135,7 +135,7 @@ pub(crate) fn indicators_system(
pub(crate) fn despawn_indicators_system(
mut commands: Commands,
mut query: Query<(Entity, &Indicator)>,
entity_query: Query<(&Transform, &ComputedVisibility), (With<Indicated>, Without<Indicator>)>,
entity_query: Query<Entity, (With<Indicated>, Without<Indicator>)>,
) {
for (entity, indicator) in &mut query {
if let Err(_) = entity_query.get(indicator.entity) {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/menus/credits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Plugin for CreditsPlugin {
}
}

#[derive(serde::Deserialize, TypeUuid, TypePath)]
#[derive(serde::Deserialize, TypeUuid, TypePath, Asset)]
#[uuid = "6763db47-17ca-4530-b604-94492c3a4c58"]
pub struct Credits(Vec<CreditSection>);

Expand Down
54 changes: 32 additions & 22 deletions src/world/astronomy/starfield.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
use bevy::{prelude::*, render::view::NoFrustumCulling};
use bevy_tiling_background::{
BackgroundImageBundle, BackgroundMaterial, SetImageRepeatingExt, TilingBackgroundPlugin,
use bevy::{
prelude::*,
render::{
texture::{ImageAddressMode, ImageLoaderSettings, ImageSampler, ImageSamplerDescriptor},
view::NoFrustumCulling,
},
};

use crate::core::resources::assets::SpriteAssets;
/// The setup function
pub(crate) fn spawn_starfield(mut commands: Commands, assets: Res<AssetServer>) {
let sampler_desc = ImageSamplerDescriptor {
address_mode_u: ImageAddressMode::Repeat,
address_mode_v: ImageAddressMode::Repeat,
..Default::default()
};

pub struct StarfieldPlugin;
impl Plugin for StarfieldPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(TilingBackgroundPlugin::<BackgroundMaterial>::default());
}
}
let settings = move |s: &mut ImageLoaderSettings| {
s.sampler = ImageSampler::Descriptor(sampler_desc.clone());
};

/// The setup function
pub(crate) fn spawn_starfield(
mut commands: Commands,
sprites: Res<SpriteAssets>,
mut materials: ResMut<Assets<BackgroundMaterial>>,
) {
let image = sprites.background.clone();
// Queue a command to set the image to be repeating once the image is loaded.
commands.set_image_repeating(image.clone());
let image = assets.load_with_settings("space/backgrounds/custom.png", settings);

// TODO: The Starfield no longer moves parallax to the foreground.
// Find a way to reimplement this behaviour.
commands.spawn((
BackgroundImageBundle::from_image(image, materials.as_mut())
.at_z_layer(-0.1)
.with_movement_scale(0.1),
SpriteBundle {
texture: image,
sprite: Sprite {
// TODO: Scale for a galaxy (change image, make procedural, etc.)
rect: Some(Rect::new(-1_000_000., -1_000_000., 1_000_000., 1_000_000.)),
..default()
},
transform: Transform {
translation: Vec3::new(0., 0., -899.),
..default()
},
..default()
},
NoFrustumCulling,
Name::new("Background"),
));
Expand Down
4 changes: 2 additions & 2 deletions src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use bevy::prelude::*;
pub mod astronomy;
pub mod spatial;

use self::{astronomy::starfield::StarfieldPlugin, spatial::SpatialPlugin};
use self::spatial::SpatialPlugin;

pub struct WorldPlugin;
impl Plugin for WorldPlugin {
fn build(&self, app: &mut App) {
app.add_plugins((StarfieldPlugin, SpatialPlugin));
app.add_plugins(SpatialPlugin);
}
}

0 comments on commit 0b6d1be

Please sign in to comment.