use bevy::asset::{Asset, Handle};
use bevy::ecs::component::Component;
use bevy::ecs::event::Event;
use bevy::prelude::Visibility;
use bevy::reflect::{Reflect, TypePath};
use bevy::scene::Scene;
use bevy::image::TextureAtlasLayout;
use bevy::transform::components::Transform;
use bevy_platform::collections::HashMap;
use tiled_parse::types::*;
#[derive(Component)]
#[require(Transform, Visibility)]
pub struct TiledMapScene(pub Handle<TiledMapAsset>);
#[derive(Component, Reflect, Copy, Clone, Debug)]
pub struct TiledMapContainer;
#[derive(Component, Reflect, Copy, Clone, Debug)]
pub enum TiledId {
Layer(tiled_parse::types::ID),
Tile(tiled_parse::types::ID),
Object(tiled_parse::types::ID),
}
#[derive(Component, Reflect, Copy, Clone, Debug)]
pub struct TileObject(pub tiled_parse::types::ID);
#[derive(Component, Reflect, Copy, Clone, Debug)]
pub struct TiledIndex(pub usize, pub usize);
impl Into<(usize, usize)> for TiledIndex {
fn into(self) -> (usize, usize) {
(self.0, self.1)
}
}
#[derive(Reflect, Copy, Clone, Debug)]
pub enum TiledAnimationPlayer {
Once,
Cycled
}
#[derive(Component, Reflect, Clone, Debug)]
pub struct TiledAnimation {
pub animation: Vec<AnimationFrameReflect>,
pub start_time: f32,
pub player: TiledAnimationPlayer
}
#[derive(Reflect, Copy, Clone, Debug)]
pub struct AnimationFrameReflect {
pub tile_id: ID,
pub duration: f32
}
impl From<AnimationFrame> for AnimationFrameReflect {
fn from(AnimationFrame { tile_id, duration }: AnimationFrame) -> Self {
Self { tile_id, duration }
}
}
#[derive(Event, Reflect, Copy, Clone, Debug)]
pub struct TiledAnimationCompleted;
#[derive(TypePath, Asset)]
pub struct TiledMapAsset {
pub map: tiled_parse::types::TiledMap,
pub tilemap_textures: Vec<Handle<bevy::prelude::Image>>,
pub tilemap_atlases: Vec<Handle<TextureAtlasLayout>>,
pub scene: Handle<Scene>,
}
#[derive(Component, Reflect, Debug)]
pub struct SerializedComponents(pub HashMap<SceneSerializedComponents, Vec<u8>>);
#[derive(Reflect, PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub enum SceneSerializedComponents {
SerCollider,
SerRigidBody,
}