thedes_gen/map/layer/
matter.rs1use thedes_domain::{
2 geometry::CoordPair,
3 map::{AccessError, Map},
4 matter::{Biome, Ground},
5};
6
7use super::{Layer, LayerDistribution};
8
9pub type GroundLayerError = AccessError;
10pub type BiomeLayerError = AccessError;
11pub type GroundDistrError = AccessError;
12
13#[derive(Debug, Clone)]
14pub struct GroundLayer;
15
16impl Layer for GroundLayer {
17 type Data = Ground;
18 type Error = GroundLayerError;
19
20 fn get(
21 &self,
22 map: &mut Map,
23 point: CoordPair,
24 ) -> Result<Self::Data, Self::Error> {
25 map.get_ground(point)
26 }
27
28 fn set(
29 &self,
30 map: &mut Map,
31 point: CoordPair,
32 value: Self::Data,
33 ) -> Result<(), Self::Error> {
34 map.set_ground(point, value)
35 }
36}
37
38#[derive(Debug, Clone)]
39pub struct BiomeLayer;
40
41impl Layer for BiomeLayer {
42 type Data = Biome;
43 type Error = BiomeLayerError;
44
45 fn get(
46 &self,
47 map: &mut Map,
48 point: CoordPair,
49 ) -> Result<Self::Data, Self::Error> {
50 map.get_biome(point)
51 }
52
53 fn set(
54 &self,
55 map: &mut Map,
56 point: CoordPair,
57 value: Self::Data,
58 ) -> Result<(), Self::Error> {
59 map.set_biome(point, value)
60 }
61}
62
63#[derive(Debug, Clone)]
64pub struct GroundLayerDistr {
65 _private: (),
66}
67
68impl Default for GroundLayerDistr {
69 fn default() -> Self {
70 Self { _private: () }
71 }
72}
73
74impl LayerDistribution for GroundLayerDistr {
75 type Data = Ground;
76 type Error = GroundDistrError;
77
78 fn sample<R>(
79 &self,
80 map: &mut Map,
81 point: CoordPair,
82 _rng: R,
83 ) -> Result<Self::Data, Self::Error>
84 where
85 R: rand::Rng,
86 {
87 let ground = match map.get_biome(point)? {
88 Biome::Plains => Ground::Grass,
89 Biome::Desert => Ground::Sand,
90 Biome::Wasteland => Ground::Stone,
91 };
92 Ok(ground)
93 }
94}