Skip to content

Commit

Permalink
Merge pull request #518 from StarArawn/add-more-serde-support
Browse files Browse the repository at this point in the history
Added more serde support
  • Loading branch information
StarArawn authored Mar 2, 2024
2 parents b75d4b1 + 78aa6cc commit 1e345d1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl Default for TilemapRenderSettings {
/// A component which stores a reference to the tilemap entity.
#[derive(Component, Reflect, Clone, Copy, Debug, Hash)]
#[reflect(Component, MapEntities)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TilemapId(pub Entity);

impl MapEntities for TilemapId {
Expand Down
4 changes: 1 addition & 3 deletions src/render/extract.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use bevy::math::Affine3A;
use bevy::prelude::Res;
use bevy::prelude::Time;
use bevy::render::primitives::{Aabb, Frustum};
use bevy::render::render_resource::FilterMode;
use bevy::render::render_resource::TextureFormat;
use bevy::{math::Vec4, prelude::*, render::Extract, utils::HashMap};
use bevy::{prelude::*, render::Extract, utils::HashMap};

use crate::prelude::TilemapGridSize;
use crate::prelude::TilemapRenderSettings;
Expand Down
7 changes: 7 additions & 0 deletions src/tiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ impl From<&TilePos> for Vec2 {

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

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

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

impl Default for TileVisible {
Expand All @@ -95,6 +98,7 @@ impl Default for TileVisible {
/// Flips the tiles texture along the X, Y or diagonal axes
#[derive(Component, Reflect, Default, Clone, Copy, Debug, Hash)]
#[reflect(Component)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TileFlip {
/// Flip tile along the x axis.
pub x: bool,
Expand All @@ -105,6 +109,7 @@ pub struct TileFlip {

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

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

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

0 comments on commit 1e345d1

Please sign in to comment.