voxel-zone/common/src/space/level_serde.rs

43 lines
1.5 KiB
Rust

use serde::{Serialize, Deserialize};
use thiserror::Error;
use crate::space::level_tile::LevelTile;
use crate::space::two_dimensional::depth_tiles::Direction;
use super::two_dimensional::depth_tiles::DepthTile;
#[cfg(feature = "three_dimensional")]
use super::three_dimensional::vec3generic::Vec3Generic;
#[cfg(all(feature = "three_dimensional"))]
pub fn create_export_map(voxels: &mut super::three_dimensional::hash_map_container::VoxelHashMapLayer<LevelTile>) -> Result<ExportedMap, ExportError> {
let project_voxels_dir = |d| super::three_dimensional::project_to_2d::create_tilemap(voxels, d, 32, 32, 32);
Ok(ExportedMap {
tiles_north: project_voxels_dir(Direction::North),
tiles_south: project_voxels_dir(Direction::South),
tiles_east: project_voxels_dir(Direction::East),
tiles_west: project_voxels_dir(Direction::West),
player_start: Vec3Generic { x: 0, y: 0, z: 0 },
start_direction: Direction::North,
})
}
#[cfg(all(feature = "serde", feature = "three_dimensional"))]
#[derive(Debug, Error)]
pub enum ExportError {
#[error("serialization failed")]
SerializationError(#[from] ron::Error)
}
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg(feature = "std")]
pub struct ExportedMap {
pub tiles_north: Vec<DepthTile<LevelTile>>,
pub tiles_south: Vec<DepthTile<LevelTile>>,
pub tiles_east: Vec<DepthTile<LevelTile>>,
pub tiles_west: Vec<DepthTile<LevelTile>>,
pub player_start: Vec3Generic<i32>,
pub start_direction: Direction,
}