Skip to content

Commit

Permalink
feat!: upgrade to bevy and bevy_ecs_tilemap 0.11 (#204)
Browse files Browse the repository at this point in the history
I don't know if this works 100% as I don't use the plugin myself and am
updating for a Patreon, I just sort of guessed the ordering for what
used to be base sets and now need a hard scheduler. let me know if
something is in the wrong order and ill fix it

---------

Co-authored-by: Trevor Lovell <trevorlovelldesign@gmail.com>
  • Loading branch information
PhaestusFox and Trouv authored Jul 31, 2023
1 parent 6f4a8b4 commit ef1b075
Show file tree
Hide file tree
Showing 20 changed files with 143 additions and 209 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ members = ["macros"]

[dependencies]
bevy_ecs_ldtk_macros = { version = "0.7.0", optional = true, path = "macros" }
bevy_ecs_tilemap = { version = "0.10", default-features = false }
bevy = { version = "0.10", default-features = false, features = ["bevy_sprite"] }
bevy_ecs_tilemap = { version = "0.11", default-features = false }
bevy = { version = "0.11", default-features = false, features = ["bevy_sprite"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
regex = "1"
Expand All @@ -26,10 +26,10 @@ thiserror = "1.0"
paste = "1.0"

[dev-dependencies]
bevy = "0.10"
bevy_rapier2d = "0.21"
bevy = "0.11"
bevy_rapier2d = "0.22.0"
rand = "0.8"
bevy-inspector-egui = "0.18"
bevy-inspector-egui = "0.19.0"

[features]
default = ["derive", "render"]
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ use bevy_ecs_ldtk::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(LdtkPlugin)
.add_startup_system(setup)
.add_plugins(LdtkPlugin)
.add_system(Startup, setup)
.insert_resource(LevelSelection::Index(0))
.register_ldtk_entity::<MyBundle>("MyEntityIdentifier")
.run();
Expand All @@ -65,7 +65,6 @@ pub struct MyBundle {
a: ComponentA,
b: ComponentB,
#[sprite_sheet_bundle]
#[bundle]
sprite_bundle: SpriteSheetBundle,
}
```
Expand All @@ -86,7 +85,7 @@ for additional level-loading options.
### Compatibility
| bevy | bevy_ecs_tilemap | LDtk | bevy_ecs_ldtk |
| --- | --- | --- | --- |
| 0.10 | 0.10 | 1.3.3 | main |
| 0.11 | 0.11 | 1.3.3 | main |
| 0.10 | 0.10 | 1.1 | 0.7 |
| 0.10 | 0.10 | 1.1 | 0.6 |
| 0.9 | 0.9 | 1.1 | 0.5 |
Expand Down
5 changes: 2 additions & 3 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ fn main() {
.add_plugins(
DefaultPlugins.set(ImagePlugin::default_nearest()), // prevents blurry sprites
)
.add_plugin(LdtkPlugin)
.add_startup_system(setup)
.add_plugins(LdtkPlugin)
.add_systems(Startup, setup)
.insert_resource(LevelSelection::Index(0))
.register_ldtk_entity::<MyBundle>("MyEntityIdentifier")
.run();
Expand All @@ -33,6 +33,5 @@ pub struct MyBundle {
a: ComponentA,
b: ComponentB,
#[sprite_sheet_bundle]
#[bundle]
sprite_bundle: SpriteSheetBundle,
}
2 changes: 1 addition & 1 deletion examples/field_instances/equipment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy_ecs_ldtk::prelude::*;
use thiserror::Error;

/// This enum mirrors an equivalent enum in the LDtk project called "Equipment".
#[derive(Debug, Reflect, FromReflect)]
#[derive(Debug, Reflect)]
enum EquipmentType {
Helmet,
Armor,
Expand Down
13 changes: 8 additions & 5 deletions examples/field_instances/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ fn main() {
.add_plugins(
DefaultPlugins.set(ImagePlugin::default_nearest()), // prevents blurry sprites
)
.add_plugin(LdtkPlugin)
.add_plugins(LdtkPlugin)
.insert_resource(LevelSelection::default())
.add_startup_system(setup)
.add_system(mother::resolve_mother_references)
.add_systems(Startup, setup)
.add_systems(Update, mother::resolve_mother_references)
.init_resource::<level_title::LevelTitle>()
.add_system(level_title::set_level_title_to_current_level.run_if(on_event::<LevelEvent>()))
.add_systems(
Update,
level_title::set_level_title_to_current_level.run_if(on_event::<LevelEvent>()),
)
.register_ldtk_entity::<enemy::EnemyBundle>("Enemy")
// The rest of this is bevy_inspector_egui boilerplate
.add_plugin(WorldInspectorPlugin::new())
.add_plugins(WorldInspectorPlugin::new())
.register_type::<health::Health>()
.register_type::<equipment::EquipmentDrops>()
.register_type::<mother::Mother>()
Expand Down
6 changes: 3 additions & 3 deletions examples/level_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use rand::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(LdtkPlugin)
.add_startup_system(setup)
.add_system(toggle_levels)
.add_plugins(LdtkPlugin)
.add_systems(Startup, setup)
.add_systems(Update, toggle_levels)
// No LevelSelection resource!
.insert_resource(LdtkSettings {
// By default, levels are just spawned at the origin of the world.
Expand Down
8 changes: 0 additions & 8 deletions examples/platformer/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ pub struct Climber {
#[derive(Clone, Default, Bundle, LdtkEntity)]
pub struct PlayerBundle {
#[sprite_bundle("player.png")]
#[bundle]
pub sprite_bundle: SpriteBundle,
#[from_entity_instance]
#[bundle]
pub collider_bundle: ColliderBundle,
pub player: Player,
#[worldly]
Expand Down Expand Up @@ -138,7 +136,6 @@ pub struct Climbable;
#[derive(Clone, Debug, Default, Bundle, LdtkIntCell)]
pub struct LadderBundle {
#[from_int_grid_cell]
#[bundle]
pub sensor_bundle: SensorBundle,
pub climbable: Climbable,
}
Expand Down Expand Up @@ -202,10 +199,8 @@ impl LdtkEntity for Patrol {
#[derive(Clone, Default, Bundle, LdtkEntity)]
pub struct MobBundle {
#[sprite_sheet_bundle]
#[bundle]
pub sprite_sheet_bundle: SpriteSheetBundle,
#[from_entity_instance]
#[bundle]
pub collider_bundle: ColliderBundle,
pub enemy: Enemy,
#[ldtk_entity]
Expand All @@ -215,17 +210,14 @@ pub struct MobBundle {
#[derive(Clone, Default, Bundle, LdtkEntity)]
pub struct ChestBundle {
#[sprite_sheet_bundle]
#[bundle]
pub sprite_sheet_bundle: SpriteSheetBundle,
#[from_entity_instance]
#[bundle]
pub collider_bundle: ColliderBundle,
}

#[derive(Clone, Default, Bundle, LdtkEntity)]
pub struct PumpkinsBundle {
#[sprite_sheet_bundle(no_grid)]
#[bundle]
pub sprite_sheet_bundle: SpriteSheetBundle,
}

Expand Down
34 changes: 17 additions & 17 deletions examples/platformer/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ mod systems;
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.add_plugin(LdtkPlugin)
.add_plugin(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(100.0))
// Required to prevent race conditions between bevy_ecs_ldtk's and bevy_rapier's systems
.configure_set(LdtkSystemSet::ProcessApi.before(PhysicsSet::SyncBackend))
.add_plugins((
LdtkPlugin,
RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(100.0),
))
.insert_resource(RapierConfiguration {
gravity: Vec2::new(0.0, -2000.0),
..Default::default()
Expand All @@ -28,19 +28,19 @@ fn main() {
set_clear_color: SetClearColor::FromLevelBackground,
..Default::default()
})
.add_startup_system(systems::setup)
.add_system(systems::spawn_wall_collision)
.add_system(systems::movement)
.add_system(systems::detect_climb_range)
.add_system(systems::ignore_gravity_if_climbing)
.add_system(systems::patrol)
.add_system(systems::camera_fit_inside_current_level)
.add_system(systems::update_level_selection)
.add_system(systems::dbg_player_items)
.add_system(systems::spawn_ground_sensor)
.add_system(systems::ground_detection)
.add_system(systems::update_on_ground)
.add_system(systems::restart_level)
.add_systems(Startup, systems::setup)
.add_systems(Update, systems::spawn_wall_collision)
.add_systems(Update, systems::movement)
.add_systems(Update, systems::detect_climb_range)
.add_systems(Update, systems::ignore_gravity_if_climbing)
.add_systems(Update, systems::patrol)
.add_systems(Update, systems::camera_fit_inside_current_level)
.add_systems(Update, systems::update_level_selection)
.add_systems(Update, systems::dbg_player_items)
.add_systems(Update, systems::spawn_ground_sensor)
.add_systems(Update, systems::ground_detection)
.add_systems(Update, systems::update_on_ground)
.add_systems(Update, systems::restart_level)
.register_ldtk_int_cell::<components::WallBundle>(1)
.register_ldtk_int_cell::<components::LadderBundle>(2)
.register_ldtk_int_cell::<components::WallBundle>(3)
Expand Down
6 changes: 3 additions & 3 deletions examples/traitless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use bevy_ecs_ldtk::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.add_plugin(LdtkPlugin)
.add_startup_system(setup)
.add_system(process_my_entity)
.add_plugins(LdtkPlugin)
.add_systems(Startup, setup)
.add_systems(Update, process_my_entity)
.insert_resource(LevelSelection::Index(0))
.run();
}
Expand Down
10 changes: 0 additions & 10 deletions src/app/ldtk_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ use std::{collections::HashMap, marker::PhantomData};
/// #[derive(Bundle, LdtkEntity)]
/// pub struct Gem {
/// #[sprite_bundle("textures/gem.png")]
/// #[bundle]
/// sprite_bundle: SpriteBundle,
/// sellable: Sellable,
/// }
Expand All @@ -93,7 +92,6 @@ use std::{collections::HashMap, marker::PhantomData};
/// player: PlayerComponent,
/// health: Health,
/// #[sprite_bundle] // Uses the Editor Visual sprite in LDtk
/// #[bundle]
/// sprite_bundle: SpriteBundle,
/// }
/// ```
Expand All @@ -120,7 +118,6 @@ use std::{collections::HashMap, marker::PhantomData};
/// # struct BleedDamage;
/// #[derive(Bundle, LdtkEntity)]
/// pub struct Sword {
/// #[bundle]
/// #[sprite_sheet_bundle("weapons.png", 32.0, 32.0, 4, 5, 5.0, 1.0, 17)]
/// sprite_sheet: SpriteSheetBundle,
/// damage: Damage,
Expand All @@ -130,7 +127,6 @@ use std::{collections::HashMap, marker::PhantomData};
/// pub struct Dagger {
/// damage: Damage,
/// bleed_damage: BleedDamage,
/// #[bundle]
/// #[sprite_sheet_bundle]
/// sprite_sheet: SpriteSheetBundle,
/// }
Expand All @@ -153,7 +149,6 @@ use std::{collections::HashMap, marker::PhantomData};
/// pub struct PlayerBundle {
/// player: Player,
/// #[sprite_sheet_bundle]
/// #[bundle]
/// sprite_sheet_bundle: SpriteSheetBundle,
/// #[worldly]
/// worldly: Worldly,
Expand All @@ -177,7 +172,6 @@ use std::{collections::HashMap, marker::PhantomData};
/// block: Block,
/// movable: Movable,
/// #[sprite_sheet_bundle]
/// #[bundle]
/// sprite_sheet_bundle: SpriteSheetBundle,
/// #[grid_coords]
/// grid_coords: GridCoords,
Expand All @@ -202,14 +196,12 @@ use std::{collections::HashMap, marker::PhantomData};
/// pub struct Weapon {
/// damage: Damage,
/// #[sprite_bundle]
/// #[bundle]
/// sprite: SpriteBundle,
/// }
///
/// #[derive(Bundle, LdtkEntity)]
/// pub struct Dagger {
/// #[ldtk_entity]
/// #[bundle]
/// weapon_bundle: Weapon,
/// bleed_damage: BleedDamage,
/// }
Expand Down Expand Up @@ -245,7 +237,6 @@ use std::{collections::HashMap, marker::PhantomData};
/// #[derive(Bundle, LdtkEntity)]
/// pub struct NickelBundle {
/// #[sprite_bundle]
/// #[bundle]
/// sprite: SpriteBundle,
/// #[from_entity_instance]
/// sellable: Sellable,
Expand Down Expand Up @@ -278,7 +269,6 @@ use std::{collections::HashMap, marker::PhantomData};
/// pub struct PlayerBundle {
/// player: Player,
/// #[with(player_initial_inventory)]
/// #[bundle]
/// collider: InventoryBundle,
/// }
///
Expand Down
1 change: 0 additions & 1 deletion src/app/ldtk_int_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ use std::{collections::HashMap, marker::PhantomData};
/// #[derive(Bundle, LdtkIntCell)]
/// pub struct DestructibleWall {
/// #[ldtk_int_cell]
/// #[bundle]
/// wall: Wall,
/// damage: Damage,
/// }
Expand Down
6 changes: 3 additions & 3 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{ldtk, resources::LevelSelection};
use bevy::{
asset::{AssetLoader, AssetPath, LoadContext, LoadedAsset},
prelude::*,
reflect::TypeUuid,
reflect::{TypePath, TypeUuid},
render::render_resource::{Extent3d, TextureDimension, TextureFormat},
utils::BoxedFuture,
};
Expand All @@ -27,7 +27,7 @@ pub type LevelMap = HashMap<String, Handle<LdtkLevel>>;
///
/// Load your ldtk project with the asset server, then insert the handle into the
/// [LdtkWorldBundle].
#[derive(Clone, TypeUuid)]
#[derive(Clone, TypeUuid, TypePath)]
#[uuid = "ecfb87b7-9cd9-4970-8482-f2f68b770d31"]
pub struct LdtkAsset {
pub project: ldtk::LdtkJson,
Expand Down Expand Up @@ -194,7 +194,7 @@ impl AssetLoader for LdtkLoader {
/// The label is just the level's identifier.
///
/// Loaded as a dependency to the [LdtkAsset] when loading an ldtk file with external levels.
#[derive(TypeUuid, Reflect, FromReflect)]
#[derive(TypeUuid, Reflect)]
#[uuid = "5448469b-2134-44f5-a86c-a7b829f70a0c"]
pub struct LdtkLevel {
pub level: ldtk::Level,
Expand Down
2 changes: 1 addition & 1 deletion src/components/entity_iid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::borrow::Cow;
/// [Component] added to all [LdtkEntity]s by default.
///
/// The `iid` stored in this component can be used to uniquely identify LDtk entities within an [LdtkAsset].
#[derive(Clone, Debug, Default, Deref, Hash, Eq, PartialEq, Component, FromReflect, Reflect)]
#[derive(Clone, Debug, Default, Deref, Hash, Eq, PartialEq, Component, Reflect)]
#[reflect(Component, Default, Debug)]
pub struct EntityIid(Cow<'static, str>);

Expand Down
1 change: 0 additions & 1 deletion src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ pub struct Respawn;

#[derive(Copy, Clone, Debug, Default, Bundle)]
pub(crate) struct TileGridBundle {
#[bundle]
pub tile_bundle: TileBundle,
pub grid_coords: GridCoords,
}
Expand Down
5 changes: 3 additions & 2 deletions src/ldtk/field_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use regex::Regex;

use crate::ldtk::color;

#[derive(PartialEq, Debug, Clone, Serialize, Reflect, FromReflect)]
#[derive(PartialEq, Debug, Clone, Serialize, Reflect)]
pub struct FieldInstance {
/// Field definition identifier
#[serde(rename = "__identifier")]
Expand Down Expand Up @@ -189,7 +189,8 @@ impl<'de> Deserialize<'de> for FieldInstance {
}
}

#[derive(PartialEq, Debug, Clone, Serialize, Reflect, FromReflect)]
#[derive(PartialEq, Debug, Clone, Serialize, Reflect)]
#[reflect_value()]
#[serde(untagged)]
/// The actual value of a field instance on a [Level] or [EntityInstance].
///
Expand Down
Loading

0 comments on commit ef1b075

Please sign in to comment.