diff --git a/src/code/snippets/Cargo.lock b/src/code/snippets/Cargo.lock index 815fc0fd..cd33e177 100644 --- a/src/code/snippets/Cargo.lock +++ b/src/code/snippets/Cargo.lock @@ -1093,7 +1093,7 @@ dependencies = [ [[package]] name = "fyrox" version = "0.34.1" -source = "git+https://github.com/FyroxEngine/Fyrox?rev=c865306042407c686cf53c83c7d9c2471a460b3e#c865306042407c686cf53c83c7d9c2471a460b3e" +source = "git+https://github.com/FyroxEngine/Fyrox?rev=7b25f44d96e289abf36c3a616ba474bbe6d5f428#7b25f44d96e289abf36c3a616ba474bbe6d5f428" dependencies = [ "fyrox-impl", ] @@ -1101,7 +1101,7 @@ dependencies = [ [[package]] name = "fyrox-animation" version = "0.2.0" -source = "git+https://github.com/FyroxEngine/Fyrox?rev=c865306042407c686cf53c83c7d9c2471a460b3e#c865306042407c686cf53c83c7d9c2471a460b3e" +source = "git+https://github.com/FyroxEngine/Fyrox?rev=7b25f44d96e289abf36c3a616ba474bbe6d5f428#7b25f44d96e289abf36c3a616ba474bbe6d5f428" dependencies = [ "fxhash", "fyrox-core", @@ -1123,7 +1123,7 @@ dependencies = [ [[package]] name = "fyrox-core" version = "0.28.1" -source = "git+https://github.com/FyroxEngine/Fyrox?rev=c865306042407c686cf53c83c7d9c2471a460b3e#c865306042407c686cf53c83c7d9c2471a460b3e" +source = "git+https://github.com/FyroxEngine/Fyrox?rev=7b25f44d96e289abf36c3a616ba474bbe6d5f428#7b25f44d96e289abf36c3a616ba474bbe6d5f428" dependencies = [ "android-activity", "arrayvec", @@ -1156,7 +1156,7 @@ dependencies = [ [[package]] name = "fyrox-core-derive" version = "0.23.0" -source = "git+https://github.com/FyroxEngine/Fyrox?rev=c865306042407c686cf53c83c7d9c2471a460b3e#c865306042407c686cf53c83c7d9c2471a460b3e" +source = "git+https://github.com/FyroxEngine/Fyrox?rev=7b25f44d96e289abf36c3a616ba474bbe6d5f428#7b25f44d96e289abf36c3a616ba474bbe6d5f428" dependencies = [ "convert_case", "darling", @@ -1169,7 +1169,7 @@ dependencies = [ [[package]] name = "fyrox-graph" version = "0.1.0" -source = "git+https://github.com/FyroxEngine/Fyrox?rev=c865306042407c686cf53c83c7d9c2471a460b3e#c865306042407c686cf53c83c7d9c2471a460b3e" +source = "git+https://github.com/FyroxEngine/Fyrox?rev=7b25f44d96e289abf36c3a616ba474bbe6d5f428#7b25f44d96e289abf36c3a616ba474bbe6d5f428" dependencies = [ "fxhash", "fyrox-core", @@ -1179,7 +1179,7 @@ dependencies = [ [[package]] name = "fyrox-impl" version = "0.34.1" -source = "git+https://github.com/FyroxEngine/Fyrox?rev=c865306042407c686cf53c83c7d9c2471a460b3e#c865306042407c686cf53c83c7d9c2471a460b3e" +source = "git+https://github.com/FyroxEngine/Fyrox?rev=7b25f44d96e289abf36c3a616ba474bbe6d5f428#7b25f44d96e289abf36c3a616ba474bbe6d5f428" dependencies = [ "base64 0.22.1", "bitflags 2.6.0", @@ -1237,7 +1237,7 @@ dependencies = [ [[package]] name = "fyrox-math" version = "0.2.0" -source = "git+https://github.com/FyroxEngine/Fyrox?rev=c865306042407c686cf53c83c7d9c2471a460b3e#c865306042407c686cf53c83c7d9c2471a460b3e" +source = "git+https://github.com/FyroxEngine/Fyrox?rev=7b25f44d96e289abf36c3a616ba474bbe6d5f428#7b25f44d96e289abf36c3a616ba474bbe6d5f428" dependencies = [ "arrayvec", "bytemuck", @@ -1250,7 +1250,7 @@ dependencies = [ [[package]] name = "fyrox-resource" version = "0.12.0" -source = "git+https://github.com/FyroxEngine/Fyrox?rev=c865306042407c686cf53c83c7d9c2471a460b3e#c865306042407c686cf53c83c7d9c2471a460b3e" +source = "git+https://github.com/FyroxEngine/Fyrox?rev=7b25f44d96e289abf36c3a616ba474bbe6d5f428#7b25f44d96e289abf36c3a616ba474bbe6d5f428" dependencies = [ "fxhash", "fyrox-core", @@ -1263,7 +1263,7 @@ dependencies = [ [[package]] name = "fyrox-sound" version = "0.35.0" -source = "git+https://github.com/FyroxEngine/Fyrox?rev=c865306042407c686cf53c83c7d9c2471a460b3e#c865306042407c686cf53c83c7d9c2471a460b3e" +source = "git+https://github.com/FyroxEngine/Fyrox?rev=7b25f44d96e289abf36c3a616ba474bbe6d5f428#7b25f44d96e289abf36c3a616ba474bbe6d5f428" dependencies = [ "fyrox-core", "fyrox-resource", @@ -1280,7 +1280,7 @@ dependencies = [ [[package]] name = "fyrox-ui" version = "0.25.1" -source = "git+https://github.com/FyroxEngine/Fyrox?rev=c865306042407c686cf53c83c7d9c2471a460b3e#c865306042407c686cf53c83c7d9c2471a460b3e" +source = "git+https://github.com/FyroxEngine/Fyrox?rev=7b25f44d96e289abf36c3a616ba474bbe6d5f428#7b25f44d96e289abf36c3a616ba474bbe6d5f428" dependencies = [ "bytemuck", "copypasta", @@ -1301,7 +1301,7 @@ dependencies = [ [[package]] name = "fyroxed_base" version = "0.21.1" -source = "git+https://github.com/FyroxEngine/Fyrox?rev=c865306042407c686cf53c83c7d9c2471a460b3e#c865306042407c686cf53c83c7d9c2471a460b3e" +source = "git+https://github.com/FyroxEngine/Fyrox?rev=7b25f44d96e289abf36c3a616ba474bbe6d5f428#7b25f44d96e289abf36c3a616ba474bbe6d5f428" dependencies = [ "cargo_metadata", "fyrox", diff --git a/src/code/snippets/Cargo.toml b/src/code/snippets/Cargo.toml index 6b2b0e27..596110da 100644 --- a/src/code/snippets/Cargo.toml +++ b/src/code/snippets/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -fyrox = { git = "https://github.com/FyroxEngine/Fyrox", rev = "c865306042407c686cf53c83c7d9c2471a460b3e" } -fyroxed_base = { git = "https://github.com/FyroxEngine/Fyrox", rev = "c865306042407c686cf53c83c7d9c2471a460b3e" } +fyrox = { git = "https://github.com/FyroxEngine/Fyrox", rev = "7b25f44d96e289abf36c3a616ba474bbe6d5f428" } +fyroxed_base = { git = "https://github.com/FyroxEngine/Fyrox", rev = "7b25f44d96e289abf36c3a616ba474bbe6d5f428" } strum = "0.26.0" strum_macros = "0.26.0" \ No newline at end of file diff --git a/src/code/snippets/src/resource/custom.rs b/src/code/snippets/src/resource/custom.rs index 0a35e349..14781dbd 100644 --- a/src/code/snippets/src/resource/custom.rs +++ b/src/code/snippets/src/resource/custom.rs @@ -1,8 +1,6 @@ use fyrox::asset::io::ResourceIo; use fyrox::asset::loader::LoaderPayload; -use fyrox::asset::manager::ResourceManager; use fyrox::asset::state::LoadError; -use fyrox::core::futures::executor::block_on; use fyrox::plugin::{Plugin, PluginRegistrationContext}; use fyrox::{ asset::{ @@ -11,7 +9,6 @@ use fyrox::{ }, core::{ io::{self}, - parking_lot::Mutex, reflect::prelude::*, type_traits::prelude::*, uuid::Uuid, @@ -115,16 +112,7 @@ fn main() { // Register property editor. editor.inspector.property_editors.insert( - ResourceFieldPropertyEditorDefinition::::new( - Arc::new(Mutex::new( - |resource_manager: &ResourceManager, path: &Path| { - resource_manager - .try_request::(path) - .map(block_on) - }, - )), - editor.message_sender.clone(), - ), + ResourceFieldPropertyEditorDefinition::::new(editor.message_sender.clone()), ); // ... diff --git a/src/code/snippets/src/scene/tilemap.rs b/src/code/snippets/src/scene/tilemap.rs index 8a186ea5..39ff6a91 100644 --- a/src/code/snippets/src/scene/tilemap.rs +++ b/src/code/snippets/src/scene/tilemap.rs @@ -1,3 +1,6 @@ +use fyrox::scene::dim2::collider::{ColliderBuilder, ColliderShape, GeometrySource, TileMapShape}; +use fyrox::scene::dim2::rigidbody::RigidBodyBuilder; +use fyrox::scene::rigidbody::RigidBodyType; use fyrox::{ asset::untyped::ResourceKind, core::{algebra::Vector2, color::Color, math::Rect, pool::Handle}, @@ -62,3 +65,19 @@ fn create_tile_map(graph: &mut Graph) -> Handle { .build(graph) } // ANCHOR_END: create_tile_map + +// ANCHOR: tile_map_physics +fn add_tile_map_physics(tile_map: Handle, graph: &mut Graph) { + // Create a new collider with tile map shape. + let collider = ColliderBuilder::new(BaseBuilder::new()) + .with_shape(ColliderShape::TileMap(TileMapShape { + tile_map: GeometrySource(tile_map), + })) + .build(graph); + + // Create a static rigid body with the tile map collider. + let rigid_body = RigidBodyBuilder::new(BaseBuilder::new().with_children([collider])) + .with_body_type(RigidBodyType::Static) + .build(graph); +} +// ANCHOR_END: tile_map_physics diff --git a/src/scene/tile_map_physics.png b/src/scene/tile_map_physics.png new file mode 100644 index 00000000..e79001ce Binary files /dev/null and b/src/scene/tile_map_physics.png differ diff --git a/src/scene/tilemap.md b/src/scene/tilemap.md index afe33ecb..44b350ed 100644 --- a/src/scene/tilemap.md +++ b/src/scene/tilemap.md @@ -89,40 +89,60 @@ Select some tiles on the palette and start drawing: ![drawing](drawing.png) +## Drawing Tools + There are number of tools (apart from the drawing itself) that could be useful while editing tile maps. -## Erase +### Erase ![erase](erase.gif) Erases tiles using the shape of the current brush, could be activated using `Shift` key or by clicking on the button with eraser icon. -## Flood fill +### Flood fill ![flood fill](flood_fill.gif) Fills a region with the same tile kind (or empty space) using random tiles from the current brush. Could be activated using the button with paint bucket icon. -## Pick +### Pick ![pick](pick.gif) Picks a rectangular region of tiles from the tile map itself and turns them into the current brush. Could be activated using `Alt` key or by clicking the button with pipette icon. -## Rectangular fill +### Rectangular fill ![rect fill](rect_fill.gif) Fills a rectangular region with the tiles from the current brush. It tiles the given region using the tiles from current brush. Could be activated using `Ctrl` key of by clicking on the button with the tiles icon. -## Nine slice +### Nine slice ![nine slice](nine_slice.gif) Fills a rectangular region using a 3x3 brush (the size limitation could be dropped in the future). The corners of the brush will be placed at the corners of the selected region, the middle tiles between corners will be -duplicated from corner to corner. The center tile will be used to fill the rest of the rectangle. \ No newline at end of file +duplicated from corner to corner. The center tile will be used to fill the rest of the rectangle. + +## Physics + +Tile maps supports physics for tiles, and it could be enabled by using special collider shape called `TileMap`. In code +it could be done something like this: + +```rust +{{#include ../code/snippets/src/scene/tilemap.rs:tile_map_physics}} +``` + +In the editor it could be done by creating a static 2D rigid body with a 2D collider that has `TileMap` shape: + +![tile map physics](tile_map_physics.png) + +## Layers + +Tile map does not support any layers on its own, but layers could be added very easy by simply creating another tile +map with its own tile set and shifting this new layer by Z axis towards camera on some small value. \ No newline at end of file