minetest_worldmapper/
config.rs

1use crate::color::Color;
2use serde_derive::Deserialize;
3use std::collections::HashMap;
4
5#[derive(Deserialize, Debug, Clone)]
6pub struct HillShading {
7    #[serde(default = "default_hillshading_enabled")]
8    pub enabled: bool,
9    /// Which alpha a node has to has to be considered terrain
10    #[serde(default = "default_terrain_min_alpha")]
11    pub min_alpha: u8,
12}
13
14impl Default for HillShading {
15    fn default() -> Self {
16        HillShading {
17            enabled: default_hillshading_enabled(),
18            min_alpha: default_terrain_min_alpha(),
19        }
20    }
21}
22
23#[derive(Deserialize, Debug, Clone)]
24pub struct Config {
25    /// Which opacity is considered enough to
26    /// continue with the next pixel
27    #[serde(default = "default_sufficient_alpha")]
28    pub sufficient_alpha: u8,
29    /// Which color to place after reaching `sufficient_alpha`
30    pub background_color: Color,
31    pub node_colors: HashMap<String, Color>,
32    #[serde(default)]
33    pub hill_shading: HillShading,
34}
35
36const fn default_sufficient_alpha() -> u8 {
37    230
38}
39
40const fn default_terrain_min_alpha() -> u8 {
41    128
42}
43
44const fn default_hillshading_enabled() -> bool {
45    true
46}
47
48impl Config {
49    pub fn get_color(&self, itemstring: &[u8]) -> Option<&Color> {
50        String::from_utf8(itemstring.to_vec())
51            .ok()
52            .and_then(|key| self.node_colors.get(&key))
53    }
54}