Skip to content

Commit 5ba1641

Browse files
committed
Added more serde support
1 parent b75d4b1 commit 5ba1641

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/map/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl Default for TilemapRenderSettings {
4444
/// A component which stores a reference to the tilemap entity.
4545
#[derive(Component, Reflect, Clone, Copy, Debug, Hash)]
4646
#[reflect(Component, MapEntities)]
47+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4748
pub struct TilemapId(pub Entity);
4849

4950
impl MapEntities for TilemapId {

src/render/extract.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use bevy::math::Affine3A;
2-
use bevy::prelude::Res;
3-
use bevy::prelude::Time;
42
use bevy::render::primitives::{Aabb, Frustum};
53
use bevy::render::render_resource::FilterMode;
64
use bevy::render::render_resource::TextureFormat;
7-
use bevy::{math::Vec4, prelude::*, render::Extract, utils::HashMap};
5+
use bevy::{prelude::*, render::Extract, utils::HashMap};
86

97
use crate::prelude::TilemapGridSize;
108
use crate::prelude::TilemapRenderSettings;

src/tiles/mod.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod storage;
22

33
use bevy::{
4-
math::{UVec2, Vec2},
4+
math::{IVec2, UVec2, Vec2},
55
prelude::{Bundle, Color, Component, Reflect, ReflectComponent},
66
};
77
pub use storage::*;
@@ -53,6 +53,15 @@ impl From<UVec2> for TilePos {
5353
}
5454
}
5555

56+
impl From<IVec2> for TilePos {
57+
fn from(v: IVec2) -> Self {
58+
Self {
59+
x: v.x as u32,
60+
y: v.y as u32,
61+
}
62+
}
63+
}
64+
5665
impl From<TilePos> for Vec2 {
5766
fn from(pos: TilePos) -> Self {
5867
Vec2::new(pos.x as f32, pos.y as f32)
@@ -67,12 +76,14 @@ impl From<&TilePos> for Vec2 {
6776

6877
/// A texture index into the atlas or texture array for a single tile. Indices in an atlas are horizontal based.
6978
#[derive(Component, Reflect, Default, Clone, Copy, Debug, Hash)]
79+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7080
#[reflect(Component)]
7181
pub struct TileTextureIndex(pub u32);
7282

7383
/// A custom color for the tile.
7484
#[derive(Component, Reflect, Default, Clone, Copy, Debug)]
7585
#[reflect(Component)]
86+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7687
pub struct TileColor(pub Color);
7788

7889
impl From<Color> for TileColor {
@@ -84,6 +95,7 @@ impl From<Color> for TileColor {
8495
/// Hides or shows a tile based on the boolean. Default: True
8596
#[derive(Component, Reflect, Clone, Copy, Debug, Hash)]
8697
#[reflect(Component)]
98+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8799
pub struct TileVisible(pub bool);
88100

89101
impl Default for TileVisible {
@@ -95,6 +107,7 @@ impl Default for TileVisible {
95107
/// Flips the tiles texture along the X, Y or diagonal axes
96108
#[derive(Component, Reflect, Default, Clone, Copy, Debug, Hash)]
97109
#[reflect(Component)]
110+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
98111
pub struct TileFlip {
99112
/// Flip tile along the x axis.
100113
pub x: bool,
@@ -105,6 +118,7 @@ pub struct TileFlip {
105118

106119
/// This an optional tile bundle with default components.
107120
#[derive(Bundle, Default, Clone, Copy, Debug)]
121+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
108122
pub struct TileBundle {
109123
pub position: TilePos,
110124
pub texture_index: TileTextureIndex,
@@ -117,12 +131,14 @@ pub struct TileBundle {
117131

118132
#[derive(Component, Reflect, Default, Clone, Copy, Debug)]
119133
#[reflect(Component)]
134+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
120135
pub struct TilePosOld(pub TilePos);
121136

122137
/// A component that is attached to a Tile entity that
123138
/// tells the GPU how to animate the tile.
124139
/// Currently all frames must be aligned in your tilemap.
125140
#[derive(Component, Reflect, Clone, Copy, Debug)]
141+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
126142
pub struct AnimatedTile {
127143
/// The start frame index in the tilemap atlas/array (inclusive).
128144
pub start: u32,

0 commit comments

Comments
 (0)