tiger_lib/
mod_metadata.rsuse std::path::{Path, PathBuf};
use anyhow::{Context, Result};
use crate::block::Block;
use crate::fileset::{FileEntry, FileKind};
use crate::parse::json::parse_json_file;
use crate::token::Token;
use crate::util::fix_slashes_for_target_platform;
#[derive(Clone, Debug)]
pub struct ModMetadata {
modpath: PathBuf,
block: Block,
}
impl ModMetadata {
pub fn read(mod_dir: &Path) -> Result<Self> {
let in_mod_path = PathBuf::from(".metadata/metadata.json");
let pathname = fix_slashes_for_target_platform(mod_dir.join(&in_mod_path));
let entry = FileEntry::new(in_mod_path, FileKind::Mod, pathname.clone());
let block = parse_json_file(&entry)
.with_context(|| format!("Could not read metadata file {}", pathname.display()))?;
Ok(Self { modpath: mod_dir.to_path_buf(), block })
}
pub fn modpath(&self) -> &Path {
&self.modpath
}
pub fn replace_paths(&self) -> Vec<PathBuf> {
if let Some(custom_data) = self.block.get_field_block("game_custom_data") {
if let Some(replace_paths) = custom_data.get_field_list("replace_paths") {
return replace_paths.iter().map(|t| PathBuf::from(t.as_str())).collect();
}
}
Vec::new()
}
pub fn display_name(&self) -> Option<&'static str> {
self.block.get_field_value("name").map(Token::as_str)
}
}