summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock20
-rw-r--r--Cargo.toml1
-rw-r--r--src/random_tables.rs11
3 files changed, 30 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2c0bb18..dd58246 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -94,6 +94,7 @@ name = "dmn"
version = "0.1.0"
dependencies = [
"clap",
+ "include_dir",
"rand",
"serde",
"serde_yaml",
@@ -123,6 +124,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12"
[[package]]
+name = "include_dir"
+version = "0.7.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "18762faeff7122e89e0857b02f7ce6fcc0d101d5e9ad2ad7846cc01d61b7f19e"
+dependencies = [
+ "include_dir_macros",
+]
+
+[[package]]
+name = "include_dir_macros"
+version = "0.7.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b139284b5cf57ecfa712bcc66950bb635b31aff41c188e8a4cfc758eca374a3f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+]
+
+[[package]]
name = "indexmap"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 345e4bd..02728aa 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,6 +11,7 @@ repository = "https://git.aikuro.net/poems/dmn"
[dependencies]
clap = { version = "^4.4", features = ["cargo"] }
+include_dir = "0.7.3"
rand = "^0.8"
serde = { version = "^1.0", features = ["derive"] }
serde_yaml = "^0.9"
diff --git a/src/random_tables.rs b/src/random_tables.rs
index 1d9df02..2428ad2 100644
--- a/src/random_tables.rs
+++ b/src/random_tables.rs
@@ -3,6 +3,7 @@ use serde_yaml;
use std::collections::HashMap;
use std::error::Error;
use std::string::String;
+use include_dir::{include_dir, Dir};
use crate::dice;
#[derive(Debug, Deserialize)]
@@ -27,10 +28,16 @@ pub struct RandomTables {
tables: HashMap<String, RandomTable>,
}
+const YAML_DIR : Dir = include_dir!("src/data/random_tables/");
+
impl RandomTables {
pub fn new() -> Result<Self, Box<dyn Error>> {
- let tables_yaml = include_str!("data/random_tables/ua_magic_items.yaml");
- let tables: HashMap<String, RandomTable> = serde_yaml::from_str(tables_yaml)?;
+ let mut tables_yaml = String::new();
+ for entry in YAML_DIR.files() {
+ tables_yaml.push_str(entry.contents_utf8().unwrap());
+ }
+
+ let tables: HashMap<String, RandomTable> = serde_yaml::from_str(tables_yaml.as_str())?;
Ok(RandomTables { tables })
}