Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more serde support #518

Merged
merged 3 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading