2021-01-30 21:29:59 +00:00
|
|
|
#![allow(clippy::too_many_arguments, clippy::needless_range_loop)]
|
2022-06-18 14:06:54 +00:00
|
|
|
#![allow(clippy::not_unsafe_ptr_arg_deref)]
|
2022-12-24 11:00:50 +00:00
|
|
|
#![allow(clippy::borrowed_box)]
|
2022-11-27 16:29:29 +00:00
|
|
|
#![allow(incomplete_features)]
|
2023-04-02 10:07:08 +00:00
|
|
|
#![allow(ambiguous_glob_reexports)]
|
2022-07-01 15:52:00 +00:00
|
|
|
#![deny(missing_docs)]
|
2022-07-01 16:20:50 +00:00
|
|
|
#![deny(clippy::missing_docs_in_private_items)]
|
2022-06-03 14:35:18 +00:00
|
|
|
#![feature(test)]
|
2022-06-18 12:17:29 +00:00
|
|
|
#![feature(const_option)]
|
2023-01-02 09:41:57 +00:00
|
|
|
#![feature(is_some_and)]
|
2022-07-18 08:16:47 +00:00
|
|
|
#![feature(new_uninit)]
|
2022-07-18 08:49:58 +00:00
|
|
|
#![feature(get_mut_unchecked)]
|
2022-09-17 07:38:02 +00:00
|
|
|
#![feature(strict_provenance)]
|
2022-10-15 15:21:24 +00:00
|
|
|
#![feature(fn_traits)]
|
|
|
|
#![feature(unboxed_closures)]
|
2022-11-27 16:29:29 +00:00
|
|
|
#![feature(trait_upcasting)]
|
2023-04-02 10:07:08 +00:00
|
|
|
#![feature(lazy_cell)]
|
2021-01-30 21:29:59 +00:00
|
|
|
|
2022-06-19 19:34:08 +00:00
|
|
|
//! PkmnLib
|
|
|
|
//! PkmnLib is a full featured implementation of Pokemon. while currently focused on implementing
|
|
|
|
//! generation 7, this library tries to offload generational differences such as move effects
|
|
|
|
//! to a scripting library.
|
|
|
|
//!
|
2022-06-03 14:35:18 +00:00
|
|
|
|
2022-10-15 15:21:24 +00:00
|
|
|
extern crate core;
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate enum_display_derive;
|
|
|
|
|
|
|
|
use std::fmt::{Display, Formatter};
|
2022-06-19 19:34:08 +00:00
|
|
|
#[doc(hidden)]
|
|
|
|
pub use utils::*;
|
|
|
|
|
|
|
|
use crate::dynamic_data::ScriptCategory;
|
2022-06-06 11:54:59 +00:00
|
|
|
|
2022-06-19 19:34:08 +00:00
|
|
|
/// The defines module holds the core defines of the library
|
2021-01-30 21:29:59 +00:00
|
|
|
pub mod defines;
|
2022-06-19 19:34:08 +00:00
|
|
|
/// The dynamic data module holds data that can change during execution, and things that relate to
|
|
|
|
/// this. This includes things as Pokemon themselves, battles, etc.
|
2021-01-31 16:31:22 +00:00
|
|
|
pub mod dynamic_data;
|
2022-09-18 16:02:13 +00:00
|
|
|
/// The Foreign Function Interface allows for non Rust applications to call this library.
|
|
|
|
#[cfg(feature = "ffi")]
|
|
|
|
mod ffi;
|
2022-07-18 08:16:47 +00:00
|
|
|
/// Script implementations handles the different ways that dynamic scripts get loaded during battle.
|
|
|
|
pub mod script_implementations;
|
2022-06-19 19:34:08 +00:00
|
|
|
/// The static data module holds data that can be set once, and then never change. This includes
|
|
|
|
/// things such as data about Pokemon species, data about items, etc.
|
2021-01-30 21:29:59 +00:00
|
|
|
pub mod static_data;
|
2022-06-19 19:34:08 +00:00
|
|
|
/// The utils module includes misc utils that are used within PkmnLib
|
2021-01-30 21:29:59 +00:00
|
|
|
pub mod utils;
|
2022-06-06 11:54:59 +00:00
|
|
|
|
2022-06-19 19:34:08 +00:00
|
|
|
/// The PokemonError enum holds all different error states that can be encountered in PkmnLib.
|
2022-06-06 11:54:59 +00:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub enum PokemonError {
|
2022-06-19 19:34:08 +00:00
|
|
|
/// A script was requested, but we were unable to find it.
|
|
|
|
ScriptNotFound {
|
|
|
|
/// The category of the script we requested,
|
|
|
|
category: ScriptCategory,
|
|
|
|
/// The unique key of the requested script.
|
|
|
|
name: StringKey,
|
|
|
|
},
|
|
|
|
/// We requested data for a specific target, but that target does not exist on the battle field.
|
2022-06-12 15:57:39 +00:00
|
|
|
InvalidTargetRequested,
|
2022-06-19 19:34:08 +00:00
|
|
|
|
|
|
|
/// Misc errors. Use of this should be minimized, but it is useful for early development.
|
|
|
|
MiscError,
|
2022-06-06 11:54:59 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 19:34:08 +00:00
|
|
|
/// A simple result type.
|
2022-06-11 15:22:46 +00:00
|
|
|
pub type PkmnResult<T> = Result<T, PokemonError>;
|
2022-10-15 15:21:24 +00:00
|
|
|
|
|
|
|
impl Display for PokemonError {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
|
|
|
PokemonError::ScriptNotFound { category, name } => {
|
2023-01-02 10:25:36 +00:00
|
|
|
write!(f, "No script found with category `{category}` and name `{name}`")
|
2022-10-15 15:21:24 +00:00
|
|
|
}
|
|
|
|
PokemonError::InvalidTargetRequested => {
|
|
|
|
write!(f, "Invalid target was requested")
|
|
|
|
}
|
|
|
|
PokemonError::MiscError => {
|
|
|
|
write!(f, "An unknown error occurred")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|