Minor cleanup
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2023-01-05 12:59:17 +01:00
parent 417b776a83
commit c1da29bdeb
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 30 additions and 30 deletions

View File

@ -56,7 +56,7 @@ mod implementation {
struct ExecutingMoveInner { struct ExecutingMoveInner {
reference: ExternRef<ExecutingMoveImpl>, reference: ExternRef<ExecutingMoveImpl>,
number_of_hits: CachedValue<u8>, number_of_hits: CachedValue<u8>,
user: CachedValue<PokemonImpl>, user: CachedValue<Pokemon>,
chosen_move: CachedValue<LearnedMove>, chosen_move: CachedValue<LearnedMove>,
use_move: CachedValue<MoveData>, use_move: CachedValue<MoveData>,
} }
@ -73,7 +73,7 @@ mod implementation {
executing_move_get_number_of_hits(reference) executing_move_get_number_of_hits(reference)
}), }),
user: cached_value!({ user: cached_value!({
executing_move_get_user(reference).get_value().unwrap() Rc::new(executing_move_get_user(reference).get_value().unwrap())
}), }),
chosen_move: cached_value!({ chosen_move: cached_value!({
executing_move_get_chosen_move(reference) executing_move_get_chosen_move(reference)
@ -95,7 +95,7 @@ mod implementation {
self.inner.value().number_of_hits.value() self.inner.value().number_of_hits.value()
} }
fn user(&self) -> Pokemon { fn user(&self) -> Pokemon {
Rc::new(self.inner.value().user.value()) self.inner.value().user.value()
} }
fn chosen_move(&self) -> LearnedMove { fn chosen_move(&self) -> LearnedMove {
self.inner.value().chosen_move.value() self.inner.value().chosen_move.value()

View File

@ -55,7 +55,7 @@ pub trait PokemonTrait: WithVolatile {
fn has_type_by_name(&self, type_name: &str) -> bool; fn has_type_by_name(&self, type_name: &str) -> bool;
fn get_learned_move(&self, index: usize) -> Option<LearnedMove>; fn get_learned_move(&self, index: usize) -> Option<LearnedMove>;
fn change_stat_boost(&self, stat: Statistic, diff_amount: i8, self_inflicted: bool) -> bool; fn change_stat_boost(&self, stat: Statistic, diff_amount: i8, self_inflicted: bool) -> bool;
fn ability_script<'a>(&'a self) -> Option<&'a Box<dyn Script>>; fn ability_script(&self) -> Option<&Box<dyn Script>>;
fn change_species(&self, species: Species, form: Form); fn change_species(&self, species: Species, form: Form);
fn change_form(&self, form: Form); fn change_form(&self, form: Form);
fn is_fainted(&self) -> bool; fn is_fainted(&self) -> bool;
@ -131,6 +131,24 @@ mod implementation {
fn effort_values(&self) -> ClampedStatisticSet<u8>; fn effort_values(&self) -> ClampedStatisticSet<u8>;
} }
fn active_ability(&self) -> Ability {
unsafe {
let implementation = pokemon_get_active_ability(self.reference())
.get_value()
.unwrap();
Rc::new(implementation)
}
}
fn held_item(&self) -> Option<Item> {
unsafe {
let i = pokemon_get_held_item(self.inner.reference).get_value();
if let Some(i) = i {
Some(Rc::new(i))
} else {
None
}
}
}
fn battle(&self) -> Option<Battle> { fn battle(&self) -> Option<Battle> {
unsafe { unsafe {
let b = pokemon_get_battle(self.reference()).get_value(); let b = pokemon_get_battle(self.reference()).get_value();
@ -229,18 +247,6 @@ mod implementation {
pokemon_set_weight(self.reference(), weight); pokemon_set_weight(self.reference(), weight);
} }
} }
fn clear_status(&self) {
unsafe {
pokemon_clear_status(self.reference());
}
}
fn battle_side(&self) -> BattleSide {
self.battle()
.unwrap()
.sides()
.get(self.battle_side_index() as u32)
.unwrap()
}
wasm_reference_getters_funcs! { wasm_reference_getters_funcs! {
Pokemon, Pokemon,
@ -249,12 +255,9 @@ mod implementation {
fn nature(&self) -> Nature; fn nature(&self) -> Nature;
} }
fn active_ability(&self) -> Ability { fn clear_status(&self) {
unsafe { unsafe {
let implementation = pokemon_get_active_ability(self.reference()) pokemon_clear_status(self.reference());
.get_value()
.unwrap();
Rc::new(implementation)
} }
} }
@ -264,15 +267,12 @@ mod implementation {
fn display_form(&self) -> Option<Form>; fn display_form(&self) -> Option<Form>;
} }
fn held_item(&self) -> Option<Item> { fn battle_side(&self) -> BattleSide {
unsafe { self.battle()
let i = pokemon_get_held_item(self.inner.reference).get_value(); .unwrap()
if let Some(i) = i { .sides()
Some(Rc::new(i)) .get(self.battle_side_index() as u32)
} else { .unwrap()
None
}
}
} }
#[cfg(not(feature = "mock_data"))] #[cfg(not(feature = "mock_data"))]