Skip to content

Commit

Permalink
Fix clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Lysai authored and pingw33n committed Jul 1, 2020
1 parent 992cf8a commit 1031387
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
13 changes: 6 additions & 7 deletions src/game/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ impl Inventory {
}

pub fn handle(&mut self, cmd: UiCommand, rpg: &Rpg, ui: &mut Ui) {
match cmd.data {
UiCommandData::Inventory(c) => match c {
if let UiCommandData::Inventory(c) = cmd.data {
match c {
Command::Show => {
self.show(rpg, ui);
}
Expand All @@ -77,7 +77,6 @@ impl Inventory {
self.internal.as_mut().unwrap().toggle_mouse_mode(ui);
}
}
_ => {}
}
}

Expand Down Expand Up @@ -259,7 +258,7 @@ impl Internal {
let obj = world.objects().get(self.obj);
for item in &obj.inventory.items {
let item_obj = &world.objects().get(item.object);
let inv_list_item = Self::to_inv_list_item(item, item_obj);
let inv_list_item = Self::make_list_item(item, item_obj);
match () {
_ if item_obj.flags.contains(Flag::Worn) => {
assert!(wearing.items().is_empty());
Expand All @@ -283,7 +282,7 @@ impl Internal {
}

// display_inventory_info
fn to_inv_list_item(item: &InventoryItem, obj: &Object) -> inventory_list::Item {
fn make_list_item(item: &InventoryItem, obj: &Object) -> inventory_list::Item {
let proto = obj.proto().unwrap();
let count = if obj.item_kind() == Some(ItemKind::Ammo) {
obj.proto().unwrap().max_ammo_count().unwrap() * (item.count - 1)
Expand Down Expand Up @@ -521,9 +520,9 @@ impl Internal {
};
let msg = BString::concat(&[
name.as_bytes(),
"\n--------------------\n".as_bytes(),
b"\n--------------------\n",
description.as_bytes(),
"\n".as_bytes(),
b"\n",
weight_msg.as_bytes()]);
ui.widget_mut::<Panel>(self.item_descr).text_mut().unwrap().text = msg;
self.switch_text_panels(false, ui);
Expand Down
1 change: 0 additions & 1 deletion src/game/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,6 @@ impl Objects {
/// 1. There's a path between them which is not sight-blocked (see `sight_blocker_for_object()`).
/// 2. Screen distance between objects is within the limit.
// action_can_talk_to()
#[must_use]
pub fn can_talk(&self, obj1: Handle, obj2: Handle) -> Result<(), CantTalkSpatial> {
let o1 = self.get(obj1);
let o2 = self.get(obj2);
Expand Down
2 changes: 1 addition & 1 deletion src/game/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl GameState {

let world_view_rect = Rect::with_size(0, 0, 640, 379);
let world_view = {
let win = ui.new_window(world_view_rect.clone(), None);
let win = ui.new_window(world_view_rect, None);
ui.new_widget(win, world_view_rect, None, None, WorldView::new(world.clone()))
};
let message_panel = hud::create(ui);
Expand Down
2 changes: 1 addition & 1 deletion src/game/ui/action_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn show(actions: Vec<(Action, UiCommandData)>, win: Handle, ui: &mut Ui) ->
};

ui.show_cursor_ghost();
ui.set_cursor_constraint(placement.rect.clone());
ui.set_cursor_constraint(placement.rect);
ui.set_cursor_pos(placement.rect.top_left());

let action_menu = ui.new_widget(win, placement.rect, Some(Cursor::Hidden), None,
Expand Down
6 changes: 3 additions & 3 deletions src/game/ui/inventory_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl InventoryList {

pub fn can_scroll(&self, scroll: Scroll) -> bool {
match scroll {
Scroll::Down => self.scroll_idx + 1 <= self.max_scroll_idx(),
Scroll::Down => self.scroll_idx < self.max_scroll_idx(),
Scroll::Up => self.scroll_idx > 0,
}
}
Expand All @@ -89,7 +89,7 @@ impl InventoryList {
pub fn scroll(&mut self, scroll: Scroll) {
self.set_scroll_idx(match scroll {
Scroll::Down => self.scroll_idx + 1,
Scroll::Up => self.scroll_idx.checked_sub(1).unwrap_or(0),
Scroll::Up => self.scroll_idx.saturating_sub(1),
});
}

Expand All @@ -106,7 +106,7 @@ impl InventoryList {
}

fn max_scroll_idx(&self) -> usize {
self.items.len().checked_sub(self.visible_items).unwrap_or(0)
self.items.len().saturating_sub(self.visible_items)
}

fn item_index_at(&self, rect: Rect, pos: Point) -> Option<usize> {
Expand Down

0 comments on commit 1031387

Please sign in to comment.