Skip to content

Commit

Permalink
chore: Update Bevy to 0.13 (#83)
Browse files Browse the repository at this point in the history
* Update to Bevy 0.13
  • Loading branch information
Zac8668 authored Feb 27, 2024
1 parent 66c9ff6 commit bd94d14
Show file tree
Hide file tree
Showing 8 changed files with 823 additions and 675 deletions.
1,418 changes: 782 additions & 636 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ license = "PolyForm NonCommercial v1.0"
default-run = "astratomic"

[dependencies]
bevy = {version = "0.12", features =["file_watcher"]}
bevy-inspector-egui = "0.22"
bevy = {version = "0.13", features =["file_watcher"]}
bevy-inspector-egui = "0.23"
rand = { version = "0.8", features = ["small_rng"] }
fastrand = "2.0"
async-channel = "2.1"
Expand All @@ -20,20 +20,20 @@ serde_derive = "1.0"
bincode = "1.3"
serde-big-array = "0.5"
ron = "0.8"
bevy-async-task = "1.3"
bevy-async-task = "1.4"

contour = "0.12"
bevy_rapier2d = { version = "0.23", features = [ "simd-stable", "debug-render-2d", "parallel" ] }
geo = "0.27"
bevy_rapier2d = { version = "0.25", features = [ "simd-stable", "debug-render-2d", "parallel" ] }
geo = "0.28"
rotsprite = "0.1"

egui = "0.24"
bevy_egui = "0.24"
egui = "0.25"
bevy_egui = "0.25"
puffin = "0.18"
puffin_egui = "0.24"
puffin_egui = "0.26"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
bevy_dylib = "0.12.1"
bevy_dylib = "0.13"

# Optimize dependencies even in development
[profile.dev.package."*"]
Expand Down
6 changes: 1 addition & 5 deletions src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ pub struct AnimationTimer(pub Timer);

fn animate_sprite(
time: Res<Time>,
mut query: Query<(
&AnimationIndices,
&mut AnimationTimer,
&mut TextureAtlasSprite,
)>,
mut query: Query<(&AnimationIndices, &mut AnimationTimer, &mut TextureAtlas)>,
) {
for (indices, mut timer, mut sprite) in &mut query {
timer.tick(time.delta());
Expand Down
3 changes: 2 additions & 1 deletion src/chunk.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::render::render_resource::*;
use bevy::render::{render_asset::RenderAssetUsages, render_resource::*};
use std::collections::HashSet;

use crate::{prelude::*, rigidbody};
Expand Down Expand Up @@ -69,6 +69,7 @@ impl Chunk {
TextureDimension::D2,
vec![0; CHUNK_LENGHT.pow(2) * 4],
TextureFormat::Rgba8UnormSrgb,
RenderAssetUsages::RENDER_WORLD,
)
}

Expand Down
14 changes: 7 additions & 7 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn brush(
mut chunk_manager: ResMut<ChunkManager>,
mut dirty_rects: ResMut<DirtyRects>,
prev_mpos: Res<PreviousMousePos>,
input: (Res<Input<MouseButton>>, Res<Input<KeyCode>>),
input: (Res<ButtonInput<MouseButton>>, Res<ButtonInput<KeyCode>>),
) {
let atom;
if input.0.pressed(MouseButton::Middle) {
Expand Down Expand Up @@ -174,9 +174,9 @@ fn render_actors(mut gizmos: Gizmos, actors: Query<&Actor>) {
}
}

fn _camera(keys: Res<Input<KeyCode>>, mut camera_q: Query<&mut Transform, With<Camera>>) {
let x = -(keys.pressed(KeyCode::A) as u8 as f32) + keys.pressed(KeyCode::D) as u8 as f32;
let y = -(keys.pressed(KeyCode::S) as u8 as f32) + keys.pressed(KeyCode::W) as u8 as f32;
fn _camera(keys: Res<ButtonInput<KeyCode>>, mut camera_q: Query<&mut Transform, With<Camera>>) {
let x = -(keys.pressed(KeyCode::KeyA) as u8 as f32) + keys.pressed(KeyCode::KeyD) as u8 as f32;
let y = -(keys.pressed(KeyCode::KeyS) as u8 as f32) + keys.pressed(KeyCode::KeyW) as u8 as f32;

let v = Vec2::new(x, y).normalize_or_zero().extend(0.);
camera_q.single_mut().translation += v * _CAMERA_SPEED;
Expand All @@ -186,7 +186,7 @@ pub trait Rect2dGradient {
fn rect_2d_gradient(&mut self, position: Vec2, rotation: f32, size: Vec2);
}

impl<'a> Rect2dGradient for Gizmos<'a> {
impl<'a, 'b> Rect2dGradient for Gizmos<'a, 'b> {
fn rect_2d_gradient(&mut self, position: Vec2, rotation: f32, size: Vec2) {
let rotation = Mat2::from_angle(rotation);
let [tl, tr, br, bl] = rect_inner(size).map(|vec2| position + rotation * vec2);
Expand Down Expand Up @@ -216,12 +216,12 @@ pub fn grab_rigidbodies(
window: Query<&Window>,
camera_q: Query<(&Camera, &GlobalTransform)>,
mut grabbed: ResMut<Grabbed>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
) {
let (camera, camera_transform) = camera_q.single();
let window = window.single();

if input.pressed(KeyCode::R) {
if input.pressed(KeyCode::KeyR) {
if let Some(world_position) = window
.cursor_position()
.and_then(|cursor| camera.viewport_to_world(camera_transform, cursor))
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn main() {

let mut app = App::new();

app.add_state::<GameState>()
app.init_state::<GameState>()
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
//local plugins
.add_plugins((
Expand Down
4 changes: 3 additions & 1 deletion src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ fn button_system(

match *button_type {
ButtonType::Start => next_state.set(GameState::Game),
ButtonType::Quit => exit.send(AppExit),
ButtonType::Quit => {
exit.send(AppExit);
}
}
}
Interaction::Hovered => {
Expand Down
33 changes: 18 additions & 15 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct ToolFront;
pub fn player_setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
mut texture_atlases: ResMut<Assets<TextureAtlasLayout>>,
) {
let pos: IVec2;
if let Ok(file) = File::open("assets/world/player") {
Expand All @@ -66,10 +66,13 @@ pub fn player_setup(
};

let player_handle = asset_server.load("player/player_sheet.png");
let player_atlas =
TextureAtlas::from_grid(player_handle, Vec2::new(24.0, 24.0), 8, 5, None, None);
let player_atlas_handle = texture_atlases.add(player_atlas);
let animation_indices = AnimationIndices { first: 0, last: 1 };
let player_atlas_layout =
TextureAtlasLayout::from_grid(Vec2::new(24.0, 24.0), 8, 5, None, None);
let atlas = TextureAtlas {
index: animation_indices.first,
layout: texture_atlases.add(player_atlas_layout),
};
let player_transform = GlobalTransform::from_xyz(5. * 3., -8. * 3., PLAYER_LAYER);

let tool_handle = asset_server.load("player/player_tool.png");
Expand Down Expand Up @@ -99,9 +102,9 @@ pub fn player_setup(
player_actor.clone(),
Player::default(),
SpriteSheetBundle {
texture_atlas: player_atlas_handle,
sprite: TextureAtlasSprite::new(animation_indices.first),
atlas,
global_transform: player_transform,
texture: player_handle,
..default()
},
animation_indices,
Expand Down Expand Up @@ -233,7 +236,7 @@ pub fn tool_system(
mut tool: Query<(&mut Transform, &GlobalTransform, &mut Sprite), With<Tool>>,
mut camera: Query<(&Camera, &GlobalTransform), Without<Tool>>,
tool_front_ent: Query<Entity, With<ToolFront>>,
querys: (Query<&Window>, Query<(&mut TextureAtlasSprite, &Player)>),
querys: (Query<&Window>, Query<(&mut Sprite, &Player), Without<Tool>>),
resources: (ResMut<ChunkManager>, ResMut<DirtyRects>, Res<Inputs>),
materials: (Res<Assets<Materials>>, Res<MaterialsHandle>),
) {
Expand Down Expand Up @@ -366,8 +369,8 @@ pub fn update_player_sprite(mut query: Query<(&mut Transform, &Actor), With<Play
pub struct SavingTask(pub Option<Task<()>>);

pub fn get_input(
keys: Res<Input<KeyCode>>,
mouse_buttons: Res<Input<MouseButton>>,
keys: Res<ButtonInput<KeyCode>>,
mouse_buttons: Res<ButtonInput<MouseButton>>,
mut inputs: ResMut<Inputs>,
) {
//Jump
Expand All @@ -379,10 +382,10 @@ pub fn get_input(
}

//Movement
if keys.pressed(KeyCode::A) {
if keys.pressed(KeyCode::KeyA) {
inputs.left = 1.;
}
if keys.pressed(KeyCode::D) {
if keys.pressed(KeyCode::KeyD) {
inputs.right = 1.;
}

Expand All @@ -395,13 +398,13 @@ pub fn get_input(
}

//Numbers, to select atoms
if keys.just_pressed(KeyCode::Key1) {
if keys.just_pressed(KeyCode::Digit1) {
inputs.numbers[0] = true;
} else if keys.just_pressed(KeyCode::Key2) {
} else if keys.just_pressed(KeyCode::Digit2) {
inputs.numbers[1] = true;
} else if keys.just_pressed(KeyCode::Key3) {
} else if keys.just_pressed(KeyCode::Digit3) {
inputs.numbers[2] = true;
} else if keys.just_pressed(KeyCode::Key4) {
} else if keys.just_pressed(KeyCode::Digit4) {
inputs.numbers[3] = true;
}
}
Expand Down

0 comments on commit bd94d14

Please sign in to comment.