Skip to main content

dotzuki_engine/
map.rs

1use std::fmt::Debug;
2use std::hash::Hash;
3
4/// Describes a connection between two maps on the overworld.
5///
6/// Connections allow seamless scrolling between adjacent maps
7/// without a fade transition. The engine uses this to preload
8/// the connected map's block data when the player approaches
9/// the border.
10#[derive(Debug, Clone)]
11pub struct MapConnection<M: MapTrait> {
12    /// The direction of the connection: "north", "south", "east", or "west".
13    pub direction: String,
14
15    /// The connected map.
16    pub map: M,
17
18    /// The offset (in tiles) along the connection border.
19    ///
20    /// Positive values shift the connected map to the right (horizontal)
21    /// or down (vertical); negative values shift left/up.
22    pub offset: i8,
23}
24
25/// Marker trait for map identifiers.
26///
27/// Implementations are typically lightweight enums or numeric IDs
28/// that uniquely identify a map in the game world. Maps are copied
29/// frequently during transitions and connection lookups, so they
30/// must be cheap to clone.
31pub trait MapTrait: Copy + Eq + Hash + Debug + 'static {}
32
33/// Provider trait that supplies map data to the engine.
34///
35/// This is the central abstraction for loading map dimensions,
36/// tile block data, border blocks, and connection information.
37/// The overworld system queries this provider to render maps and
38/// handle movement/collision.
39pub trait MapProvider<M: MapTrait> {
40    /// Returns the dimensions of the map as `(width, height)` in tiles.
41    fn dimensions(&self, map: M) -> (u8, u8);
42
43    /// Returns the tileset ID used by this map.
44    fn tileset(&self, map: M) -> u8;
45
46    /// Returns the block data for the map.
47    ///
48    /// Each byte in the returned slice corresponds to a block index
49    /// in the tileset's block definition table. Blocks are stored
50    /// in row-major order.
51    fn block_data(&self, map: M) -> &[u8];
52
53    /// Returns the border block ID used to fill the area outside the map.
54    fn border_block(&self, map: M) -> u8;
55
56    /// Returns the list of connected maps for seamless scrolling.
57    fn connections(&self, map: M) -> Vec<MapConnection<M>>;
58}