Skip to main content

ck3_regions/
config.rs

1use std::path::PathBuf;
2
3use crate::{
4    cli::{Cli, ModeArg},
5    model::game::TitleTier,
6};
7
8//
9// pub enum ModeSettings
10//
11
12#[derive(Debug, Clone)]
13pub enum ModeSettings {
14    TitleBasedRegions{
15        region_title_tier: TitleTier,
16    },
17    PredefinedRegions{
18        input_regions_map_path: PathBuf,
19    }
20}
21
22impl ModeSettings {
23    pub fn from_cli_mode_arg(mode_arg: ModeArg) -> Self {
24        assert!(mode_arg.regions_map.is_none() || mode_arg.title_tier.is_none(), "mode_arg must be unambiguous");
25
26        if let Some(region_title_tier) = mode_arg.title_tier {
27            Self::TitleBasedRegions { region_title_tier }
28        } else {
29            Self::PredefinedRegions { input_regions_map_path: mode_arg.regions_map.unwrap() }
30        }
31    }
32}
33
34//
35// pub struct ModPaths
36//
37
38#[derive(Debug, Clone)]
39pub struct ModPaths {
40    pub mod_root:        PathBuf,
41    pub raw_regions_map: PathBuf,
42    pub regions_map:     PathBuf,
43    pub adjacency_map_0: PathBuf,
44    //pub adjacency_map_1: PathBuf,
45    pub proximity_map:   PathBuf,
46}
47
48impl ModPaths {
49    pub fn new(mod_root_path: PathBuf, mod_prefix: &str) -> Self {
50        Self {
51            raw_regions_map: mod_root_path.join(format!("map_data/{}_dynamic_terrain_regions_raw.png", mod_prefix)),
52            regions_map:     mod_root_path.join(format!("map_data/{}_dynamic_terrain_regions.png",     mod_prefix)),
53            adjacency_map_0: mod_root_path.join(format!("map_data/{}_dynamic_terrain_adjacency.png", mod_prefix)),
54            //adjacency_map_1: mod_root_path.join(format!("map_data/{}_dynamic_terrain_adjacency_1.png", mod_prefix)),
55            proximity_map:   mod_root_path.join(format!("map_data/{}_dynamic_terrain_proximity.png",   mod_prefix)),
56            mod_root:        mod_root_path,
57        }
58    }
59}
60
61//
62// pub struct Config
63//
64
65#[derive(Debug, Clone)]
66pub struct Config {
67    pub mode_settings:             ModeSettings,
68    pub proximity_distance_limit:  f32,
69    pub mod_paths:                 ModPaths,
70    pub mod_prefix:                String,
71    //pub must_expand_regions        bool, // TODO?
72    pub output_metadata_yaml_path: Option<PathBuf>,
73    pub must_expand_regions:       bool,
74    pub must_attempt_early_exit:   bool,
75    pub is_dry_run:                bool,
76    pub is_color_disabled:         bool,
77}
78
79impl Config {
80    pub fn from_cli(cli: Cli) -> Self {
81        Self {
82            mode_settings:             ModeSettings::from_cli_mode_arg(cli.mode_arg),
83            proximity_distance_limit:  cli.proximity_limit,
84            mod_paths:                 ModPaths::new(cli.mod_root_path, &cli.mod_prefix),
85            mod_prefix:                cli.mod_prefix,
86            output_metadata_yaml_path: cli.output_metadata_yaml_path,
87            must_expand_regions:       cli.must_expand_regions,
88            must_attempt_early_exit:   cli.must_attempt_early_exit,
89            is_dry_run:                cli.is_dry_run,
90            is_color_disabled:         cli.is_color_disabled,
91        }
92    }
93}
94
95//
96// Interface
97//
98
99pub fn is_valid_mod_prefix(prefix_str: &str) -> bool {
100    !prefix_str.is_empty() && prefix_str.chars().all(|c| c.is_ascii_alphanumeric() || c == '_')
101}