From 8ed2109bcf5947f56927c5a09d7e6d84fc503e3c Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Thu, 11 Jun 2020 18:06:11 +0100 Subject: [PATCH] Fixed suppressed clippy warnings for #587 - collapsible_if --- client/src/cmd.rs | 41 +- client/src/lib.rs | 14 +- server/src/cmd.rs | 34 +- server/src/events/entity_manipulation.rs | 427 +++++++++--------- server/src/events/inventory_manip.rs | 12 +- .../src/audio/sfx/event_mapper/combat/mod.rs | 27 +- voxygen/src/hud/chat.rs | 48 +- voxygen/src/menu/char_selection/ui.rs | 40 +- voxygen/src/mesh/terrain.rs | 2 +- voxygen/src/render/pipelines/figure.rs | 2 +- voxygen/src/render/pipelines/sprite.rs | 2 +- voxygen/src/ui/widgets/tooltip.rs | 11 +- world/examples/water.rs | 1 - world/src/column/mod.rs | 56 ++- world/src/sim/erosion.rs | 39 +- world/src/sim/mod.rs | 31 +- world/src/site/settlement/mod.rs | 15 +- 17 files changed, 375 insertions(+), 427 deletions(-) diff --git a/client/src/cmd.rs b/client/src/cmd.rs index 5d8c8008db..911e20dbcf 100644 --- a/client/src/cmd.rs +++ b/client/src/cmd.rs @@ -79,7 +79,6 @@ fn nth_word(line: &str, n: usize) -> Option { } #[allow(clippy::chars_next_cmp)] // TODO: Pending review in #587 -#[allow(clippy::collapsible_if)] // TODO: Pending review in #587 pub fn complete(line: &str, client: &Client) -> Vec { let word = if line.chars().last().map_or(true, char::is_whitespace) { "" @@ -93,29 +92,27 @@ pub fn complete(line: &str, client: &Client) -> Vec { if i == 0 { // Completing chat command name complete_command(word) - } else { - if let Ok(cmd) = cmd.parse::() { - if let Some(arg) = cmd.data().args.get(i - 1) { - // Complete ith argument - arg.complete(word, &client) - } else { - // Complete past the last argument - match cmd.data().args.last() { - Some(ArgumentSpec::SubCommand) => { - if let Some(index) = nth_word(line, cmd.data().args.len()) { - complete(&line[index..], &client) - } else { - vec![] - } - }, - Some(ArgumentSpec::Message) => complete_player(word, &client), - _ => vec![], // End of command. Nothing to complete - } - } + } else if let Ok(cmd) = cmd.parse::() { + if let Some(arg) = cmd.data().args.get(i - 1) { + // Complete ith argument + arg.complete(word, &client) } else { - // Completing for unknown chat command - complete_player(word, &client) + // Complete past the last argument + match cmd.data().args.last() { + Some(ArgumentSpec::SubCommand) => { + if let Some(index) = nth_word(line, cmd.data().args.len()) { + complete(&line[index..], &client) + } else { + vec![] + } + }, + Some(ArgumentSpec::Message) => complete_player(word, &client), + _ => vec![], // End of command. Nothing to complete + } } + } else { + // Completing for unknown chat command + complete_player(word, &client) } } else { // Not completing a command diff --git a/client/src/lib.rs b/client/src/lib.rs index 2498d49dc7..a524b4aeca 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -702,7 +702,7 @@ impl Client { } /// Handle new server messages. - #[allow(clippy::collapsible_if)] // TODO: Pending review in #587 + fn handle_new_messages(&mut self) -> Result, Error> { let mut frontend_events = Vec::new(); @@ -713,12 +713,12 @@ impl Client { let duration_since_last_pong = self.state.get_time() - self.last_server_pong; // Dispatch a notification to the HUD warning they will be kicked in {n} seconds - if duration_since_last_pong >= SERVER_TIMEOUT_GRACE_PERIOD { - if self.state.get_time() - duration_since_last_pong > 0. { - frontend_events.push(Event::DisconnectionNotification( - (self.state.get_time() - duration_since_last_pong).round() as u64, - )); - } + if duration_since_last_pong >= SERVER_TIMEOUT_GRACE_PERIOD + && self.state.get_time() - duration_since_last_pong > 0. + { + frontend_events.push(Event::DisconnectionNotification( + (self.state.get_time() - duration_since_last_pong).round() as u64, + )); } } diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 2e4187ad33..500c0dff70 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -224,7 +224,6 @@ fn handle_goto( } } -#[allow(clippy::collapsible_if)] // TODO: Pending review in #587 #[allow(clippy::option_map_unit_fn)] // TODO: Pending review in #587 fn handle_kill( server: &mut Server, @@ -235,12 +234,10 @@ fn handle_kill( ) { let reason = if client == target { comp::HealthSource::Suicide + } else if let Some(uid) = server.state.read_storage::().get(client) { + comp::HealthSource::Attack { by: *uid } } else { - if let Some(uid) = server.state.read_storage::().get(client) { - comp::HealthSource::Attack { by: *uid } - } else { - comp::HealthSource::Command - } + comp::HealthSource::Command }; server .state @@ -385,7 +382,6 @@ fn handle_alias( } } -#[allow(clippy::collapsible_if)] // TODO: Pending review in #587 #[allow(clippy::identity_conversion)] // TODO: Pending review in #587 #[allow(clippy::useless_format)] // TODO: Pending review in #587 fn handle_tp( @@ -401,20 +397,18 @@ fn handle_tp( .join() .find(|(_, player)| player.alias == alias) .map(|(entity, _)| entity) + } else if client != target { + Some(client) } else { - if client != target { - Some(client) - } else { - server.notify_client( - client, - ServerMsg::private("You must specify a player name".to_string()), - ); - server.notify_client( - client, - ServerMsg::private(String::from(action.help_string())), - ); - return; - } + server.notify_client( + client, + ServerMsg::private("You must specify a player name".to_string()), + ); + server.notify_client( + client, + ServerMsg::private(String::from(action.help_string())), + ); + return; }; if let Some(_pos) = server.state.read_component_cloned::(target) { if let Some(player) = opt_player { diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 3f7124220c..bcbeb93a2b 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -24,7 +24,6 @@ pub fn handle_damage(server: &Server, uid: Uid, change: HealthChange) { } } -#[allow(clippy::collapsible_if)] // TODO: Pending review in #587 #[allow(clippy::option_map_unit_fn)] // TODO: Pending review in #587 pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSource) { let state = server.state_mut(); @@ -102,224 +101,222 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSourc .ecs() .write_storage::() .insert(entity, comp::CharacterState::default()); - } else { - if state.ecs().read_storage::().contains(entity) { - // Replace npc with loot - let _ = state - .ecs() - .write_storage() - .insert(entity, Body::Object(object::Body::Pouch)); + } else if state.ecs().read_storage::().contains(entity) { + // Replace npc with loot + let _ = state + .ecs() + .write_storage() + .insert(entity, Body::Object(object::Body::Pouch)); - let mut item_drops = state.ecs().write_storage::(); - let item = if let Some(item_drop) = item_drops.get(entity).cloned() { - item_drops.remove(entity); - item_drop.0 - } else { - assets::load_expect_cloned::( - [ - "common.items.cheese", - "common.items.apple", - "common.items.cheese", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.collar", - "common.items.cheese", - "common.items.apple", - "common.items.cheese", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.collar", - "common.items.cheese", - "common.items.apple", - "common.items.cheese", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.collar", - "common.items.veloritefrag", - "common.items.cheese", - "common.items.apple", - "common.items.cheese", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.collar", - "common.items.cheese", - "common.items.apple", - "common.items.cheese", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.collar", - "common.items.cheese", - "common.items.apple", - "common.items.cheese", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.cheese", - "common.items.mushroom", - "common.items.apple", - "common.items.collar", - "common.items.collar", - "common.items.collar", - "common.items.collar", - "common.items.collar", - "common.items.veloritefrag", - "common.items.veloritefrag", - "common.items.veloritefrag", - "common.items.veloritefrag", - "common.items.veloritefrag", - "common.items.veloritefrag", - "common.items.veloritefrag", - "common.items.veloritefrag", - "common.items.velorite", - "common.items.armor.ring.ring_0", - "common.items.armor.neck.neck_0", - "common.items.mushroom", - "common.items.coconut", - "common.items.coconut", - "common.items.coconut", - "common.items.coconut", - "common.items.coconut", - "common.items.potion_minor", - "common.items.potion_minor", - "common.items.potion_minor", - "common.items.potion_minor", - "common.items.potion_minor", - "common.items.potion_minor", - "common.items.weapons.tool.broom", - "common.items.weapons.tool.shovel-1", - "common.items.weapons.staff.staff_nature", - "common.items.flowers.yellow", - "common.items.armor.pants.worker_blue_0", - "common.items.armor.chest.worker_yellow_0", - "common.items.armor.chest.worker_green_0", - "common.items.armor.chest.worker_orange_0", - "common.items.armor.back.short_0", - "common.items.weapons.staff.staff_nature", - "common.items.weapons.sword.starter_sword", - "common.items.weapons.axe.starter_axe", - "common.items.weapons.staff.staff_nature", - "common.items.weapons.hammer.starter_hammer", - "common.items.weapons.bow.starter_bow", - "common.items.weapons.staff.starter_staff", - "common.items.weapons.sword.starter_sword", - "common.items.weapons.axe.starter_axe", - "common.items.weapons.staff.staff_nature", - "common.items.weapons.hammer.starter_hammer", - "common.items.weapons.bow.starter_bow", - "common.items.weapons.staff.starter_staff", - "common.items.weapons.sword.starter_sword", - "common.items.weapons.axe.starter_axe", - "common.items.weapons.staff.staff_nature", - "common.items.weapons.hammer.starter_hammer", - "common.items.weapons.bow.starter_bow", - "common.items.weapons.staff.starter_staff", - "common.items.weapons.sword.greatsword_2h_simple-0", - "common.items.weapons.sword.greatsword_2h_simple-1", - "common.items.weapons.sword.greatsword_2h_simple-2", - "common.items.weapons.sword.long_2h_simple-0", - "common.items.weapons.sword.long_2h_simple-1", - "common.items.weapons.sword.long_2h_simple-2", - "common.items.weapons.sword.long_2h_simple-3", - "common.items.weapons.sword.long_2h_simple-4", - "common.items.weapons.sword.long_2h_simple-5", - ] - .choose(&mut rand::thread_rng()) - .unwrap(), - ) - }; - - let _ = state.ecs().write_storage().insert(entity, item); - - state.ecs().write_storage::().remove(entity); - state.ecs().write_storage::().remove(entity); - state - .ecs() - .write_storage::() - .remove(entity); - state - .ecs() - .write_storage::() - .remove(entity); - state - .ecs() - .write_storage::() - .remove(entity); + let mut item_drops = state.ecs().write_storage::(); + let item = if let Some(item_drop) = item_drops.get(entity).cloned() { + item_drops.remove(entity); + item_drop.0 } else { - if let Err(err) = state.delete_entity_recorded(entity) { - error!("Failed to delete destroyed entity: {:?}", err); - } - } + assets::load_expect_cloned::( + [ + "common.items.cheese", + "common.items.apple", + "common.items.cheese", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.collar", + "common.items.cheese", + "common.items.apple", + "common.items.cheese", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.collar", + "common.items.cheese", + "common.items.apple", + "common.items.cheese", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.collar", + "common.items.veloritefrag", + "common.items.cheese", + "common.items.apple", + "common.items.cheese", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.collar", + "common.items.cheese", + "common.items.apple", + "common.items.cheese", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.collar", + "common.items.cheese", + "common.items.apple", + "common.items.cheese", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.cheese", + "common.items.mushroom", + "common.items.apple", + "common.items.collar", + "common.items.collar", + "common.items.collar", + "common.items.collar", + "common.items.collar", + "common.items.veloritefrag", + "common.items.veloritefrag", + "common.items.veloritefrag", + "common.items.veloritefrag", + "common.items.veloritefrag", + "common.items.veloritefrag", + "common.items.veloritefrag", + "common.items.veloritefrag", + "common.items.velorite", + "common.items.armor.ring.ring_0", + "common.items.armor.neck.neck_0", + "common.items.mushroom", + "common.items.coconut", + "common.items.coconut", + "common.items.coconut", + "common.items.coconut", + "common.items.coconut", + "common.items.potion_minor", + "common.items.potion_minor", + "common.items.potion_minor", + "common.items.potion_minor", + "common.items.potion_minor", + "common.items.potion_minor", + "common.items.weapons.tool.broom", + "common.items.weapons.tool.shovel-1", + "common.items.weapons.staff.staff_nature", + "common.items.flowers.yellow", + "common.items.armor.pants.worker_blue_0", + "common.items.armor.chest.worker_yellow_0", + "common.items.armor.chest.worker_green_0", + "common.items.armor.chest.worker_orange_0", + "common.items.armor.back.short_0", + "common.items.weapons.staff.staff_nature", + "common.items.weapons.sword.starter_sword", + "common.items.weapons.axe.starter_axe", + "common.items.weapons.staff.staff_nature", + "common.items.weapons.hammer.starter_hammer", + "common.items.weapons.bow.starter_bow", + "common.items.weapons.staff.starter_staff", + "common.items.weapons.sword.starter_sword", + "common.items.weapons.axe.starter_axe", + "common.items.weapons.staff.staff_nature", + "common.items.weapons.hammer.starter_hammer", + "common.items.weapons.bow.starter_bow", + "common.items.weapons.staff.starter_staff", + "common.items.weapons.sword.starter_sword", + "common.items.weapons.axe.starter_axe", + "common.items.weapons.staff.staff_nature", + "common.items.weapons.hammer.starter_hammer", + "common.items.weapons.bow.starter_bow", + "common.items.weapons.staff.starter_staff", + "common.items.weapons.sword.greatsword_2h_simple-0", + "common.items.weapons.sword.greatsword_2h_simple-1", + "common.items.weapons.sword.greatsword_2h_simple-2", + "common.items.weapons.sword.long_2h_simple-0", + "common.items.weapons.sword.long_2h_simple-1", + "common.items.weapons.sword.long_2h_simple-2", + "common.items.weapons.sword.long_2h_simple-3", + "common.items.weapons.sword.long_2h_simple-4", + "common.items.weapons.sword.long_2h_simple-5", + ] + .choose(&mut rand::thread_rng()) + .unwrap(), + ) + }; - // TODO: Add Delete(time_left: Duration) component - /* - // If not a player delete the entity - if let Err(err) = state.delete_entity_recorded(entity) { - error!("Failed to delete destroyed entity: {:?}", err); - } - */ + let _ = state.ecs().write_storage().insert(entity, item); + + state.ecs().write_storage::().remove(entity); + state.ecs().write_storage::().remove(entity); + state + .ecs() + .write_storage::() + .remove(entity); + state + .ecs() + .write_storage::() + .remove(entity); + state + .ecs() + .write_storage::() + .remove(entity); + } else { + let _ = state + .delete_entity_recorded(entity) + .map_err(|err| error!("Failed to delete destroyed entity: {:?}", err)); } + + // TODO: Add Delete(time_left: Duration) component + /* + // If not a player delete the entity + if let Err(err) = state.delete_entity_recorded(entity) { + error!("Failed to delete destroyed entity: {:?}", err); + } + */ } pub fn handle_land_on_ground(server: &Server, entity: EcsEntity, vel: Vec3) { diff --git a/server/src/events/inventory_manip.rs b/server/src/events/inventory_manip.rs index e79b2645d6..3c87baac02 100644 --- a/server/src/events/inventory_manip.rs +++ b/server/src/events/inventory_manip.rs @@ -30,7 +30,6 @@ pub fn snuff_lantern(storage: &mut WriteStorage, entity: Ecs } #[allow(clippy::block_in_if_condition_stmt)] // TODO: Pending review in #587 -#[allow(clippy::collapsible_if)] // TODO: Pending review in #587 #[allow(clippy::let_and_return)] // TODO: Pending review in #587 pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::InventoryManip) { let state = server.state_mut(); @@ -95,12 +94,11 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv entity, comp::InventoryUpdate::new(comp::InventoryUpdateEvent::CollectFailed), ); - } else { - if block.is_collectible() && state.try_set_block(pos, Block::empty()).is_some() - { - comp::Item::try_reclaim_from_block(block) - .map(|item| state.give_item(entity, item)); - } + } else if block.is_collectible() + && state.try_set_block(pos, Block::empty()).is_some() + { + comp::Item::try_reclaim_from_block(block) + .map(|item| state.give_item(entity, item)); } } }, diff --git a/voxygen/src/audio/sfx/event_mapper/combat/mod.rs b/voxygen/src/audio/sfx/event_mapper/combat/mod.rs index a025ebd001..8125449d95 100644 --- a/voxygen/src/audio/sfx/event_mapper/combat/mod.rs +++ b/voxygen/src/audio/sfx/event_mapper/combat/mod.rs @@ -129,7 +129,6 @@ impl CombatEventMapper { } } - #[allow(clippy::collapsible_if)] // TODO: Pending review in #587 fn map_event( character_state: &CharacterState, previous_state: &PreviousEntityState, @@ -151,22 +150,16 @@ impl CombatEventMapper { CharacterAbilityType::from(character_state), ToolCategory::from(data.kind), ); - } else { - if let Some(wield_event) = match ( - previous_state.weapon_drawn, - character_state.is_dodge(), - Self::weapon_drawn(character_state), - ) { - (false, false, true) => { - Some(SfxEvent::Wield(ToolCategory::from(data.kind))) - }, - (true, false, false) => { - Some(SfxEvent::Unwield(ToolCategory::from(data.kind))) - }, - _ => None, - } { - return wield_event; - } + } else if let Some(wield_event) = match ( + previous_state.weapon_drawn, + character_state.is_dodge(), + Self::weapon_drawn(character_state), + ) { + (false, false, true) => Some(SfxEvent::Wield(ToolCategory::from(data.kind))), + (true, false, false) => Some(SfxEvent::Unwield(ToolCategory::from(data.kind))), + _ => None, + } { + return wield_event; } } } diff --git a/voxygen/src/hud/chat.rs b/voxygen/src/hud/chat.rs index b190c3b17c..384ef4ff1a 100644 --- a/voxygen/src/hud/chat.rs +++ b/voxygen/src/hud/chat.rs @@ -146,7 +146,6 @@ impl<'a> Widget for Chat<'a> { #[allow(clippy::unused_unit)] // TODO: Pending review in #587 fn style(&self) -> Self::Style { () } - #[allow(clippy::collapsible_if)] // TODO: Pending review in #587 #[allow(clippy::redundant_clone)] // TODO: Pending review in #587 #[allow(clippy::single_match)] // TODO: Pending review in #587 fn update(self, args: widget::UpdateArgs) -> Self::Event { @@ -200,24 +199,20 @@ impl<'a> Widget for Chat<'a> { state.update(|s| s.input.retain(|c| c != '\t')); //tab_dir + 1 } - if !state.completions.is_empty() { - if tab_dir != 0 || state.completions_index.is_none() { - state.update(|s| { - let len = s.completions.len(); - s.completions_index = Some( - (s.completions_index.unwrap_or(0) + (tab_dir + len as isize) as usize) - % len, - ); - if let Some(replacement) = &s.completions.get(s.completions_index.unwrap()) - { - let (completed, offset) = - do_tab_completion(cursor, &s.input, replacement); - force_cursor = - cursor_offset_to_index(offset, &completed, &ui, &self.fonts); - s.input = completed; - } - }); - } + if !state.completions.is_empty() && (tab_dir != 0 || state.completions_index.is_none()) + { + state.update(|s| { + let len = s.completions.len(); + s.completions_index = Some( + (s.completions_index.unwrap_or(0) + (tab_dir + len as isize) as usize) + % len, + ); + if let Some(replacement) = &s.completions.get(s.completions_index.unwrap()) { + let (completed, offset) = do_tab_completion(cursor, &s.input, replacement); + force_cursor = cursor_offset_to_index(offset, &completed, &ui, &self.fonts); + s.input = completed; + } + }); } false } else if let Some(cursor) = state.input.find('\t') { @@ -236,10 +231,8 @@ impl<'a> Widget for Chat<'a> { if s.history_pos < s.history.len() { s.history_pos += 1; } - } else { - if s.history_pos > 0 { - s.history_pos -= 1; - } + } else if s.history_pos > 0 { + s.history_pos -= 1; } if s.history_pos > 0 { s.input = s.history.get(s.history_pos - 1).unwrap().to_owned(); @@ -368,17 +361,16 @@ impl<'a> Widget for Chat<'a> { // Chat Arrow // Check if already at bottom. - if !Self::scrolled_to_bottom(state, ui) { - if Button::image(self.imgs.chat_arrow) + if !Self::scrolled_to_bottom(state, ui) + && Button::image(self.imgs.chat_arrow) .w_h(20.0, 20.0) .hover_image(self.imgs.chat_arrow_mo) .press_image(self.imgs.chat_arrow_press) .bottom_right_with_margins_on(state.ids.message_box_bg, 0.0, -22.0) .set(state.ids.chat_arrow, ui) .was_clicked() - { - ui.scroll_widget(state.ids.message_box, [0.0, std::f64::MAX]); - } + { + ui.scroll_widget(state.ids.message_box, [0.0, std::f64::MAX]); } // We've started a new tab completion. Populate tab completion suggestions. diff --git a/voxygen/src/menu/char_selection/ui.rs b/voxygen/src/menu/char_selection/ui.rs index 9fbbd16001..47209c7301 100644 --- a/voxygen/src/menu/char_selection/ui.rs +++ b/voxygen/src/menu/char_selection/ui.rs @@ -399,7 +399,6 @@ impl CharSelectionUi { // TODO: Split this into multiple modules or functions. #[allow(clippy::clone_on_copy)] // TODO: Pending review in #587 - #[allow(clippy::collapsible_if)] // TODO: Pending review in #587 #[allow(clippy::useless_let_if_seq)] // TODO: Pending review in #587 #[allow(clippy::unnecessary_operation)] // TODO: Pending review in #587 fn update_layout(&mut self, client: &mut Client) -> Vec { @@ -826,15 +825,14 @@ impl CharSelectionUi { .image_color(color) .set(self.ids.character_box_2, ui_widgets) .was_clicked() + && !character_limit_reached { - if !character_limit_reached { - self.mode = Mode::Create { - name: "Character Name".to_string(), - body: humanoid::Body::random(), - loadout: comp::Loadout::default(), - tool: Some(STARTER_SWORD), - }; - } + self.mode = Mode::Create { + name: "Character Name".to_string(), + body: humanoid::Body::random(), + loadout: comp::Loadout::default(), + tool: Some(STARTER_SWORD), + }; } // LOADING SCREEN HERE @@ -903,21 +901,19 @@ impl CharSelectionUi { .set(self.ids.create_button, ui_widgets) .was_clicked() {} - } else { - if create_button - .set(self.ids.create_button, ui_widgets) - .was_clicked() - { - self.info_content = InfoContent::CreatingCharacter; + } else if create_button + .set(self.ids.create_button, ui_widgets) + .was_clicked() + { + self.info_content = InfoContent::CreatingCharacter; - events.push(Event::AddCharacter { - alias: name.clone(), - tool: tool.map(|tool| tool.to_string()), - body: comp::Body::Humanoid(body.clone()), - }); + events.push(Event::AddCharacter { + alias: name.clone(), + tool: tool.map(|tool| tool.to_string()), + body: comp::Body::Humanoid(body.clone()), + }); - to_select = true; - } + to_select = true; } // Character Name Input Rectangle::fill_with([320.0, 50.0], color::rgba(0.0, 0.0, 0.0, 0.97)) diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index e6ba3de44d..b56b9cf6eb 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -206,7 +206,7 @@ impl<'a, V: RectRasterableVol + ReadVol + Debug> type Supplement = Aabb; type TranslucentPipeline = FluidPipeline; - #[allow(clippy::collapsible_if)] // TODO: Pending review in #587 + #[allow(clippy::collapsible_if)] #[allow(clippy::many_single_char_names)] #[allow(clippy::needless_range_loop)] // TODO: Pending review in #587 #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 diff --git a/voxygen/src/render/pipelines/figure.rs b/voxygen/src/render/pipelines/figure.rs index af22de0b1d..94d1272112 100644 --- a/voxygen/src/render/pipelines/figure.rs +++ b/voxygen/src/render/pipelines/figure.rs @@ -46,7 +46,7 @@ gfx_defines! { } impl Vertex { - #[allow(clippy::collapsible_if)] // TODO: Pending review in #587 + #[allow(clippy::collapsible_if)] pub fn new(pos: Vec3, norm: Vec3, col: Rgb, ao: f32, bone_idx: u8) -> Self { let norm_bits = if norm.x != 0.0 { if norm.x < 0.0 { 0 } else { 1 } diff --git a/voxygen/src/render/pipelines/sprite.rs b/voxygen/src/render/pipelines/sprite.rs index 0829727dcd..c0747faa88 100644 --- a/voxygen/src/render/pipelines/sprite.rs +++ b/voxygen/src/render/pipelines/sprite.rs @@ -45,7 +45,7 @@ gfx_defines! { } impl Vertex { - #[allow(clippy::collapsible_if)] // TODO: Pending review in #587 + #[allow(clippy::collapsible_if)] pub fn new(pos: Vec3, norm: Vec3, col: Rgb, ao: f32) -> Self { let norm_bits = if norm.x != 0.0 { if norm.x < 0.0 { 0 } else { 1 } diff --git a/voxygen/src/ui/widgets/tooltip.rs b/voxygen/src/ui/widgets/tooltip.rs index 6084da25e4..5fbf97368b 100644 --- a/voxygen/src/ui/widgets/tooltip.rs +++ b/voxygen/src/ui/widgets/tooltip.rs @@ -368,7 +368,6 @@ impl<'a> Widget for Tooltip<'a> { fn style(&self) -> Self::Style { self.style.clone() } - #[allow(clippy::collapsible_if)] // TODO: Pending review in #587 fn update(self, args: widget::UpdateArgs) { let widget::UpdateArgs { id, @@ -440,13 +439,11 @@ impl<'a> Widget for Tooltip<'a> { if !self.title_text.is_empty() { desc.down_from(state.ids.title, V_PAD * 0.5 + title_space) .align_left_of(state.ids.title) + } else if self.image.is_some() { + desc.right_from(state.ids.image, H_PAD) + .align_top_of(state.ids.image) } else { - if self.image.is_some() { - desc.right_from(state.ids.image, H_PAD) - .align_top_of(state.ids.image) - } else { - desc.top_left_with_margins_on(state.ids.image_frame, V_PAD, H_PAD) - } + desc.top_left_with_margins_on(state.ids.image_frame, V_PAD, H_PAD) } .set(state.ids.desc, ui); } diff --git a/world/examples/water.rs b/world/examples/water.rs index 0e3bd6c594..d1bb627eb5 100644 --- a/world/examples/water.rs +++ b/world/examples/water.rs @@ -9,7 +9,6 @@ use veloren_world::{ const W: usize = 1024; const H: usize = 1024; -#[allow(clippy::collapsible_if)] // TODO: Pending review in #587 #[allow(clippy::needless_update)] // TODO: Pending review in #587 #[allow(clippy::unused_io_amount)] // TODO: Pending review in #587 fn main() { diff --git a/world/src/column/mod.rs b/world/src/column/mod.rs index c648ab29ca..8d3bc2a419 100644 --- a/world/src/column/mod.rs +++ b/world/src/column/mod.rs @@ -168,7 +168,6 @@ impl<'a> Sampler<'a> for ColumnGen<'a> { type Index = Vec2; type Sample = Option>; - #[allow(clippy::collapsible_if)] // TODO: Pending review in #587 #[allow(clippy::float_cmp)] // TODO: Pending review in #587 #[allow(clippy::if_same_then_else)] // TODO: Pending review in #587 #[allow(clippy::nonminimal_bool)] // TODO: Pending review in #587 @@ -679,36 +678,33 @@ impl<'a> Sampler<'a> for ColumnGen<'a> { let (_, dist, _, (river_t, _, downhill_river_chunk)) = if let Some(dist) = max_border_river_dist { dist - } else { - if lake_dist - <= TerrainChunkSize::RECT_SIZE.x as f64 * 1.0 - || in_bounds - { - let gouge_factor = 0.0; - return Some(( - in_bounds - || downhill_water_alt - .max(river_chunk.water_alt) - > alt_for_river, - Some(lake_dist as f32), - alt_for_river, - (downhill_water_alt + } else if lake_dist + <= TerrainChunkSize::RECT_SIZE.x as f64 * 1.0 + || in_bounds + { + let gouge_factor = 0.0; + return Some(( + in_bounds + || downhill_water_alt .max(river_chunk.water_alt) - - river_gouge), - alt_for_river, - river_scale_factor as f32 - * (1.0 - gouge_factor), - )); - } else { - return Some(( - false, - Some(lake_dist as f32), - alt_for_river, - downhill_water_alt, - alt_for_river, - river_scale_factor as f32, - )); - } + > alt_for_river, + Some(lake_dist as f32), + alt_for_river, + (downhill_water_alt.max(river_chunk.water_alt) + - river_gouge), + alt_for_river, + river_scale_factor as f32 + * (1.0 - gouge_factor), + )); + } else { + return Some(( + false, + Some(lake_dist as f32), + alt_for_river, + downhill_water_alt, + alt_for_river, + river_scale_factor as f32, + )); }; let lake_dist = dist.y; diff --git a/world/src/sim/erosion.rs b/world/src/sim/erosion.rs index 35fbf72749..1412de21af 100644 --- a/world/src/sim/erosion.rs +++ b/world/src/sim/erosion.rs @@ -687,7 +687,6 @@ fn get_max_slope( /// Copyright 2003 by the American Geophysical Union /// 10.1029/135GM09 #[allow(clippy::assign_op_pattern)] // TODO: Pending review in #587 -#[allow(clippy::collapsible_if)] // TODO: Pending review in #587 #[allow(clippy::many_single_char_names)] #[allow(clippy::too_many_arguments)] fn erode( @@ -1388,19 +1387,17 @@ fn erode( // NOTE: If we want erosion to proceed underwater, use h_j here instead // of wh_j. new_h_i = wh_j; - } else { - if compute_stats && new_h_i > 0.0 { - let dxy = (uniform_idx_as_vec2(posi) - uniform_idx_as_vec2(posj)) - .map(|e| e as f64); - let neighbor_distance = (neighbor_coef * dxy).magnitude(); - let dz = (new_h_i - wh_j).max(0.0); - let mag_slope = dz / neighbor_distance; + } else if compute_stats && new_h_i > 0.0 { + let dxy = (uniform_idx_as_vec2(posi) - uniform_idx_as_vec2(posj)) + .map(|e| e as f64); + let neighbor_distance = (neighbor_coef * dxy).magnitude(); + let dz = (new_h_i - wh_j).max(0.0); + let mag_slope = dz / neighbor_distance; - nland += 1; - sumsed_land += sed; - sumh += new_h_i; - sums += mag_slope; - } + nland += 1; + sumsed_land += sed; + sumh += new_h_i; + sums += mag_slope; } } else { new_h_i = old_elev_i; @@ -1628,15 +1625,13 @@ fn erode( if compute_stats { ncorr += 1; } - } else { - if compute_stats && new_h_i > 0.0 { - let dz = (new_h_i - h_j).max(0.0); - let slope = dz / neighbor_distance; - sums += slope; - nland += 1; - sumh += new_h_i; - sumsed_land += sed; - } + } else if compute_stats && new_h_i > 0.0 { + let dz = (new_h_i - h_j).max(0.0); + let slope = dz / neighbor_distance; + sums += slope; + nland += 1; + sumh += new_h_i; + sumsed_land += sed; } if compute_stats { ntherm += 1; diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index 1481717462..09fef5d196 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -1821,7 +1821,6 @@ pub struct RegionInfo { } impl SimChunk { - #[allow(clippy::collapsible_if)] // TODO: Pending review in #587 #[allow(clippy::if_same_then_else)] // TODO: Pending review in #587 fn generate(posi: usize, gen_ctx: &GenCtx, gen_cdf: &GenCdf) -> Self { let pos = uniform_idx_as_vec2(posi); @@ -2012,23 +2011,21 @@ impl SimChunk { } else { ForestKind::Savannah } + } else if humidity > CONFIG.jungle_hum { + // Temperate climate with jungle humidity... + // https://en.wikipedia.org/wiki/Humid_subtropical_climates are often + // densely wooded and full of water. Semitropical rainforests, basically. + // For now we just treet them like other rainforests. + ForestKind::Oak + } else if humidity > CONFIG.forest_hum { + // Moderate climate, moderate humidity. + ForestKind::Oak + } else if humidity > CONFIG.desert_hum { + // With moderate temperature and low humidity, we should probably see + // something different from savannah, but oh well... + ForestKind::Savannah } else { - if humidity > CONFIG.jungle_hum { - // Temperate climate with jungle humidity... - // https://en.wikipedia.org/wiki/Humid_subtropical_climates are often - // densely wooded and full of water. Semitropical rainforests, basically. - // For now we just treet them like other rainforests. - ForestKind::Oak - } else if humidity > CONFIG.forest_hum { - // Moderate climate, moderate humidity. - ForestKind::Oak - } else if humidity > CONFIG.desert_hum { - // With moderate temperature and low humidity, we should probably see - // something different from savannah, but oh well... - ForestKind::Savannah - } else { - ForestKind::Savannah - } + ForestKind::Savannah } } else { // For now we don't take humidity into account for cold climates (but we really diff --git a/world/src/site/settlement/mod.rs b/world/src/site/settlement/mod.rs index 1d6c587c5a..0ec91ef30d 100644 --- a/world/src/site/settlement/mod.rs +++ b/world/src/site/settlement/mod.rs @@ -481,7 +481,6 @@ impl Settlement { } } - #[allow(clippy::collapsible_if)] // TODO: Pending review in #587 #[allow(clippy::identity_op)] // TODO: Pending review in #587 #[allow(clippy::modulo_one)] // TODO: Pending review in #587 pub fn apply_to<'a>( @@ -645,14 +644,12 @@ impl Settlement { }) .map(|kind| Block::new(kind, Rgb::white())); } - } else { - if roll(0, 20) == 0 { - surface_block = - Some(Block::new(BlockKind::ShortGrass, Rgb::white())); - } else if roll(1, 30) == 0 { - surface_block = - Some(Block::new(BlockKind::MediumGrass, Rgb::white())); - } + } else if roll(0, 20) == 0 { + surface_block = + Some(Block::new(BlockKind::ShortGrass, Rgb::white())); + } else if roll(1, 30) == 0 { + surface_block = + Some(Block::new(BlockKind::MediumGrass, Rgb::white())); } Some(if in_furrow { dirt } else { mound })