Skip to content

Commit

Permalink
Cargo fmt and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
villuna committed Feb 11, 2024
1 parent 090159f commit 1de1064
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 39 deletions.
32 changes: 17 additions & 15 deletions src/app/main_menu.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
app::{GameState, TextureCache, StateTransition, Context, RenderContext, ui_elements::Button},
app::{ui_elements::Button, Context, GameState, RenderContext, StateTransition, TextureCache},
render::{
shapes::{LinearGradient, Shape, ShapeBuilder, SolidColour},
text::Text,
Expand Down Expand Up @@ -43,39 +43,41 @@ impl MainMenu {

let title = Text::new(
renderer,
&Section::new().add_text(
glyph_brush::Text::new("Unnamed Taiko\nSimulator!")
.with_color([141. / 255., 64. / 255., 255. / 255., 1.])
.with_font_id(*renderer.font("MPLUSRounded1c-Bold.ttf").unwrap())
.with_scale(70.0)
).with_screen_position((100., 95.))
&Section::new()
.add_text(
glyph_brush::Text::new("Unnamed Taiko\nSimulator!")
.with_color([141. / 255., 64. / 255., 1., 1.])
.with_font_id(*renderer.font("MPLUSRounded1c-Bold.ttf").unwrap())
.with_scale(70.0),
)
.with_screen_position((100., 95.)),
)?;

let taiko_mode_button = Button::new(
"Taiko Mode",
[100., 290.],
[290., 65.],
SolidColour::new([120./255., 29./255., 29./255., 1.]),
SolidColour::new([120. / 255., 29. / 255., 29. / 255., 1.]),
40.,
renderer
renderer,
)?;

let settings_button = Button::new(
"Settings",
[100., 370.],
[290., 65.],
SolidColour::new([43./255., 111./255., 27./255., 1.]),
SolidColour::new([43. / 255., 111. / 255., 27. / 255., 1.]),
40.,
renderer
renderer,
)?;

let exit_button = Button::new(
"Exit",
[100., 930.],
[150., 50.],
SolidColour::new([72./255., 72./255., 72./255., 1.]),
SolidColour::new([72. / 255., 72. / 255., 72. / 255., 1.]),
30.,
renderer
renderer,
)?;

Ok(MainMenu {
Expand All @@ -96,7 +98,7 @@ impl MainMenu {
}

impl GameState for MainMenu {
fn render<'app, 'pass>(&'pass mut self, ctx: &mut RenderContext<'app, 'pass>) {
fn render<'pass>(&'pass mut self, ctx: &mut RenderContext<'_, 'pass>) {
ctx.render(&self.background);
ctx.render(&self.gradient);
ctx.render(&self.menu_frame);
Expand All @@ -113,7 +115,7 @@ impl GameState for MainMenu {

if self.taiko_mode_button.is_clicked(ctx) {
StateTransition::Push(Box::new(
SongSelect::new(ctx.textures, ctx.renderer).unwrap()
SongSelect::new(ctx.textures, ctx.renderer).unwrap(),
))
} else if self.exit_button.is_clicked(ctx) {
StateTransition::Exit
Expand Down
14 changes: 8 additions & 6 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub trait GameState {
// TODO: Fix this up.
fn debug_ui(&mut self, _ctx: egui::Context, _audio: &mut AudioManager) {}

fn render<'app, 'pass>(&'pass mut self, _ctx: &mut RenderContext<'app, 'pass>) {}
fn render<'pass>(&'pass mut self, _ctx: &mut RenderContext<'_, 'pass>) {}

fn handle_event(&mut self, _ctx: &mut Context, _event: &WindowEvent<'_>) {}
}
Expand Down Expand Up @@ -109,16 +109,16 @@ pub struct MouseState {

impl MouseState {
fn handle_input(&mut self, event: &WindowEvent<'_>) {
match event {
&WindowEvent::CursorMoved { position, .. } => {
match *event {
WindowEvent::CursorMoved { position, .. } => {
self.position = Some((position.x as f32, position.y as f32));
}

&WindowEvent::CursorLeft { .. } => {
WindowEvent::CursorLeft { .. } => {
self.position = None;
}

&WindowEvent::MouseInput { state, button, .. } => {
WindowEvent::MouseInput { state, button, .. } => {
let pressed = state == ElementState::Pressed;

self.button_map.entry(button).or_insert((false, false)).1 = pressed;
Expand All @@ -130,7 +130,9 @@ impl MouseState {

/// Returns whether or not the given button is pressed this frame.
pub fn is_pressed(&self, button: MouseButton) -> bool {
self.button_map.get(&button).is_some_and(|&(_, pressed)| pressed)
self.button_map
.get(&button)
.is_some_and(|&(_, pressed)| pressed)
}

/// Returns whether or not the given button was just pressed this frame (i.e: pressed this frame
Expand Down
5 changes: 1 addition & 4 deletions src/app/song_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ fn read_song_dir<P: AsRef<Path>>(path: P) -> anyhow::Result<Song> {
}

impl SongSelect {
pub fn new(
textures: &mut TextureCache,
renderer: &Renderer,
) -> anyhow::Result<Self> {
pub fn new(textures: &mut TextureCache, renderer: &Renderer) -> anyhow::Result<Self> {
let test_tracks = read_song_list_dir(SONGS_DIR)?;
let bg_sprite = Sprite::new(
textures.get(&renderer.device, &renderer.queue, "song_select_bg.jpg")?,
Expand Down
4 changes: 2 additions & 2 deletions src/app/taiko_mode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ use winit::event::{ElementState, WindowEvent};

use crate::{
app::{self, GameState, RenderContext, StateTransition, TextureCache},
beatmap_parser::track::{NoteTrack, NoteType, Song},
render::{
self,
shapes::{LinearGradient, Shape, ShapeBuilder, SolidColour},
text::Text,
texture::Sprite,
},
beatmap_parser::track::{NoteTrack, NoteType, Song},
settings::SETTINGS,
};

Expand Down Expand Up @@ -545,7 +545,7 @@ impl GameState for TaikoMode {
let mut current = self.current_time();
let settings = SETTINGS.read().unwrap();
let offset = settings.game.global_note_offset / 1000.0;
current = current - offset;
current -= offset;

if let &WindowEvent::KeyboardInput {
input,
Expand Down
13 changes: 7 additions & 6 deletions src/app/ui_elements/button.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use lyon::tessellation::FillVertexConstructor;
use crate::app::Context;
use crate::render::context::Renderable;
use crate::render::shapes::{Shape, ShapeBuilder, ShapeVertex, SolidColour};
use crate::render::text::Text;
use crate::render::{RenderPassContext, Renderer};
use crate::app::Context;
use lyon::tessellation::FillVertexConstructor;
use wgpu_text::glyph_brush;
use wgpu_text::glyph_brush::{HorizontalAlign, Layout, Section, VerticalAlign};
use winit::event::MouseButton;
Expand Down Expand Up @@ -60,7 +60,7 @@ impl Button {

let outline = ShapeBuilder::new()
.position([pos[0], pos[1], 0.])
.stroke_roundrect([0., 0.], size, 12., SolidColour::new([220./255.; 4]), 3.)?
.stroke_roundrect([0., 0.], size, 12., SolidColour::new([220. / 255.; 4]), 3.)?
.build(&renderer.device);

let shadow = ShapeBuilder::new()
Expand All @@ -87,8 +87,10 @@ impl Button {

pub fn update(&mut self, ctx: &mut Context) {
self.mouse_entered = ctx.mouse.cursor_pos().is_some_and(|(x, y)| {
x >= self.pos[0] && x <= self.pos[0] + self.size[0] &&
y >= self.pos[1] && y <= self.pos[1] + self.size[1]
x >= self.pos[0]
&& x <= self.pos[0] + self.size[0]
&& y >= self.pos[1]
&& y <= self.pos[1] + self.size[1]
});
}

Expand All @@ -109,4 +111,3 @@ impl Renderable for Button {
}
}
}

2 changes: 1 addition & 1 deletion src/beatmap_parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ mod tja_parser;
pub mod track;

pub use tja_parser::*;
pub use track::*;
pub use track::*;
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod app;
pub mod beatmap_parser;
pub mod settings;
pub mod render;
pub mod settings;
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::time::Instant;

use taiko::{app::{MainMenu, App}, render::Renderer};
use taiko::{
app::{App, MainMenu},
render::Renderer,
};

use taiko::settings::{self, ResolutionState, SETTINGS};

Expand Down
2 changes: 1 addition & 1 deletion src/render/egui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Egui {
pub fn render<'a>(
&'a self,
render_pass: &mut wgpu::RenderPass<'a>,
paint_jobs: &'a Vec<egui::ClippedPrimitive>,
paint_jobs: &'a [egui::ClippedPrimitive],
screen_descriptor: &ScreenDescriptor,
) {
self.renderer
Expand Down
4 changes: 3 additions & 1 deletion src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ impl Renderer {
.ok()
.and_then(|f| f.file_name().into_string().ok())
.filter(|f| f.ends_with(".ttf"))
else { continue; };
else {
continue;
};

let id = text_brush.add_font(FontArc::try_from_vec(std::fs::read(format!(
"assets/fonts/{}",
Expand Down
6 changes: 6 additions & 0 deletions src/render/shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ impl ShapeBuilder {
}
}

impl Default for ShapeBuilder {
fn default() -> Self {
Self::new()
}
}

impl Shape {
/// Moves the whole shape to the given position.
pub fn set_position(&self, position: [f32; 3], queue: &wgpu::Queue) {
Expand Down
2 changes: 1 addition & 1 deletion src/render/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Text {
});

render_pass.set_pipeline(renderer.pipeline("outline").unwrap());
render_pass.set_bind_group(0, &renderer.screen_bind_group(), &[]);
render_pass.set_bind_group(0, renderer.screen_bind_group(), &[]);
render_pass.set_bind_group(1, &texture.bind_group, &[]);
render_pass.set_vertex_buffer(0, texture.vertex_buffer.slice(..));
render_pass.set_index_buffer(texture.index_buffer.slice(..), wgpu::IndexFormat::Uint16);
Expand Down

0 comments on commit 1de1064

Please sign in to comment.