Moves a bunch of libraries to traits
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-12-24 12:00:50 +01:00
parent bce636b97e
commit 47df85e8d3
47 changed files with 730 additions and 358 deletions

View File

@@ -1,4 +1,6 @@
use crate::dynamic_data::{BattleStatCalculator, DamageLibrary, DynamicLibrary, MiscLibrary, ScriptResolver};
use crate::dynamic_data::{
BattleStatCalculator, DamageLibrary, DynamicLibrary, DynamicLibraryImpl, MiscLibrary, ScriptResolver,
};
use crate::ffi::{IdentifiablePointer, OwnedPtr};
use crate::static_data::StaticData;
use std::sync::Arc;
@@ -6,20 +8,20 @@ use std::sync::Arc;
/// Instantiates a new DynamicLibrary with given parameters.
#[no_mangle]
extern "C" fn dynamic_library_new(
static_data: OwnedPtr<StaticData>,
static_data: OwnedPtr<Box<dyn StaticData>>,
stat_calculator: OwnedPtr<Box<dyn BattleStatCalculator>>,
damage_library: OwnedPtr<Box<dyn DamageLibrary>>,
misc_library: OwnedPtr<Box<dyn MiscLibrary>>,
script_resolver: OwnedPtr<Box<dyn ScriptResolver>>,
) -> IdentifiablePointer<Arc<DynamicLibrary>> {
) -> IdentifiablePointer<Arc<dyn DynamicLibrary>> {
unsafe {
Arc::new(DynamicLibrary::new(
let a: Arc<dyn DynamicLibrary> = Arc::new(DynamicLibraryImpl::new(
*Box::from_raw(static_data),
*Box::from_raw(stat_calculator),
*Box::from_raw(damage_library),
*Box::from_raw(misc_library),
*Box::from_raw(script_resolver),
))
.into()
));
a.into()
}
}

View File

@@ -9,7 +9,7 @@ use std::sync::Arc;
/// Initializes a new battle.
#[no_mangle]
extern "C" fn battle_new(
library: ExternPointer<Arc<DynamicLibrary>>,
library: ExternPointer<Arc<dyn DynamicLibrary>>,
parties: *const OwnedPtr<BattleParty>,
parties_length: usize,
can_flee: u8,
@@ -46,7 +46,7 @@ extern "C" fn battle_new(
/// The library the battle uses for handling.
#[no_mangle]
extern "C" fn battle_library(ptr: ExternPointer<Arc<Battle>>) -> IdentifiablePointer<Arc<DynamicLibrary>> {
extern "C" fn battle_library(ptr: ExternPointer<Arc<Battle>>) -> IdentifiablePointer<Arc<dyn DynamicLibrary>> {
ptr.as_ref().library().clone().into()
}

View File

@@ -10,7 +10,7 @@ extern "C" fn learned_move_new(
move_data: ExternPointer<Arc<dyn MoveData>>,
learn_method: MoveLearnMethod,
) -> IdentifiablePointer<Arc<LearnedMove>> {
Arc::new(LearnedMove::new(move_data.as_ref(), learn_method)).into()
Arc::new(LearnedMove::new(move_data.as_ref().clone(), learn_method)).into()
}
/// Drops a learned move.

View File

@@ -11,7 +11,7 @@ use std::sync::Arc;
/// Instantiates a new Pokemon.
#[no_mangle]
extern "C" fn pokemon_new(
library: ExternPointer<Arc<DynamicLibrary>>,
library: ExternPointer<Arc<dyn DynamicLibrary>>,
species: ExternPointer<Arc<dyn Species>>,
form: ExternPointer<Arc<dyn Form>>,
hidden_ability: bool,
@@ -48,7 +48,7 @@ unsafe extern "C" fn pokemon_drop(ptr: OwnedPtr<Arc<Pokemon>>) {
/// The library data of the Pokemon.
#[no_mangle]
extern "C" fn pokemon_library(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<DynamicLibrary>> {
extern "C" fn pokemon_library(ptr: ExternPointer<Arc<Pokemon>>) -> IdentifiablePointer<Arc<dyn DynamicLibrary>> {
ptr.as_ref().library().clone().into()
}