A lot of cleanup work
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
c1da29bdeb
commit
d4c30d50aa
|
@ -1,5 +1,4 @@
|
||||||
use crate::script;
|
use crate::script;
|
||||||
use alloc::boxed::Box;
|
|
||||||
use core::any::Any;
|
use core::any::Any;
|
||||||
use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon};
|
use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon};
|
||||||
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use alloc::boxed::Box;
|
|
||||||
use core::any::Any;
|
use core::any::Any;
|
||||||
use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon};
|
use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon};
|
||||||
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||||
|
|
|
@ -3,7 +3,7 @@ use alloc::boxed::Box;
|
||||||
use core::any::Any;
|
use core::any::Any;
|
||||||
use core::sync::atomic::{AtomicBool, Ordering};
|
use core::sync::atomic::{AtomicBool, Ordering};
|
||||||
use pkmn_lib_interface::app_interface::{
|
use pkmn_lib_interface::app_interface::{
|
||||||
BattleSide, DamageSource, DataLibrary, ExecutingMove, Pokemon, TurnChoice, WithVolatile,
|
BattleSide, DamageSource, ExecutingMove, Pokemon, TurnChoice, WithVolatile,
|
||||||
};
|
};
|
||||||
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,7 @@ use crate::weather::hail::Hail;
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use core::any::Any;
|
use core::any::Any;
|
||||||
use core::sync::atomic::{AtomicU32, Ordering};
|
use core::sync::atomic::{AtomicU32, Ordering};
|
||||||
use pkmn_lib_interface::app_interface::{
|
use pkmn_lib_interface::app_interface::{ExecutingMove, MoveCategory, Pokemon, WithVolatile};
|
||||||
BattleSide, ExecutingMove, MoveCategory, Pokemon, WithVolatile,
|
|
||||||
};
|
|
||||||
use pkmn_lib_interface::handling::ScriptCapabilities::OnEndTurn;
|
use pkmn_lib_interface::handling::ScriptCapabilities::OnEndTurn;
|
||||||
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::script;
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
use core::any::Any;
|
use core::any::Any;
|
||||||
use core::sync::atomic::{AtomicI8, Ordering};
|
use core::sync::atomic::{AtomicI8, Ordering};
|
||||||
use pkmn_lib_interface::app_interface::list::{ImmutableList, ImmutableListTrait};
|
use pkmn_lib_interface::app_interface::list::ImmutableList;
|
||||||
use pkmn_lib_interface::app_interface::{
|
use pkmn_lib_interface::app_interface::{
|
||||||
DynamicLibrary, EffectParameter, ExecutingMove, Pokemon, Statistic,
|
DynamicLibrary, EffectParameter, ExecutingMove, Pokemon, Statistic,
|
||||||
};
|
};
|
||||||
|
@ -34,7 +34,7 @@ impl Script for ChangeAllTargetStats {
|
||||||
|
|
||||||
fn on_initialize(
|
fn on_initialize(
|
||||||
&self,
|
&self,
|
||||||
_library: &DynamicLibrary,
|
_library: DynamicLibrary,
|
||||||
parameters: Option<ImmutableList<Rc<EffectParameter>>>,
|
parameters: Option<ImmutableList<Rc<EffectParameter>>>,
|
||||||
) {
|
) {
|
||||||
self.amount.store(
|
self.amount.store(
|
||||||
|
|
|
@ -42,7 +42,7 @@ macro_rules! change_stat_effect {
|
||||||
|
|
||||||
fn on_initialize(
|
fn on_initialize(
|
||||||
&self,
|
&self,
|
||||||
_library: &DynamicLibrary,
|
_library: DynamicLibrary,
|
||||||
parameters: Option<ImmutableList<Rc<EffectParameter>>>,
|
parameters: Option<ImmutableList<Rc<EffectParameter>>>,
|
||||||
) {
|
) {
|
||||||
self.amount.store(
|
self.amount.store(
|
||||||
|
|
|
@ -3,7 +3,7 @@ use alloc::rc::Rc;
|
||||||
use atomic_float::AtomicF32;
|
use atomic_float::AtomicF32;
|
||||||
use core::any::Any;
|
use core::any::Any;
|
||||||
use core::sync::atomic::Ordering;
|
use core::sync::atomic::Ordering;
|
||||||
use pkmn_lib_interface::app_interface::list::{ImmutableList, ImmutableListTrait};
|
use pkmn_lib_interface::app_interface::list::ImmutableList;
|
||||||
use pkmn_lib_interface::app_interface::{DynamicLibrary, EffectParameter, ExecutingMove, Pokemon};
|
use pkmn_lib_interface::app_interface::{DynamicLibrary, EffectParameter, ExecutingMove, Pokemon};
|
||||||
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ impl Script for Drain {
|
||||||
|
|
||||||
fn on_initialize(
|
fn on_initialize(
|
||||||
&self,
|
&self,
|
||||||
_library: &DynamicLibrary,
|
_library: DynamicLibrary,
|
||||||
parameters: Option<ImmutableList<Rc<EffectParameter>>>,
|
parameters: Option<ImmutableList<Rc<EffectParameter>>>,
|
||||||
) {
|
) {
|
||||||
self.heal_modifier.store(
|
self.heal_modifier.store(
|
||||||
|
|
|
@ -2,8 +2,7 @@ use alloc::rc::Rc;
|
||||||
|
|
||||||
use crate::app_interface::list::ImmutableList;
|
use crate::app_interface::list::ImmutableList;
|
||||||
use crate::app_interface::{
|
use crate::app_interface::{
|
||||||
BattleParty, BattlePartyImpl, BattleRandom, BattleSide, ChoiceQueue, DynamicLibrary, Pokemon,
|
BattleParty, BattleRandom, BattleSide, ChoiceQueue, DynamicLibrary, Pokemon, StringKey,
|
||||||
StringKey,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg_attr(feature = "mock_data", mockall::automock)]
|
#[cfg_attr(feature = "mock_data", mockall::automock)]
|
||||||
|
@ -33,6 +32,7 @@ pub type MockBattle = MockBattleTrait;
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
mod implementation {
|
mod implementation {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::app_interface::dynamic_data::dynamic_library::DynamicLibraryImpl;
|
||||||
use crate::app_interface::list::{
|
use crate::app_interface::list::{
|
||||||
BattlePartyImmutableList, BattleSideImmutableList, ImmutableListWasm,
|
BattlePartyImmutableList, BattleSideImmutableList, ImmutableListWasm,
|
||||||
};
|
};
|
||||||
|
@ -44,8 +44,8 @@ mod implementation {
|
||||||
use crate::handling::cached_value::CachedValue;
|
use crate::handling::cached_value::CachedValue;
|
||||||
use crate::handling::Cacheable;
|
use crate::handling::Cacheable;
|
||||||
use crate::{
|
use crate::{
|
||||||
cached_value, cached_value_getters, wasm_value_getters, wasm_value_getters_extern,
|
cached_value, cached_value_getters, wasm_value_getters_extern, wasm_value_getters_funcs,
|
||||||
wasm_value_getters_funcs, ExternRef, ExternalReferenceType, StringKey, VecExternRef,
|
ExternRef, ExternalReferenceType, StringKey, VecExternRef,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BattleInner {
|
struct BattleInner {
|
||||||
|
@ -68,7 +68,9 @@ mod implementation {
|
||||||
Self::from_ref(reference, &|reference| Self {
|
Self::from_ref(reference, &|reference| Self {
|
||||||
inner: Rc::new(BattleInner {
|
inner: Rc::new(BattleInner {
|
||||||
reference,
|
reference,
|
||||||
library: cached_value!({ battle_get_library(reference).get_value().unwrap() }),
|
library: cached_value!({
|
||||||
|
Rc::new(battle_get_library(reference).get_value().unwrap())
|
||||||
|
}),
|
||||||
parties: cached_value!({
|
parties: cached_value!({
|
||||||
let reference = battle_get_parties(reference);
|
let reference = battle_get_parties(reference);
|
||||||
Rc::new(BattlePartyImmutableList::from_ref(reference))
|
Rc::new(BattlePartyImmutableList::from_ref(reference))
|
||||||
|
@ -168,7 +170,7 @@ mod implementation {
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
extern "wasm" {
|
extern "wasm" {
|
||||||
fn battle_get_library(r: ExternRef<BattleImpl>) -> ExternRef<DynamicLibrary>;
|
fn battle_get_library(r: ExternRef<BattleImpl>) -> ExternRef<DynamicLibraryImpl>;
|
||||||
fn battle_get_parties(r: ExternRef<BattleImpl>) -> VecExternRef<BattlePartyImpl>;
|
fn battle_get_parties(r: ExternRef<BattleImpl>) -> VecExternRef<BattlePartyImpl>;
|
||||||
fn battle_get_sides(r: ExternRef<BattleImpl>) -> VecExternRef<BattleSideImpl>;
|
fn battle_get_sides(r: ExternRef<BattleImpl>) -> VecExternRef<BattleSideImpl>;
|
||||||
fn battle_get_random(r: ExternRef<BattleImpl>) -> ExternRef<BattleRandomImpl>;
|
fn battle_get_random(r: ExternRef<BattleImpl>) -> ExternRef<BattleRandomImpl>;
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
use crate::app_interface::{Party, PartyImpl};
|
use crate::app_interface::Party;
|
||||||
use crate::handling::cached_value::CachedValue;
|
|
||||||
use crate::handling::Cacheable;
|
|
||||||
use crate::{cached_value, cached_value_getters, ExternRef, ExternalReferenceType};
|
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
|
|
||||||
pub trait BattlePartyTrait {
|
pub trait BattlePartyTrait {
|
||||||
|
@ -10,6 +7,15 @@ pub trait BattlePartyTrait {
|
||||||
|
|
||||||
pub type BattleParty = Rc<dyn BattlePartyTrait>;
|
pub type BattleParty = Rc<dyn BattlePartyTrait>;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
mod implementation {
|
||||||
|
use crate::app_interface::{BattlePartyTrait, Party, PartyImpl};
|
||||||
|
use crate::handling::cached_value::CachedValue;
|
||||||
|
use crate::handling::extern_ref::{ExternRef, ExternalReferenceType};
|
||||||
|
use crate::handling::Cacheable;
|
||||||
|
use crate::{cached_value, cached_value_getters};
|
||||||
|
use alloc::rc::Rc;
|
||||||
|
|
||||||
struct BattlePartyInner {
|
struct BattlePartyInner {
|
||||||
reference: ExternRef<BattlePartyImpl>,
|
reference: ExternRef<BattlePartyImpl>,
|
||||||
party: CachedValue<Rc<PartyImpl>>,
|
party: CachedValue<Rc<PartyImpl>>,
|
||||||
|
@ -20,7 +26,6 @@ pub struct BattlePartyImpl {
|
||||||
inner: Rc<BattlePartyInner>,
|
inner: Rc<BattlePartyInner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
impl BattlePartyImpl {
|
impl BattlePartyImpl {
|
||||||
pub fn new(reference: ExternRef<BattlePartyImpl>) -> Self {
|
pub fn new(reference: ExternRef<BattlePartyImpl>) -> Self {
|
||||||
Self::from_ref(reference, &|reference| Self {
|
Self::from_ref(reference, &|reference| Self {
|
||||||
|
@ -34,7 +39,6 @@ impl BattlePartyImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
impl BattlePartyTrait for BattlePartyImpl {
|
impl BattlePartyTrait for BattlePartyImpl {
|
||||||
cached_value_getters! {
|
cached_value_getters! {
|
||||||
fn party(&self) -> Party;
|
fn party(&self) -> Party;
|
||||||
|
@ -54,3 +58,7 @@ impl ExternalReferenceType for BattlePartyImpl {
|
||||||
extern "wasm" {
|
extern "wasm" {
|
||||||
fn battle_party_get_party(r: ExternRef<BattlePartyImpl>) -> ExternRef<PartyImpl>;
|
fn battle_party_get_party(r: ExternRef<BattlePartyImpl>) -> ExternRef<PartyImpl>;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
pub use implementation::*;
|
||||||
|
|
|
@ -1,57 +1,66 @@
|
||||||
use crate::app_interface::StaticData;
|
use crate::app_interface::StaticData;
|
||||||
|
use alloc::rc::Rc;
|
||||||
|
|
||||||
|
pub trait DynamicLibraryTrait {
|
||||||
|
fn data_library(&self) -> StaticData;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type DynamicLibrary = Rc<dyn DynamicLibraryTrait>;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
mod implementation {
|
||||||
|
use super::*;
|
||||||
|
use crate::app_interface::dynamic_data::dynamic_library::DynamicLibraryTrait;
|
||||||
|
use crate::app_interface::StaticDataImpl;
|
||||||
|
use crate::cached_value;
|
||||||
use crate::handling::cached_value::CachedValue;
|
use crate::handling::cached_value::CachedValue;
|
||||||
|
use crate::handling::extern_ref::{ExternRef, ExternalReferenceType};
|
||||||
use crate::handling::Cacheable;
|
use crate::handling::Cacheable;
|
||||||
use crate::{cached_value, ExternRef, ExternalReferenceType};
|
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
|
|
||||||
struct DynamicLibraryInner {
|
struct DynamicLibraryInner {
|
||||||
ptr: ExternRef<DynamicLibrary>,
|
ptr: ExternRef<DynamicLibraryImpl>,
|
||||||
static_data: CachedValue<StaticData>,
|
static_data: CachedValue<StaticData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct DynamicLibrary {
|
pub struct DynamicLibraryImpl {
|
||||||
inner: Rc<DynamicLibraryInner>,
|
inner: Rc<DynamicLibraryInner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::handling::cacheable::cacheable!(DynamicLibrary);
|
crate::handling::cacheable::cacheable!(DynamicLibraryImpl);
|
||||||
|
|
||||||
impl DynamicLibrary {
|
impl DynamicLibraryImpl {
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
pub(crate) fn new(ptr: ExternRef<Self>) -> Self {
|
pub(crate) fn new(ptr: ExternRef<Self>) -> Self {
|
||||||
Self::from_ref(ptr, &|ptr| Self {
|
Self::from_ref(ptr, &|ptr| Self {
|
||||||
inner: Rc::new(DynamicLibraryInner {
|
inner: Rc::new(DynamicLibraryInner {
|
||||||
ptr,
|
ptr,
|
||||||
static_data: cached_value!({
|
static_data: cached_value!({
|
||||||
dynamic_library_get_static_data(ptr).get_value().unwrap()
|
Rc::new(dynamic_library_get_static_data(ptr).get_value().unwrap())
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "mock_data")]
|
|
||||||
pub fn new(data: StaticData) -> Self {
|
|
||||||
Self {
|
|
||||||
inner: Rc::new(DynamicLibraryInner {
|
|
||||||
ptr: ExternRef::mock(),
|
|
||||||
static_data: data.into(),
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn data_library(&self) -> StaticData {
|
impl DynamicLibraryTrait for DynamicLibraryImpl {
|
||||||
|
fn data_library(&self) -> StaticData {
|
||||||
self.inner.static_data.value()
|
self.inner.static_data.value()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
impl ExternalReferenceType for DynamicLibraryImpl {
|
||||||
impl ExternalReferenceType for DynamicLibrary {
|
|
||||||
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
||||||
DynamicLibrary::new(reference)
|
DynamicLibraryImpl::new(reference)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "wasm" {
|
||||||
|
fn dynamic_library_get_static_data(
|
||||||
|
ptr: ExternRef<DynamicLibraryImpl>,
|
||||||
|
) -> ExternRef<StaticDataImpl>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
extern "wasm" {
|
pub use implementation::*;
|
||||||
fn dynamic_library_get_static_data(ptr: ExternRef<DynamicLibrary>) -> ExternRef<StaticData>;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
use crate::app_interface::PokemonImpl;
|
|
||||||
use crate::app_interface::{LearnedMove, MoveData, Pokemon};
|
use crate::app_interface::{LearnedMove, MoveData, Pokemon};
|
||||||
use crate::handling::cached_value::CachedValue;
|
use crate::handling::Script;
|
||||||
use crate::handling::temporary::Temporary;
|
|
||||||
use crate::{cached_value, ExternRef, ExternalReferenceType, Script};
|
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
|
|
||||||
#[cfg_attr(feature = "mock_data", mockall::automock)]
|
#[cfg_attr(feature = "mock_data", mockall::automock)]
|
||||||
|
@ -47,6 +43,11 @@ pub use implementation::*;
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
mod implementation {
|
mod implementation {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::app_interface::{LearnedMoveImpl, PokemonImpl};
|
||||||
|
use crate::cached_value;
|
||||||
|
use crate::handling::cached_value::CachedValue;
|
||||||
|
use crate::handling::extern_ref::{ExternRef, ExternalReferenceType};
|
||||||
|
use crate::handling::temporary::Temporary;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ExecutingMoveImpl {
|
pub struct ExecutingMoveImpl {
|
||||||
|
@ -57,7 +58,7 @@ mod implementation {
|
||||||
reference: ExternRef<ExecutingMoveImpl>,
|
reference: ExternRef<ExecutingMoveImpl>,
|
||||||
number_of_hits: CachedValue<u8>,
|
number_of_hits: CachedValue<u8>,
|
||||||
user: CachedValue<Pokemon>,
|
user: CachedValue<Pokemon>,
|
||||||
chosen_move: CachedValue<LearnedMove>,
|
chosen_move: CachedValue<Rc<LearnedMoveImpl>>,
|
||||||
use_move: CachedValue<MoveData>,
|
use_move: CachedValue<MoveData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,9 +77,11 @@ mod implementation {
|
||||||
Rc::new(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!({
|
||||||
|
Rc::new(
|
||||||
executing_move_get_chosen_move(reference)
|
executing_move_get_chosen_move(reference)
|
||||||
.get_value()
|
.get_value()
|
||||||
.unwrap()
|
.unwrap(),
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
use_move: cached_value!({
|
use_move: cached_value!({
|
||||||
executing_move_get_use_move(reference).get_value().unwrap()
|
executing_move_get_use_move(reference).get_value().unwrap()
|
||||||
|
@ -196,7 +199,7 @@ mod implementation {
|
||||||
fn executing_move_get_user(r: ExternRef<ExecutingMoveImpl>) -> ExternRef<PokemonImpl>;
|
fn executing_move_get_user(r: ExternRef<ExecutingMoveImpl>) -> ExternRef<PokemonImpl>;
|
||||||
fn executing_move_get_chosen_move(
|
fn executing_move_get_chosen_move(
|
||||||
r: ExternRef<ExecutingMoveImpl>,
|
r: ExternRef<ExecutingMoveImpl>,
|
||||||
) -> ExternRef<LearnedMove>;
|
) -> ExternRef<LearnedMoveImpl>;
|
||||||
fn executing_move_get_use_move(r: ExternRef<ExecutingMoveImpl>) -> ExternRef<MoveData>;
|
fn executing_move_get_use_move(r: ExternRef<ExecutingMoveImpl>) -> ExternRef<MoveData>;
|
||||||
#[allow(improper_ctypes)]
|
#[allow(improper_ctypes)]
|
||||||
fn executing_move_get_script(r: ExternRef<ExecutingMoveImpl>) -> *const dyn Script;
|
fn executing_move_get_script(r: ExternRef<ExecutingMoveImpl>) -> *const dyn Script;
|
||||||
|
|
|
@ -1,18 +1,6 @@
|
||||||
use crate::app_interface::MoveData;
|
use crate::app_interface::MoveData;
|
||||||
use crate::handling::cacheable::Cacheable;
|
|
||||||
use crate::handling::cached_value::CachedValue;
|
|
||||||
use crate::{
|
|
||||||
cached_value, cached_value_getters, wasm_value_getters, ExternRef, ExternalReferenceType,
|
|
||||||
};
|
|
||||||
|
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
|
|
||||||
struct LearnedMoveInner {
|
|
||||||
reference: ExternRef<LearnedMove>,
|
|
||||||
move_data: CachedValue<MoveData>,
|
|
||||||
learn_method: CachedValue<MoveLearnMethod>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Default)]
|
#[derive(Copy, Clone, Debug, Default)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum MoveLearnMethod {
|
pub enum MoveLearnMethod {
|
||||||
|
@ -23,22 +11,44 @@ pub enum MoveLearnMethod {
|
||||||
Level = 1,
|
Level = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait LearnedMoveTrait {
|
||||||
|
fn move_data(&self) -> MoveData;
|
||||||
|
fn learn_method(&self) -> MoveLearnMethod;
|
||||||
|
fn restore_all_uses(&self);
|
||||||
|
fn restore_uses(&self, uses: u8);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type LearnedMove = Rc<dyn LearnedMoveTrait>;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
mod implementation {
|
||||||
|
use super::*;
|
||||||
|
use crate::handling::cached_value::CachedValue;
|
||||||
|
use crate::handling::extern_ref::{ExternRef, ExternalReferenceType};
|
||||||
|
use crate::handling::Cacheable;
|
||||||
|
use crate::{cached_value, cached_value_getters, wasm_value_getters};
|
||||||
|
use alloc::rc::Rc;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct LearnedMove {
|
pub struct LearnedMoveImpl {
|
||||||
inner: Rc<LearnedMoveInner>,
|
inner: Rc<LearnedMoveInner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::handling::cacheable::cacheable!(LearnedMove);
|
struct LearnedMoveInner {
|
||||||
|
reference: ExternRef<LearnedMoveImpl>,
|
||||||
|
move_data: CachedValue<MoveData>,
|
||||||
|
learn_method: CachedValue<MoveLearnMethod>,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
crate::handling::cacheable::cacheable!(LearnedMoveImpl);
|
||||||
impl ExternalReferenceType for LearnedMove {
|
|
||||||
|
impl ExternalReferenceType for LearnedMoveImpl {
|
||||||
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
||||||
Self::new(reference)
|
Self::new(reference)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LearnedMove {
|
impl LearnedMoveImpl {
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
pub fn new(reference: ExternRef<Self>) -> Self {
|
pub fn new(reference: ExternRef<Self>) -> Self {
|
||||||
Self::from_ref(reference, &|reference| Self {
|
Self::from_ref(reference, &|reference| Self {
|
||||||
inner: Rc::new(LearnedMoveInner {
|
inner: Rc::new(LearnedMoveInner {
|
||||||
|
@ -50,21 +60,21 @@ impl LearnedMove {
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
cached_value_getters! {
|
|
||||||
pub fn move_data(&self) -> MoveData;
|
|
||||||
pub fn learn_method(&self) -> MoveLearnMethod;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
impl LearnedMoveTrait for LearnedMoveImpl {
|
||||||
pub fn restore_all_uses(&self) {
|
cached_value_getters! {
|
||||||
|
fn move_data(&self) -> MoveData;
|
||||||
|
fn learn_method(&self) -> MoveLearnMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn restore_all_uses(&self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
learned_move_restore_all_uses(self.inner.reference);
|
learned_move_restore_all_uses(self.inner.reference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
fn restore_uses(&self, uses: u8) {
|
||||||
pub fn restore_uses(&self, uses: u8) {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
learned_move_restore_uses(self.inner.reference, uses);
|
learned_move_restore_uses(self.inner.reference, uses);
|
||||||
}
|
}
|
||||||
|
@ -72,15 +82,18 @@ impl LearnedMove {
|
||||||
}
|
}
|
||||||
|
|
||||||
wasm_value_getters! {
|
wasm_value_getters! {
|
||||||
LearnedMove,
|
LearnedMoveImpl,
|
||||||
pub fn max_pp(&self) -> u8;
|
pub fn max_pp(&self) -> u8;
|
||||||
pub fn remaining_pp(&self) -> u8;
|
pub fn remaining_pp(&self) -> u8;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
extern "wasm" {
|
extern "wasm" {
|
||||||
fn learned_move_get_move_data(r: ExternRef<LearnedMove>) -> ExternRef<MoveData>;
|
fn learned_move_get_move_data(r: ExternRef<LearnedMoveImpl>) -> ExternRef<MoveData>;
|
||||||
fn learned_move_get_learn_method(r: ExternRef<LearnedMove>) -> MoveLearnMethod;
|
fn learned_move_get_learn_method(r: ExternRef<LearnedMoveImpl>) -> MoveLearnMethod;
|
||||||
fn learned_move_restore_uses(r: ExternRef<LearnedMove>, uses: u8);
|
fn learned_move_restore_uses(r: ExternRef<LearnedMoveImpl>, uses: u8);
|
||||||
fn learned_move_restore_all_uses(r: ExternRef<LearnedMove>);
|
fn learned_move_restore_all_uses(r: ExternRef<LearnedMoveImpl>);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
pub use implementation::*;
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub use battle_party::*;
|
||||||
pub use battle_random::*;
|
pub use battle_random::*;
|
||||||
pub use battle_side::*;
|
pub use battle_side::*;
|
||||||
pub use choice_queue::*;
|
pub use choice_queue::*;
|
||||||
pub use dynamic_library::DynamicLibrary;
|
pub use dynamic_library::*;
|
||||||
pub use executing_move::*;
|
pub use executing_move::*;
|
||||||
pub use learned_move::*;
|
pub use learned_move::*;
|
||||||
pub use party::*;
|
pub use party::*;
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
use crate::app_interface::Pokemon;
|
use crate::app_interface::Pokemon;
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
use crate::app_interface::PokemonImpl;
|
|
||||||
use crate::{ExternRef, ExternalReferenceType};
|
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
|
|
||||||
pub trait PartyTrait {
|
pub trait PartyTrait {
|
||||||
|
@ -11,19 +8,23 @@ pub trait PartyTrait {
|
||||||
|
|
||||||
pub type Party = Rc<dyn PartyTrait>;
|
pub type Party = Rc<dyn PartyTrait>;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
mod implementation {
|
||||||
|
use super::*;
|
||||||
|
use crate::app_interface::PokemonImpl;
|
||||||
|
use crate::handling::extern_ref::{ExternRef, ExternalReferenceType};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct PartyImpl {
|
pub struct PartyImpl {
|
||||||
reference: ExternRef<Self>,
|
reference: ExternRef<Self>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
impl PartyImpl {
|
impl PartyImpl {
|
||||||
pub fn new(reference: ExternRef<PartyImpl>) -> Self {
|
pub fn new(reference: ExternRef<PartyImpl>) -> Self {
|
||||||
Self { reference }
|
Self { reference }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
impl PartyTrait for PartyImpl {
|
impl PartyTrait for PartyImpl {
|
||||||
fn get_pokemon(&self, index: usize) -> Option<Pokemon> {
|
fn get_pokemon(&self, index: usize) -> Option<Pokemon> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -41,15 +42,17 @@ impl PartyTrait for PartyImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
impl ExternalReferenceType for PartyImpl {
|
impl ExternalReferenceType for PartyImpl {
|
||||||
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
||||||
Self::new(reference)
|
Self::new(reference)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
extern "wasm" {
|
extern "wasm" {
|
||||||
fn party_get_pokemon(r: ExternRef<PartyImpl>, index: usize) -> ExternRef<PokemonImpl>;
|
fn party_get_pokemon(r: ExternRef<PartyImpl>, index: usize) -> ExternRef<PokemonImpl>;
|
||||||
fn party_get_length(r: ExternRef<PartyImpl>) -> usize;
|
fn party_get_length(r: ExternRef<PartyImpl>) -> usize;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
pub use implementation::*;
|
||||||
|
|
|
@ -86,7 +86,10 @@ mod implementation {
|
||||||
use super::*;
|
use super::*;
|
||||||
use cstr_core::CString;
|
use cstr_core::CString;
|
||||||
|
|
||||||
use crate::app_interface::{AbilityImpl, BattleImpl, ItemImpl, StatisticSetImpl};
|
use crate::app_interface::dynamic_data::dynamic_library::DynamicLibraryImpl;
|
||||||
|
use crate::app_interface::{
|
||||||
|
AbilityImpl, BattleImpl, ItemImpl, LearnedMoveImpl, StatisticSetImpl,
|
||||||
|
};
|
||||||
use crate::handling::cached_value::CachedValue;
|
use crate::handling::cached_value::CachedValue;
|
||||||
use crate::handling::Cacheable;
|
use crate::handling::Cacheable;
|
||||||
use crate::implementation::ScriptPtr;
|
use crate::implementation::ScriptPtr;
|
||||||
|
@ -94,7 +97,7 @@ mod implementation {
|
||||||
cached_value, cached_value_getters, wasm_optional_reference_getters_extern,
|
cached_value, cached_value_getters, wasm_optional_reference_getters_extern,
|
||||||
wasm_optional_reference_getters_funcs, wasm_reference_getters_extern,
|
wasm_optional_reference_getters_funcs, wasm_reference_getters_extern,
|
||||||
wasm_reference_getters_funcs, wasm_value_getters_extern, wasm_value_getters_funcs,
|
wasm_reference_getters_funcs, wasm_value_getters_extern, wasm_value_getters_funcs,
|
||||||
ExternRef, ExternalReferenceType, Script,
|
ExternRef, ExternalReferenceType,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PokemonInner {
|
struct PokemonInner {
|
||||||
|
@ -208,7 +211,14 @@ mod implementation {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
fn get_learned_move(&self, index: usize) -> Option<LearnedMove> {
|
fn get_learned_move(&self, index: usize) -> Option<LearnedMove> {
|
||||||
unsafe { pokemon_get_learned_move(self.inner.reference, index).get_value() }
|
unsafe {
|
||||||
|
let v = pokemon_get_learned_move(self.inner.reference, index).get_value();
|
||||||
|
if let Some(v) = v {
|
||||||
|
Some(Rc::new(v))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn change_stat_boost(
|
fn change_stat_boost(
|
||||||
&self,
|
&self,
|
||||||
|
@ -350,7 +360,9 @@ mod implementation {
|
||||||
Self::from_ref(reference, &|reference| Self {
|
Self::from_ref(reference, &|reference| Self {
|
||||||
inner: Rc::new(PokemonInner {
|
inner: Rc::new(PokemonInner {
|
||||||
reference,
|
reference,
|
||||||
library: cached_value!({ pokemon_get_library(reference).get_value().unwrap() }),
|
library: cached_value!({
|
||||||
|
Rc::new(pokemon_get_library(reference).get_value().unwrap())
|
||||||
|
}),
|
||||||
flat_stats: cached_value!({
|
flat_stats: cached_value!({
|
||||||
Rc::new(pokemon_get_flat_stats(reference).get_value().unwrap())
|
Rc::new(pokemon_get_flat_stats(reference).get_value().unwrap())
|
||||||
}),
|
}),
|
||||||
|
@ -428,7 +440,7 @@ mod implementation {
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "wasm" {
|
extern "wasm" {
|
||||||
fn pokemon_get_library(r: ExternRef<PokemonImpl>) -> ExternRef<DynamicLibrary>;
|
fn pokemon_get_library(r: ExternRef<PokemonImpl>) -> ExternRef<DynamicLibraryImpl>;
|
||||||
fn pokemon_get_flat_stats(r: ExternRef<PokemonImpl>) -> ExternRef<StatisticSetImpl<u32>>;
|
fn pokemon_get_flat_stats(r: ExternRef<PokemonImpl>) -> ExternRef<StatisticSetImpl<u32>>;
|
||||||
fn pokemon_get_stat_boosts(r: ExternRef<PokemonImpl>)
|
fn pokemon_get_stat_boosts(r: ExternRef<PokemonImpl>)
|
||||||
-> ExternRef<ClampedStatisticSet<i8>>;
|
-> ExternRef<ClampedStatisticSet<i8>>;
|
||||||
|
@ -452,7 +464,7 @@ mod implementation {
|
||||||
fn pokemon_get_learned_move(
|
fn pokemon_get_learned_move(
|
||||||
r: ExternRef<PokemonImpl>,
|
r: ExternRef<PokemonImpl>,
|
||||||
index: usize,
|
index: usize,
|
||||||
) -> ExternRef<LearnedMove>;
|
) -> ExternRef<LearnedMoveImpl>;
|
||||||
fn pokemon_change_stat_boost(
|
fn pokemon_change_stat_boost(
|
||||||
r: ExternRef<PokemonImpl>,
|
r: ExternRef<PokemonImpl>,
|
||||||
tat: Statistic,
|
tat: Statistic,
|
||||||
|
|
|
@ -1,70 +1,8 @@
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
use crate::app_interface::PokemonImpl;
|
|
||||||
use crate::app_interface::{LearnedMove, Pokemon};
|
use crate::app_interface::{LearnedMove, Pokemon};
|
||||||
use crate::handling::cached_value::CachedValue;
|
use crate::handling::Script;
|
||||||
use crate::handling::temporary::Temporary;
|
|
||||||
use crate::ExternRef;
|
|
||||||
use crate::{cached_value, ExternalReferenceType, Script};
|
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
|
|
||||||
pub trait BaseTurnChoiceDataTrait {
|
|
||||||
fn reference(&self) -> u32;
|
|
||||||
fn user(&self) -> Pokemon;
|
|
||||||
fn speed(&self) -> u32;
|
|
||||||
fn has_failed(&self) -> bool;
|
|
||||||
fn fail(&self);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
struct BaseTurnChoiceDataImpl {
|
|
||||||
reference: ExternRef<TurnChoice>,
|
|
||||||
user: CachedValue<Rc<PokemonImpl>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
impl BaseTurnChoiceDataTrait for BaseTurnChoiceDataImpl {
|
|
||||||
fn reference(&self) -> u32 {
|
|
||||||
self.reference.get_internal_index()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn user(&self) -> Pokemon {
|
|
||||||
self.user.value()
|
|
||||||
}
|
|
||||||
fn speed(&self) -> u32 {
|
|
||||||
unsafe { turn_choice_get_speed(self.reference) }
|
|
||||||
}
|
|
||||||
fn has_failed(&self) -> bool {
|
|
||||||
unsafe { turn_choice_has_failed(self.reference) }
|
|
||||||
}
|
|
||||||
fn fail(&self) {
|
|
||||||
unsafe { turn_choice_fail(self.reference) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type BaseTurnChoiceData = Rc<dyn BaseTurnChoiceDataTrait>;
|
|
||||||
|
|
||||||
struct MoveTurnChoiceDataInner {
|
|
||||||
base: BaseTurnChoiceData,
|
|
||||||
used_move: CachedValue<LearnedMove>,
|
|
||||||
target_side: CachedValue<u8>,
|
|
||||||
target_index: CachedValue<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait MoveTurnChoiceDataTrait {
|
|
||||||
fn base(&self) -> BaseTurnChoiceData;
|
|
||||||
fn used_move(&self) -> LearnedMove;
|
|
||||||
fn target_side(&self) -> u8;
|
|
||||||
fn target_index(&self) -> u8;
|
|
||||||
fn priority(&self) -> i8;
|
|
||||||
fn move_script(&self) -> Option<&Box<dyn Script>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct MoveTurnChoiceDataImpl {
|
|
||||||
inner: Temporary<MoveTurnChoiceDataInner>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum TurnChoice {
|
pub enum TurnChoice {
|
||||||
Move(Box<dyn MoveTurnChoiceDataTrait>),
|
Move(Box<dyn MoveTurnChoiceDataTrait>),
|
||||||
Item(),
|
Item(),
|
||||||
|
@ -98,6 +36,70 @@ impl TurnChoice {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait BaseTurnChoiceDataTrait {
|
||||||
|
fn reference(&self) -> u32;
|
||||||
|
fn user(&self) -> Pokemon;
|
||||||
|
fn speed(&self) -> u32;
|
||||||
|
fn has_failed(&self) -> bool;
|
||||||
|
fn fail(&self);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type BaseTurnChoiceData = Rc<dyn BaseTurnChoiceDataTrait>;
|
||||||
|
|
||||||
|
pub trait MoveTurnChoiceDataTrait {
|
||||||
|
fn base(&self) -> BaseTurnChoiceData;
|
||||||
|
fn used_move(&self) -> LearnedMove;
|
||||||
|
fn target_side(&self) -> u8;
|
||||||
|
fn target_index(&self) -> u8;
|
||||||
|
fn priority(&self) -> i8;
|
||||||
|
fn move_script(&self) -> Option<&Box<dyn Script>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
mod implementation {
|
||||||
|
use super::*;
|
||||||
|
use crate::app_interface::{LearnedMoveImpl, PokemonImpl};
|
||||||
|
use crate::cached_value;
|
||||||
|
use crate::handling::cached_value::CachedValue;
|
||||||
|
use crate::handling::extern_ref::{ExternRef, ExternalReferenceType};
|
||||||
|
use crate::handling::temporary::Temporary;
|
||||||
|
|
||||||
|
struct BaseTurnChoiceDataImpl {
|
||||||
|
reference: ExternRef<TurnChoice>,
|
||||||
|
user: CachedValue<Rc<PokemonImpl>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BaseTurnChoiceDataTrait for BaseTurnChoiceDataImpl {
|
||||||
|
fn reference(&self) -> u32 {
|
||||||
|
self.reference.get_internal_index()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn user(&self) -> Pokemon {
|
||||||
|
self.user.value()
|
||||||
|
}
|
||||||
|
fn speed(&self) -> u32 {
|
||||||
|
unsafe { turn_choice_get_speed(self.reference) }
|
||||||
|
}
|
||||||
|
fn has_failed(&self) -> bool {
|
||||||
|
unsafe { turn_choice_has_failed(self.reference) }
|
||||||
|
}
|
||||||
|
fn fail(&self) {
|
||||||
|
unsafe { turn_choice_fail(self.reference) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct MoveTurnChoiceDataInner {
|
||||||
|
base: BaseTurnChoiceData,
|
||||||
|
used_move: CachedValue<LearnedMove>,
|
||||||
|
target_side: CachedValue<u8>,
|
||||||
|
target_index: CachedValue<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct MoveTurnChoiceDataImpl {
|
||||||
|
inner: Temporary<MoveTurnChoiceDataInner>,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
impl MoveTurnChoiceDataTrait for MoveTurnChoiceDataImpl {
|
impl MoveTurnChoiceDataTrait for MoveTurnChoiceDataImpl {
|
||||||
fn base(&self) -> BaseTurnChoiceData {
|
fn base(&self) -> BaseTurnChoiceData {
|
||||||
|
@ -148,9 +150,11 @@ impl MoveTurnChoiceDataInner {
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
used_move: cached_value!({
|
used_move: cached_value!({
|
||||||
|
Rc::new(
|
||||||
turn_choice_move_used_move(reference.cast())
|
turn_choice_move_used_move(reference.cast())
|
||||||
.get_value()
|
.get_value()
|
||||||
.unwrap()
|
.unwrap(),
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
target_side: cached_value!({ turn_choice_move_target_side(reference.cast()) }),
|
target_side: cached_value!({ turn_choice_move_target_side(reference.cast()) }),
|
||||||
target_index: cached_value!({ turn_choice_move_target_index(reference.cast()) }),
|
target_index: cached_value!({ turn_choice_move_target_index(reference.cast()) }),
|
||||||
|
@ -158,7 +162,6 @@ impl MoveTurnChoiceDataInner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
extern "wasm" {
|
extern "wasm" {
|
||||||
fn turn_choice_get_kind(r: ExternRef<TurnChoice>) -> u8;
|
fn turn_choice_get_kind(r: ExternRef<TurnChoice>) -> u8;
|
||||||
fn turn_choice_get_user(r: ExternRef<TurnChoice>) -> ExternRef<PokemonImpl>;
|
fn turn_choice_get_user(r: ExternRef<TurnChoice>) -> ExternRef<PokemonImpl>;
|
||||||
|
@ -166,10 +169,16 @@ extern "wasm" {
|
||||||
fn turn_choice_has_failed(r: ExternRef<TurnChoice>) -> bool;
|
fn turn_choice_has_failed(r: ExternRef<TurnChoice>) -> bool;
|
||||||
fn turn_choice_fail(r: ExternRef<TurnChoice>);
|
fn turn_choice_fail(r: ExternRef<TurnChoice>);
|
||||||
|
|
||||||
fn turn_choice_move_used_move(r: ExternRef<MoveTurnChoiceDataImpl>) -> ExternRef<LearnedMove>;
|
fn turn_choice_move_used_move(
|
||||||
|
r: ExternRef<MoveTurnChoiceDataImpl>,
|
||||||
|
) -> ExternRef<LearnedMoveImpl>;
|
||||||
fn turn_choice_move_target_side(r: ExternRef<MoveTurnChoiceDataImpl>) -> u8;
|
fn turn_choice_move_target_side(r: ExternRef<MoveTurnChoiceDataImpl>) -> u8;
|
||||||
fn turn_choice_move_target_index(r: ExternRef<MoveTurnChoiceDataImpl>) -> u8;
|
fn turn_choice_move_target_index(r: ExternRef<MoveTurnChoiceDataImpl>) -> u8;
|
||||||
fn turn_choice_move_priority(r: ExternRef<MoveTurnChoiceDataImpl>) -> i8;
|
fn turn_choice_move_priority(r: ExternRef<MoveTurnChoiceDataImpl>) -> i8;
|
||||||
#[allow(improper_ctypes)]
|
#[allow(improper_ctypes)]
|
||||||
fn turn_choice_move_script(r: ExternRef<MoveTurnChoiceDataImpl>) -> *const Box<dyn Script>;
|
fn turn_choice_move_script(r: ExternRef<MoveTurnChoiceDataImpl>) -> *const Box<dyn Script>;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
pub use implementation::*;
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::{ExternalReferenceType, VecExternRef};
|
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
|
|
||||||
pub trait ImmutableListTrait<T> {
|
pub trait ImmutableListTrait<T> {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::app_interface::{DataLibrary, Item, ItemImpl};
|
use crate::app_interface::{DataLibrary, ItemImpl};
|
||||||
use crate::{ExternRef, ExternalReferenceType, StringKey};
|
use crate::{ExternRef, ExternalReferenceType, StringKey};
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
use spin::rwlock::RwLock;
|
use spin::rwlock::RwLock;
|
||||||
|
|
|
@ -1,23 +1,42 @@
|
||||||
use crate::{cached_value, cached_value_getters, ExternRef, ExternalReferenceType, StringKey};
|
use crate::app_interface::item_library::ItemLibrary;
|
||||||
|
use crate::app_interface::move_library::MoveLibrary;
|
||||||
|
use crate::app_interface::species_library::SpeciesLibrary;
|
||||||
|
use crate::app_interface::type_library::TypeLibrary;
|
||||||
|
use crate::app_interface::LevelInt;
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
use move_library::MoveLibrary;
|
|
||||||
use spin::rwlock::RwLock;
|
|
||||||
|
|
||||||
pub mod item_library;
|
pub mod item_library;
|
||||||
pub mod move_library;
|
pub mod move_library;
|
||||||
pub mod species_library;
|
pub mod species_library;
|
||||||
pub mod type_library;
|
pub mod type_library;
|
||||||
|
|
||||||
use crate::app_interface::species_library::SpeciesLibrary;
|
pub trait StaticDataTrait {
|
||||||
use crate::app_interface::type_library::TypeLibrary;
|
fn move_library(&self) -> MoveLibrary;
|
||||||
use crate::app_interface::{get_hash, LevelInt};
|
fn item_library(&self) -> ItemLibrary;
|
||||||
|
fn species_library(&self) -> SpeciesLibrary;
|
||||||
|
fn type_library(&self) -> TypeLibrary;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type StaticData = Rc<dyn StaticDataTrait>;
|
||||||
|
|
||||||
|
pub trait LibrarySettingsTrait {
|
||||||
|
fn maximum_level(&self) -> LevelInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type LibrarySettings = Rc<dyn LibrarySettingsTrait>;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
mod implementation {
|
||||||
|
use super::*;
|
||||||
|
use crate::app_interface::{get_hash, StringKey};
|
||||||
use crate::handling::cached_value::CachedValue;
|
use crate::handling::cached_value::CachedValue;
|
||||||
|
use crate::handling::extern_ref::{ExternRef, ExternalReferenceType};
|
||||||
use crate::handling::Cacheable;
|
use crate::handling::Cacheable;
|
||||||
pub use item_library::*;
|
use crate::{cached_value, cached_value_getters};
|
||||||
pub use move_library::*;
|
use spin::RwLock;
|
||||||
|
|
||||||
struct StaticDataInner {
|
struct StaticDataInner {
|
||||||
reference: ExternRef<StaticData>,
|
reference: ExternRef<StaticDataImpl>,
|
||||||
move_library: CachedValue<MoveLibrary>,
|
move_library: CachedValue<MoveLibrary>,
|
||||||
item_library: CachedValue<ItemLibrary>,
|
item_library: CachedValue<ItemLibrary>,
|
||||||
species_library: CachedValue<SpeciesLibrary>,
|
species_library: CachedValue<SpeciesLibrary>,
|
||||||
|
@ -26,13 +45,13 @@ struct StaticDataInner {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct StaticData {
|
pub struct StaticDataImpl {
|
||||||
inner: Rc<StaticDataInner>,
|
inner: Rc<StaticDataInner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticData {
|
impl StaticDataImpl {
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
pub(crate) fn new(reference: ExternRef<StaticData>) -> Self {
|
pub(crate) fn new(reference: ExternRef<StaticDataImpl>) -> Self {
|
||||||
Self::from_ref(reference, &|reference| Self {
|
Self::from_ref(reference, &|reference| Self {
|
||||||
inner: Rc::new(StaticDataInner {
|
inner: Rc::new(StaticDataInner {
|
||||||
reference,
|
reference,
|
||||||
|
@ -51,103 +70,83 @@ impl StaticData {
|
||||||
static_data_get_type_library(reference).get_value().unwrap()
|
static_data_get_type_library(reference).get_value().unwrap()
|
||||||
}),
|
}),
|
||||||
settings: cached_value!({
|
settings: cached_value!({
|
||||||
|
Rc::new(
|
||||||
static_data_get_library_settings(reference)
|
static_data_get_library_settings(reference)
|
||||||
.get_value()
|
.get_value()
|
||||||
.unwrap()
|
.unwrap(),
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "mock_data")]
|
|
||||||
pub fn mock(
|
|
||||||
moves: MoveLibrary,
|
|
||||||
items: ItemLibrary,
|
|
||||||
species: SpeciesLibrary,
|
|
||||||
types: TypeLibrary,
|
|
||||||
settings: LibrarySettings,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
inner: Rc::new(StaticDataInner {
|
|
||||||
reference: ExternRef::mock(),
|
|
||||||
move_library: moves.into(),
|
|
||||||
item_library: items.into(),
|
|
||||||
species_library: species.into(),
|
|
||||||
type_library: types.into(),
|
|
||||||
settings: settings.into(),
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl StaticDataTrait for StaticDataImpl {
|
||||||
cached_value_getters! {
|
cached_value_getters! {
|
||||||
pub fn move_library(&self) -> MoveLibrary;
|
fn move_library(&self) -> MoveLibrary;
|
||||||
pub fn item_library(&self) -> ItemLibrary;
|
fn item_library(&self) -> ItemLibrary;
|
||||||
pub fn species_library(&self) -> SpeciesLibrary;
|
fn species_library(&self) -> SpeciesLibrary;
|
||||||
pub fn type_library(&self) -> TypeLibrary;
|
fn type_library(&self) -> TypeLibrary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::handling::cacheable::cacheable!(StaticData);
|
crate::handling::cacheable::cacheable!(StaticDataImpl);
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
impl ExternalReferenceType for StaticData {
|
impl ExternalReferenceType for StaticDataImpl {
|
||||||
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
||||||
StaticData::new(reference)
|
StaticDataImpl::new(reference)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct LibrarySettingsImpl {
|
||||||
|
inner: Rc<LibrarySettingsInner>,
|
||||||
|
}
|
||||||
|
|
||||||
struct LibrarySettingsInner {
|
struct LibrarySettingsInner {
|
||||||
maximum_level: CachedValue<LevelInt>,
|
maximum_level: CachedValue<LevelInt>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
impl LibrarySettingsImpl {
|
||||||
pub struct LibrarySettings {
|
|
||||||
inner: Rc<LibrarySettingsInner>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LibrarySettings {
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
pub(crate) fn new(ptr: ExternRef<LibrarySettings>) -> Self {
|
pub(crate) fn new(ptr: ExternRef<LibrarySettingsImpl>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: Rc::new(LibrarySettingsInner {
|
inner: Rc::new(LibrarySettingsInner {
|
||||||
maximum_level: cached_value!({ library_settings_get_maximum_level(ptr) }),
|
maximum_level: cached_value!({ library_settings_get_maximum_level(ptr) }),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "mock_data")]
|
|
||||||
pub fn mock(maximum_level: LevelInt) -> Self {
|
|
||||||
Self {
|
|
||||||
inner: Rc::new(LibrarySettingsInner {
|
|
||||||
maximum_level: maximum_level.into(),
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl LibrarySettingsTrait for LibrarySettingsImpl {
|
||||||
cached_value_getters! {
|
cached_value_getters! {
|
||||||
pub fn maximum_level(&self) -> LevelInt;
|
fn maximum_level(&self) -> LevelInt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
impl ExternalReferenceType for LibrarySettings {
|
impl ExternalReferenceType for LibrarySettingsImpl {
|
||||||
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
fn from_extern_value(reference: ExternRef<Self>) -> Self {
|
||||||
LibrarySettings::new(reference)
|
LibrarySettingsImpl::new(reference)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
extern "wasm" {
|
extern "wasm" {
|
||||||
fn static_data_get_move_library(ptr: ExternRef<StaticData>) -> ExternRef<MoveLibrary>;
|
fn static_data_get_move_library(ptr: ExternRef<StaticDataImpl>) -> ExternRef<MoveLibrary>;
|
||||||
fn static_data_get_item_library(ptr: ExternRef<StaticData>) -> ExternRef<ItemLibrary>;
|
fn static_data_get_item_library(ptr: ExternRef<StaticDataImpl>) -> ExternRef<ItemLibrary>;
|
||||||
fn static_data_get_species_library(ptr: ExternRef<StaticData>) -> ExternRef<SpeciesLibrary>;
|
fn static_data_get_species_library(
|
||||||
fn static_data_get_type_library(ptr: ExternRef<StaticData>) -> ExternRef<TypeLibrary>;
|
ptr: ExternRef<StaticDataImpl>,
|
||||||
fn static_data_get_library_settings(ptr: ExternRef<StaticData>) -> ExternRef<LibrarySettings>;
|
) -> ExternRef<SpeciesLibrary>;
|
||||||
|
fn static_data_get_type_library(ptr: ExternRef<StaticDataImpl>) -> ExternRef<TypeLibrary>;
|
||||||
|
fn static_data_get_library_settings(
|
||||||
|
ptr: ExternRef<StaticDataImpl>,
|
||||||
|
) -> ExternRef<LibrarySettingsImpl>;
|
||||||
|
|
||||||
fn library_settings_get_maximum_level(ptr: ExternRef<LibrarySettings>) -> LevelInt;
|
fn library_settings_get_maximum_level(ptr: ExternRef<LibrarySettingsImpl>) -> LevelInt;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
|
||||||
pub trait DataLibrary<T>: Cacheable
|
pub trait DataLibrary<T>: Cacheable
|
||||||
where
|
where
|
||||||
T: ExternalReferenceType,
|
T: ExternalReferenceType,
|
||||||
|
@ -201,6 +200,20 @@ where
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
pub use implementation::*;
|
||||||
|
|
||||||
|
#[cfg(feature = "mock_data")]
|
||||||
|
mod mocked {
|
||||||
|
use super::*;
|
||||||
|
use crate::app_interface::StringKey;
|
||||||
|
use crate::handling::cached_value::CachedValue;
|
||||||
|
use crate::handling::extern_ref::{ExternRef, ExternalReferenceType};
|
||||||
|
use crate::handling::Cacheable;
|
||||||
|
use crate::{cached_value, cached_value_getters};
|
||||||
|
use spin::RwLock;
|
||||||
|
|
||||||
#[cfg(feature = "mock_data")]
|
#[cfg(feature = "mock_data")]
|
||||||
pub trait DataLibrary<T>: Cacheable
|
pub trait DataLibrary<T>: Cacheable
|
||||||
|
@ -230,3 +243,7 @@ where
|
||||||
self.get_cache().write().insert(hash, item);
|
self.get_cache().write().insert(hash, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "mock_data")]
|
||||||
|
pub use mocked::*;
|
||||||
|
|
|
@ -5,7 +5,6 @@ use crate::app_interface::{
|
||||||
};
|
};
|
||||||
use crate::handling::ScriptCapabilities;
|
use crate::handling::ScriptCapabilities;
|
||||||
use crate::{ExternRef, ExternalReferenceType, StringKey};
|
use crate::{ExternRef, ExternalReferenceType, StringKey};
|
||||||
use alloc::boxed::Box;
|
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
use core::any::Any;
|
use core::any::Any;
|
||||||
use core::fmt::Debug;
|
use core::fmt::Debug;
|
||||||
|
@ -26,7 +25,7 @@ pub trait Script {
|
||||||
/// This function is ran when this script starts being in effect.
|
/// This function is ran when this script starts being in effect.
|
||||||
fn on_initialize(
|
fn on_initialize(
|
||||||
&self,
|
&self,
|
||||||
_library: &DynamicLibrary,
|
_library: DynamicLibrary,
|
||||||
_parameters: Option<ImmutableList<Rc<EffectParameter>>>,
|
_parameters: Option<ImmutableList<Rc<EffectParameter>>>,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,14 +41,6 @@ impl<T> Temporary<T> {
|
||||||
}
|
}
|
||||||
self.value.clone()
|
self.value.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn value_ref(&self) -> &T {
|
|
||||||
if self.is_deleted.load(Ordering::SeqCst) {
|
|
||||||
panic!("Accessed value after it had been deleted");
|
|
||||||
}
|
|
||||||
self.value.as_ref()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
|
|
@ -24,7 +24,6 @@ static ALLOC: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc {};
|
||||||
|
|
||||||
pub(crate) use crate::app_interface::StringKey;
|
pub(crate) use crate::app_interface::StringKey;
|
||||||
pub(crate) use crate::handling::extern_ref::*;
|
pub(crate) use crate::handling::extern_ref::*;
|
||||||
pub(crate) use crate::handling::Script;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
@ -36,7 +35,7 @@ pub mod utils;
|
||||||
mod implementation {
|
mod implementation {
|
||||||
use crate::app_interface::list::{EffectParameterImmutableList, ImmutableListWasm};
|
use crate::app_interface::list::{EffectParameterImmutableList, ImmutableListWasm};
|
||||||
use crate::app_interface::{
|
use crate::app_interface::{
|
||||||
BattleImpl, DamageSource, DynamicLibrary, EffectParameter, ExecutingMoveImpl, ItemImpl,
|
BattleImpl, DamageSource, DynamicLibraryImpl, EffectParameter, ExecutingMoveImpl, ItemImpl,
|
||||||
PokemonImpl, Statistic, StringKey, TurnChoice, TypeIdentifier,
|
PokemonImpl, Statistic, StringKey, TurnChoice, TypeIdentifier,
|
||||||
};
|
};
|
||||||
use crate::handling::extern_ref::ExternRef;
|
use crate::handling::extern_ref::ExternRef;
|
||||||
|
@ -187,11 +186,11 @@ mod implementation {
|
||||||
|
|
||||||
fn script_on_initialize(
|
fn script_on_initialize(
|
||||||
script: ScriptPtr,
|
script: ScriptPtr,
|
||||||
library: ExternRef<DynamicLibrary>,
|
library: ExternRef<DynamicLibraryImpl>,
|
||||||
parameters: VecExternRef<EffectParameter>,
|
parameters: VecExternRef<EffectParameter>,
|
||||||
) {
|
) {
|
||||||
let parameters = Rc::new(EffectParameterImmutableList::from_ref(parameters));
|
let parameters = Rc::new(EffectParameterImmutableList::from_ref(parameters));
|
||||||
script.val().unwrap().on_initialize(&library.not_null(), Some(parameters));
|
script.val().unwrap().on_initialize(library.not_null_rc(), Some(parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn script_on_before_turn(
|
fn script_on_before_turn(
|
||||||
|
|
|
@ -1,14 +1,23 @@
|
||||||
use alloc::alloc::alloc;
|
#[macro_export]
|
||||||
use alloc::string::String;
|
macro_rules! println { ($($args:tt)*) => { crate::utils::print_raw(alloc::format!($($args)*).as_bytes()); } }
|
||||||
use core::alloc::Layout;
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[macro_export]
|
||||||
use core::panic::PanicInfo;
|
#[cfg(debug_assertions)]
|
||||||
#[cfg(feature = "mock_data")]
|
macro_rules! dbg { ($($args:tt)*) => { crate::utils::print_raw(alloc::format!($($args)*).as_bytes()); } }
|
||||||
use cstr_core::CStr;
|
|
||||||
use cstr_core::{c_char, CString};
|
#[macro_export]
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
|
macro_rules! dbg {
|
||||||
|
($($args:tt)*) => {{}};
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
#[cfg(not(feature = "mock_data"))]
|
mod implementation {
|
||||||
|
use alloc::alloc::alloc;
|
||||||
|
use core::alloc::Layout;
|
||||||
|
use core::panic::PanicInfo;
|
||||||
|
use cstr_core::{c_char, CString};
|
||||||
|
|
||||||
extern "wasm" {
|
extern "wasm" {
|
||||||
fn _print(s: *const u8);
|
fn _print(s: *const u8);
|
||||||
fn _error(message: *const u8, file: *const u8, line: u32, position: u32);
|
fn _error(message: *const u8, file: *const u8, line: u32, position: u32);
|
||||||
|
@ -22,26 +31,6 @@ pub fn print_raw(s: &[u8]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "mock_data")]
|
|
||||||
pub fn print_raw(s: &[u8]) {
|
|
||||||
unsafe {
|
|
||||||
println!("{}", String::from_utf8_lossy(s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! println { ($($args:tt)*) => { pkmn_lib_interface::utils::print_raw(alloc::format!($($args)*).as_bytes()); } }
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
macro_rules! dbg { ($($args:tt)*) => { pkmn_lib_interface::utils::print_raw(alloc::format!($($args)*).as_bytes()); } }
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
macro_rules! dbg {
|
|
||||||
($($args:tt)*) => {{}};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
@ -82,3 +71,21 @@ unsafe extern "wasm" fn allocate_mem(len: u32, align: u32) -> *mut u8 {
|
||||||
unsafe extern "wasm" fn dealloc_cstring(ptr: *mut c_char) {
|
unsafe extern "wasm" fn dealloc_cstring(ptr: *mut c_char) {
|
||||||
CString::from_raw(ptr);
|
CString::from_raw(ptr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
pub use implementation::*;
|
||||||
|
|
||||||
|
#[cfg(feature = "mock_data")]
|
||||||
|
mod mocked {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub fn print_raw(s: &[u8]) {
|
||||||
|
unsafe {
|
||||||
|
println!("{}", String::from_utf8_lossy(s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "mock_data")]
|
||||||
|
pub use mocked::*;
|
||||||
|
|
Loading…
Reference in New Issue