Style and Clippy fixes.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-10-14 16:53:30 +02:00
parent 9efe1b4e22
commit 691bf7c12e
56 changed files with 354 additions and 249 deletions

View File

@@ -24,6 +24,12 @@ pub struct Gen7BattleStatCalculator {
identifier: ValueIdentifier,
}
impl Default for Gen7BattleStatCalculator {
fn default() -> Self {
Self::new()
}
}
impl Gen7BattleStatCalculator {
/// Creates a new Gen 7 battle stat calculator
pub fn new() -> Self {

View File

@@ -224,11 +224,7 @@ impl DamageLibrary for Gen7DamageLibrary {
float_damage = (float_damage * hit_data.effectiveness()).floor();
let mut damage = if float_damage <= 0.0 {
if hit_data.effectiveness() == 0.0 {
0
} else {
1
}
u32::from(hit_data.effectiveness() != 0.0)
} else if float_damage >= u32::MAX as f32 {
u32::MAX
} else {

View File

@@ -345,7 +345,7 @@ impl Battle {
.library()
.load_script(self.into(), ScriptCategory::Weather, &weather)
.unwrap()
.expect(format!("Couldn't find weather script by name {}", weather).as_str());
.unwrap_or_else(|| panic!("Couldn't find weather script by name {}", weather));
self.weather.set(script);
} else {
self.weather.clear();

View File

@@ -1,7 +1,6 @@
use std::sync::atomic::{AtomicU8, Ordering};
use std::sync::Arc;
use crate::dynamic_data::Pokemon;
use crate::static_data::MoveData;
use crate::{ValueIdentifiable, ValueIdentifier};

View File

@@ -457,7 +457,8 @@ impl Pokemon {
.calculate_flat_stats(self, &self.flat_stats);
self.recalculate_boosted_stats();
}
/// Calculates the boosted stats on the Pokemon. This should be called when a stat boost changes.
/// Calculates the boosted stats on the Pokemon, _without_ recalculating the flat stats.
/// This should be called when a stat boost changes.
pub fn recalculate_boosted_stats(&self) {
self.library
.stat_calculator()
@@ -516,7 +517,7 @@ impl Pokemon {
let ability_script = self
.library
.load_script((&*self).into(), ScriptCategory::Ability, self.active_ability().name())
.load_script(self.into(), ScriptCategory::Ability, self.active_ability().name())
.unwrap();
if let Some(ability_script) = ability_script {
self.ability_script
@@ -614,7 +615,7 @@ impl Pokemon {
}
}
/// Damages the Pokemon by a certain amount of damage, from a specific damage source.
/// Damages the Pokemon by a certain amount of damage, from a damage source.
pub fn damage(&self, mut damage: u32, source: DamageSource) {
if damage > self.current_health() {
damage = self.current_health();
@@ -820,7 +821,7 @@ pub mod test {
fn construct_pokemon() {
let lib = Arc::new(crate::dynamic_data::libraries::dynamic_library::test::build());
let species = lib.static_data().species().get(&"foo".into()).unwrap().clone();
let form = species.get_form(&"default".into()).unwrap().clone();
let form = species.get_form(&"default".into()).unwrap();
let pokemon = Pokemon::new(
lib,

View File

@@ -47,7 +47,7 @@ impl PokemonBuilder {
};
let species = self.library.static_data().species().get(&self.species).unwrap().clone();
let form = species.get_default_form().clone();
let form = species.get_default_form();
let p = Pokemon::new(
self.library,
species,

View File

@@ -93,11 +93,9 @@ impl PokemonParty {
/// Checks if the party contains a given pokemon.
pub fn has_pokemon(&self, pokemon: &Pokemon) -> bool {
for p in &self.pokemon {
if let Some(p) = p {
if std::ptr::eq(p.as_ref(), pokemon) {
return true;
}
for p in self.pokemon.iter().flatten() {
if std::ptr::eq(p.as_ref(), pokemon) {
return true;
}
}
false

View File

@@ -239,7 +239,7 @@ mod tests {
impl TestScript {
fn new() -> Self {
Self {
name: StringKey::new("test".into()),
name: "test".into(),
is_marked_for_deletion: Default::default(),
suppressed_count: AtomicUsize::new(0),
test_count: AtomicUsize::new(0),
@@ -247,7 +247,7 @@ mod tests {
}
fn new_with_name(name: &str) -> Self {
Self {
name: StringKey::new(name.into()),
name: name.into(),
is_marked_for_deletion: Default::default(),
suppressed_count: AtomicUsize::new(0),
test_count: AtomicUsize::new(0),
@@ -424,7 +424,7 @@ mod tests {
"test_b"
);
set.remove(&StringKey::new("test_c".into()));
set.remove(&"test_c".into());
assert!(aggregator.get_next().is_none());
}
@@ -451,7 +451,7 @@ mod tests {
"test_a"
);
set.remove(&StringKey::new("test_b".into()));
set.remove(&"test_b".into());
assert_eq!(
aggregator

View File

@@ -398,7 +398,7 @@ mod tests {
impl TestScript {
fn new() -> Self {
Self {
name: StringKey::new("test".into()),
name: "test".into(),
container: AtomicPtr::<ScriptContainer>::default(),
suppressed_count: AtomicUsize::new(0),
marked_for_deletion: Default::default(),
@@ -537,10 +537,7 @@ mod tests {
h.join().unwrap();
}
assert_eq!(
container.script.read().as_ref().unwrap().name(),
&StringKey::new("script2".into())
);
assert_eq!(container.script.read().as_ref().unwrap().name(), &"script2".into());
}
}
@@ -556,20 +553,20 @@ pub enum ScriptOwnerData {
None,
}
impl Into<ScriptOwnerData> for &Pokemon {
fn into(self) -> ScriptOwnerData {
ScriptOwnerData::Pokemon(AtomicPtr::new(self as *const Pokemon as *mut Pokemon))
impl From<&Pokemon> for ScriptOwnerData {
fn from(p: &Pokemon) -> Self {
ScriptOwnerData::Pokemon(AtomicPtr::new(p as *const Pokemon as *mut Pokemon))
}
}
impl Into<ScriptOwnerData> for &BattleSide {
fn into(self) -> ScriptOwnerData {
ScriptOwnerData::BattleSide(AtomicPtr::new(self as *const BattleSide as *mut BattleSide))
impl From<&BattleSide> for ScriptOwnerData {
fn from(p: &BattleSide) -> Self {
ScriptOwnerData::BattleSide(AtomicPtr::new(p as *const BattleSide as *mut BattleSide))
}
}
impl Into<ScriptOwnerData> for &Battle {
fn into(self) -> ScriptOwnerData {
ScriptOwnerData::Battle(AtomicPtr::new(self as *const Battle as *mut Battle))
impl From<&Battle> for ScriptOwnerData {
fn from(p: &Battle) -> Self {
ScriptOwnerData::Battle(AtomicPtr::new(p as *const Battle as *mut Battle))
}
}