Rename unique_identifier --> personality_value, minor fixes
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-07-09 11:17:43 +02:00
parent bc9b3ed964
commit f6df95a824
8 changed files with 70 additions and 46 deletions

View File

@@ -50,8 +50,8 @@ struct PokemonData {
level: Atomic<LevelInt>,
/// The amount of experience of the Pokemon.
experience: AtomicU32,
/// A unique random number for this Pokemon.
unique_identifier: u32,
/// The personality value of the Pokemon.
personality_value: u32,
/// The gender of the Pokemon.
gender: RwLock<Gender>,
@@ -171,7 +171,7 @@ impl Pokemon {
display_form: None,
level: Atomic::new(level),
experience: AtomicU32::new(experience),
unique_identifier,
personality_value: unique_identifier,
gender: RwLock::new(gender),
coloring,
held_item: RwLock::new(None),
@@ -239,16 +239,19 @@ impl Pokemon {
}
}
/// The current level of the Pokemon.
/// [See also](https://bulbapedia.bulbagarden.net/wiki/Level)
pub fn level(&self) -> LevelInt {
self.data.level.load(Ordering::Relaxed)
}
/// The amount of experience of the Pokemon.
/// [See also](https://bulbapedia.bulbagarden.net/wiki/Experience)
pub fn experience(&self) -> u32 {
self.data.experience.load(Ordering::Relaxed)
}
/// A unique random number for this Pokemon.
pub fn unique_identifier(&self) -> u32 {
self.data.unique_identifier
/// The personality value of the Pokemon.
/// [See also](https://bulbapedia.bulbagarden.net/wiki/Personality_value)
pub fn personality_value(&self) -> u32 {
self.data.personality_value
}
/// The gender of the Pokemon.
pub fn gender(&self) -> Gender {

View File

@@ -3,7 +3,7 @@ use parking_lot::lock_api::RwLockReadGuard;
use parking_lot::{RawRwLock, RwLock};
use crate::dynamic_data::models::pokemon::Pokemon;
use crate::VecExt;
use crate::{PkmnError, VecExt};
/// A list of Pokemon belonging to a trainer.
#[derive(Debug)]
@@ -43,8 +43,18 @@ impl PokemonParty {
}
/// Swaps two Pokemon in the party around.
pub fn switch(&self, a: usize, b: usize) {
pub fn switch(&self, a: usize, b: usize) -> Result<()> {
let write_lock = self.pokemon.write();
if a >= write_lock.len() || b >= write_lock.len() {
return Err(PkmnError::IndexOutOfBounds {
index: if a >= write_lock.len() { a } else { b },
len: write_lock.len(),
}
.into());
}
self.pokemon.write().swap(a, b);
Ok(())
}
/// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon.

View File

@@ -76,21 +76,24 @@ extern "C" fn pokemon_display_form(handle: FFIHandle<Pokemon>) -> FFIHandle<Arc<
}
/// The level of the Pokemon.
/// [See also](https://bulbapedia.bulbagarden.net/wiki/Level)
#[no_mangle]
extern "C" fn pokemon_level(handle: FFIHandle<Pokemon>) -> LevelInt {
handle.from_ffi_handle().level()
}
/// The experience of the Pokemon.
/// [See also](https://bulbapedia.bulbagarden.net/wiki/Experience)
#[no_mangle]
extern "C" fn pokemon_experience(handle: FFIHandle<Pokemon>) -> u32 {
handle.from_ffi_handle().experience()
}
/// The unique identifier of the Pokemon.
/// The personality value of the Pokemon.
/// [See also](https://bulbapedia.bulbagarden.net/wiki/Personality_value)
#[no_mangle]
extern "C" fn pokemon_unique_identifier(handle: FFIHandle<Pokemon>) -> u32 {
handle.from_ffi_handle().unique_identifier()
extern "C" fn pokemon_personality_value(handle: FFIHandle<Pokemon>) -> u32 {
handle.from_ffi_handle().personality_value()
}
/// The gender of the Pokemon.

View File

@@ -19,10 +19,10 @@ extern "C" fn pokemon_party_at(ptr: FFIHandle<Arc<PokemonParty>>, index: usize)
}
}
/// Gets a Pokemon at an index in the party.
/// Swaps two Pokemon in the party around.
#[no_mangle]
extern "C" fn pokemon_party_switch(ptr: FFIHandle<Arc<PokemonParty>>, a: usize, b: usize) {
ptr.from_ffi_handle().switch(a, b);
extern "C" fn pokemon_party_switch(ptr: FFIHandle<Arc<PokemonParty>>, a: usize, b: usize) -> FFIResult<()> {
ptr.from_ffi_handle().switch(a, b).into()
}
/// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon.

View File

@@ -448,11 +448,11 @@ register! {
wasm_ok(get_value_call_getter!(pokemon.experience(), env))
}
fn pokemon_get_unique_identifier(
fn pokemon_get_personality_value(
env: FunctionEnvMut<WebAssemblyEnv>,
pokemon: ExternRef<Pokemon>,
) -> WasmResult<u32> {
wasm_ok(get_value_call_getter!(pokemon.unique_identifier(), env))
wasm_ok(get_value_call_getter!(pokemon.personality_value(), env))
}
fn pokemon_get_coloring(