From c48f91ee4ef66fbecbcfd08a803a745b1f5c323b Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Wed, 24 May 2023 17:47:32 +0300 Subject: [PATCH] chore(client): fmt, clippy --- client/src/game_status/parser.rs | 71 +++++++++++++--------- client/src/main.rs | 10 ++- client/src/plugins/game/ui/mod.rs | 2 +- client/src/plugins/game/ui/state_button.rs | 5 +- client/src/util/mod.rs | 21 ++++--- 5 files changed, 67 insertions(+), 42 deletions(-) diff --git a/client/src/game_status/parser.rs b/client/src/game_status/parser.rs index 4496cfe..df67f48 100644 --- a/client/src/game_status/parser.rs +++ b/client/src/game_status/parser.rs @@ -16,7 +16,7 @@ use crate::{ util::action_to_log, }; -use super::{GameStatus, PlayerState, PlayerStatus, LogSection, LogEntry}; +use super::{GameStatus, LogEntry, LogSection, PlayerState, PlayerStatus}; /// funny unsafe wrapper fn get_invoker_target_next<'a>( @@ -36,8 +36,7 @@ fn get_invoker_target_next<'a>( let invoker_ref: *mut PlayerStatus = players.get_mut(invoker).unwrap() as *mut _; let target_ref: *mut PlayerStatus = players.get_mut(target).unwrap() as *mut _; - let next_turn_n: usize = if ((*invoker_ref).turn_n + 1) > (players.len() - 1) - { + let next_turn_n: usize = if ((*invoker_ref).turn_n + 1) > (players.len() - 1) { 0 } else { (*invoker_ref).turn_n + 1 @@ -262,19 +261,23 @@ fn parse_action(action: &Action, game: &Game, game_status: &mut GameStatus) { } if *amount == 1 { - game_status.log.push(LogEntry::from_sections([ - LogSection::bold(&results.first().unwrap().to_string()), - ])); + game_status + .log + .push(LogEntry::from_sections([LogSection::bold( + &results.first().unwrap().to_string(), + )])); } else { - game_status.log.push(LogEntry::from_sections([ - LogSection::bold( - &format!( - " {} = {}", - results.iter().map(ToString::to_string).collect::>().join(" "), - results.iter().sum::(), - ) - ), - ])); + game_status + .log + .push(LogEntry::from_sections([LogSection::bold(&format!( + " {} = {}", + results + .iter() + .map(ToString::to_string) + .collect::>() + .join(" "), + results.iter().sum::(), + ))])); } } Command::GivePlays { amount } => { @@ -290,19 +293,23 @@ fn parse_action(action: &Action, game: &Game, game_status: &mut GameStatus) { } if *amount == 1 { - game_status.log.push(LogEntry::from_sections([ - LogSection::bold(&results.first().unwrap().to_string()), - ])); + game_status + .log + .push(LogEntry::from_sections([LogSection::bold( + &results.first().unwrap().to_string(), + )])); } else { - game_status.log.push(LogEntry::from_sections([ - LogSection::bold( - &format!( - " {} = {}", - results.iter().map(ToString::to_string).collect::>().join(" "), - results.iter().sum::(), - ) - ), - ])); + game_status + .log + .push(LogEntry::from_sections([LogSection::bold(&format!( + " {} = {}", + results + .iter() + .map(ToString::to_string) + .collect::>() + .join(" "), + results.iter().sum::(), + ))])); } } Command::GiveBuys { amount } => { @@ -312,7 +319,7 @@ fn parse_action(action: &Action, game: &Game, game_status: &mut GameStatus) { target.vp += amount; } Command::MarkCardInDeckToBeTrashed { index } => { - if target.deck.len() == 0 { + if target.deck.is_empty() { return; } match index { @@ -321,7 +328,13 @@ fn parse_action(action: &Action, game: &Game, game_status: &mut GameStatus) { } None => { let deck_len = target.deck.len(); - target.deck.get_mut(Rng::with_seed(action.seed.parse::().unwrap()).usize(0..deck_len)).unwrap().to_be_trashed = true; + target + .deck + .get_mut( + Rng::with_seed(action.seed.parse::().unwrap()).usize(0..deck_len), + ) + .unwrap() + .to_be_trashed = true; } } } diff --git a/client/src/main.rs b/client/src/main.rs index 71b5896..83bc017 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -130,7 +130,9 @@ fn setup( asset_server: Res, mut lcm_ev_w: EventWriter, ) { - commands.insert_resource(CardManifestHandle { handle: asset_server.load("card_manifest.yaml") }); + commands.insert_resource(CardManifestHandle { + handle: asset_server.load("card_manifest.yaml"), + }); lcm_ev_w.send(LoadCardManifestEvent); commands @@ -155,7 +157,11 @@ fn load_card_manifest( yaml_assets: Res>, card_manifest_handle: Res, ) { - let card_manifest_yaml: String = yaml_assets.get(&card_manifest_handle.handle).unwrap().0.clone(); + let card_manifest_yaml: String = yaml_assets + .get(&card_manifest_handle.handle) + .unwrap() + .0 + .clone(); let card_manifest: CardManifest = serde_yaml::from_str(&card_manifest_yaml).unwrap(); commands.insert_resource(card_manifest); } diff --git a/client/src/plugins/game/ui/mod.rs b/client/src/plugins/game/ui/mod.rs index 11826dd..2078ff9 100644 --- a/client/src/plugins/game/ui/mod.rs +++ b/client/src/plugins/game/ui/mod.rs @@ -13,7 +13,7 @@ use crate::{ api::game::{Action, Command, Game}, game_status::PlayerState, plugins::GameActionCreateCallEvent, - AppState, Global, CardManifest, + AppState, CardManifest, Global, }; use super::{GameData, RefreshGameEvent}; diff --git a/client/src/plugins/game/ui/state_button.rs b/client/src/plugins/game/ui/state_button.rs index 7b3cee0..2ade822 100644 --- a/client/src/plugins/game/ui/state_button.rs +++ b/client/src/plugins/game/ui/state_button.rs @@ -12,7 +12,8 @@ use crate::{ api::game::{Action, Command}, game_status::PlayerState, plugins::{GameActionCreateCallEvent, GameData}, - AppState, Global, util::get_next_player, + util::get_next_player, + AppState, Global, }; pub struct StateButtonPlugin; @@ -168,7 +169,7 @@ fn interact_state_button( action: Action::new( &game.id, &user.id, - &next_player.0, + next_player.0, &Command::EndTurn {}, None, ), diff --git a/client/src/util/mod.rs b/client/src/util/mod.rs index 4aede69..489c91f 100644 --- a/client/src/util/mod.rs +++ b/client/src/util/mod.rs @@ -6,7 +6,10 @@ * See LICENSE for licensing information. */ -use bevy::{asset::{AssetLoader, LoadedAsset}, reflect::TypeUuid}; +use bevy::{ + asset::{AssetLoader, LoadedAsset}, + reflect::TypeUuid, +}; pub mod egui; @@ -15,9 +18,11 @@ pub use action_to_log::action_to_log; use crate::game_status::{GameStatus, PlayerStatus}; -pub fn get_next_player<'a>(player: &'a PlayerStatus, game_status: &'a GameStatus) -> (&'a String, &'a PlayerStatus) { - let next_turn_n: usize = if (player.turn_n + 1) > (game_status.players.len() - 1) - { +pub fn get_next_player<'a>( + player: &'a PlayerStatus, + game_status: &'a GameStatus, +) -> (&'a String, &'a PlayerStatus) { + let next_turn_n: usize = if (player.turn_n + 1) > (game_status.players.len() - 1) { 0 } else { player.turn_n + 1 @@ -39,10 +44,10 @@ pub struct YamlLoader; impl AssetLoader for YamlLoader { fn load<'a>( - &'a self, - bytes: &'a [u8], - load_context: &'a mut bevy::asset::LoadContext, - ) -> bevy::utils::BoxedFuture<'a, Result<(), bevy::asset::Error>> { + &'a self, + bytes: &'a [u8], + load_context: &'a mut bevy::asset::LoadContext, + ) -> bevy::utils::BoxedFuture<'a, Result<(), bevy::asset::Error>> { Box::pin(async move { let yaml_str = std::str::from_utf8(bytes)?; let asset = YamlAsset(yaml_str.into()); -- 2.44.1