1#[cfg(all(feature = "_supports_ldtk", feature = "bevy"))]
2mod assets;
3#[cfg(feature = "bevy")]
4mod camera;
5#[cfg(feature = "bevy")]
6mod map_query;
7#[cfg(not(feature = "bevy"))]
8mod map_query_neutral;
9#[cfg(not(feature = "bevy"))]
10use map_query_neutral as map_query;
11
12#[cfg(feature = "bevy")]
13mod pregen;
14mod system;
15
16#[cfg(feature = "_supports_ldtk")]
17pub mod ldtk;
18
19pub static mut LDTK_TILE_SCALE: AtomicU32 = AtomicU32::new(32);
20pub fn get_ldtk_tile_scale() -> f32 {
21 unsafe { *LDTK_TILE_SCALE.get_mut() as f32 }
22}
23pub fn set_ldtk_tile_scale_u32(scale: u32) {
24 unsafe {
25 LDTK_TILE_SCALE.store(scale, Ordering::Release);
26 }
27}
28pub fn set_ldtk_tile_scale_f32(scale: f32) {
29 unsafe {
30 LDTK_TILE_SCALE.store(scale as u32, Ordering::Release);
31 }
32}
33
34#[cfg(feature = "bevy")]
35mod __plugin {
36 use bevy::ecs::query::QueryFilter;
37 use std::marker::PhantomData;
38
39 use bevy::prelude::*;
40
41 pub struct MicroLDTKPlugin;
42 impl Plugin for MicroLDTKPlugin {
43 fn build(&self, app: &mut App) {
44 #[cfg(feature = "_supports_ldtk")]
45 {
46 app.add_event::<super::system::LevelDataUpdated>()
47 .init_asset::<super::ldtk::Project>()
48 .init_asset::<super::ldtk::Level>()
49 .init_asset::<super::ldtk::LevelSet>()
50 .init_asset_loader::<super::ldtk::LdtkLoader>()
51 .init_asset_loader::<super::ldtk::LdtkLevelLoader>()
52 .init_resource::<super::assets::TilesetIndex>()
53 .init_resource::<super::assets::LevelIndex>()
54 .add_systems(
55 Update,
56 (
57 super::assets::handle_ldtk_project_events,
58 super::assets::handle_ldtk_level_events,
59 super::assets::handle_ldtk_level_set_events,
60 ),
61 );
62 }
63 }
64 }
65
66 impl<CameraFilter: QueryFilter + Send + Sync + 'static> MicroLDTKCameraPlugin<CameraFilter> {
67 pub fn new() -> Self {
68 Self {
69 _p: PhantomData::default(),
70 }
71 }
72 }
73 impl<CameraFilter: QueryFilter + Send + Sync + 'static> Default
74 for MicroLDTKCameraPlugin<CameraFilter>
75 {
76 fn default() -> Self {
77 Self::new()
78 }
79 }
80
81 pub struct MicroLDTKCameraPlugin<CameraFilter: QueryFilter> {
82 _p: PhantomData<CameraFilter>,
83 }
84 impl<CameraFilter: QueryFilter + Send + Sync + 'static> Plugin
85 for MicroLDTKCameraPlugin<CameraFilter>
86 {
87 fn build(&self, app: &mut App) {
88 app.add_systems(
89 PostUpdate,
90 super::camera::lock_camera_to_level::<CameraFilter>,
91 );
92 }
93 }
94}
95
96use std::sync::atomic::{AtomicU32, Ordering};
97#[cfg(feature = "bevy")]
98pub use __plugin::{MicroLDTKCameraPlugin, MicroLDTKPlugin};
99#[cfg(feature = "bevy")]
100pub use assets::{LevelIndex, TileMetadata, TilesetIndex};
101#[cfg(feature = "bevy")]
102pub use camera::CameraBounder;
103pub use ldtk::{LdtkProject, Level, AutoLayerRuleGroup};
104#[cfg(feature = "bevy")]
105pub use ldtk::LdtkLoader;
106pub use map_query::{CameraBounds, InstanceRef, MapQuery};
107#[cfg(feature = "autotile")]
108pub use micro_autotile as autotile;
109#[cfg(feature = "bevy")]
110pub use pregen::{write_layer_to_texture, write_map_to_texture, Rasterise};
111pub use system::*;