A lot more work on a bunch of different parts of the system.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
use crate::defines::LevelInt;
|
||||
use crate::static_data::growth_rates::growth_rate::GrowthRate;
|
||||
use crate::StringKey;
|
||||
use hashbrown::HashMap;
|
||||
use std::fmt;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
|
||||
pub struct GrowthRateLibrary {
|
||||
growth_rates: HashMap<String, Box<dyn GrowthRate>>,
|
||||
growth_rates: HashMap<StringKey, Box<dyn GrowthRate>>,
|
||||
}
|
||||
|
||||
impl GrowthRateLibrary {
|
||||
@@ -15,14 +16,14 @@ impl GrowthRateLibrary {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn calculate_level(&self, growth_rate: &str, experience: u32) -> LevelInt {
|
||||
pub fn calculate_level(&self, growth_rate: &StringKey, experience: u32) -> LevelInt {
|
||||
self.growth_rates[growth_rate].calculate_level(experience)
|
||||
}
|
||||
pub fn calculate_experience(&self, growth_rate: &str, level: LevelInt) -> u32 {
|
||||
pub fn calculate_experience(&self, growth_rate: &StringKey, level: LevelInt) -> u32 {
|
||||
self.growth_rates[growth_rate].calculate_experience(level)
|
||||
}
|
||||
pub fn add_growth_rate(&mut self, key: &str, value: Box<dyn GrowthRate>) {
|
||||
self.growth_rates.insert(key.to_string(), value);
|
||||
pub fn add_growth_rate(&mut self, key: &StringKey, value: Box<dyn GrowthRate>) {
|
||||
self.growth_rates.insert(key.clone(), value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ pub mod tests {
|
||||
// Borrow as mut so we can insert
|
||||
let w = &mut lib;
|
||||
w.add_growth_rate(
|
||||
"test_growthrate",
|
||||
&"test_growthrate".into(),
|
||||
Box::new(LookupGrowthRate::new(vec![0, 5, 10, 100])),
|
||||
);
|
||||
// Drops borrow as mut
|
||||
@@ -54,14 +55,14 @@ pub mod tests {
|
||||
#[test]
|
||||
fn add_growth_rate_to_library_and_calculate_level() {
|
||||
let lib = build();
|
||||
assert_eq!(lib.calculate_level("test_growthrate", 3), 1);
|
||||
assert_eq!(lib.calculate_level("test_growthrate", 50), 3);
|
||||
assert_eq!(lib.calculate_level(&"test_growthrate".into(), 3), 1);
|
||||
assert_eq!(lib.calculate_level(&"test_growthrate".into(), 50), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_growth_rate_to_library_and_calculate_experience() {
|
||||
let lib = build();
|
||||
assert_eq!(lib.calculate_experience("test_growthrate", 1), 0);
|
||||
assert_eq!(lib.calculate_experience("test_growthrate", 3), 10);
|
||||
assert_eq!(lib.calculate_experience(&"test_growthrate".into(), 1), 0);
|
||||
assert_eq!(lib.calculate_experience(&"test_growthrate".into(), 3), 10);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user