2025-06-25 02:15:27 +03:00
|
|
|
use std::{fmt::Display, path::PathBuf};
|
|
|
|
|
|
2025-06-24 19:56:47 +03:00
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, PartialEq, Eq)]
|
|
|
|
|
pub struct EnemyDrop {
|
|
|
|
|
pub from: String,
|
2025-06-25 02:15:27 +03:00
|
|
|
pub chance: EnemyDropChance,
|
2025-06-24 19:56:47 +03:00
|
|
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub info: Option<String>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl EnemyDrop {
|
|
|
|
|
pub fn texture(&self) -> String {
|
|
|
|
|
self.from.replace(" ", "_").to_lowercase()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, PartialEq, Eq)]
|
2025-06-25 02:15:27 +03:00
|
|
|
#[serde(untagged)]
|
|
|
|
|
pub enum EnemyDropChance {
|
|
|
|
|
Fixed(u8),
|
|
|
|
|
Variable(String),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Display for EnemyDropChance {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
match self {
|
|
|
|
|
EnemyDropChance::Fixed(val) => f.write_str(&format!("{val}%")),
|
|
|
|
|
EnemyDropChance::Variable(val) => f.write_str(val),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Deserialize, PartialEq, Eq)]
|
|
|
|
|
#[serde(default)]
|
2025-06-24 19:56:47 +03:00
|
|
|
pub struct MaterialDrops {
|
|
|
|
|
pub kind: String,
|
|
|
|
|
pub shard: Vec<EnemyDrop>,
|
|
|
|
|
pub stone: Vec<EnemyDrop>,
|
|
|
|
|
pub gem: Vec<EnemyDrop>,
|
|
|
|
|
pub crystal: Vec<EnemyDrop>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl MaterialDrops {
|
2025-06-25 02:15:27 +03:00
|
|
|
pub fn import(path: &str) -> Vec<MaterialDrops> {
|
|
|
|
|
let mut drops: Vec<MaterialDrops> = vec![];
|
|
|
|
|
|
|
|
|
|
// Loading multiple files into one vector due to the size of each board
|
|
|
|
|
let paths = std::fs::read_dir(path)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.filter_map(|f| f.ok())
|
|
|
|
|
.map(|f| f.path())
|
|
|
|
|
.filter_map(|p| match p.extension().is_some_and(|e| e == "toml") {
|
|
|
|
|
true => Some(p),
|
|
|
|
|
false => None,
|
|
|
|
|
})
|
|
|
|
|
.collect::<Vec<PathBuf>>();
|
|
|
|
|
|
|
|
|
|
for path in paths {
|
|
|
|
|
let drops_str = std::fs::read_to_string(path).unwrap();
|
|
|
|
|
let enemy_drops = toml::from_str::<MaterialDrops>(&drops_str).unwrap();
|
|
|
|
|
drops.push(enemy_drops);
|
|
|
|
|
}
|
|
|
|
|
drops.sort_by(|a, b| a.kind.cmp(&b.kind));
|
|
|
|
|
|
|
|
|
|
drops
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-24 19:56:47 +03:00
|
|
|
pub fn drops(&self, kind: &str) -> &[EnemyDrop] {
|
|
|
|
|
match kind {
|
|
|
|
|
"shard" => &self.shard,
|
|
|
|
|
"stone" => &self.stone,
|
|
|
|
|
"gem" => &self.gem,
|
|
|
|
|
"crystal" => &self.crystal,
|
|
|
|
|
_ => &self.shard,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|