Skip to content

Commit

Permalink
clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Grokmoo committed Jan 13, 2025
1 parent 7810801 commit 06be535
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 44 deletions.
5 changes: 1 addition & 4 deletions sulis_state/src/area_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,10 +637,7 @@ impl AreaState {
return None;
}

let index = match self.transition_grid[(x + y * self.area.width) as usize] {
None => return None,
Some(index) => index,
};
let index = self.transition_grid[(x + y * self.area.width) as usize]?;

self.area.transitions.get(index)
}
Expand Down
10 changes: 2 additions & 8 deletions sulis_state/src/area_state/prop_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,19 +317,13 @@ impl PropHandler {
}

pub fn get_mut_at(&mut self, x: i32, y: i32) -> Option<&mut PropState> {
let index = match self.index_at(x, y) {
None => return None,
Some(index) => index,
};
let index = self.index_at(x, y)?;

Some(self.get_mut(index))
}

pub fn get_at(&self, x: i32, y: i32) -> Option<&PropState> {
let index = match self.index_at(x, y) {
None => return None,
Some(index) => index,
};
let index = self.index_at(x, y)?;

Some(self.get(index))
}
Expand Down
5 changes: 1 addition & 4 deletions sulis_state/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,7 @@ impl<'a> Iterator for EquippedIterator<'a> {
type Item = &'a ItemState;
fn next(&mut self) -> Option<&'a ItemState> {
loop {
let slot = match self.slot_iterator.next() {
None => return None,
Some(slot) => slot,
};
let slot = self.slot_iterator.next()?;

match self.inventory.equipped.get(slot) {
None => (),
Expand Down
7 changes: 2 additions & 5 deletions sulis_state/src/path_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,14 @@ pub fn move_towards_point(
dest: Destination,
cb: Option<Box<dyn ScriptCallback>>,
) -> Option<Anim> {
let path = match find_path(
let path = find_path(
finder,
area,
&entity.borrow(),
entities_to_ignore,
dest,
true,
) {
None => return None,
Some(path) => path,
};
)?;

let mut anim =
animation::move_animation::new(entity, path, Config::animation_base_time_millis());
Expand Down
5 changes: 1 addition & 4 deletions sulis_state/src/turn_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,10 +994,7 @@ impl TurnManager {
}

fn check_encounter_cleared(&self, entity: &Rc<RefCell<EntityState>>) -> Option<usize> {
let ai_group = match entity.borrow().ai_group() {
None => return None,
Some(index) => index,
};
let ai_group = entity.borrow().ai_group()?;

debug!("Check encounter cleared: {}", ai_group);
for other in self.entity_iter() {
Expand Down
24 changes: 5 additions & 19 deletions sulis_view/src/action_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,7 @@ impl TransitionAction {
return None;
}

let transition = area_state.get_transition_at(x, y);
let transition = match transition {
None => return None,
Some(transition) => transition,
};
let transition = area_state.get_transition_at(x, y)?;

let cb_action = Box::new(TransitionAction {
x,
Expand Down Expand Up @@ -544,10 +540,7 @@ impl AttackAction {
fn create_if_valid(x: i32, y: i32) -> Option<Box<dyn ActionKind>> {
let area_state = GameState::area_state();
let area_state = area_state.borrow();
let target = match get_attack_target(&area_state, x, y) {
None => return None,
Some(target) => target,
};
let target = get_attack_target(&area_state, x, y)?;
let pc = match GameState::selected().first() {
None => return None,
Some(pc) => Rc::clone(pc),
Expand Down Expand Up @@ -640,11 +633,8 @@ impl MoveThenAction {
cb_action: Box<dyn ActionKind>,
mut cursor_state: animation_state::Kind,
) -> Option<Box<dyn ActionKind>> {
let move_action = match MoveAction::new_if_valid(
pos.x, pos.y, size.width, size.height, Some(dist)) {
None => return None,
Some(move_action) => move_action,
};
let move_action = MoveAction::new_if_valid(
pos.x, pos.y, size.width, size.height, Some(dist))?;

if GameState::is_combat_active() {
let total_ap = cb_action.ap() + move_action.ap();
Expand Down Expand Up @@ -745,11 +735,7 @@ impl MoveAction {
max_path_len: None,
};

let path = match GameState::can_move_towards_dest(&pc.borrow(), &entities_to_ignore(), dest)
{
None => return None,
Some(path) => path,
};
let path = GameState::can_move_towards_dest(&pc.borrow(), &entities_to_ignore(), dest)?;

let (ap, path) = if !path.is_empty() {
let pc = pc.borrow();
Expand Down

0 comments on commit 06be535

Please sign in to comment.