wip: checkpoint multi-game core work
This commit is contained in:
+1
-24
@@ -1,24 +1 @@
|
||||
use anyhow::{Context, Result};
|
||||
use serde::de::DeserializeOwned;
|
||||
use std::path::Path;
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Generic loader for JSON arrays from a directory.
|
||||
pub fn load_json_dir<T: DeserializeOwned>(dir: &Path) -> Result<Vec<T>> {
|
||||
let mut items = Vec::new();
|
||||
if !dir.exists() {
|
||||
return Ok(items);
|
||||
}
|
||||
for entry in std::fs::read_dir(dir).with_context(|| format!("reading dir {dir:?}"))? {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
if path.extension().map(|e| e == "json").unwrap_or(false) {
|
||||
let content =
|
||||
std::fs::read_to_string(&path).with_context(|| format!("reading {path:?}"))?;
|
||||
let batch: Vec<T> =
|
||||
serde_json::from_str(&content).with_context(|| format!("parsing {path:?}"))?;
|
||||
items.extend(batch);
|
||||
}
|
||||
}
|
||||
Ok(items)
|
||||
}
|
||||
// Reserved for future modding loader utilities.
|
||||
|
||||
@@ -1,4 +1,2 @@
|
||||
//! Modding support: load JSON data files from the data/ directory.
|
||||
//! All game content (cards, packs, objectives, SBCs) is data-driven.
|
||||
|
||||
pub mod loader;
|
||||
|
||||
Reference in New Issue
Block a user