ck3-regions 0.1.2

Generates title-based region textures for use with the custom dynamic terrain shader system implemented in some CK3 mods.
Documentation
use std::io::Error as IoError;
use thiserror::Error;
use image::ImageError;

use crate::{
    loading::{MapDataLoadingError, ProvincesMapLoadingError},
    map::PredefinedRegionsLoadingError,
};

#[derive(Error, Debug)]
pub enum Error {
    #[error("failed to load map data: {0}")]
    MapDataLoadingFailed(#[from] MapDataLoadingError),
    #[error("failed to load provinces map: {0}")]
    ProvincesMapLoadingFailed(#[from] ProvincesMapLoadingError),
    #[error("failed to load predefined regions map: {0}")]
    PredefinedRegionsLoadingFailed(#[from] PredefinedRegionsLoadingError),
    #[error("failed to process image: {0}")]
    ImageError(#[from] ImageError),
    #[error("failed to write metadata file: {0}")]
    MetadataWritingFailed(#[source] IoError)
}

impl Error {
    pub fn from_write_metadata_error(io_error: IoError) -> Self {
        Self::MetadataWritingFailed(io_error)
    }

    pub fn eprint_encountered_map_data_errors(&self) {
        if let Self::MapDataLoadingFailed(MapDataLoadingError::InvalidMapData(map_data_errors)) = self {
            for map_data_error in map_data_errors {
                eprintln!("{}", map_data_error);
            }
        }
    }
}