112 lines
2.6 KiB
Rust
112 lines
2.6 KiB
Rust
use std::collections::{HashMap, BTreeMap};
|
|
use serde::{Serialize, Deserialize};
|
|
use std::fs::File;
|
|
use std::io::Read;
|
|
|
|
use crate::entity::item::armor::ArmorType;
|
|
use crate::entity::item::shield::ShieldType;
|
|
use crate::entity::item::unit::UnitType;
|
|
|
|
|
|
fn load_data_file<T: serde::de::DeserializeOwned>(path: &str) -> T {
|
|
let mut f = File::open(path).unwrap();
|
|
let mut s = String::new();
|
|
f.read_to_string(&mut s);
|
|
|
|
toml::from_str::<T>(s.as_str()).unwrap()
|
|
}
|
|
|
|
|
|
struct WeaponStats {
|
|
|
|
}
|
|
|
|
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
|
|
pub struct ArmorStats {
|
|
pub stars: u32,
|
|
pub dfp: i32,
|
|
pub evp: i32,
|
|
pub dfp_modifier: u32,
|
|
pub evp_modifier: u32,
|
|
pub team_points: u32,
|
|
pub level_req: u32,
|
|
pub efr: i32,
|
|
pub eic: i32,
|
|
pub eth: i32,
|
|
pub elt: i32,
|
|
pub edk: i32,
|
|
}
|
|
|
|
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
|
|
pub struct ShieldStats {
|
|
pub stars: u32,
|
|
pub dfp: i32,
|
|
pub evp: i32,
|
|
pub dfp_modifier: u32,
|
|
pub evp_modifier: u32,
|
|
pub team_points: u32,
|
|
pub level_req: u32,
|
|
pub efr: i32,
|
|
pub eic: i32,
|
|
pub eth: i32,
|
|
pub elt: i32,
|
|
pub edk: i32,
|
|
}
|
|
|
|
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
|
|
pub struct UnitStats {
|
|
pub stars: u32,
|
|
pub stat: u32,
|
|
pub amount: u32,
|
|
pub team_points: u32,
|
|
pub modifier: u32,
|
|
}
|
|
|
|
|
|
pub fn armor_stats() -> HashMap<ArmorType, ArmorStats> {
|
|
let armor_stats: HashMap<String, ArmorStats> = load_data_file("data/item_stats/armor_stats.toml");
|
|
armor_stats.iter()
|
|
.map(|(name, stats)| {
|
|
(name.parse().unwrap(), *stats)
|
|
}).collect()
|
|
}
|
|
|
|
pub fn shield_stats() -> HashMap<ShieldType, ShieldStats> {
|
|
let shield_stats: HashMap<String, ShieldStats> = load_data_file("data/item_stats/shield_stats.toml");
|
|
shield_stats.iter()
|
|
.map(|(name, stats)| {
|
|
(name.parse().unwrap(), *stats)
|
|
}).collect()
|
|
}
|
|
|
|
pub fn unit_stats() -> BTreeMap<UnitType, UnitStats> {
|
|
let unit_stats: BTreeMap<String, UnitStats> = load_data_file("data/item_stats/unit_stats.toml");
|
|
unit_stats.iter()
|
|
.map(|(name, stats)| {
|
|
(name.parse().unwrap(), *stats)
|
|
}).collect()
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_armor_stats() {
|
|
let astat = armor_stats();
|
|
assert!(astat.get(&ArmorType::CrimsonCoat).unwrap().stars == 11);
|
|
}
|
|
|
|
#[test]
|
|
fn test_shield_stats() {
|
|
let sstat = shield_stats();
|
|
assert!(sstat.get(&ShieldType::RedRing).unwrap().stars == 11);
|
|
}
|
|
|
|
#[test]
|
|
fn test_unit_stats() {
|
|
let ustat = unit_stats();
|
|
assert!(ustat.get(&UnitType::ElfArm).unwrap().stars == 5);
|
|
}
|
|
}
|