Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
micutio committed Nov 10, 2022
1 parent 7edf28e commit ea1307e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 62 deletions.
81 changes: 38 additions & 43 deletions src/entity/act/hereditary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,43 230,40 @@ impl Action for Attack {
.flatten()
.find(|o| o.physics.is_blocking && o.pos.is_equal(&target_pos));

match valid_target {
Some(t) => {
// deal damage
t.actuators.hp -= self.lvl;
debug!("target hp: {}/{}", t.actuators.hp, t.actuators.max_hp);
if owner.physics.is_visible {
state.log.add(
format!(
"{} attacked {} for {} damage",
&owner.visual.name, &t.visual.name, self.lvl
),
game::msg::Class::Info,
);
// show particle effect
ui::register_particle(
t.pos,
ui::Rgba::new(200, 10, 10, 180), // TODO:
ui::palette().col_transparent,
'x',
250.0,
0.0,
(1.0, 1.0),
);
}
if let Some(t) = valid_target {
// deal damage
t.actuators.hp -= self.lvl;
debug!("target hp: {}/{}", t.actuators.hp, t.actuators.max_hp);
if owner.physics.is_visible {
state.log.add(
format!(
"{} attacked {} for {} damage",
&owner.visual.name, &t.visual.name, self.lvl
),
game::msg::Class::Info,
);
// show particle effect
ui::register_particle(
t.pos,
ui::Rgba::new(200, 10, 10, 180), // TODO:
ui::palette().col_transparent,
'x',
250.0,
0.0,
(1.0, 1.0),
);
}

ActionResult::Success {
callback: ObjectFeedback::NoFeedback,
}
ActionResult::Success {
callback: ObjectFeedback::NoFeedback,
}
None => {
if owner.is_player() {
state
.log
.add("Nothing to attack here", game::msg::Class::Info);
}
ActionResult::Failure
} else {
if owner.is_player() {
state
.log
.add("Nothing to attack here", game::msg::Class::Info);
}
ActionResult::Failure
}
}

Expand Down Expand Up @@ -904,15 901,13 @@ impl Action for BinaryFission {
None
} else {
// create a new object
let child_ctrl = match &owner.control {
Some(ctrl) => match ctrl {
control::Controller::Npc(ai) => Some(control::Controller::Npc(ai.clone())),
control::Controller::Player(_) => {
Some(control::Controller::Player(control::Player::new()))
}
},
None => None,
};
let child_ctrl = owner.control.as_ref().map(|ctrl| match ctrl {
control::Controller::Npc(ai) => control::Controller::Npc(ai.clone()),
control::Controller::Player(_) => {
control::Controller::Player(control::Player::new())
}
});

let mut child = Object::new()
.position(&t.pos)
.living(true)
Expand Down
9 changes: 5 additions & 4 deletions src/game/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,13 759,14 @@ impl rltk::GameState for Game {
genome_editor.display(&mut self.state, ctx)
}
}
RunState::InfoBox(infobox) => match infobox.display(ctx) {
Some(infobox) => RunState::InfoBox(infobox),
None => {
RunState::InfoBox(infobox) => {
if let Some(infobox) = infobox.display(ctx) {
RunState::InfoBox(infobox)
} else {
self.require_render = true;
RunState::Ticking
}
},
}
RunState::NewGame => {
// start new game
ctx.set_active_console(consts::WORLD_CON);
Expand Down
24 changes: 12 additions & 12 deletions src/game/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 200,10 @@ impl ObjectStore {
}

pub fn extract_by_index(&mut self, index: usize) -> Option<Object> {
match self.objects.get_mut(index) {
Some(item) => item.take(),
None => panic!(" Error: invalid index {}", index),
}
self.objects.get_mut(index).map_or_else(
|| panic!(" Error: invalid index {}", index),
std::option::Option::take,
)
}

/// Extract a blocking object with the given position and return both the object and its index.
Expand Down Expand Up @@ -340,20 340,20 @@ impl Index<usize> for ObjectStore {

fn index(&self, i: usize) -> &Self::Output {
let item = self.objects.get(i);
match item {
Some(obj_option) => obj_option,
None => panic!("[GameObjects::index] Error: invalid index {}", i),
}
item.map_or_else(
|| panic!("[GameObjects::index] Error: invalid index {}", i),
|obj_option| obj_option,
)
}
}

impl IndexMut<usize> for ObjectStore {
fn index_mut(&mut self, i: usize) -> &mut Self::Output {
let item = self.objects.get_mut(i);
match item {
Some(obj_option) => obj_option,
None => panic!("[GameObjects::index] Error: invalid index {}", i),
}
item.map_or_else(
|| panic!("[GameObjects::index] Error: invalid index {}", i),
|obj_option| obj_option,
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/custom/genome_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 402,7 @@ impl GenomeEditor {
);
draw_batch.print_color(
rltk::Point::new(connect_end.x spacing, connect_end.y 2),
&genome.trait_family,
genome.trait_family,
color,
);
draw_batch.print_color(
Expand Down
4 changes: 2 additions & 2 deletions src/ui/dialog/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 9,13 @@ pub fn info_screen() -> InfoBox {
"Q first quick action".to_string(),
"E second quick action".to_string(),
"SPACE pass turn".to_string(),
"".to_string(),
String::new(),
"Reassign Actions".to_string(),
"SHIFT P set primary".to_string(),
"SHIFT S set secondary".to_string(),
"SHIFT Q set first quick".to_string(),
"SHIFT E set second quick".to_string(),
"".to_string(),
String::new(),
"Other".to_string(),
"C display character info".to_string(),
"F1 display controls".to_string(),
Expand Down

0 comments on commit ea1307e

Please sign in to comment.