use serde::{Deserialize, Serialize};
use specta::Type;
use std::path::{Path, PathBuf};
use crate::parser::{ObjectType, RawModuleLocation};
#[allow(clippy::module_name_repetitions)]
#[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Type)]
#[serde(rename_all = "camelCase")]
pub struct ParserOptions {
pub attach_metadata_to_raws: bool,
pub skip_apply_copy_tags_from: bool,
pub skip_apply_creature_variations: bool,
pub object_types_to_parse: Vec<ObjectType>,
pub locations_to_parse: Vec<RawModuleLocation>,
pub dwarf_fortress_directory: PathBuf,
pub legends_exports_to_parse: Vec<PathBuf>,
pub raw_files_to_parse: Vec<PathBuf>,
pub raw_modules_to_parse: Vec<PathBuf>,
pub module_info_files_to_parse: Vec<PathBuf>,
pub log_summary: bool,
}
impl Default for ParserOptions {
fn default() -> Self {
Self {
attach_metadata_to_raws: false,
skip_apply_copy_tags_from: false,
skip_apply_creature_variations: false,
log_summary: false,
object_types_to_parse: vec![
ObjectType::Creature,
ObjectType::CreatureVariation,
ObjectType::Entity,
ObjectType::Plant,
ObjectType::Inorganic,
ObjectType::MaterialTemplate,
ObjectType::Graphics,
ObjectType::TilePage,
],
locations_to_parse: vec![],
dwarf_fortress_directory: PathBuf::from(""),
legends_exports_to_parse: Vec::new(),
raw_files_to_parse: Vec::new(),
raw_modules_to_parse: Vec::new(),
module_info_files_to_parse: Vec::new(),
}
}
}
impl ParserOptions {
pub fn new<P: AsRef<Path>>(target_path: P) -> Self {
Self {
dwarf_fortress_directory: target_path.as_ref().to_path_buf(),
..Default::default()
}
}
pub fn attach_metadata_to_raws(&mut self) {
self.attach_metadata_to_raws = true;
}
pub fn skip_apply_copy_tags_from(&mut self) {
self.skip_apply_copy_tags_from = true;
}
pub fn skip_apply_creature_variations(&mut self) {
self.skip_apply_creature_variations = true;
}
pub fn set_object_types_to_parse(&mut self, raws_to_parse: Vec<ObjectType>) {
self.object_types_to_parse = raws_to_parse;
}
pub fn add_object_type_to_parse(&mut self, raw_to_parse: ObjectType) {
if self.object_types_to_parse.contains(&raw_to_parse) {
return;
}
self.object_types_to_parse.push(raw_to_parse);
}
pub fn include_graphics(&mut self) {
self.add_object_type_to_parse(ObjectType::Graphics);
self.add_object_type_to_parse(ObjectType::TilePage);
}
pub fn set_locations_to_parse(&mut self, locations_to_parse: Vec<RawModuleLocation>) {
self.locations_to_parse = locations_to_parse;
}
pub fn set_raw_files_to_parse(&mut self, raw_files_to_parse: Vec<PathBuf>) {
self.raw_files_to_parse = raw_files_to_parse;
}
pub fn set_raw_modules_to_parse(&mut self, raw_modules_to_parse: Vec<PathBuf>) {
self.raw_modules_to_parse = raw_modules_to_parse;
}
pub fn set_module_info_files_to_parse(&mut self, module_info_files_to_parse: Vec<PathBuf>) {
self.module_info_files_to_parse = module_info_files_to_parse;
}
pub fn set_legends_exports_to_parse(&mut self, legends_exports_to_parse: Vec<PathBuf>) {
self.legends_exports_to_parse = legends_exports_to_parse;
}
pub fn add_legends_export_to_parse<P: AsRef<Path>>(&mut self, legends_export_to_parse: &P) {
self.legends_exports_to_parse
.push(legends_export_to_parse.as_ref().to_path_buf());
}
pub fn add_raw_file_to_parse<P: AsRef<Path>>(&mut self, raw_file_to_parse: &P) {
self.raw_files_to_parse
.push(raw_file_to_parse.as_ref().to_path_buf());
}
pub fn add_raw_module_to_parse<P: AsRef<Path>>(&mut self, raw_module_to_parse: &P) {
self.raw_modules_to_parse
.push(raw_module_to_parse.as_ref().to_path_buf());
}
pub fn add_module_info_file_to_parse<P: AsRef<Path>>(&mut self, module_info_file_to_parse: &P) {
self.module_info_files_to_parse
.push(module_info_file_to_parse.as_ref().to_path_buf());
}
pub fn log_summary(&mut self) {
self.log_summary = true;
}
pub fn add_location_to_parse(&mut self, location_to_parse: RawModuleLocation) {
self.locations_to_parse.push(location_to_parse);
}
}