Example cleanup (#6131)

Co-authored-by: devil-ira <justthecooldude@gmail.com>
This commit is contained in:
ira 2022-09-30 13:25:27 +00:00
parent 6929d95f7f
commit 3aaf746675
9 changed files with 14 additions and 12 deletions

View file

@ -275,8 +275,8 @@ impl Plugin for ColoredMesh2dPlugin {
);
// Register our custom draw function and pipeline, and add our render systems
let render_app = app.get_sub_app_mut(RenderApp).unwrap();
render_app
app.get_sub_app_mut(RenderApp)
.unwrap()
.add_render_command::<Transparent2d, DrawColoredMesh2d>()
.init_resource::<ColoredMesh2dPipeline>()
.init_resource::<SpecializedRenderPipelines<ColoredMesh2dPipeline>>()

View file

@ -16,7 +16,7 @@ fn grab_mouse(
mouse: Res<Input<MouseButton>>,
key: Res<Input<KeyCode>>,
) {
let window = windows.get_primary_mut().unwrap();
let window = windows.primary_mut();
if mouse.just_pressed(MouseButton::Left) {
window.set_cursor_visibility(false);
window.set_cursor_lock_mode(true);

View file

@ -13,7 +13,6 @@ use bevy::{
renderer::{RenderContext, RenderDevice},
RenderApp, RenderStage,
},
window::WindowDescriptor,
};
use std::borrow::Cow;

View file

@ -47,7 +47,7 @@ struct UiFont(Handle<Font>);
impl FromWorld for UiFont {
fn from_world(world: &mut World) -> Self {
let asset_server = world.get_resource::<AssetServer>().unwrap();
let asset_server = world.resource::<AssetServer>();
UiFont(asset_server.load("fonts/FiraSans-Bold.ttf"))
}
}

View file

@ -4,7 +4,7 @@
//! [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.WindowDescriptor.html#structfield.transparent)
//! for more details.
use bevy::{prelude::*, window::WindowDescriptor};
use bevy::prelude::*;
fn main() {
App::new()

View file

@ -65,7 +65,7 @@ fn toggle_resolution(
mut windows: ResMut<Windows>,
resolution: Res<ResolutionSettings>,
) {
let window = windows.get_primary_mut().unwrap();
let window = windows.primary_mut();
if keys.just_pressed(KeyCode::Key1) {
let res = resolution.small;
@ -87,7 +87,7 @@ fn on_resize_system(
mut q: Query<&mut Text, With<ResolutionText>>,
mut resize_reader: EventReader<WindowResized>,
) {
let mut text = q.get_single_mut().unwrap();
let mut text = q.single_mut();
for e in resize_reader.iter() {
// When resolution is being changed
text.sections[0].value = format!("{:.1} x {:.1}", e.width, e.height);

View file

@ -1,8 +1,11 @@
//! Illustrates how to change window settings and shows how to affect
//! the mouse pointer in various ways.
use bevy::{prelude::*, window::PresentMode};
use bevy_internal::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
window::PresentMode,
};
fn main() {
App::new()

View file

@ -19,7 +19,7 @@ fn main() {
fn minimise_automatically(mut windows: ResMut<Windows>, mut frames: Local<u32>) {
if *frames == 60 {
windows.get_primary_mut().unwrap().set_minimized(true);
windows.primary_mut().set_minimized(true);
} else {
*frames += 1;
}

View file

@ -98,7 +98,7 @@ fn change_window_size(
fn sync_dimensions(dim: Res<Dimensions>, mut windows: ResMut<Windows>) {
if dim.is_changed() {
windows.get_primary_mut().unwrap().set_resolution(
windows.primary_mut().set_resolution(
dim.width.try_into().unwrap(),
dim.height.try_into().unwrap(),
);