Adds attract
This commit is contained in:
@@ -7,7 +7,8 @@ use crate::handling::cached_value::CachedValue;
|
||||
use crate::handling::Cacheable;
|
||||
use crate::{
|
||||
cached_value, cached_value_getters, wasm_optional_reference_getters, wasm_reference_getters,
|
||||
wasm_value_getters, DynamicLibrary, ExternRef, ExternalReferenceType, Script, TypeIdentifier,
|
||||
wasm_value_getters, DynamicLibrary, ExternRef, ExternalReferenceType, Script, ScriptPtr,
|
||||
TypeIdentifier,
|
||||
};
|
||||
use alloc::boxed::Box;
|
||||
use alloc::rc::Rc;
|
||||
@@ -178,6 +179,49 @@ impl Pokemon {
|
||||
.get(self.battle_side_index() as u32)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "mock_data"))]
|
||||
pub fn add_volatile(&self, script: Box<dyn Script>) -> &dyn Script {
|
||||
unsafe {
|
||||
pokemon_add_volatile(self.inner.reference, ScriptPtr::new(script))
|
||||
.val()
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "mock_data"))]
|
||||
pub fn add_volatile_by_name(&self, script_name: &str) -> &dyn Script {
|
||||
unsafe {
|
||||
let ptr = CString::new(script_name).unwrap();
|
||||
pokemon_add_volatile_by_name(self.inner.reference, ptr.into_raw())
|
||||
.val()
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "mock_data"))]
|
||||
pub fn remove_volatile(&self, script: &dyn Script) {
|
||||
unsafe {
|
||||
let name = CString::new(script.get_name()).unwrap();
|
||||
pokemon_remove_volatile(self.inner.reference, name.into_raw());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "mock_data"))]
|
||||
pub fn get_volatile<T>(&self, script_name: &str) -> Option<&T>
|
||||
where
|
||||
T: Script + 'static,
|
||||
{
|
||||
unsafe {
|
||||
let script_name = CString::new(script_name).unwrap();
|
||||
let s = pokemon_get_volatile(self.inner.reference, script_name.into_raw()).val();
|
||||
if let Some(s) = s {
|
||||
Some(s.as_any().downcast_ref().unwrap())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "mock_data"))]
|
||||
@@ -275,6 +319,12 @@ extern "wasm" {
|
||||
fn pokemon_change_form(r: ExternRef<Pokemon>, form: ExternRef<Form>);
|
||||
fn pokemon_damage(r: ExternRef<Pokemon>, damage: u32, source: DamageSource);
|
||||
fn pokemon_heal(r: ExternRef<Pokemon>, amount: u32, allow_revive: bool) -> bool;
|
||||
|
||||
fn pokemon_add_volatile_by_name(r: ExternRef<Pokemon>, name: *const c_char) -> ScriptPtr;
|
||||
fn pokemon_add_volatile(r: ExternRef<Pokemon>, script: ScriptPtr) -> ScriptPtr;
|
||||
fn pokemon_has_volatile(r: ExternRef<Pokemon>, name: *const c_char) -> bool;
|
||||
fn pokemon_remove_volatile(r: ExternRef<Pokemon>, name: *const c_char);
|
||||
fn pokemon_get_volatile(r: ExternRef<Pokemon>, name: *const c_char) -> ScriptPtr;
|
||||
}
|
||||
|
||||
#[cfg(feature = "mock_data")]
|
||||
|
||||
@@ -10,6 +10,7 @@ use alloc::vec::Vec;
|
||||
use spin::RwLock;
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Eq, PartialEq)]
|
||||
pub enum Gender {
|
||||
Male = 0,
|
||||
Female = 1,
|
||||
|
||||
Reference in New Issue
Block a user