feat: Add optional map serialization.
This commit is contained in:
parent
25518879d9
commit
f02e263749
|
@ -11,6 +11,7 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
rand = "0.8"
|
||||
serde = { version = "1", optional = true, features = ["derive"]}
|
||||
|
||||
[package.metadata.release]
|
||||
publish = false
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
//! Support function for 2D geometry
|
||||
//!
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Position on the map
|
||||
#[derive(Default, PartialEq, Copy, Clone, Debug, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||
pub struct Point {
|
||||
pub x: usize,
|
||||
pub y: usize,
|
||||
|
@ -29,6 +33,7 @@ impl Point {
|
|||
|
||||
/// Rectangle region on the map
|
||||
#[derive(Hash, PartialEq, Eq, Copy, Clone, Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||
pub struct Rect {
|
||||
pub x1: usize,
|
||||
pub x2: usize,
|
||||
|
|
|
@ -7,10 +7,15 @@
|
|||
//! specific game.
|
||||
//!
|
||||
|
||||
use super::geometry::{usize_abs, Point, Rect};
|
||||
use std::fmt;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::geometry::{usize_abs, Point, Rect};
|
||||
|
||||
#[derive(PartialEq, Copy, Clone, Debug, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||
pub struct Tile {
|
||||
is_blocked: bool,
|
||||
index: usize,
|
||||
|
@ -30,6 +35,7 @@ pub struct NoData;
|
|||
|
||||
/// Map data
|
||||
#[derive(Default, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||
pub struct Map<D: Clone + Default> {
|
||||
pub tiles: Vec<Tile>,
|
||||
pub width: usize,
|
||||
|
|
Loading…
Reference in New Issue
Block a user