Skip to content

Commit

Permalink
Merge branch 'chore/update-to-bevy-0.13'
Browse files Browse the repository at this point in the history
  • Loading branch information
idanarye committed Feb 24, 2024
2 parents 3d81388 + 6bcdc17 commit c90e0ce
Show file tree
Hide file tree
Showing 18 changed files with 246 additions and 241 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## 0.18.0 - 2024-02-18
### Changed
- Upgrade bevy_egui to 0.24.
- [**BREAKING**] Changed some API types to use Bevy's new math types (instead
of vectors):
- `VpeolDragPlane` now uses `Plane3d`.
- `Vpeol3dPluginForEditor` also uses `Plane3d`.
- `Vpeol3dCameraControl` uses `Plane3d` for the camera drag plane, and
`Direction3d` for configuring the UP direction to maintain while rotating
the camera.


### Fixed
- [**BREAKING**] Typo - `Rotatation` -> `Rotation` in Vpeol.
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ exclude = [
[dependencies]
bevy-yoleck-macros = { version = "0.9.1", path = "macros" }
anyhow = "^1"
bevy = { version = "^0.12", default-features = false }
bevy_egui = { version = "^0.24", default-features = false, features = ["default_fonts"] }
bevy = { version = "^0.13", default-features = false }
bevy_egui = { version = "^0.25", default-features = false, features = ["default_fonts"] }
serde = "^1"
serde_json = "^1"
thiserror = "^1"
Expand All @@ -42,7 +42,8 @@ vpeol_3d = [
]

[dev-dependencies]
bevy = { version = "^0.12", default-features = false, features = ["bevy_sprite", "x11"] }
bevy = { version = "^0.13", default-features = false, features = ["bevy_sprite", "x11"] }
bevy_egui = { version = "^0.25", default-features = false, features = ["default_fonts", "render"] }

[[example]]
name = "example2d"
Expand Down
10 changes: 10 additions & 0 deletions MIGRATION-GUIDES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Migrating to Yoleck 0.19

## Using the new Bevy types

Bevy 0.13 introduces types for defining directions and planes, which can be used instead of vectors. Yoleck (mainly Vpeol) uses them now in its API. The conversion should be straightforward.

## `vpeol_read_click_on_entity`

Bevy 0.13 [split `WorldQuery` to `QueryData` and `FilterData`](https://bevyengine.org/learn/migration-guides/0-12-to-0-13/#split-worldquery-into-querydata-and-queryfilter) (though there is still a `WorldQuery` trait with some of that functionality). When you use `vpeol_read_click_on_entity`, the data passed to it is `QueryFilter`, not `QueryData` - which measn that if it's a component (which should usually be the case) you need `vpeol_read_click_on_entity::<Has<MyComponent>>` and not `vpeol_read_click_on_entity::<&MyComponent>` (which would have worked before)

# Migrating to Yoleck 0.17

## Loading levels
Expand Down
55 changes: 28 additions & 27 deletions examples/doors_to_other_levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,17 @@ struct Player {
fn populate_player(
mut populate: YoleckPopulate<(), With<IsPlayer>>,
asset_server: Res<AssetServer>,
mut texture_cache: Local<Option<Handle<Image>>>,
) {
populate.populate(|_ctx, mut cmd, ()| {
cmd.insert((SpriteBundle {
sprite: Sprite {
custom_size: Some(Vec2::new(100.0, 100.0)),
..Default::default()
},
texture: asset_server.load("sprites/player.png"),
texture: texture_cache
.get_or_insert_with(|| asset_server.load("sprites/player.png"))
.clone(),
..Default::default()
},));
});
Expand Down Expand Up @@ -154,19 +157,19 @@ fn control_camera(
fn control_player(
mut player_query: Query<&mut Transform, With<IsPlayer>>,
time: Res<Time>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
) {
let mut velocity = Vec3::ZERO;
if input.pressed(KeyCode::Up) {
if input.pressed(KeyCode::ArrowUp) {
velocity += Vec3::Y;
}
if input.pressed(KeyCode::Down) {
if input.pressed(KeyCode::ArrowDown) {
velocity -= Vec3::Y;
}
if input.pressed(KeyCode::Left) {
if input.pressed(KeyCode::ArrowLeft) {
velocity -= Vec3::X;
}
if input.pressed(KeyCode::Right) {
if input.pressed(KeyCode::ArrowRight) {
velocity += Vec3::X;
}
velocity *= 800.0;
Expand Down Expand Up @@ -284,44 +287,42 @@ fn edit_doorway_rotation(
fn populate_doorway(
mut populate: YoleckPopulate<(), With<Doorway>>,
asset_server: Res<AssetServer>,
mut asset_handle_cache: Local<Option<Handle<TextureAtlas>>>,
mut texture_atlas_assets: ResMut<Assets<TextureAtlas>>,
mut asset_handle_cache: Local<Option<(Handle<Image>, Handle<TextureAtlasLayout>)>>,
mut texture_atlas_layout_assets: ResMut<Assets<TextureAtlasLayout>>,
) {
populate.populate(|_ctx, mut cmd, ()| {
let texture_atlas = asset_handle_cache
let (texture, texture_atlas_layout) = asset_handle_cache
.get_or_insert_with(|| {
texture_atlas_assets.add(TextureAtlas::from_grid(
(
asset_server.load("sprites/doorway.png"),
Vec2::new(64.0, 64.0),
1,
2,
None,
None,
))
texture_atlas_layout_assets.add(TextureAtlasLayout::from_grid(
// asset_server.load("sprites/doorway.png"),
Vec2::new(64.0, 64.0),
1,
2,
None,
None,
)),
)
})
.clone();
cmd.insert(SpriteSheetBundle {
sprite: TextureAtlasSprite {
custom_size: Some(Vec2::new(100.0, 100.0)),
index: 0,
..Default::default()
},
texture_atlas,
..Default::default()
});
cmd.insert(SpriteBundle {
sprite: Sprite {
custom_size: Some(Vec2::new(100.0, 100.0)),
..Default::default()
},
texture: asset_server.load("sprites/doorway.png"),
atlas: TextureAtlas {
layout: texture_atlas_layout,
index: 0,
},
texture,
..Default::default()
});
});
}

fn set_doorways_sprite_index(
mut query: Query<(&mut TextureAtlasSprite, Has<DoorIsOpen>), With<Doorway>>,
mut query: Query<(&mut TextureAtlas, Has<DoorIsOpen>), With<Doorway>>,
) {
for (mut sprite, door_is_open) in query.iter_mut() {
sprite.index = if door_is_open { 1 } else { 0 };
Expand Down
85 changes: 48 additions & 37 deletions examples/example2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::Path;
use bevy::ecs::system::SystemState;
use bevy::prelude::*;
use bevy::render::mesh::Indices;
use bevy::render::render_asset::RenderAssetUsages;
use bevy::render::render_resource::PrimitiveTopology;
use bevy::sprite::Mesh2dHandle;
use bevy::utils::Uuid;
Expand Down Expand Up @@ -156,43 +157,40 @@ fn setup_camera(mut commands: Commands) {

#[derive(Resource)]
struct GameAssets {
fruits_sprite_sheet: Handle<TextureAtlas>,
fruits_sprite_sheet_texture: Handle<Image>,
fruits_sprite_sheet_layout: Handle<TextureAtlasLayout>,
fruits_sprite_sheet_egui: (egui::TextureId, Vec<egui::Rect>),
font: Handle<Font>,
}

impl FromWorld for GameAssets {
fn from_world(world: &mut World) -> Self {
let mut system_state =
SystemState::<(Res<AssetServer>, ResMut<Assets<TextureAtlas>>, EguiContexts)>::new(
world,
);
let (asset_server, mut texture_atlas_assets, mut egui_context) =
let mut system_state = SystemState::<(
Res<AssetServer>,
ResMut<Assets<TextureAtlasLayout>>,
EguiContexts,
)>::new(world);
let (asset_server, mut texture_atlas_layout_assets, mut egui_context) =
system_state.get_mut(world);
let fruits_atlas = TextureAtlas::from_grid(
asset_server.load("sprites/fruits.png"),
Vec2::new(64.0, 64.0),
3,
1,
None,
None,
);
let fruits_atlas_texture = asset_server.load("sprites/fruits.png");
let fruits_atlas_layout =
TextureAtlasLayout::from_grid(Vec2::new(64.0, 64.0), 3, 1, None, None);
let fruits_egui = {
(
egui_context.add_image(fruits_atlas.texture.clone()),
fruits_atlas
egui_context.add_image(fruits_atlas_texture.clone()),
fruits_atlas_layout
.textures
.iter()
.map(|rect| {
[
[
rect.min.x / fruits_atlas.size.x,
rect.min.y / fruits_atlas.size.y,
rect.min.x / fruits_atlas_layout.size.x,
rect.min.y / fruits_atlas_layout.size.y,
]
.into(),
[
rect.max.x / fruits_atlas.size.x,
rect.max.y / fruits_atlas.size.y,
rect.max.x / fruits_atlas_layout.size.x,
rect.max.y / fruits_atlas_layout.size.y,
]
.into(),
]
Expand All @@ -202,7 +200,8 @@ impl FromWorld for GameAssets {
)
};
Self {
fruits_sprite_sheet: texture_atlas_assets.add(fruits_atlas),
fruits_sprite_sheet_texture: fruits_atlas_texture,
fruits_sprite_sheet_layout: texture_atlas_layout_assets.add(fruits_atlas_layout),
fruits_sprite_sheet_egui: fruits_egui,
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
}
Expand All @@ -223,14 +222,17 @@ struct Player {
fn populate_player(
mut populate: YoleckPopulate<(), With<IsPlayer>>,
asset_server: Res<AssetServer>,
mut texture_cache: Local<Option<Handle<Image>>>,
) {
populate.populate(|_ctx, mut cmd, ()| {
cmd.insert((SpriteBundle {
sprite: Sprite {
custom_size: Some(Vec2::new(100.0, 100.0)),
..Default::default()
},
texture: asset_server.load("sprites/player.png"),
texture: texture_cache
.get_or_insert_with(|| asset_server.load("sprites/player.png"))
.clone(),
..Default::default()
},));
});
Expand Down Expand Up @@ -267,19 +269,19 @@ fn edit_player(
fn control_player(
mut player_query: Query<&mut Transform, With<IsPlayer>>,
time: Res<Time>,
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
) {
let mut velocity = Vec3::ZERO;
if input.pressed(KeyCode::Up) {
if input.pressed(KeyCode::ArrowUp) {
velocity += Vec3::Y;
}
if input.pressed(KeyCode::Down) {
if input.pressed(KeyCode::ArrowDown) {
velocity -= Vec3::Y;
}
if input.pressed(KeyCode::Left) {
if input.pressed(KeyCode::ArrowLeft) {
velocity -= Vec3::X;
}
if input.pressed(KeyCode::Right) {
if input.pressed(KeyCode::ArrowRight) {
velocity += Vec3::X;
}
velocity *= 400.0;
Expand Down Expand Up @@ -343,12 +345,15 @@ fn edit_fruit_type(
let knob_position =
(*position + Vec2::new(-30.0 + index as f32 * 30.0, 50.0)).extend(1.0);
knob.cmd.insert(SpriteSheetBundle {
sprite: TextureAtlasSprite {
index,
sprite: Sprite {
custom_size: Some(Vec2::new(20.0, 20.0)),
..Default::default()
},
texture_atlas: assets.fruits_sprite_sheet.clone(),
atlas: TextureAtlas {
layout: assets.fruits_sprite_sheet_layout.clone(),
index,
},
texture: assets.fruits_sprite_sheet_texture.clone(),
transform: Transform::from_translation(knob_position),
global_transform: Transform::from_translation(knob_position).into(),
..Default::default()
Expand Down Expand Up @@ -408,12 +413,15 @@ fn populate_fruit(
cmd.with_children(|commands| {
let mut child = commands.spawn(marking.marker());
child.insert(SpriteSheetBundle {
sprite: TextureAtlasSprite {
index: fruit.index,
sprite: Sprite {
custom_size: Some(Vec2::new(100.0, 100.0)),
..Default::default()
},
texture_atlas: assets.fruits_sprite_sheet.clone(),
atlas: TextureAtlas {
layout: assets.fruits_sprite_sheet_layout.clone(),
index: fruit.index,
},
texture: assets.fruits_sprite_sheet_texture.clone(),
..Default::default()
});
});
Expand Down Expand Up @@ -540,11 +548,14 @@ fn populate_triangle(
.get_mut(mesh_handle)
.expect("mesh inserted by previous invocation of this system")
} else {
let mesh_handle = mesh_assets.add(Mesh::new(PrimitiveTopology::TriangleList));
let mesh_handle = mesh_assets.add(Mesh::new(
PrimitiveTopology::TriangleList,
RenderAssetUsages::default(),
));
let mesh = mesh_assets.get_mut(&mesh_handle);
cmd.insert(ColorMesh2dBundle {
mesh: Mesh2dHandle(mesh_handle),
material: material_assets.add(Color::GREEN.into()),
material: material_assets.add(Color::GREEN),
..Default::default()
});
mesh.expect("mesh was just inserted")
Expand All @@ -562,7 +573,7 @@ fn populate_triangle(
let i = i as u32;
indices.extend([0, i, i + 1]);
}
mesh.set_indices(Some(Indices::U32(indices)));
mesh.insert_indices(Indices::U32(indices));
});
}

Expand Down Expand Up @@ -590,7 +601,7 @@ fn edit_laser_pointer(
};
if button.clicked() {
exclusive_queue.push_back(
vpeol_read_click_on_entity::<&YoleckEntityUuid>
vpeol_read_click_on_entity::<With<YoleckEntityUuid>>
.pipe(yoleck_map_entity_to_uuid)
.pipe(
|In(target): In<Option<Uuid>>, mut edit: YoleckEdit<&mut LaserPointer>| {
Expand Down
Loading

0 comments on commit c90e0ce

Please sign in to comment.