From 98c9b05a021109abfdc11a061574337c2000b54d Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Tue, 8 Nov 2022 09:20:56 -0700 Subject: [PATCH 1/4] Combine scene serialization sections --- .../book/migration-guides/0.8-0.9/_index.md | 133 +----------------- 1 file changed, 6 insertions(+), 127 deletions(-) diff --git a/content/learn/book/migration-guides/0.8-0.9/_index.md b/content/learn/book/migration-guides/0.8-0.9/_index.md index f91812f9e3..be1fcc0144 100644 --- a/content/learn/book/migration-guides/0.8-0.9/_index.md +++ b/content/learn/book/migration-guides/0.8-0.9/_index.md @@ -177,6 +177,7 @@ commands.entity(some_entity).remove_bundle::(); // New (0.9) commands.entity(some_entity).remove::(); ``` + Replace `remove_bundle_intersection` with `remove_intersection`: ```rust @@ -624,141 +625,19 @@ After: ); ``` -### [Replace root list with struct](https://github.com/bevyengine/bevy/pull/6354) - -The scene file format now uses a struct as the root object rather than a list of entities. The list of entities is now found in the `entities` field of this struct. - -```rust -// Old (Bevy 0.8) -[ - ( - entity: 0, - components: [ - // Components... - ] - ), -] - -// New (Bevy 0.9) -( - entities: [ - ( - entity: 0, - components: [ - // Components... - ] - ), - ] -) -``` - -### [Use map for scene `components`](https://github.com/bevyengine/bevy/pull/6345) +### Scene serialization format improvements from [#6354](https://github.com/bevyengine/bevy/pull/6354), [#6345](https://github.com/bevyengine/bevy/pull/6345), and [#5723](https://github.com/bevyengine/bevy/pull/5723) -The scene format now uses a map to represent the collection of components. Scene files will need to update from the old list format. +* The root of the scene is now a struct rather than a list +* Components are now a map keyed by type name rather than a list +* Type information is now omitted when possible, making scenes much more compact -```rust -// Old (Bevy 0.8) -[ - ( - entity: 0, - components: [ - { - "bevy_transform::components::transform::Transform": ( - translation: ( - x: 0.0, - y: 0.0, - z: 0.0 - ), - rotation: (0.0, 0.0, 0.0, 1.0), - scale: ( - x: 1.0, - y: 1.0, - z: 1.0 - ), - ), - }, - { - "my_crate::Foo": ( - text: "Hello World", - ), - }, - { - "my_crate::Bar": ( - baz: 123, - ), - }, - ], - ), -] - -// New (Bevy 0.9) -[ - ( - entity: 0, - components: { - "bevy_transform::components::transform::Transform": ( - translation: ( - x: 0.0, - y: 0.0, - z: 0.0 - ), - rotation: (0.0, 0.0, 0.0, 1.0), - scale: ( - x: 1.0, - y: 1.0, - z: 1.0 - ), - ), - "my_crate::Foo": ( - text: "Hello World", - ), - "my_crate::Bar": ( - baz: 123 - ), - }, - ), -] -``` +See [this diff](https://github.com/bevyengine/bevy/compare/v0.8.0...main#diff-12b7f105bbb2a716e818a2a7eb2c79d40bef29ae8cba45b536c79cfa16b83558) for an illustration. ### [Derive `Reflect` + `FromReflect` for input types](https://github.com/bevyengine/bevy/pull/6232) * `Input` now implements `Reflect` via `#[reflect]` instead of `#[reflect_value]`. This means it now exposes its private fields via the `Reflect` trait rather than being treated as a value type. For code that relies on the `Input` struct being treated as a value type by reflection, it is still possible to wrap the `Input` type with a wrapper struct and apply `#[reflect_value]` to it. * As a reminder, private fields exposed via reflection are not subject to any stability guarantees. -### [Improve serialization format even more](https://github.com/bevyengine/bevy/pull/5723) - -This PR reduces the verbosity of the scene format. Scenes will need to be updated accordingly: - -```js -// Old format -{ - "type": "my_game::item::Item", - "struct": { - "id": { - "type": "alloc::string::String", - "value": "bevycraft:stone", - }, - "tags": { - "type": "alloc::vec::Vec", - "list": [ - { - "type": "alloc::string::String", - "value": "material" - }, - ], - }, - } -} - -// New format -{ - "my_game::item::Item": ( - id: "bevycraft:stone", - tags: ["material"] - ) -} -``` - ### [Relax bounds on `Option`](https://github.com/bevyengine/bevy/pull/5658) If using `Option` with Bevy’s reflection API, `T` now needs to implement `FromReflect` rather than just `Clone`. This can be achieved easily by simply deriving `FromReflect`: From 9d09d0b7072e79e552c4778ba592cb13823dd323 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Tue, 8 Nov 2022 09:41:54 -0700 Subject: [PATCH 2/4] Embed diff --- .../book/migration-guides/0.8-0.9/_index.md | 101 +++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/content/learn/book/migration-guides/0.8-0.9/_index.md b/content/learn/book/migration-guides/0.8-0.9/_index.md index be1fcc0144..35bae3dee8 100644 --- a/content/learn/book/migration-guides/0.8-0.9/_index.md +++ b/content/learn/book/migration-guides/0.8-0.9/_index.md @@ -631,7 +631,106 @@ After: * Components are now a map keyed by type name rather than a list * Type information is now omitted when possible, making scenes much more compact -See [this diff](https://github.com/bevyengine/bevy/compare/v0.8.0...main#diff-12b7f105bbb2a716e818a2a7eb2c79d40bef29ae8cba45b536c79cfa16b83558) for an illustration. +```diff +-[ +- ( +- entity: 0, +- components: [ +- { +- "type": "bevy_transform::components::transform::Transform", +- "struct": { +- "translation": { +- "type": "glam::vec3::Vec3", +- "value": (0.0, 0.0, 0.0), +- }, +- "rotation": { +- "type": "glam::quat::Quat", +- "value": (0.0, 0.0, 0.0, 1.0), +- }, +- "scale": { +- "type": "glam::vec3::Vec3", +- "value": (1.0, 1.0, 1.0), +- }, +- }, ++( ++ entities: { ++ 0: ( ++ components: { ++ "bevy_transform::components::transform::Transform": ( ++ translation: ( ++ x: 0.0, ++ y: 0.0, ++ z: 0.0 ++ ), ++ rotation: (0.0, 0.0, 0.0, 1.0), ++ scale: ( ++ x: 1.0, ++ y: 1.0, ++ z: 1.0 ++ ), ++ ), ++ "scene::ComponentB": ( ++ value: "hello", ++ ), ++ "scene::ComponentA": ( ++ x: 1.0, ++ y: 2.0, ++ ), + }, +- { +- "type": "scene::ComponentB", +- "struct": { +- "value": { +- "type": "alloc::string::String", +- "value": "hello", +- }, +- }, ++ ), ++ 1: ( ++ components: { ++ "scene::ComponentA": ( ++ x: 3.0, ++ y: 4.0, ++ ), + }, +- { +- "type": "scene::ComponentA", +- "struct": { +- "x": { +- "type": "f32", +- "value": 1.0, +- }, +- "y": { +- "type": "f32", +- "value": 2.0, +- }, +- }, +- }, +- ], +- ), +- ( +- entity: 1, +- components: [ +- { +- "type": "scene::ComponentA", +- "struct": { +- "x": { +- "type": "f32", +- "value": 3.0, +- }, +- "y": { +- "type": "f32", +- "value": 4.0, +- }, +- }, +- }, +- ], +- ), +-] ++ ), ++ } ++) +``` ### [Derive `Reflect` + `FromReflect` for input types](https://github.com/bevyengine/bevy/pull/6232) From f8362a4f6fa97c859acb9a75c29c286044a5904b Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Tue, 8 Nov 2022 10:00:08 -0700 Subject: [PATCH 3/4] Undiff the diff --- .../book/migration-guides/0.8-0.9/_index.md | 203 +++++++++--------- 1 file changed, 104 insertions(+), 99 deletions(-) diff --git a/content/learn/book/migration-guides/0.8-0.9/_index.md b/content/learn/book/migration-guides/0.8-0.9/_index.md index 35bae3dee8..83a4593229 100644 --- a/content/learn/book/migration-guides/0.8-0.9/_index.md +++ b/content/learn/book/migration-guides/0.8-0.9/_index.md @@ -631,105 +631,110 @@ After: * Components are now a map keyed by type name rather than a list * Type information is now omitted when possible, making scenes much more compact -```diff --[ -- ( -- entity: 0, -- components: [ -- { -- "type": "bevy_transform::components::transform::Transform", -- "struct": { -- "translation": { -- "type": "glam::vec3::Vec3", -- "value": (0.0, 0.0, 0.0), -- }, -- "rotation": { -- "type": "glam::quat::Quat", -- "value": (0.0, 0.0, 0.0, 1.0), -- }, -- "scale": { -- "type": "glam::vec3::Vec3", -- "value": (1.0, 1.0, 1.0), -- }, -- }, -+( -+ entities: { -+ 0: ( -+ components: { -+ "bevy_transform::components::transform::Transform": ( -+ translation: ( -+ x: 0.0, -+ y: 0.0, -+ z: 0.0 -+ ), -+ rotation: (0.0, 0.0, 0.0, 1.0), -+ scale: ( -+ x: 1.0, -+ y: 1.0, -+ z: 1.0 -+ ), -+ ), -+ "scene::ComponentB": ( -+ value: "hello", -+ ), -+ "scene::ComponentA": ( -+ x: 1.0, -+ y: 2.0, -+ ), - }, -- { -- "type": "scene::ComponentB", -- "struct": { -- "value": { -- "type": "alloc::string::String", -- "value": "hello", -- }, -- }, -+ ), -+ 1: ( -+ components: { -+ "scene::ComponentA": ( -+ x: 3.0, -+ y: 4.0, -+ ), - }, -- { -- "type": "scene::ComponentA", -- "struct": { -- "x": { -- "type": "f32", -- "value": 1.0, -- }, -- "y": { -- "type": "f32", -- "value": 2.0, -- }, -- }, -- }, -- ], -- ), -- ( -- entity: 1, -- components: [ -- { -- "type": "scene::ComponentA", -- "struct": { -- "x": { -- "type": "f32", -- "value": 3.0, -- }, -- "y": { -- "type": "f32", -- "value": 4.0, -- }, -- }, -- }, -- ], -- ), --] -+ ), -+ } -+) +```javascript +// Old (Bevy 0.8) +[ + ( + entity: 0, + components: [ + { + "type": "bevy_transform::components::transform::Transform", + "struct": { + "translation": { + "type": "glam::vec3::Vec3", + "value": (0.0, 0.0, 0.0), + }, + "rotation": { + "type": "glam::quat::Quat", + "value": (0.0, 0.0, 0.0, 1.0), + }, + "scale": { + "type": "glam::vec3::Vec3", + "value": (1.0, 1.0, 1.0), + }, + }, + }, + { + "type": "scene::ComponentB", + "struct": { + "value": { + "type": "alloc::string::String", + "value": "hello", + }, + }, + }, + { + "type": "scene::ComponentA", + "struct": { + "x": { + "type": "f32", + "value": 1.0, + }, + "y": { + "type": "f32", + "value": 2.0, + }, + }, + }, + ], + ), + ( + entity: 1, + components: [ + { + "type": "scene::ComponentA", + "struct": { + "x": { + "type": "f32", + "value": 3.0, + }, + "y": { + "type": "f32", + "value": 4.0, + }, + }, + }, + ], + ), +] + +// New (Bevy 0.9) +( + entities: { + 0: ( + components: { + "bevy_transform::components::transform::Transform": ( + translation: ( + x: 0.0, + y: 0.0, + z: 0.0 + ), + rotation: (0.0, 0.0, 0.0, 1.0), + scale: ( + x: 1.0, + y: 1.0, + z: 1.0 + ), + ), + "scene::ComponentB": ( + value: "hello", + ), + "scene::ComponentA": ( + x: 1.0, + y: 2.0, + ), + }, + ), + 1: ( + components: { + "scene::ComponentA": ( + x: 3.0, + y: 4.0, + ), + }, + ), + } +) ``` ### [Derive `Reflect` + `FromReflect` for input types](https://github.com/bevyengine/bevy/pull/6232) From 5bf793c8a0c45d72fc82287d24584c864048527c Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Tue, 8 Nov 2022 11:16:20 -0700 Subject: [PATCH 4/4] Add migration advice --- content/learn/book/migration-guides/0.8-0.9/_index.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/content/learn/book/migration-guides/0.8-0.9/_index.md b/content/learn/book/migration-guides/0.8-0.9/_index.md index 83a4593229..1dd17fa478 100644 --- a/content/learn/book/migration-guides/0.8-0.9/_index.md +++ b/content/learn/book/migration-guides/0.8-0.9/_index.md @@ -631,6 +631,10 @@ After: * Components are now a map keyed by type name rather than a list * Type information is now omitted when possible, making scenes much more compact +Scenes serialized with Bevy 0.8 will need to be recreated, but it is possible to hand-edit scenes to match the new format. + +Here's an example scene in the old and new format: + ```javascript // Old (Bevy 0.8) [