From f2c604e489bc93680485eb411296c149d759b170 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Tue, 30 Jul 2024 12:56:30 -0500 Subject: [PATCH] Resolve all warnings --- Cargo.lock | 24 ++++++++++++++++++++++++ Cargo.toml | 2 +- src/assets.rs | 20 +++++++++++++++++--- src/main.rs | 22 ++++++++++++++-------- src/movement.rs | 3 --- src/player.rs | 30 ++++++++---------------------- src/statue.rs | 47 +++++++++++++++++++++++------------------------ 7 files changed, 87 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53913cf..079d6ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -468,6 +468,7 @@ dependencies = [ "bevy_time", "bevy_utils", "const-fnv1a-hash", + "sysinfo", ] [[package]] @@ -2276,6 +2277,15 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "610a5acd306ec67f907abe5567859a3c693fb9886eb1f012ab8f2a47bef3db51" +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3122,6 +3132,20 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sysinfo" +version = "0.30.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a5b4ddaee55fb2bea2bf0e5000747e5f5c0de765e5a5ff87f4cd106439f4bb3" +dependencies = [ + "cfg-if", + "core-foundation-sys", + "libc", + "ntapi", + "once_cell", + "windows 0.52.0", +] + [[package]] name = "taffy" version = "0.5.2" diff --git a/Cargo.toml b/Cargo.toml index c4f1922..5c35bca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,13 +21,13 @@ bevy = { version = "0.14.0", default-features = false, features = [ "trace", # tracing is nice "wayland", "wav", # sound files + "sysinfo_plugin", # probably will want this for troubleshooting or just surfacing useful information to the gamer (such as FPS?) # TODO: would be nice to get this working while developing "dynamic_linking", # NOTE: Features we may want at some point. # "vorbis", # music -- maybe mp3? - # "sysinfo_plugin", # probably will want this for troubleshooting or just surfacing useful information to the gamer # "bevy_gizmos", # debug geometry? # "track_change_detection", # for hot-reloading of assets? (scripts?) # "file_watcher", # for hot-reloading of assets? (scripts?) diff --git a/src/assets.rs b/src/assets.rs index 8ce0690..323d9a4 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -2,17 +2,24 @@ use bevy::prelude::*; #[derive(Resource, Debug, Default)] pub struct AssetLoader { - pub images: Sprites, + pub layouts: Layouts, + pub images: Images, pub sounds: Sounds, pub fonts: Fonts, } #[derive(Resource, Debug, Default)] -pub struct Sprites { +pub struct Layouts { pub player: Handle, pub statue: Handle, } +#[derive(Resource, Debug, Default)] +pub struct Images { + pub player: Handle, + pub statue: Handle, +} + #[derive(Resource, Debug, Default)] pub struct Sounds { pub meow: Handle, @@ -28,6 +35,9 @@ pub fn startup( asset_server: Res, mut texture_atlases: ResMut>, ) { + let props = asset_server.load("img/Props.png"); + let player = asset_server.load("img/Player.png"); + let player_atlas = TextureAtlasLayout::from_grid( UVec2::new(32, 64), 3, @@ -42,7 +52,11 @@ pub fn startup( let statue_atlas_handle = texture_atlases.add(statue_atlas); *assets = AssetLoader { - images: Sprites { + images: Images { + player, + statue: props.clone(), + }, + layouts: Layouts { player: player_atlas_handle, statue: statue_atlas_handle, }, diff --git a/src/main.rs b/src/main.rs index 764f2c1..ae8b1f8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,9 +19,8 @@ pub enum Game { #[derive(States, Default, Debug, Clone, PartialEq, Eq, Hash)] pub enum View { - // #[default] - // LoadingScreen, #[default] + LoadingScreen, MainMenu, InGame, } @@ -32,7 +31,7 @@ struct MainMenuSet; #[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)] struct InGameSet; -fn main() { +fn main() -> AppExit { let mut app = App::new(); app.add_plugins(( @@ -55,17 +54,21 @@ fn main() { FrameTimeDiagnosticsPlugin, )) .init_resource::() - .insert_state(View::default()) - .insert_state(Game::default()) + .init_state::() + .init_state::() .add_systems(OnEnter(View::MainMenu), main_menu::startup) .add_systems(OnExit(View::MainMenu), main_menu::exit) .add_systems(OnEnter(View::InGame), (player::startup, statue::startup)) .add_systems(OnExit(View::InGame), (player::exit, statue::exit)) - .add_systems(Startup, (startup, assets::startup, camera::startup)) + .add_systems( + OnEnter(View::LoadingScreen), + (startup, assets::startup, camera::startup), + ) .add_systems( Update, ( update, + finish_setup.run_if(in_state(View::LoadingScreen)), ( player::sprite_select, player::controls, @@ -91,8 +94,7 @@ fn main() { // brightness: 1., // }); - let exit = app.run(); - info!("Exit: {:#?}", exit); + app.run() } fn toggle_fullscreen(mut window: Mut) { @@ -106,6 +108,10 @@ fn toggle_fullscreen(mut window: Mut) { #[derive(Component)] struct FpsText; +fn finish_setup(mut app_state: ResMut>) { + app_state.set(View::MainMenu); +} + fn startup(mut commands: Commands, assets: Res) { commands.spawn(( FpsText, diff --git a/src/movement.rs b/src/movement.rs index 9ef1ac4..4f7eff2 100644 --- a/src/movement.rs +++ b/src/movement.rs @@ -1,8 +1,5 @@ use bevy::prelude::*; -#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)] -struct SystemSet; - #[derive(Component, Deref, DerefMut, Debug, Default)] pub struct Velocity(pub Vec2); diff --git a/src/player.rs b/src/player.rs index 0535735..d6e8cbb 100644 --- a/src/player.rs +++ b/src/player.rs @@ -4,10 +4,10 @@ use bevy::{prelude::*, window::PrimaryWindow}; use crate::camera::Watched; use crate::movement::YSortable; +use crate::statue; use crate::{ assets::AssetLoader, movement::{Heading, Mover, Speed, Velocity}, - statue::Statue, }; const PLAYER_SPEED: f32 = 1000.; @@ -21,22 +21,21 @@ pub struct Crosshair; pub fn startup( mut commands: Commands, assets: Res, - asset_server: Res, mut meshes: ResMut>, mut materials: ResMut>, ) { - let texture = asset_server.load("img/Player.png"); let listener = SpatialListener::new(1.); commands .spawn((Player, YSortable, Watched)) .with_children(|player| { player.spawn(( - SpriteSheetBundle { - texture, - transform: Transform::from_scale(Vec3::new(2., 2., 1.)), - atlas: assets.images.player.clone().into(), - sprite: Sprite::default(), + SpriteBundle { + texture: assets.images.player.clone().into(), + ..default() + }, + TextureAtlas { + layout: assets.layouts.player.clone().into(), ..default() }, Mover { @@ -92,7 +91,6 @@ pub fn startup( pub fn controls( mut commands: Commands, mut player_q: Query<(&mut Sprite, &mut TextureAtlas, &mut Heading, Entity), With>, - asset_server: Res, input: Res>, mouse_input: Res>, assets: Res, @@ -130,19 +128,7 @@ pub fn controls( .map(|ray| ray.origin.truncate()) { let spos = world_position.extend(-world_position.y); - let statue_texture = asset_server.load("img/Props.png").clone(); - commands.spawn(( - Statue, - SpriteSheetBundle { - texture: statue_texture, - atlas: TextureAtlas { - layout: assets.images.statue.clone(), - index: 0, - }, - transform: Transform::from_translation(spos), - ..Default::default() - }, - )); + commands.spawn(statue::statue_at_position(&assets, spos)); } } _ => {} diff --git a/src/statue.rs b/src/statue.rs index b5f7982..64f38d0 100644 --- a/src/statue.rs +++ b/src/statue.rs @@ -4,34 +4,33 @@ use bevy::prelude::*; #[derive(Component, Debug)] pub struct Statue; -pub fn startup(mut commands: Commands, assets: Res, asset_server: Res) { - let texture = asset_server.load("img/Props.png"); - commands.spawn(( +pub fn statue_at_position( + assets: &Res, + translation: Vec3, +) -> ( + Statue, + YSortable, + bevy::prelude::SpriteBundle, + bevy::prelude::TextureAtlas, +) { + ( Statue, YSortable, - SpriteSheetBundle { - texture: texture.clone(), - atlas: TextureAtlas { - layout: assets.images.statue.clone(), - index: 0, - }, - transform: Transform::from_translation(Vec3::new(50., 50., 0.)), - ..Default::default() + SpriteBundle { + transform: Transform::from_translation(translation), + texture: assets.images.statue.clone(), + ..default() }, - )); - commands.spawn(( - Statue, - YSortable, - SpriteSheetBundle { - texture: texture.clone(), - atlas: TextureAtlas { - layout: assets.images.statue.clone(), - index: 0, - }, - transform: Transform::from_translation(Vec3::new(50., 100., 0.)), - ..Default::default() + TextureAtlas { + layout: assets.layouts.statue.clone(), + ..default() }, - )); + ) +} + +pub fn startup(mut commands: Commands, assets: Res) { + commands.spawn(statue_at_position(&assets, Vec3::new(50., 50., 0.))); + commands.spawn(statue_at_position(&assets, Vec3::new(50., 100., 0.))); } pub fn exit(mut commands: Commands, q: Query>) {