|
@ -1,5 +1,57 @@ |
|
|
|
|
|
use std::collections::HashMap;
|
|
|
use serde::{Serialize, Deserialize};
|
|
|
use serde::{Serialize, Deserialize};
|
|
|
use crate::entity::item::tool::ToolType;
|
|
|
use crate::entity::item::tool::ToolType;
|
|
|
|
|
|
use std::io::Read;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
|
struct MagStats {
|
|
|
|
|
|
feed_table: u32,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
|
struct MagFeedTable {
|
|
|
|
|
|
def: i32,
|
|
|
|
|
|
pow: i32,
|
|
|
|
|
|
dex: i32,
|
|
|
|
|
|
mnd: i32,
|
|
|
|
|
|
iq: i32,
|
|
|
|
|
|
syn: i32,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lazy_static::lazy_static! {
|
|
|
|
|
|
static ref MAG_STATS: HashMap<MagType, MagStats> = {
|
|
|
|
|
|
let mut f = std::fs::File::open("data/item_stats/mag_stats.toml").unwrap();
|
|
|
|
|
|
let mut s = String::new();
|
|
|
|
|
|
f.read_to_string(&mut s).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let mag_stats: HashMap<String, MagStats> = toml::from_str(&s).unwrap();
|
|
|
|
|
|
mag_stats.into_iter()
|
|
|
|
|
|
.map(|(name, stats)| {
|
|
|
|
|
|
(name.parse().unwrap(), stats)
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<HashMap<MagType, MagStats>>()
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static ref MAG_FEEDING_TABLES: Vec<HashMap<ToolType, MagFeedTable>> = {
|
|
|
|
|
|
let mut f = std::fs::File::open("data/item_stats/mag_feed_table.toml").unwrap();
|
|
|
|
|
|
let mut s = String::new();
|
|
|
|
|
|
f.read_to_string(&mut s).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let mut feed: HashMap<String, Vec<HashMap<String, MagFeedTable>>> = toml::from_str(&s).unwrap();
|
|
|
|
|
|
let feed = feed.remove("feedtable".into()).unwrap();
|
|
|
|
|
|
feed.into_iter()
|
|
|
|
|
|
.map(|table| {
|
|
|
|
|
|
table.into_iter()
|
|
|
|
|
|
.map(|(tool, stats)| {
|
|
|
|
|
|
(tool.parse().unwrap(), stats)
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect()
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<HashMap<ToolType, MagFeedTable>>>()
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
pub enum ItemParseError {
|
|
|
pub enum ItemParseError {
|
|
@ -389,4 +441,44 @@ impl Mag { |
|
|
Err(ItemParseError::InvalidMagBytes) // TODO: error handling if wrong bytes are given
|
|
|
Err(ItemParseError::InvalidMagBytes) // TODO: error handling if wrong bytes are given
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
mod test {
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
use std::io::Read;
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_load_mag_stats() {
|
|
|
|
|
|
let mut f = std::fs::File::open("data/item_stats/mag_stats.toml").unwrap();
|
|
|
|
|
|
let mut s = String::new();
|
|
|
|
|
|
f.read_to_string(&mut s).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let mags: HashMap<String, MagStats> = toml::from_str(&s).unwrap();
|
|
|
|
|
|
let _mags = mags.into_iter()
|
|
|
|
|
|
.map(|(name, stats)| {
|
|
|
|
|
|
(name.parse().unwrap(), stats)
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<HashMap<MagType, MagStats>>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_load_mag_feed_table() {
|
|
|
|
|
|
let mut f = std::fs::File::open("data/item_stats/mag_feed_table.toml").unwrap();
|
|
|
|
|
|
let mut s = String::new();
|
|
|
|
|
|
f.read_to_string(&mut s).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let mut feed: HashMap<String, Vec<HashMap<String, MagFeedTable>>> = toml::from_str(&s).unwrap();
|
|
|
|
|
|
let feed = feed.remove("feedtable".into()).unwrap();
|
|
|
|
|
|
let _feed = feed.into_iter()
|
|
|
|
|
|
.map(|table| {
|
|
|
|
|
|
table.into_iter()
|
|
|
|
|
|
.map(|(tool, stats)| {
|
|
|
|
|
|
(tool.parse().unwrap(), stats)
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect()
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<Vec<HashMap<ToolType, MagFeedTable>>>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|