Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to bevy 0.9 #288

Merged
merged 3 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,420 changes: 813 additions & 607 deletions Cargo.lock

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ members = [
]

[dependencies.bevy]
version = "0.8"
version = "0.9"
default-features = false
features = [
"x11",
Expand All @@ -26,22 +26,23 @@ features = [
punchy_macros = { path = "./macros" }

anyhow = "1.0.58"
bevy-parallax = "0.2.0"
bevy_egui = "0.15.0"
egui_extras = "0.18.0"
bevy_kira_audio = { version = "0.11.0", features = ["mp3"] }
bevy_rapier2d = { version = "0.16.0", features = ["debug-render"] }
iyes_loopless = { version = "0.8.0", features = ["states"] }
bevy-parallax = "0.3.0"
bevy_egui = "0.18.0"
egui_extras = "0.20.0"
bevy_kira_audio = { version = "0.13.0", features = ["mp3"] }
bevy_rapier2d = { version = "0.19.0", features = ["debug-render"] }
iyes_loopless = { version = "0.9.0", features = ["states"] }
serde = { version = "1.0.137", features = ["derive"] }
serde_yaml = "0.9.2"
thiserror = "1.0.31"
structopt = "0.3.26"
rand = "0.8.5"
getrandom = { version = "0.2", features = ["js"] }

leafwing-input-manager = { version = "0.6", default-features = false }
leafwing-input-manager = { version = "0.7", default-features = false }
unic-langid = "0.9.0"
bevy_fluent = "0.4.0"
bevy_fluent = "0.5.0"
fluent_content="0.0.3"
sys-locale = "0.2.1"
fluent = "0.16.0"
directories = "4.0.1"
Expand All @@ -50,9 +51,9 @@ once_cell = "1.13.0"
bevy_mod_js_scripting = { git = "https://github.com/jakobhellermann/bevy_mod_js_scripting.git" }

# Debug tools
bevy-inspector-egui = { version = "0.12.1" }
bevy-inspector-egui-rapier = { version = "0.5.0", features = ["rapier2d"] }
bevy_mod_debugdump = { version = "0.5.0", optional = true }
bevy-inspector-egui = { version = "0.15.0" }
bevy-inspector-egui-rapier = { version = "0.9.0", features = ["rapier2d"] }
bevy_mod_debugdump = { version = "0.6.0", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3", features = ["Window","Location","Storage"] }
Expand Down
8 changes: 6 additions & 2 deletions src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Animation {
animations,
current_frame: 0,
current_animation: None,
timer: Timer::from_seconds(fps, false),
timer: Timer::from_seconds(fps, TimerMode::Once),
played_once: false,
}
}
Expand All @@ -132,7 +132,11 @@ impl Animation {
self.current_frame = 0;
self.timer.reset();
self.timer.unpause();
self.timer.set_repeating(repeating);
self.timer.set_mode(if repeating {
TimerMode::Repeating
} else {
TimerMode::Once
});
self.played_once = false;
}

Expand Down
17 changes: 17 additions & 0 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ impl AssetLoader for FighterLoader {
meta.spritesheet.tile_size.as_vec2(),
meta.spritesheet.columns,
meta.spritesheet.rows,
None,
None,
))
.with_dependency(texture_path),
);
Expand All @@ -331,6 +333,8 @@ impl AssetLoader for FighterLoader {
attachment.tile_size.as_vec2(),
attachment.columns,
attachment.rows,
None,
None,
))
.with_dependency(texture_path),
);
Expand Down Expand Up @@ -420,6 +424,8 @@ impl AssetLoader for ItemLoader {
spritesheet.tile_size.as_vec2(),
spritesheet.columns,
spritesheet.rows,
None,
None,
))
.with_dependency(texture_path),
);
Expand Down Expand Up @@ -447,6 +453,8 @@ impl AssetLoader for ItemLoader {
spritesheet.tile_size.as_vec2(),
spritesheet.columns,
spritesheet.rows,
None,
None,
))
.with_dependency(texture_path),
);
Expand Down Expand Up @@ -494,3 +502,12 @@ impl AssetLoader for EguiFontLoader {
&["ttf"]
}
}

#[derive(Debug, Clone, Resource, Deref, DerefMut)]
pub struct EguiFontDefinitions(pub egui::FontDefinitions);

impl EguiFontDefinitions {
pub fn get_fonts(&self) -> &egui::FontDefinitions {
&self.0
}
}
2 changes: 1 addition & 1 deletion src/attack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn attack_damage_system(
commands
.entity(hurtbox_parent_entity)
.insert(FlashingTimer {
timer: Timer::new(Duration::from_millis(100), true),
timer: Timer::new(Duration::from_millis(100), TimerMode::Repeating),
});

event_writer.send(DamageEvent {
Expand Down
8 changes: 5 additions & 3 deletions src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ use rand::{prelude::SliceRandom, thread_rng};

use bevy::{prelude::*, utils::HashMap};
use bevy_egui::{egui::output::OutputEvent, EguiContext};
use bevy_kira_audio::{AudioApp, AudioChannel, AudioSource};
use bevy_kira_audio::{AudioApp, AudioChannel, AudioControl, AudioSource};
use iyes_loopless::prelude::*;

use crate::{
animation::Animation,
config::ENGINE_CONFIG,
metadata::{GameMeta, LevelMeta},
metadata::{GameMeta, LevelHandle, LevelMeta},
GameState,
};

/// For readability.
const IMPOSSIBLE_ANIMATION_I: usize = usize::MAX;

#[derive(Resource)]
pub struct MusicChannel;

#[derive(Resource)]
pub struct EffectsChannel;

pub fn set_audio_channels_volume(
Expand Down Expand Up @@ -137,7 +139,7 @@ pub fn stop_menu_music(music_channel: Res<AudioChannel<MusicChannel>>) {
}

pub fn play_level_music(
level_handle: Res<Handle<LevelMeta>>,
level_handle: Res<LevelHandle>,
assets: Res<Assets<LevelMeta>>,
music_channel: Res<AudioChannel<MusicChannel>>,
) {
Expand Down
14 changes: 7 additions & 7 deletions src/collision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ impl BodyLayers {
// The layer is represented by 1 shifted 0 places to the left: 0b0001.
// The second layer is represented by 1 shifted one place to the left: 0b0010.
// And so on for the rest of the layers.
pub const ENEMY: u32 = 1 << 0;
pub const PLAYER: u32 = 1 << 1;
pub const PLAYER_ATTACK: u32 = 1 << 2;
pub const ENEMY_ATTACK: u32 = 1 << 3;
pub const BREAKABLE_ITEM: u32 = 1 << 4;
pub const ENEMY: Group = Group::GROUP_1;
pub const PLAYER: Group = Group::GROUP_2;
pub const PLAYER_ATTACK: Group = Group::GROUP_3;
pub const ENEMY_ATTACK: Group = Group::GROUP_4;
pub const BREAKABLE_ITEM: Group = Group::GROUP_5;
// u32::MAX is a u32 with all of it's bits set to 1, so this will contain all of the layers.
pub const ALL: u32 = u32::MAX;
pub const ALL: Group = Group::ALL;
}

#[derive(Bundle)]
Expand All @@ -32,7 +32,7 @@ pub struct PhysicsBundle {
}

impl PhysicsBundle {
pub fn new(meta: &ColliderMeta, body_layers: u32) -> Self {
pub fn new(meta: &ColliderMeta, body_layers: Group) -> Self {
PhysicsBundle {
collider: (Collider::cuboid(meta.size.x / 2., meta.size.y / 2.)),
sensor: Sensor,
Expand Down
20 changes: 11 additions & 9 deletions src/fighter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,22 @@ impl ActiveFighterBundle {
},
};
let hurtbox = commands
.spawn_bundle(PhysicsBundle::new(&fighter.hurtbox, body_layers))
.insert_bundle(TransformBundle::from_transform(Transform::from_xyz(
0.0,
fighter.collision_offset,
0.0,
)))
.insert(Hurtbox)
.spawn((
PhysicsBundle::new(&fighter.hurtbox, body_layers),
TransformBundle::from_transform(Transform::from_xyz(
0.0,
fighter.collision_offset,
0.0,
)),
Hurtbox,
))
.id();

let animated_spritesheet_bundle = active_fighter_bundle.animated_spritesheet_bundle.clone();

commands
.entity(entity)
.insert_bundle(active_fighter_bundle)
.insert(active_fighter_bundle)
.push_children(&[hurtbox]);

if let Some(attachment) = &fighter.attachment {
Expand All @@ -179,7 +181,7 @@ impl ActiveFighterBundle {
attachment_spritesheet.sprite_sheet.sprite.anchor = bevy::sprite::Anchor::Center;

let attachment_ent = commands
.spawn_bundle(attachment_spritesheet)
.spawn(attachment_spritesheet)
.insert(Attached {
position_face: false,
sync_animation: true,
Expand Down
Loading