60 lines
2.0 KiB
Rust
Executable File
60 lines
2.0 KiB
Rust
Executable File
use crate::defines::LevelInt;
|
|
use crate::{ValueIdentifiable, ValueIdentifier};
|
|
use anyhow::Result;
|
|
use anyhow_ext::ensure;
|
|
use std::fmt::Debug;
|
|
|
|
/// This library holds several misc settings for the library.
|
|
pub trait LibrarySettings: Debug + ValueIdentifiable {
|
|
/// The highest level a Pokemon can be.
|
|
fn maximum_level(&self) -> LevelInt;
|
|
|
|
/// The chance of a Pokemon being shiny, as the denominator of a fraction, where the nominator
|
|
/// is 1. For example, if this is 1000, then the chance of a Pokemon being shiny is 1/1000.
|
|
fn shiny_rate(&self) -> u32;
|
|
}
|
|
|
|
/// This library holds several misc settings for the library.
|
|
#[derive(Debug)]
|
|
pub struct LibrarySettingsImpl {
|
|
/// A unique identifier so we know what value this is.
|
|
identifier: ValueIdentifier,
|
|
/// The highest level a Pokemon can be.
|
|
maximum_level: LevelInt,
|
|
/// The chance of a Pokemon being shiny, as the denominator of a fraction, where the nominator
|
|
/// is 1. For example, if this is 1000, then the chance of a Pokemon being shiny is 1/1000.
|
|
shiny_rate: u32,
|
|
}
|
|
|
|
impl LibrarySettingsImpl {
|
|
/// Creates a new settings library.
|
|
/// - `maximum_level` is the highest level a Pokemon can be.
|
|
/// - `shiny_rate` is the chance of a Pokemon being shiny, as the denominator of a fraction, where
|
|
/// the nominator is 1. For example, if this is 1000, then the chance of a Pokemon being shiny is
|
|
/// 1/1000.
|
|
pub fn new(maximum_level: LevelInt, shiny_rate: u32) -> Result<Self> {
|
|
ensure!(shiny_rate >= 1);
|
|
ensure!(maximum_level >= 1);
|
|
Ok(Self {
|
|
identifier: Default::default(),
|
|
maximum_level,
|
|
shiny_rate,
|
|
})
|
|
}
|
|
}
|
|
|
|
impl LibrarySettings for LibrarySettingsImpl {
|
|
fn maximum_level(&self) -> LevelInt {
|
|
self.maximum_level
|
|
}
|
|
fn shiny_rate(&self) -> u32 {
|
|
self.shiny_rate
|
|
}
|
|
}
|
|
|
|
impl ValueIdentifiable for LibrarySettingsImpl {
|
|
fn value_identifier(&self) -> ValueIdentifier {
|
|
self.identifier
|
|
}
|
|
}
|