Adds assist and assurance, fixes

This commit is contained in:
2022-09-09 20:09:56 +02:00
parent 05430c5e84
commit 365bdc8aec
57 changed files with 533 additions and 95 deletions

View File

@@ -50,6 +50,12 @@ impl Battle {
pub fn get_pokemon(&self, side: u8, index: u8) -> Option<Pokemon> {
unsafe { battle_get_pokemon(self.inner.reference, side, index).get_value() }
}
pub fn find_party_for_pokemon(&self, pokemon: &Pokemon) -> Option<BattleParty> {
unsafe {
battle_find_party_for_pokemon(self.inner.reference, pokemon.reference()).get_value()
}
}
}
wasm_value_getters! {
@@ -80,4 +86,8 @@ extern "wasm" {
fn battle_get_random(r: ExternRef<Battle>) -> ExternRef<BattleRandom>;
fn battle_get_choice_queue(r: ExternRef<Battle>) -> ExternRef<ChoiceQueue>;
fn battle_get_pokemon(r: ExternRef<Battle>, side: u8, index: u8) -> ExternRef<Pokemon>;
fn battle_find_party_for_pokemon(
r: ExternRef<Battle>,
mon: ExternRef<Pokemon>,
) -> ExternRef<BattleParty>;
}

View File

View File

View File

@@ -1,10 +1,13 @@
use crate::app_interface::{Battle, Pokemon};
use crate::handling::cacheable::Cacheable;
use crate::handling::cached_value::CachedValue;
use crate::handling::Cacheable;
use crate::{
cached_value, cached_value_getters, wasm_value_getters, ExternRef, ExternalReferenceType,
Script, ScriptPtr,
};
use alloc::boxed::Box;
use alloc::rc::Rc;
use cstr_core::{c_char, CString};
struct BattleSideInner {
reference: ExternRef<BattleSide>,
@@ -41,6 +44,39 @@ impl BattleSide {
pub fn get_pokemon(&self, index: usize) -> Option<Pokemon> {
unsafe { battleside_get_pokemon(self.inner.reference, index).get_value() }
}
#[cfg(not(feature = "mock_data"))]
pub fn add_volatile(&self, script: Box<dyn Script>) -> &dyn Script {
unsafe {
battleside_add_volatile(self.inner.reference, ScriptPtr::new(script))
.val()
.unwrap()
}
}
#[cfg(not(feature = "mock_data"))]
pub fn remove_volatile(&self, script: &dyn Script) {
unsafe {
let name = CString::new(script.get_name()).unwrap();
battleside_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 = battleside_get_volatile(self.inner.reference, script_name.into_raw()).val();
if let Some(s) = s {
Some(s.as_any().downcast_ref().unwrap())
} else {
None
}
}
}
}
wasm_value_getters! {
@@ -64,4 +100,10 @@ extern "wasm" {
fn battleside_get_pokemon_per_side(r: ExternRef<BattleSide>) -> u8;
fn battleside_get_battle(r: ExternRef<BattleSide>) -> ExternRef<Battle>;
fn battleside_get_pokemon(r: ExternRef<BattleSide>, index: usize) -> ExternRef<Pokemon>;
fn battleside_add_volatile_by_name(r: ExternRef<BattleSide>, name: *const c_char) -> ScriptPtr;
fn battleside_add_volatile(r: ExternRef<BattleSide>, script: ScriptPtr) -> ScriptPtr;
fn battleside_has_volatile(r: ExternRef<BattleSide>, name: *const c_char) -> bool;
fn battleside_remove_volatile(r: ExternRef<BattleSide>, name: *const c_char);
fn battleside_get_volatile(r: ExternRef<BattleSide>, name: *const c_char) -> ScriptPtr;
}

View File

View File

View File

View File

View File

View File

@@ -15,6 +15,10 @@ impl Party {
pub fn get_pokemon(&self, index: usize) -> Option<Pokemon> {
unsafe { party_get_pokemon(self.reference, index).get_value() }
}
pub fn length(&self) -> usize {
unsafe { party_get_length(self.reference) }
}
}
impl ExternalReferenceType for Party {
@@ -26,4 +30,5 @@ impl ExternalReferenceType for Party {
#[cfg(not(feature = "mock_data"))]
extern "wasm" {
fn party_get_pokemon(r: ExternRef<Party>, index: usize) -> ExternRef<Pokemon>;
fn party_get_length(r: ExternRef<Party>) -> usize;
}

View File

@@ -1,7 +1,7 @@
use crate::app_interface::ability::{Ability, AbilityIndex};
use crate::app_interface::{
Battle, ClampedStatisticSet, Form, Gender, Item, LearnedMove, LevelInt, Nature, Species,
Statistic, StatisticSet,
Battle, BattleSide, ClampedStatisticSet, Form, Gender, Item, LearnedMove, LevelInt, Nature,
Species, Statistic, StatisticSet,
};
use crate::handling::cached_value::CachedValue;
use crate::handling::Cacheable;
@@ -169,6 +169,15 @@ impl Pokemon {
pub fn heal(&self, amount: u32, allow_revive: bool) -> bool {
unsafe { pokemon_heal(self.inner.reference, amount, allow_revive) }
}
#[cfg(not(feature = "mock_data"))]
pub fn battle_side(&self) -> BattleSide {
self.battle()
.unwrap()
.sides()
.get(self.battle_side_index() as u32)
.unwrap()
}
}
#[cfg(not(feature = "mock_data"))]

View File

View File

0
pkmn_lib_interface/src/app_interface/list.rs Normal file → Executable file
View File

0
pkmn_lib_interface/src/app_interface/mod.rs Normal file → Executable file
View File

View File

View File

View File

View File

View File

View File

View File

View File

0
pkmn_lib_interface/src/app_interface/string_key.rs Normal file → Executable file
View File