Loads of cleanup
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
2022-11-27 17:29:29 +01:00
parent aa3ceaed3e
commit efd1acdfa5
45 changed files with 259 additions and 162 deletions

View File

@@ -32,7 +32,6 @@ struct CommonChoiceData {
/// This enum defines a single choice for a Pokemon for a battle turn.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub enum TurnChoice {
/// A move choice tells a Pokemon to use a move on a target for this turn.
Move(MoveChoice),

View File

@@ -1,7 +1,7 @@
use crate::dynamic_data::choices::TurnChoice;
use crate::dynamic_data::script_handling::ScriptSource;
use crate::dynamic_data::Pokemon;
use crate::{script_hook, ValueIdentifiable};
use crate::{script_hook, ValueIdentifiable, ValueIdentifier};
use parking_lot::lock_api::MappedRwLockReadGuard;
use parking_lot::{RawRwLock, RwLock, RwLockReadGuard};
@@ -12,8 +12,10 @@ use parking_lot::{RawRwLock, RwLock, RwLockReadGuard};
/// helper functions to change the turn order while doing the execution. This is needed, as several
/// moves in Pokemon actively mess with this order.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct ChoiceQueue {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,
/// Our storage of turn choices. Starts out completely filled, then slowly empties as turns get
/// executed.
queue: RwLock<Vec<Option<TurnChoice>>>,
@@ -26,6 +28,7 @@ impl ChoiceQueue {
pub(crate) fn new(mut queue: Vec<Option<TurnChoice>>) -> Self {
queue.sort_unstable_by(|a, b| b.cmp(a));
Self {
identifier: Default::default(),
queue: RwLock::new(queue),
current: 0,
}
@@ -119,6 +122,12 @@ impl ChoiceQueue {
}
}
impl ValueIdentifiable for ChoiceQueue {
fn value_identifier(&self) -> ValueIdentifier {
self.identifier
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -14,7 +14,6 @@ use crate::{PkmnResult, StringKey, ValueIdentifiable, ValueIdentifier};
/// The dynamic library stores a static data library, as well as holding different libraries and
/// calculators that might be customized between different generations and implementations.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct DynamicLibrary {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,
@@ -87,7 +86,7 @@ impl DynamicLibrary {
/// Loads an item script with the given unique key. If no script can be created with this
/// combinations, returns None. Note that ItemScripts are immutable, as their script should be
/// shared between all different usages.
pub fn load_item_script(&self, _key: &Arc<Item>) -> PkmnResult<Option<Arc<dyn ItemScript>>> {
pub fn load_item_script(&self, _key: &Arc<dyn Item>) -> PkmnResult<Option<Arc<dyn ItemScript>>> {
todo!()
}
}

View File

@@ -21,7 +21,7 @@ pub trait ScriptResolver: Debug + ValueIdentifiable {
/// Loads an item script with the given unique key. If no script can be created with this
/// combinations, returns None. Note that ItemScripts are immutable, as their script should be
/// shared between all different usages.
fn load_item_script(&self, _key: &Item) -> PkmnResult<Option<Arc<dyn ItemScript>>>;
fn load_item_script(&self, _key: &dyn Item) -> PkmnResult<Option<Arc<dyn ItemScript>>>;
}
use std::fmt::Display;
@@ -77,7 +77,7 @@ impl ScriptResolver for EmptyScriptResolver {
Ok(None)
}
fn load_item_script(&self, _key: &Item) -> PkmnResult<Option<Arc<dyn ItemScript>>> {
fn load_item_script(&self, _key: &dyn Item) -> PkmnResult<Option<Arc<dyn ItemScript>>> {
Ok(None)
}
}

View File

@@ -22,7 +22,6 @@ use crate::{script_hook, PkmnResult, StringKey, ValueIdentifiable, ValueIdentifi
/// A pokemon battle, with any amount of sides and pokemon per side.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct Battle {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,

View File

@@ -7,7 +7,6 @@ use crate::{ValueIdentifiable, ValueIdentifier};
/// A battle party is a wrapper around a party, with the indices for which the party is responsible
/// on the field attached.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct BattleParty {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,

View File

@@ -9,7 +9,6 @@ use crate::{script_hook, ValueIdentifiable, ValueIdentifier};
/// The RNG for a battle.
#[derive(Default)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct BattleRandom {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,

View File

@@ -18,7 +18,6 @@ use crate::{script_hook, PkmnResult, StringKey, ValueIdentifiable, ValueIdentifi
/// A side on a battle.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct BattleSide {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,

View File

@@ -11,12 +11,14 @@ use crate::dynamic_data::script_handling::{ScriptSource, ScriptSourceData, Scrip
use crate::dynamic_data::ScriptContainer;
use crate::dynamic_data::TargetList;
use crate::static_data::{MoveData, TypeIdentifier};
use crate::{PkmnResult, PokemonError};
use crate::{PkmnResult, PokemonError, ValueIdentifiable, ValueIdentifier};
/// A hit data is the data for a single hit, on a single target.
#[derive(Default, Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct HitData {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,
/// Whether or not the hit is critical.
critical: AtomicBool,
/// The base power of the hit.
@@ -85,8 +87,10 @@ impl HitData {
/// An executing move is the data of the move for while it is executing.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct ExecutingMove {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,
/// The number of hits this move has.
number_of_hits: u8,
/// A list of hits for this move. For multi target multi hit moves, this stores the hits linearly,
@@ -122,6 +126,7 @@ impl ExecutingMove {
hits.push(HitData::default())
}
Self {
identifier: Default::default(),
number_of_hits,
hits,
user,
@@ -218,3 +223,15 @@ impl ScriptSource for ExecutingMove {
self.user.get_own_scripts(scripts);
}
}
impl ValueIdentifiable for ExecutingMove {
fn value_identifier(&self) -> ValueIdentifier {
self.identifier
}
}
impl ValueIdentifiable for HitData {
fn value_identifier(&self) -> ValueIdentifier {
self.identifier
}
}

View File

@@ -7,7 +7,6 @@ use crate::{ValueIdentifiable, ValueIdentifier};
/// A learned move is the data attached to a Pokemon for a move it has learned. It has information
/// such as the remaining amount of users, how it has been learned, etc.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct LearnedMove {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,

View File

@@ -26,7 +26,6 @@ use crate::{script_hook, PkmnResult, StringKey, ValueIdentifiable, ValueIdentifi
/// An individual Pokemon as we know and love them.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct Pokemon {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,
@@ -57,7 +56,7 @@ pub struct Pokemon {
/// currently not used, and can be used for other implementations.
coloring: u8,
/// The held item of the Pokemon.
held_item: RwLock<Option<Arc<Item>>>,
held_item: RwLock<Option<Arc<dyn Item>>>,
/// The remaining health points of the Pokemon.
current_health: AtomicU32,
@@ -238,7 +237,7 @@ impl Pokemon {
self.coloring
}
/// Gets the held item of a Pokemon
pub fn held_item(&self) -> &RwLock<Option<Arc<Item>>> {
pub fn held_item(&self) -> &RwLock<Option<Arc<dyn Item>>> {
&self.held_item
}
/// Checks whether the Pokemon is holding a specific item.
@@ -250,11 +249,11 @@ impl Pokemon {
false
}
/// Changes the held item of the Pokemon. Returns the previously held item.
pub fn set_held_item(&self, item: &Arc<Item>) -> Option<Arc<Item>> {
pub fn set_held_item(&self, item: &Arc<dyn Item>) -> Option<Arc<dyn Item>> {
self.held_item.write().replace(item.clone())
}
/// Removes the held item from the Pokemon. Returns the previously held item.
pub fn remove_held_item(&self) -> Option<Arc<Item>> {
pub fn remove_held_item(&self) -> Option<Arc<dyn Item>> {
self.held_item.write().take()
}
/// Makes the Pokemon uses its held item.
@@ -524,7 +523,7 @@ impl Pokemon {
.set(ability_script)
.as_ref()
// Ensure the ability script gets initialized with the parameters for the ability.
.on_initialize(self.library.as_ref(), self.active_ability().parameters())
.on_initialize(self.library.as_ref(), self.active_ability().parameters().to_vec())
} else {
self.ability_script.clear();
}

View File

@@ -7,7 +7,6 @@ use crate::{ValueIdentifiable, ValueIdentifier};
/// A list of Pokemon belonging to a trainer.
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct PokemonParty {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,

View File

@@ -64,7 +64,7 @@ pub trait Script: Send + Sync {
/// This function is ran when this script stops being in effect, and is removed from its owner.
fn on_remove(&self) {}
/// This function is ran when this script starts being in effect.
fn on_initialize(&self, _library: &DynamicLibrary, _pars: &[EffectParameter]) {}
fn on_initialize(&self, _library: &DynamicLibrary, _pars: Vec<EffectParameter>) {}
/// This function is ran just before the start of the turn. Everyone has made its choices here,
/// and the turn is about to start. This is a great place to initialize data if you need to know
/// something has happened during a turn.
@@ -240,7 +240,7 @@ pub trait Script: Send + Sync {
fn on_switch_in(&self, _pokemon: &Pokemon) {}
/// This function is triggered on a Pokemon and its parents when the given Pokemon consumes the
/// held item it had.
fn on_after_held_item_consume(&self, _pokemon: &Pokemon, _item: &Item) {}
fn on_after_held_item_consume(&self, _pokemon: &Pokemon, _item: &dyn Item) {}
/// This function is triggered on a Pokemon and its parents when the given Pokemon gains experience,
/// and allows for changing this amount of experience.
fn change_experience_gained(&self, _fainted_mon: &Pokemon, _winning_mon: &Pokemon, _amount: &mut u32) {}
@@ -253,7 +253,7 @@ pub trait Script: Send + Sync {
/// This function is called when a Pokeball is thrown at a Pokemon, and allows modifying the catch
/// rate of this attempt. Pokeball modifier effects should be implemented here, as well as for
/// example status effects that change capture rates.
fn change_capture_rate_bonus(&self, _target: &Pokemon, _pokeball: &Item, _modifier: &mut u8) {}
fn change_capture_rate_bonus(&self, _target: &Pokemon, _pokeball: &dyn Item, _modifier: &mut u8) {}
/// Helper function to turn the self into an Any for downcasting.
fn as_any(&self) -> &dyn Any;