diff --git a/404.html b/404.html index 1148c79..dfe1af8 100644 --- a/404.html +++ b/404.html @@ -83,7 +83,7 @@ diff --git a/FAQ.html b/FAQ.html index d169cb2..d39e8b2 100644 --- a/FAQ.html +++ b/FAQ.html @@ -82,7 +82,7 @@ @@ -163,6 +163,10 @@

Avian and Rapier physics backend.

Is it possible to use Tiled "custom properties" ?

Yes, see the dedicated guide.

+

I'm using an isometric map and it seems all messed up!

+

Make sure you are actually using a "diamond" map and not a "staggered" one (which are not supported).

+

Also, for isometric maps, you may want to tweak the TilemapRenderSettings Component from bevy_ecs_tilemap. +More information in the isometric maps example

I found a bug! What should I do ?

Please have a look to already openned issues and if it does not already exists, please fill a new one !

I want to add a new feature that's not yet in the crate!

diff --git a/design/entities_tree.html b/design/entities_tree.html new file mode 100644 index 0000000..bb90d32 --- /dev/null +++ b/design/entities_tree.html @@ -0,0 +1,226 @@ + + + + + + Entities tree and marker components - bevy_ecs_tiled Documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + +
+
+

Entities tree and marker components

+

When a map is loaded, it spawns a lot of entities: for the map, for layers, for tiles, for objects, for colliders, ... +These entites are organized in a parent / child hierarchy.

+

It notably brings the capability to inherit some of the component down the tree. +For instance, if you change the Visibility of an entity, it will automatically apply to all entities below in the hierarchy.

+

It also helps to keep things nice and clean.

+

Tree hierarchy

+

Map

+

At the top of the tree, there is the map. +It notably holds the TiledMapHandle pointing to your .TMX file and all the settings that apply to it. +It can be easily identified using a dedicated marker component: TiledMapMarker.

+

Layers

+

Below the map, we have the layers. +They can be of different kinds, which each have their own marker component:

+ +

All of them are also identified by the same generic marker: TiledMapLayer.

+

Objects & Tiles

+

Objects are directly below their TiledMapObjectLayer. +They are identified by a TiledMapObject marker.

+

For tiles, it's a little more complicated. +Below the TiledMapTileLayer, we first have one TiledMapTileLayerForTileset per tileset in the map. +Finally, below these, we find the actual TiledMapTile which correspond to every tiles in the layer, for a given tileset.

+

Physics colliders

+

At the end of the hierarchy, we find physics colliders. +They are spawned below they "source", ie. either a tile or an object and can be identified using their marker component: TiledColliderMarker.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + diff --git a/design/map_events.html b/design/map_events.html new file mode 100644 index 0000000..70aac67 --- /dev/null +++ b/design/map_events.html @@ -0,0 +1,225 @@ + + + + + + Map loading events - bevy_ecs_tiled Documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + +
+
+

Map loading events

+

After loading a map, the plugin will send several events:

+ +

These events are a way to access directly raw Tiled data and easily extend the plugin capabilities.

+

For instance, you can access a tiled::Object from the corresponding event:

+

+#![allow(unused)]
+fn main() {
+use bevy::prelude::*;
+use bevy_ecs_tiled::prelude::*;
+
+fn object_created(
+    trigger: Trigger<TiledObjectCreated>,
+    map_asset: Res<Assets<TiledMap>>,
+) {
+    // Access raw Tiled data
+    let _map = trigger.event().map(&map_asset);
+    let _layer = trigger.event().layer(&map_asset);
+    let object = trigger.event().object(&map_asset);
+    info!("Loaded object: {:?}", object);
+}
+}
+
+

A dedicated example is available to demonstrate how to use these.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + diff --git a/design/why-tiled.html b/design/why-tiled.html index 6893512..07cd5b7 100644 --- a/design/why-tiled.html +++ b/design/why-tiled.html @@ -82,7 +82,7 @@ @@ -169,7 +169,7 @@

Why using T - @@ -183,7 +183,7 @@

Why using T - diff --git a/design/z_order.html b/design/z_order.html new file mode 100644 index 0000000..00eca47 --- /dev/null +++ b/design/z_order.html @@ -0,0 +1,210 @@ + + + + + + Layers Z-ordering - bevy_ecs_tiled Documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + +
+
+

Layers Z-ordering

+

When designing your map under Tiled, you expect that a layer will hide another one which is below in the layer hierarchy. +This is very useful when using isometric tiles for instance.

+

To reproduce this behaviour under Bevy, we add an arbitrary offset on the Z transform to each layers of the hierarchy.

+

If we call this offset OFFSET:

+
    +
  • the top-level layer will have a Z transform of 0
  • +
  • the second one will have a Z transform of - OFFSET
  • +
  • the next one of - 2*OFFSET
  • +
  • etc...
  • +
+

By default this offset has a value of +100. +It can be changed by tweaking the TiledMapSettings component. +Since bevy_ecs_tilemap also play with the Z-transform to adjust how tiles from a given layers are rendered, you probably don't want to have a "too low" value.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + diff --git a/guides/debug.html b/guides/debug.html index fbbe85f..8c914d4 100644 --- a/guides/debug.html +++ b/guides/debug.html @@ -82,7 +82,7 @@ @@ -160,11 +160,11 @@

-

Now, you can browse componentns from all entities spawned in your game.

+

Now, you can browse components from all entities spawned in your game.

More informations on the project github page.

TiledMapDebugPlugin

bevy_ecs_tiled provides a debug plugin that displays a gizmos where Tiled object are spawned.

-

To use it, you just have to add the plugin to your application:

+

To use it, you just have to enable the debug feature and add the plugin to your application:

use bevy::prelude::*;
 use bevy_ecs_tiled::prelude::*;
 
@@ -192,7 +192,7 @@ 

Physics

.run(); }
-

For Rapier, you also need to enable a debug plugin:

+

For Rapier, you need to enable a debug plugin:

use bevy::prelude::*;
 use bevy_rapier2d::prelude::*;
 
@@ -205,7 +205,7 @@ 

Physics

.run(); }
-

But you also need to enable either the debug-render-2d feature on bevy_rapier2d crate or the rapier_debug feature on bevy_ecs_tiled

+

And you also need to enable either the debug-render-2d feature on bevy_rapier2d crate or the rapier_debug feature on bevy_ecs_tiled

@@ -215,7 +215,7 @@

Physics

- @@ -229,7 +229,7 @@

Physics

- diff --git a/guides/images/properties_custom-type.png b/guides/images/properties_custom-type.png index bb6a89b..9a9169a 100644 Binary files a/guides/images/properties_custom-type.png and b/guides/images/properties_custom-type.png differ diff --git a/guides/images/properties_import-types.png b/guides/images/properties_import-types.png new file mode 100644 index 0000000..e91d516 Binary files /dev/null and b/guides/images/properties_import-types.png differ diff --git a/guides/images/properties_inspector.png b/guides/images/properties_inspector.png deleted file mode 100644 index bf72f7b..0000000 Binary files a/guides/images/properties_inspector.png and /dev/null differ diff --git a/guides/images/properties_tile-properties.png b/guides/images/properties_tile-properties.png deleted file mode 100644 index 68b6fc3..0000000 Binary files a/guides/images/properties_tile-properties.png and /dev/null differ diff --git a/guides/minimal.html b/guides/minimal.html index 3aa85cc..f53afb9 100644 --- a/guides/minimal.html +++ b/guides/minimal.html @@ -82,7 +82,7 @@ @@ -147,7 +147,7 @@

[dependencies] bevy = "0.14" -bevy_ecs_tiled = "0.3" +bevy_ecs_tiled = "0.4" bevy_ecs_tilemap = "0.14"

Then add the plugin to your app and spawn a map:

@@ -162,7 +162,7 @@

examples for more advanced use cases.

+

Please note that you should have the map.tmx file in your local assets/ folder, as well as required dependencies (for instance, associated tilesets).

+

You can customize various settings about how to load the map by inserting the TiledMapSettings component on the map entity.

+

Also, you can browse the examples for more advanced use cases.

@@ -150,9 +150,8 @@

Create a custom type

-

First step is to actually create a custom type.

-

To do so, in Tiled, navigate to View -> Custom Types Editor:

-

view-custom-types

-

From this panel, you will be able to define your own custom type (think of it as a struct) and describe which fields it has. -For more information see the official documentation.

-

view-custom-types

-

For instance, in the example above, we created a TileBundle custom type which has a single BiomeInfos field. -This BiomeInfos field is another custom type which has two fields: a boolean BlockLineOfSight and an enum Type.

-

We support all types except :

- -

Assign custom properties to an object or a to a tile

-

Please note that we do not support adding directly custom properties and you must use a custom type.

-

First, you need to update the "class" property and set the custom type you want.

- -

view-custom-types

-

Once the class is set, it will automatically add the custom type fields (with their default value) corresponding to this custom type to the "custom properties" tab. -You can then edit the properties you want, as it fits your game.

-

For instance, in the picture above, we declared our tile to be a TileBundle:

- -

Retrieve custom properties and map them to a Bevy component

-

To actually retrieve these custom properties in your game, you need to do three things:

- -

First, to enable the user_properties feature, you need to update your Cargo.toml file:

-
[dependencies]
-bevy_ecs_tiled = { version = "XXX", features = [ "user_properties" ] }
-
-

Then, you can define your custom type:

-

-#![allow(unused)]
-fn main() {
-// If declaring a custom type for an objet,
-// you should use instead the TiledObject derive
-#[derive(TiledCustomTile, Bundle, Default, Debug, Reflect)]
-struct TileBundle {
-    #[tiled_rename = "BiomeInfos"]
-    infos: BiomeInfos,
-}
-}
-
-

As well as other types it refers to:

-

-#![allow(unused)]
-fn main() {
-#[derive(TiledClass, Component, Default, Debug, Reflect)]
-struct BiomeInfos {
-    #[tiled_rename = "Type"]
-    ty: BiomeType,
-    #[tiled_rename = "BlockLineOfSight"]
-    block_line_of_sight: bool,
+

In addition to this guide, there is also a dedicated example.

+

Declare types to be used as custom properties

+

Your Tiled map, layer, tile or object will be represented by a Bevy Entity. +So, it makes sense that if you want to add custom properties to them, these properties should either be a Component or a Bundle.

+

Also, Tiled custom properties use Bevy Reflect mechanism. +So, in order to be usable in Tiled, your custom types must be "Reflectable". +To do, these types must derive the Reflect trait and get registered with Bevy.

+
use bevy::prelude::*;
+
+// Declare a component that is "reflectable"
+#[derive(Component, Reflect, Default)]
+#[reflect(Component, Default)]
+struct SpawnInfos {
+    has_spawned: bool,
+    ty: SpawnType,
 }
 
-#[derive(TiledEnum, Default, Reflect, Debug)]
-enum BiomeType {
+// Any 'sub-type' which is part of our component must also be "reflectable"
+#[derive(Default, Reflect)]
+#[reflect(Default)]
+enum SpawnType {
     #[default]
     Unknown,
-    Plain,
-    Desert,
-    Forest,
-    Mountain,
+    Player,
+    Enemy,
 }
-}
-
-

Note that these custom types definitions should match what you have declared in Tiled custom types editor.

-

Finally, you can register your custom type before starting the app:

-
fn main() {
+
+// Register our type with Bevy
+fn main() {
     App::new()
-        // If registering an object, use register_tiled_object() instead
-        .register_tiled_custom_tile::<TileBundle>("TileBundle")
-        .run();
+        .register_type::<SpawnInfos>();
 }
 
-

When loading a map which has tiles with the TileBundle custom type, corresponding components will be automatically inserted on the tile entity and have their value based upon the properties you set in Tiled.

-

view-custom-types

-

Note that you only see the BiomeInfos type and not TileBundle. -That's because TileBundle is a Bundle, which is actually a collection of Components.

-

Using a Component vs. a Bundle

-

This may change in the future, but bevy_ecs_tiled currently allows you to either use a Bevy Component or a Bevy Bundle to represent your tiles and objects.

-

It means that your custom type can either be:

-
    -
  • a set of "standard type" fields (ie. no nested custom type), in that case it should be a Component.
  • -
  • a set of "custom type" fiels, in that case it should be a Bundle and additional CustomClass structs should be declared.
  • -
-

Note that it's an "all or nothing" mode. -If you have a nested custom type, your struct must be a Bundle and it cannot contains an additional "standard type".

-

Further readings

-

You can have a look at the properties module API reference or the dedicated example.

-

More specifically, which attributes can be used for derive macros or the content of observer events.

+

And that's all !

+

Note that in the above example, our custom type also derive the Default trait. +It is particulary useful to do so: if you don't, you would have to fill all the fields of your custom type when you use it in Tiled.

+

Finally, note that you can also add Resource to your map. +They won't be attached to a particular entity and as such are only allowed on Tiled maps.

+

Add custom properties to your map

+

Before you can add custom properties to your map, you will need to export them from Bevy then import them in Tiled.

+

When running with the user_properties feature, your app will automatically produce an export of all types registered with Bevy. +By default, this file will be produced in your workspace with the name tiled_types_export.json. +You can change this file name or even disable its production by tweaking the TiledMapPlugin configuration (see TiledMapPluginConfig).

+

You can then import this file to Tiled. +To do so, in Tiled, navigate to View -> Custom Types Editor:

+

view-custom-types

+

Click on the Import button and load your file:

+

import-custom-types

+

Once it is done, you will be able to see all the custom types that you have imported from your application. +Note that it concerns all the types that derive the Reflect trait: there can be quite a lot !

+

view-custom-types

+

You can now add them to different elements of your map, like tiles objects, layers or the map itself. +For more information on how to do add custom properties, see the official TIled documentation. +You should only add properties imported from Bevy: adding ones that you created only in Tiled will not be loaded.

diff --git a/guides/spawn_reload.html b/guides/spawn_reload.html index ea9e61c..49e6daf 100644 --- a/guides/spawn_reload.html +++ b/guides/spawn_reload.html @@ -82,7 +82,7 @@ @@ -144,12 +144,12 @@

bevy_ecs_tiled Documentation

Spawn / Despawn / Reload a map

-

These aspects are also covered in the dedicated example.

+

These aspects are also covered in the dedicated example.

Spawn a map

Spawning a map is done in two steps:

  • first, load a map asset / a map file using the Bevy AssetServer
  • -
  • then, spawn a TiledMapBundle containing a reference to this map asset
  • +
  • then, spawn a TiledMapHandle containing a reference to this map asset

 #![allow(unused)]
@@ -162,10 +162,7 @@ 

Spawn a map

let map_handle: Handle<TiledMap> = asset_server.load("map.tmx"); // Then, spawn it, using default settings - commands.spawn(TiledMapBundle { - tiled_map: map_handle, - ..default() - }); + commands.spawn(TiledMapHandle(map_handle)); } }
@@ -210,7 +207,7 @@

Reload a map

Another use case is to load a new map over an existing one. -An easy way to do that is to just spawn the TiledMapBundle over an existing map.

+An easy way to do that is to just spawn a new TiledMapHandle over an existing map.


 #![allow(unused)]
 fn main() {
@@ -220,10 +217,10 @@ 

Reload a map} diff --git a/index.html b/index.html index b578132..6ae3a3f 100644 --- a/index.html +++ b/index.html @@ -82,7 +82,7 @@

diff --git a/migrations/v0_4.html b/migrations/v0_4.html new file mode 100644 index 0000000..fc174ac --- /dev/null +++ b/migrations/v0_4.html @@ -0,0 +1,270 @@ + + + + + + From v0.3.X to v0.4.X - bevy_ecs_tiled Documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + +
+
+

From v0.3.X to v0.4.X

+

Overview

+

Version 0.4 was initially motivated by an update to the way we handle user properties but ended as a major overhaul of the plugin to provide a better API and to give more control to the user.

+

Plugin instanciation

+

The plugin now has an associated configuration, which you need to provide when you add it to your application.

+

The easiest way is to use the default configuration value :

+
use bevy::prelude::*;
+use bevy_ecs_tiled::prelude::*;
+
+fn main() {
+    App::new()
+        // You still need the bevy_ecs_tilemap plugin
+        .add_plugins(TilemapPlugin)
+        // And now, you have to provide a configuration for bevy_ecs_tiled plugin
+        .add_plugins(TiledMapPlugin::default())
+        .run();
+}
+
+

The plugin configuration is described in the API reference

+

Tiled map spawn and configuration

+

The plugin entry point, ie. the TiledMapBundle bundle is gone. +It was cumbersome and did not allow for a proper separation of concerns (for instance, for physics).

+

Also, the Handle<TiledMap> type is not a Bevy component anymore. +It was done in order to anticipate expected changes in Bevy where Handle<T> won't be able to derive the Component trait anymore.

+

Anyway, the new way to spawn a map is now easier: you just have to spawn a TiledMapHandle referencing your .TMX file asset:

+

+#![allow(unused)]
+fn main() {
+use bevy::prelude::*;
+use bevy_ecs_tiled::prelude::*;
+
+fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
+    // Load the map: ensure any tile / tileset paths are relative to assets/ folder
+    let map_handle: Handle<TiledMap> = asset_server.load("map.tmx");
+
+    // Spawn the map with default options
+    commands.spawn(TiledMapHandle(map_handle));
+}
+}
+
+

You can customize various settings about how to load the map by inserting the TiledMapSettings component on the map entity.

+

Tiled user properties

+

Before this change, you had to define your custom types both in Tiled and in your rust code. +It was not user-friendly and error-prone.

+

Now, we take advantage of bevy_reflect to generate a file containing all the types known to Bevy. +This file can be imported in Tiled so you can use these types directly in the editor.

+

Migrating from the old implementation should be straight-forward.

+

First, you need need to update your custom types so they actually implement the Reflect trait :

+
    +
  • remove #[derive(TiledObject)], #[derive(TiledCustomTile)], #[derive(TiledClass)] and #[derive(TiledEnum)] derived traits. Make sure to also remove associated attributes.
  • +
  • add #[derive(Reflect)] derive trait on the types you want to use in Tiled.
  • +
  • make sure your components have the #[reflect(Component)] attribute
  • +
+

Then, in your main / in your plugin setup, you then need to register your types with Bevy :

+
    +
  • replace calls to register_tiled_object::<T>() with calls to register_type::<T>().
  • +
  • replace calls to register_tiled_custom_tile::<T>() with calls to register_type::<T>().
  • +
+

The final step is to actually generate the types import file (run your game once) and import the types to Tiled. +Note that you may have to update your map / your tilesets to use the new types you just imported.

+

A dedicated guide about how to setup user properties is available in this book.

+

Tiled physics

+

Eventhough functionnalities around physics did not change much, the internals have been completely reworked and the API was updated a bit.

+

Notably, now you need to instanciate another plugin and specify which physics backend you want to use. +The physics section of the book should get you through.

+

Map events

+

This is a new feature of this version which gives more control to the user over what he wants to do with a Tiled map. +More information in the dedicated section

+

Misc changes

+

enum MapPositioning

+

Both enum name and fields name have been updated to better reflect what they actually do. +You should now use the new LayerPositioning enum.

+

fn from_isometric_coords_to_bevy()

+

Parameters tiled_position: Vec2 and iso_coords: IsoCoordSystem have been swapped for better consistency with other utility functions.

+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + diff --git a/misc/api-reference.html b/misc/api-reference.html index 373741c..e6bfc2d 100644 --- a/misc/api-reference.html +++ b/misc/api-reference.html @@ -82,7 +82,7 @@ diff --git a/misc/contributing.html b/misc/contributing.html index 10ad9e6..bcd1689 100644 --- a/misc/contributing.html +++ b/misc/contributing.html @@ -82,7 +82,7 @@ diff --git a/misc/useful-links.html b/misc/useful-links.html index 353e265..f9d9a4a 100644 --- a/misc/useful-links.html +++ b/misc/useful-links.html @@ -82,7 +82,7 @@ @@ -171,7 +171,7 @@

Notable r