This commit is contained in:
@@ -7,23 +7,30 @@ use crate::defines::LevelInt;
|
||||
use crate::static_data::GrowthRate;
|
||||
use crate::StringKey;
|
||||
|
||||
/// A library to store all growth rates.
|
||||
pub struct GrowthRateLibrary {
|
||||
/// The underlying data structure.
|
||||
growth_rates: HashMap<StringKey, Box<dyn GrowthRate>>,
|
||||
}
|
||||
|
||||
impl GrowthRateLibrary {
|
||||
/// Instantiates a new growth rate library with a capacity.
|
||||
pub fn new(capacity: usize) -> GrowthRateLibrary {
|
||||
GrowthRateLibrary {
|
||||
growth_rates: HashMap::with_capacity(capacity),
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculates the level for a given growth key name and a certain experience.
|
||||
pub fn calculate_level(&self, growth_rate: &StringKey, experience: u32) -> LevelInt {
|
||||
self.growth_rates[growth_rate].calculate_level(experience)
|
||||
}
|
||||
/// Calculates the experience for a given growth key name and a certain level.
|
||||
pub fn calculate_experience(&self, growth_rate: &StringKey, level: LevelInt) -> u32 {
|
||||
self.growth_rates[growth_rate].calculate_experience(level)
|
||||
}
|
||||
|
||||
/// Adds a new growth rate with a name and value.
|
||||
pub fn add_growth_rate(&mut self, key: &StringKey, value: Box<dyn GrowthRate>) {
|
||||
self.growth_rates.insert(key.clone(), value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user