From 1874ae4546cd6dac7d570964f1c0ea5b5f1b2c54 Mon Sep 17 00:00:00 2001 From: "kaosat.dev" Date: Mon, 17 Jul 2023 23:37:25 +0200 Subject: [PATCH 01/23] chore(): bumped versions & dependency versions --- Cargo.toml | 8 ++++---- bevy_proto_backend/Cargo.toml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5ae9765..9683bdc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -99,8 +99,8 @@ bevy_ui = [ ] [dependencies] -bevy_proto_backend = { version = "0.3", path = "./bevy_proto_backend", default-features = false } -bevy = { version = ">=0.10.1", default-features = false, features = ["bevy_asset"] } +bevy_proto_backend = { version = "0.4", path = "./bevy_proto_backend", default-features = false } +bevy = { version = ">=0.11.0", default-features = false, features = ["bevy_asset"] } anyhow = "1.0" serde = "1.0" thiserror = "1.0" @@ -111,8 +111,8 @@ serde_yaml = { version = "0.9", optional = true, default-features = false } [dev-dependencies] ron = "0.8" serde_yaml = "0.9" -bevy = "0.10.1" -bevy_prototype_lyon = "0.8.0" +bevy = "0.11.0" +bevy_prototype_lyon = "0.9.0" trybuild = "1.0.71" [[example]] diff --git a/bevy_proto_backend/Cargo.toml b/bevy_proto_backend/Cargo.toml index 4eed545..3a6dd38 100644 --- a/bevy_proto_backend/Cargo.toml +++ b/bevy_proto_backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_proto_backend" -version = "0.3.0" +version = "0.4.0" edition = "2021" authors = ["Gino Valente "] description = "Backend crate for bevy_proto" @@ -63,7 +63,7 @@ bevy_ui = [ [dependencies] bevy_proto_derive = { version = "0.5", path = "../bevy_proto_derive" } -bevy = { version = ">=0.10.1", default-features = false, features = ["bevy_asset"] } +bevy = { version = ">=0.11.0", default-features = false, features = ["bevy_asset"] } anyhow = "1.0" serde = "1.0" thiserror = "1.0" From e4a2a87ef0e26614c250f332a9ae6652699af89d Mon Sep 17 00:00:00 2001 From: "kaosat.dev" Date: Mon, 17 Jul 2023 23:37:59 +0200 Subject: [PATCH 02/23] chore(): removed the FromReflect macro calls, as it is now automatically derived within the Reflect derive macro --- .../src/impls/bevy_impls/core.rs | 2 +- .../src/impls/bevy_impls/core_pipeline.rs | 20 ++--- .../src/impls/bevy_impls/gltf.rs | 4 +- .../src/impls/bevy_impls/pbr.rs | 22 +++--- .../src/impls/bevy_impls/render.rs | 10 +-- .../src/impls/bevy_impls/sprite.rs | 4 +- .../src/impls/bevy_impls/text.rs | 14 ++-- bevy_proto_backend/src/impls/bevy_impls/ui.rs | 73 +++++++------------ .../src/impls/bevy_impls/window.rs | 2 +- bevy_proto_backend/src/load/asset_loader.rs | 2 +- bevy_proto_backend/src/proto/assets.rs | 4 +- bevy_proto_backend/src/proto/color.rs | 4 +- bevy_proto_backend/src/tree/access.rs | 18 ++--- bevy_proto_derive/src/lib.rs | 2 +- 14 files changed, 80 insertions(+), 101 deletions(-) diff --git a/bevy_proto_backend/src/impls/bevy_impls/core.rs b/bevy_proto_backend/src/impls/bevy_impls/core.rs index e5a8627..2145428 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/core.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/core.rs @@ -13,7 +13,7 @@ impl_external_schematic! { #[schematic(from = NameInput)] struct Name {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub struct NameInput(String); impl From for Name { fn from(input: NameInput) -> Self { diff --git a/bevy_proto_backend/src/impls/bevy_impls/core_pipeline.rs b/bevy_proto_backend/src/impls/bevy_impls/core_pipeline.rs index c688328..7627783 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/core_pipeline.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/core_pipeline.rs @@ -6,7 +6,7 @@ use bevy::core_pipeline::fxaa::Fxaa; use bevy::core_pipeline::prepass::{DepthPrepass, NormalPrepass}; use bevy::core_pipeline::tonemapping::{DebandDither, Tonemapping}; use bevy::prelude::{Camera2d, Camera3d, Color}; -use bevy::reflect::{std_traits::ReflectDefault, FromReflect, Reflect}; +use bevy::reflect::{std_traits::ReflectDefault, Reflect}; use crate::impls::macros::{from_to, from_to_default, register_schematic}; use bevy_proto_derive::impl_external_schematic; @@ -35,7 +35,7 @@ impl_external_schematic! { #[schematic(from = BloomSettingsInput)] struct BloomSettings {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct BloomSettingsInput { pub intensity: f32, @@ -58,7 +58,7 @@ impl_external_schematic! { } ); - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct BloomPrefilterSettingsInput { pub threshold: f32, @@ -73,7 +73,7 @@ impl_external_schematic! { } ); - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub enum BloomCompositeModeInput { EnergyConserving, Additive, @@ -92,7 +92,7 @@ impl_external_schematic! { #[schematic(from = Camera2dInput)] struct Camera2d {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct Camera2dInput { pub clear_color: ClearColorConfigInput, @@ -110,7 +110,7 @@ impl_external_schematic! { #[schematic(from = Camera3dInput)] struct Camera3d {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct Camera3dInput { pub clear_color: ClearColorConfigInput, @@ -125,7 +125,7 @@ impl_external_schematic! { } ); - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum Camera3dDepthLoadOpInput { Clear(f32), @@ -149,7 +149,7 @@ impl_external_schematic! { #[schematic(from = DepthPrepassInput)] struct DepthPrepass {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub struct DepthPrepassInput; impl From for DepthPrepass { fn from(_: DepthPrepassInput) -> Self { @@ -166,7 +166,7 @@ impl_external_schematic! { #[schematic(from = NormalPrepassInput)] struct NormalPrepass {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub struct NormalPrepassInput; impl From for NormalPrepass { fn from(_: NormalPrepassInput) -> Self { @@ -179,7 +179,7 @@ impl_external_schematic! { enum Tonemapping {} } -#[derive(Reflect, FromReflect)] +#[derive(Reflect)] #[reflect(Default)] pub enum ClearColorConfigInput { Default, diff --git a/bevy_proto_backend/src/impls/bevy_impls/gltf.rs b/bevy_proto_backend/src/impls/bevy_impls/gltf.rs index c352dc2..424d71c 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/gltf.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/gltf.rs @@ -1,6 +1,6 @@ use bevy::app::App; use bevy::gltf::GltfExtras; -use bevy::reflect::{FromReflect, Reflect}; +use bevy::reflect::Reflect; use crate::impls::macros::{from_to_default, register_schematic}; use bevy_proto_derive::impl_external_schematic; @@ -13,7 +13,7 @@ impl_external_schematic! { #[schematic(from = GltfExtrasInput)] struct GltfExtras {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub struct GltfExtrasInput{ pub value: String, } diff --git a/bevy_proto_backend/src/impls/bevy_impls/pbr.rs b/bevy_proto_backend/src/impls/bevy_impls/pbr.rs index 481606b..f957dc9 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/pbr.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/pbr.rs @@ -6,7 +6,7 @@ use bevy::pbr::{ DirectionalLight, EnvironmentMapLight, FogFalloff, FogSettings, NotShadowCaster, NotShadowReceiver, PointLight, SpotLight, }; -use bevy::reflect::{std_traits::ReflectDefault, FromReflect, Reflect}; +use bevy::reflect::{std_traits::ReflectDefault, Reflect}; use crate::impls::macros::{from_to, from_to_default, register_schematic}; use crate::proto::ProtoColor; @@ -40,7 +40,7 @@ impl_external_schematic! { #[schematic(from = CascadeShadowConfigInput)] struct CascadeShadowConfig {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct CascadeShadowConfigInput { pub num_cascades: usize, @@ -78,7 +78,7 @@ impl_external_schematic! { #[schematic(from = ClusterConfigInput)] enum ClusterConfig {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum ClusterConfigInput { None, @@ -120,7 +120,7 @@ impl_external_schematic! { #[schematic(from = DirectionalLightInput)] struct DirectionalLight {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct DirectionalLightInput { pub color: ProtoColor, @@ -155,7 +155,7 @@ impl_external_schematic! { #[schematic(from = FogSettingsInput)] struct FogSettings {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct FogSettingsInput { pub color: ProtoColor, @@ -174,7 +174,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub enum FogFalloffInput { Linear { start: f32, @@ -207,7 +207,7 @@ impl_external_schematic! { #[schematic(from = NotShadowCasterInput)] struct NotShadowCaster; // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub struct NotShadowCasterInput; impl From for NotShadowCaster { fn from(_: NotShadowCasterInput) -> Self { @@ -220,7 +220,7 @@ impl_external_schematic! { #[schematic(from = NotShadowReceiverInput)] struct NotShadowReceiver; // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub struct NotShadowReceiverInput; impl From for NotShadowReceiver { fn from(_: NotShadowReceiverInput) -> Self { @@ -233,7 +233,7 @@ impl_external_schematic! { #[schematic(from = PointLightInput)] struct PointLight {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct PointLightInput { pub color: ProtoColor, @@ -263,7 +263,7 @@ impl_external_schematic! { #[schematic(from = SpotLightInput)] struct SpotLight {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct SpotLightInput { pub color: ProtoColor, @@ -297,7 +297,7 @@ impl_external_schematic! { #[schematic(from = WireframeInput)] struct Wireframe; // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub struct WireframeInput; impl From for Wireframe { fn from(_: WireframeInput) -> Self { diff --git a/bevy_proto_backend/src/impls/bevy_impls/render.rs b/bevy_proto_backend/src/impls/bevy_impls/render.rs index 2408430..fc6224f 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/render.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/render.rs @@ -1,6 +1,6 @@ use bevy::app::App; use bevy::prelude::{Camera, Entity, OrthographicProjection, PerspectiveProjection, Projection}; -use bevy::reflect::{std_traits::ReflectDefault, FromReflect, Reflect, TupleStruct}; +use bevy::reflect::{std_traits::ReflectDefault, Reflect, TupleStruct}; use bevy::render::camera::CameraRenderGraph; use bevy::render::mesh::skinning::SkinnedMesh; use bevy::render::primitives::Aabb; @@ -39,7 +39,7 @@ impl_external_schematic! { #[schematic(from = CameraRenderGraphInput)] struct CameraRenderGraph {} // --- - #[derive(Reflect, FromReflect, Default)] + #[derive(Reflect, Default)] #[reflect(Default)] pub struct CameraRenderGraphInput(Cow<'static, str>); @@ -67,7 +67,7 @@ impl_external_schematic! { #[schematic(from = ColorGradingInput)] struct ColorGrading {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct ColorGradingInput { pub exposure: f32, @@ -99,7 +99,7 @@ impl_external_schematic! { #[schematic(from = ProjectionInput)] enum Projection {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum ProjectionInput { Perspective(PerspectiveProjection), @@ -119,7 +119,7 @@ impl_external_schematic! { #[schematic(from = RenderLayersInput)] struct RenderLayers(); // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub struct RenderLayersInput(u8); impl From for RenderLayers { fn from(value: RenderLayersInput) -> Self { diff --git a/bevy_proto_backend/src/impls/bevy_impls/sprite.rs b/bevy_proto_backend/src/impls/bevy_impls/sprite.rs index d295ba3..315b0ca 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/sprite.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/sprite.rs @@ -1,6 +1,6 @@ use bevy::app::App; use bevy::math::Vec2; -use bevy::reflect::{std_traits::ReflectDefault, FromReflect, Reflect}; +use bevy::reflect::{std_traits::ReflectDefault, Reflect}; use bevy::sprite::{Anchor, Mesh2dHandle, Sprite, TextureAtlasSprite}; use crate::impls::macros::{from_to_default, register_schematic}; @@ -35,7 +35,7 @@ impl_external_schematic! { #[schematic(from = TextureAtlasSpriteInput)] struct TextureAtlasSprite {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct TextureAtlasSpriteInput { pub color: ProtoColor, diff --git a/bevy_proto_backend/src/impls/bevy_impls/text.rs b/bevy_proto_backend/src/impls/bevy_impls/text.rs index 457eeea..ddd6393 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/text.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/text.rs @@ -1,6 +1,6 @@ use bevy::app::App; use bevy::math::Vec2; -use bevy::reflect::{std_traits::ReflectDefault, FromReflect, Reflect}; +use bevy::reflect::{std_traits::ReflectDefault, Reflect}; use bevy::text::{BreakLineOn, Text, Text2dBounds, TextAlignment, TextSection, TextStyle}; use crate::impls::macros::{from_to, from_to_default, from_to_input, register_schematic}; @@ -23,7 +23,7 @@ impl_external_schematic! { #[schematic(from = TextInput)] struct Text {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct TextInput { pub sections: Vec, @@ -57,7 +57,7 @@ impl_external_schematic! { } } - #[derive(FromReflect, Reflect)] + #[derive(Reflect)] pub struct TextSectionInput { pub value: String, pub style: TextStyleInput, @@ -71,7 +71,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub struct TextStyleInput { pub font: ProtoAsset, pub font_size: f32, @@ -87,7 +87,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub enum TextAlignmentInput { Left, Center, @@ -103,7 +103,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub enum BreakLineOnInput { WordBoundary, AnyCharacter, @@ -122,7 +122,7 @@ impl_external_schematic! { #[schematic(from = Text2dBoundsInput)] struct Text2dBounds {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct Text2dBoundsInput { pub size: Vec2, diff --git a/bevy_proto_backend/src/impls/bevy_impls/ui.rs b/bevy_proto_backend/src/impls/bevy_impls/ui.rs index a2f9a9d..49583a7 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/ui.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/ui.rs @@ -1,11 +1,11 @@ use bevy::app::App; use bevy::math::{Rect, Vec2}; use bevy::prelude::{BackgroundColor, Button, Label}; -use bevy::reflect::{std_traits::ReflectDefault, FromReflect, Reflect}; +use bevy::reflect::{std_traits::ReflectDefault, Reflect}; use bevy::ui::{ - AlignContent, AlignItems, AlignSelf, CalculatedClip, CalculatedSize, Direction, Display, + AlignContent, AlignItems, AlignSelf, CalculatedClip, Direction, Display, FlexDirection, FlexWrap, FocusPolicy, Interaction, JustifyContent, Node, Overflow, - PositionType, RelativeCursorPosition, Size, Style, UiImage, UiRect, Val, ZIndex, + PositionType, RelativeCursorPosition, Style, UiImage, UiRect, Val, ZIndex, }; use crate::impls::macros::{from_to, from_to_default, register_schematic}; @@ -18,7 +18,6 @@ pub(super) fn register(app: &mut App) { BackgroundColor, Button, CalculatedClip, - CalculatedSize, FocusPolicy, Interaction, Label, @@ -49,7 +48,7 @@ impl_external_schematic! { #[schematic(from = BackgroundColorInput)] struct BackgroundColor(); // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct BackgroundColorInput(pub ProtoColor); from_to_default! { @@ -63,7 +62,7 @@ impl_external_schematic! { #[schematic(from = ButtonInput)] struct Button; // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub struct ButtonInput; from_to_default!( Button, @@ -76,7 +75,7 @@ impl_external_schematic! { #[schematic(from = CalculatedClipInput)] struct CalculatedClip {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct CalculatedClipInput { pub clip: Rect, @@ -90,31 +89,11 @@ impl_external_schematic! { } } -impl_external_schematic! { - #[schematic(from = CalculatedSizeInput)] - struct CalculatedSize {} - // --- - #[derive(Reflect, FromReflect)] - #[reflect(Default)] - pub struct CalculatedSizeInput { - pub size: Vec2, - pub preserve_aspect_ratio: bool, - } - from_to_default! { - CalculatedSize, - CalculatedSizeInput, - |value: Input| Self { - size: value.size, - preserve_aspect_ratio: value.preserve_aspect_ratio, - } - } -} - impl_external_schematic! { #[schematic(from = FocusPolicyInput)] enum FocusPolicy {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum FocusPolicyInput { Block, @@ -134,7 +113,7 @@ impl_external_schematic! { #[schematic(from = InteractionInput)] enum Interaction {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum InteractionInput { Clicked, @@ -156,7 +135,7 @@ impl_external_schematic! { #[schematic(from = LabelInput)] struct Label; // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub struct LabelInput; impl From for Label { fn from(_: LabelInput) -> Self { @@ -169,7 +148,7 @@ impl_external_schematic! { #[schematic(from = NodeInput)] struct Node {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub struct NodeInput; from_to!( Node, @@ -187,7 +166,7 @@ impl_external_schematic! { #[schematic(from = RelativeCursorPositionInput)] struct RelativeCursorPosition {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct RelativeCursorPositionInput { pub normalized: Option, @@ -205,7 +184,7 @@ impl_external_schematic! { #[schematic(from = StyleInput)] struct Style {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct StyleInput { pub display: DisplayInput, @@ -260,7 +239,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum AlignContentInput { Start, @@ -289,7 +268,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum AlignItemsInput { Start, @@ -314,7 +293,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum AlignSelfInput { Auto, @@ -341,7 +320,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum DirectionInput { Inherit, @@ -358,7 +337,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum DisplayInput { None, @@ -373,7 +352,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum FlexWrapInput { NoWrap, @@ -390,7 +369,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum FlexDirectionInput { Row, @@ -409,7 +388,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum JustifyContentInput { Start, @@ -436,7 +415,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum OverflowInput { Visible, @@ -451,7 +430,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum PositionTypeInput { Relative, @@ -466,7 +445,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct SizeInput { pub width: ValInput, @@ -481,7 +460,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub struct UiRectInput { pub left: ValInput, @@ -500,7 +479,7 @@ impl_external_schematic! { } } - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum ValInput { Undefined, @@ -547,7 +526,7 @@ impl_external_schematic! { #[schematic(from = ZIndexInput)] enum ZIndex {} // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] #[reflect(Default)] pub enum ZIndexInput { Local(i32), diff --git a/bevy_proto_backend/src/impls/bevy_impls/window.rs b/bevy_proto_backend/src/impls/bevy_impls/window.rs index bfd0aa1..2c0ffd8 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/window.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/window.rs @@ -17,7 +17,7 @@ impl_external_schematic! { #[schematic(from = PrimaryWindowInput)] struct PrimaryWindow; // --- - #[derive(Reflect, FromReflect)] + #[derive(Reflect)] pub struct PrimaryWindowInput; impl From for PrimaryWindow { fn from(_: PrimaryWindowInput) -> Self { diff --git a/bevy_proto_backend/src/load/asset_loader.rs b/bevy_proto_backend/src/load/asset_loader.rs index 691cc01..717de01 100644 --- a/bevy_proto_backend/src/load/asset_loader.rs +++ b/bevy_proto_backend/src/load/asset_loader.rs @@ -1,7 +1,7 @@ use std::marker::PhantomData; use std::sync::Arc; -use bevy::app::AppTypeRegistry; +use bevy::ecs::reflect::AppTypeRegistry; use bevy::asset::{AssetLoader, AssetPath, BoxedFuture, LoadContext, LoadedAsset}; use bevy::prelude::{Handle, World}; use parking_lot::RwLock; diff --git a/bevy_proto_backend/src/proto/assets.rs b/bevy_proto_backend/src/proto/assets.rs index 289924c..b2e12bb 100644 --- a/bevy_proto_backend/src/proto/assets.rs +++ b/bevy_proto_backend/src/proto/assets.rs @@ -1,12 +1,12 @@ use bevy::asset::{Asset, AssetPath, Handle, HandleId}; -use bevy::prelude::{FromReflect, Reflect}; +use bevy::prelude::Reflect; /// Replacement type for asset handles in a [`Schematic::Input`] generated by the /// [derive macro]. /// /// [`Schematic::Input`]: crate::schematics::Schematic::Input /// [derive macro]: bevy_proto_derive::Schematic -#[derive(Clone, Debug, Eq, PartialEq, Hash, Reflect, FromReflect)] +#[derive(Clone, Debug, Eq, PartialEq, Hash, Reflect)] pub enum ProtoAsset { /// The path to an asset relative to the `assets` directory. AssetPath(String), diff --git a/bevy_proto_backend/src/proto/color.rs b/bevy_proto_backend/src/proto/color.rs index 893fb2f..76f897a 100644 --- a/bevy_proto_backend/src/proto/color.rs +++ b/bevy_proto_backend/src/proto/color.rs @@ -1,5 +1,5 @@ use bevy::reflect::{ - std_traits::ReflectDefault, FromReflect, Reflect, ReflectDeserialize, ReflectSerialize, + std_traits::ReflectDefault, Reflect, ReflectDeserialize, ReflectSerialize, }; use bevy::render::color::Color; use serde::{Deserialize, Serialize}; @@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize}; /// /// [`Red`]: ProtoColor::Red /// [`AliceBlue`]: ProtoColor::AliceBlue -#[derive(Reflect, FromReflect, Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] +#[derive(Reflect, Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] #[reflect(Default, PartialEq, Serialize, Deserialize)] pub enum ProtoColor { /// sRGBA color diff --git a/bevy_proto_backend/src/tree/access.rs b/bevy_proto_backend/src/tree/access.rs index 61ebaad..df0e404 100644 --- a/bevy_proto_backend/src/tree/access.rs +++ b/bevy_proto_backend/src/tree/access.rs @@ -5,7 +5,7 @@ use std::slice::Iter; use std::str::FromStr; use bevy::prelude::Entity; -use bevy::reflect::{std_traits::ReflectDefault, FromReflect, Reflect, ReflectDeserialize}; +use bevy::reflect::{std_traits::ReflectDefault, Reflect, ReflectDeserialize}; use serde::Deserialize; use crate::schematics::{FromSchematicInput, SchematicContext}; @@ -13,7 +13,7 @@ use crate::schematics::{FromSchematicInput, SchematicContext}; /// A deserializable prototype entity reference. /// /// [prototype]: crate::proto::Prototypical -#[derive(Clone, Debug, PartialEq, Reflect, FromReflect, Deserialize)] +#[derive(Clone, Debug, PartialEq, Reflect, Deserialize)] #[reflect(Deserialize)] pub enum ProtoEntity { /// Access the entity from the given access path. @@ -31,7 +31,7 @@ pub enum ProtoEntity { } /// Determines how a child entity is accessed. -#[derive(Debug, Clone, Eq, PartialEq, Reflect, FromReflect, Deserialize)] +#[derive(Debug, Clone, Eq, PartialEq, Reflect, Deserialize)] #[reflect(Deserialize)] pub enum ChildAccess { /// Access the child with the given ID. @@ -81,7 +81,7 @@ impl From<(String, NonZeroIsize)> for ChildAccess { } /// Determines how a sibling entity is accessed. -#[derive(Debug, Clone, Eq, PartialEq, Reflect, FromReflect, Deserialize)] +#[derive(Debug, Clone, Eq, PartialEq, Reflect, Deserialize)] pub enum SiblingAccess { /// Access the sibling with the given ID. /// @@ -132,7 +132,7 @@ impl From<(String, NonZeroIsize)> for SiblingAccess { } } -#[derive(Debug, Clone, Eq, PartialEq, Reflect, FromReflect)] +#[derive(Debug, Clone, Eq, PartialEq, Reflect)] pub(crate) enum AccessOp { /// Access the root entity. Root, @@ -167,7 +167,7 @@ pub(crate) enum AccessOp { /// /// /// [`EntityTree`]: crate::tree::EntityTree -#[derive(Default, Clone, Eq, PartialEq, Reflect, FromReflect, Deserialize)] +#[derive(Default, Clone, Eq, PartialEq, Reflect, Deserialize)] #[reflect(Default, Deserialize)] #[serde(from = "ProtoEntity")] pub struct EntityAccess { @@ -376,10 +376,10 @@ impl FromSchematicInput for Option { /// # Example /// /// ```ignore -/// # use bevy::prelude::{Entity, FromReflect, Reflect}; +/// # use bevy::prelude::{Entity, Reflect}; /// # use bevy_proto_backend::tree::ProtoEntityList; /// # use bevy_proto_backend::schematics::{Schematic, ReflectSchematic}; -/// #[derive(Reflect, FromReflect, Schematic)] +/// #[derive(Reflect, Schematic)] /// #[reflect(Schematic)] /// struct EntityGroup { /// #[from = ProtoEntityList] @@ -387,7 +387,7 @@ impl FromSchematicInput for Option { /// } /// ``` /// -#[derive(Default, Clone, PartialEq, Reflect, FromReflect, Deserialize)] +#[derive(Default, Clone, PartialEq, Reflect, Deserialize)] #[reflect(Default, Deserialize)] #[serde(transparent)] pub struct ProtoEntityList(pub Vec); diff --git a/bevy_proto_derive/src/lib.rs b/bevy_proto_derive/src/lib.rs index fbde2f4..18e23b2 100644 --- a/bevy_proto_derive/src/lib.rs +++ b/bevy_proto_derive/src/lib.rs @@ -173,7 +173,7 @@ pub fn derive_schematic(input: TokenStream) -> TokenStream { /// // since we're using a custom input type /// } /// -/// #[derive(Reflect, FromReflect)] +/// #[derive(Reflect)] /// pub struct SomeExternalTypeInput(usize); /// impl From for SomeExternalType { /// fn from(input: SomeExternalTypeInput) -> Self { From 47a6759835f2ac644a0a4925251671ac3ad22b0e Mon Sep 17 00:00:00 2001 From: "kaosat.dev" Date: Mon, 17 Jul 2023 23:39:57 +0200 Subject: [PATCH 03/23] chore(examples): migrated examples to schedule-first --- examples/basic_schematic.rs | 4 ++-- examples/bevy/ui.rs | 4 ++-- examples/custom_config.rs | 4 ++-- examples/custom_loader.rs | 4 ++-- examples/custom_schematic.rs | 6 +++--- examples/cycles.rs | 4 ++-- examples/derive_schematic.rs | 2 +- examples/hierarchy.rs | 4 ++-- examples/hot_reload.rs | 4 ++-- examples/loading.rs | 4 ++-- examples/templates.rs | 4 ++-- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/basic_schematic.rs b/examples/basic_schematic.rs index f78834f..e93d522 100644 --- a/examples/basic_schematic.rs +++ b/examples/basic_schematic.rs @@ -18,8 +18,8 @@ fn main() { .register_type_data::() // =============== // .add_plugin(ProtoPlugin::new()) - .add_startup_systems((setup, load)) - .add_systems(( + .add_systems(Startup, (setup, load)) + .add_systems(Update, ( spawn.run_if( prototype_ready("Player") .and_then(prototype_ready("PlayerConfig")) diff --git a/examples/bevy/ui.rs b/examples/bevy/ui.rs index 0cb5d48..90f1a0c 100644 --- a/examples/bevy/ui.rs +++ b/examples/bevy/ui.rs @@ -27,8 +27,8 @@ fn main() { // .insert_resource(bevy::winit::WinitSettings::desktop_app()) .register_type::() .register_type::() - .add_startup_systems((setup, load)) - .add_systems((spawn.run_if(prototype_ready(ROOT)), inspect, mouse_scroll)) + .add_systems(Startup, (setup, load)) + .add_systems(Update, (spawn.run_if(prototype_ready(ROOT)), inspect, mouse_scroll)) .run(); } diff --git a/examples/custom_config.rs b/examples/custom_config.rs index 14de21b..09c3f28 100644 --- a/examples/custom_config.rs +++ b/examples/custom_config.rs @@ -32,8 +32,8 @@ fn main() { // ) // // =============== // - .add_startup_system(load) - .add_systems(( + .add_systems(Startup, load) + .add_systems(Update, ( // =============== // // For custom configs we also need to use `ProtoCondition::::prototype_ready` // instead of the default `prototype_ready` for our run condition: diff --git a/examples/custom_loader.rs b/examples/custom_loader.rs index ba856bc..754e54f 100644 --- a/examples/custom_loader.rs +++ b/examples/custom_loader.rs @@ -27,8 +27,8 @@ fn main() { .register_type::() .register_type::() .register_type::() - .add_startup_system(load) - .add_systems(( + .add_systems(Startup, load) + .add_systems(Update, ( spawn.run_if(prototype_ready("Player").and_then(run_once())), inspect, )) diff --git a/examples/custom_schematic.rs b/examples/custom_schematic.rs index b254e4f..c7e6b5f 100644 --- a/examples/custom_schematic.rs +++ b/examples/custom_schematic.rs @@ -13,8 +13,8 @@ fn main() { // Make sure to register your types! .register_type::() // ================ // - .add_startup_system(load) - .add_systems(( + .add_systems(Startup, load) + .add_systems(Update, ( spawn.run_if(prototype_ready("CustomSchematic").and_then(run_once())), inspect, )) @@ -39,7 +39,7 @@ struct Foo; // This struct provides configuration for `Foo` in the prototype file. // Input types must implement `FromReflect` -#[derive(Reflect, FromReflect)] +#[derive(Reflect)] struct FooInput { /// The asset path of the image to load. image: String, diff --git a/examples/cycles.rs b/examples/cycles.rs index 3555707..8d69b51 100644 --- a/examples/cycles.rs +++ b/examples/cycles.rs @@ -35,8 +35,8 @@ fn main() { CycleResponse::Panic }))), ) - .add_startup_system(load) - .add_systems(( + .add_systems(Startup, load) + .add_systems(Update, ( spawn.run_if(prototype_ready("CycleA").and_then(run_once())), inspect, )) diff --git a/examples/derive_schematic.rs b/examples/derive_schematic.rs index 3a0e009..2610842 100644 --- a/examples/derive_schematic.rs +++ b/examples/derive_schematic.rs @@ -83,7 +83,7 @@ enum Foob { }, } -#[derive(Reflect, FromReflect)] +#[derive(Reflect)] struct EntityGroup(Vec); // This implementation allows us to get a group of entities from the world diff --git a/examples/hierarchy.rs b/examples/hierarchy.rs index ba292fd..c121d7c 100644 --- a/examples/hierarchy.rs +++ b/examples/hierarchy.rs @@ -51,8 +51,8 @@ fn main() { .register_type::() .register_type::() .register_type::() - .add_startup_systems((setup, load)) - .add_systems(( + .add_systems(Startup, (setup, load)) + .add_systems(Update, ( spawn.run_if(prototype_ready("Parent").and_then(run_once())), inspect, draw_relations, diff --git a/examples/hot_reload.rs b/examples/hot_reload.rs index 330c3bd..0c3c0ca 100644 --- a/examples/hot_reload.rs +++ b/examples/hot_reload.rs @@ -25,8 +25,8 @@ fn main() { ..default() })) .add_plugin(ProtoPlugin::new()) - .add_startup_systems((setup, load)) - .add_systems((spawn.run_if(prototype_ready("ReloadableSprite")), inspect)) + .add_systems(Startup, (setup, load)) + .add_systems(Update, (spawn.run_if(prototype_ready("ReloadableSprite")), inspect)) .run(); } diff --git a/examples/loading.rs b/examples/loading.rs index 0945701..bf2fd25 100644 --- a/examples/loading.rs +++ b/examples/loading.rs @@ -10,8 +10,8 @@ fn main() { // The `ProtoPlugin` adds all the necessary systems and resources // to load and spawn prototype assets. .add_plugin(ProtoPlugin::new()) - .add_startup_systems((setup, load)) - .add_systems(( + .add_systems(Startup, (setup, load)) + .add_systems(Update, ( spawn.run_if(prototype_ready("Player").and_then(run_once())), inspect, )) diff --git a/examples/templates.rs b/examples/templates.rs index 2836eaa..ca98f75 100644 --- a/examples/templates.rs +++ b/examples/templates.rs @@ -32,8 +32,8 @@ fn main() { .add_plugin(ProtoPlugin::new()) .register_type::() .register_type::() - .add_startup_systems((load, setup)) - .add_systems(( + .add_systems(Startup, (load, setup)) + .add_systems(Update, ( spawn.run_if(prototype_ready("Player").and_then(run_once())), on_spawn, inspect, From 26300699fbfb6d75c23efa13a9db63b30e9b421f Mon Sep 17 00:00:00 2001 From: Hafiidz <3688500+Hafiidz@users.noreply.github.com> Date: Sat, 15 Jul 2023 18:45:59 +0800 Subject: [PATCH 04/23] Rename Command's "write" method to "apply" --- bevy_proto_backend/src/proto/commands.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bevy_proto_backend/src/proto/commands.rs b/bevy_proto_backend/src/proto/commands.rs index 94243d4..8f81680 100644 --- a/bevy_proto_backend/src/proto/commands.rs +++ b/bevy_proto_backend/src/proto/commands.rs @@ -186,7 +186,7 @@ impl> ProtoInsertCommand { } impl> Command for ProtoInsertCommand { - fn write(self, world: &mut World) { + fn apply(self, world: &mut World) { self.data.assert_is_registered(world); self.data @@ -217,7 +217,7 @@ impl> ProtoRemoveCommand { } impl> Command for ProtoRemoveCommand { - fn write(self, world: &mut World) { + fn apply(self, world: &mut World) { self.data.assert_is_registered(world); self.data From 85aa32485734a1f02247f3c730c1abaf4b919b5d Mon Sep 17 00:00:00 2001 From: Hafiidz <3688500+Hafiidz@users.noreply.github.com> Date: Thu, 20 Jul 2023 12:06:36 +0800 Subject: [PATCH 05/23] Changed spelling linebreak_behaviour to linebreak_behavior --- bevy_proto_backend/src/impls/bevy_impls/text.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bevy_proto_backend/src/impls/bevy_impls/text.rs b/bevy_proto_backend/src/impls/bevy_impls/text.rs index ddd6393..af148c8 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/text.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/text.rs @@ -28,7 +28,7 @@ impl_external_schematic! { pub struct TextInput { pub sections: Vec, pub alignment: TextAlignmentInput, - pub linebreak_behaviour: BreakLineOnInput, + pub linebreak_behavior: BreakLineOnInput, } from_to_input! { Text, @@ -42,7 +42,7 @@ impl_external_schematic! { Self { sections, alignment: input.alignment.into(), - linebreak_behaviour: input.linebreak_behaviour.into(), + linebreak_behavior: input.linebreak_behavior.into(), } } } @@ -52,7 +52,7 @@ impl_external_schematic! { Self { sections: Vec::new(), alignment: base.alignment.into(), - linebreak_behaviour: base.linebreak_behaviour.into(), + linebreak_behavior: base.linebreak_behavior.into(), } } } From 91c68055919901d64325ca6254f096c57cadc985 Mon Sep 17 00:00:00 2001 From: Hafiidz <3688500+Hafiidz@users.noreply.github.com> Date: Thu, 20 Jul 2023 12:08:37 +0800 Subject: [PATCH 06/23] Require #[derive(Event)] on all Events --- bevy_proto_backend/src/proto/event.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bevy_proto_backend/src/proto/event.rs b/bevy_proto_backend/src/proto/event.rs index 1f5bf69..2829afe 100644 --- a/bevy_proto_backend/src/proto/event.rs +++ b/bevy_proto_backend/src/proto/event.rs @@ -1,5 +1,6 @@ use crate::proto::Prototypical; use bevy::asset::Handle; +use bevy::prelude::Event; /// Asset lifecycle events for [prototype] assets. /// @@ -9,7 +10,7 @@ use bevy::asset::Handle; /// /// [prototype]: Prototypical /// [`AssetEvent`]: bevy::asset::AssetEvent -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Event)] pub enum ProtoAssetEvent { /// This event is fired when a prototype has been successfully created, /// registered, and cached. From 17cea8189e1ab3a472195c9d9800cf82da886fd0 Mon Sep 17 00:00:00 2001 From: Hafiidz <3688500+Hafiidz@users.noreply.github.com> Date: Thu, 20 Jul 2023 12:13:59 +0800 Subject: [PATCH 07/23] Allow custom depth texture usage --- bevy_proto_backend/src/impls/bevy_impls/core_pipeline.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bevy_proto_backend/src/impls/bevy_impls/core_pipeline.rs b/bevy_proto_backend/src/impls/bevy_impls/core_pipeline.rs index 7627783..b313dc3 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/core_pipeline.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/core_pipeline.rs @@ -1,7 +1,7 @@ use bevy::app::App; use bevy::core_pipeline::bloom::{BloomCompositeMode, BloomPrefilterSettings, BloomSettings}; use bevy::core_pipeline::clear_color::ClearColorConfig; -use bevy::core_pipeline::core_3d::Camera3dDepthLoadOp; +use bevy::core_pipeline::core_3d::{Camera3dDepthLoadOp, Camera3dDepthTextureUsage}; use bevy::core_pipeline::fxaa::Fxaa; use bevy::core_pipeline::prepass::{DepthPrepass, NormalPrepass}; use bevy::core_pipeline::tonemapping::{DebandDither, Tonemapping}; @@ -115,11 +115,13 @@ impl_external_schematic! { pub struct Camera3dInput { pub clear_color: ClearColorConfigInput, pub depth_load_op: Camera3dDepthLoadOpInput, + pub depth_texture_usages: Camera3dDepthTextureUsage, } from_to_default!( Camera3d, Camera3dInput, |value: Input| Self { + depth_texture_usages: value.depth_texture_usages.into(), clear_color: value.clear_color.into(), depth_load_op: value.depth_load_op.into() } From 1eee06e19be613003b128a95e6e5783395883219 Mon Sep 17 00:00:00 2001 From: Hafiidz <3688500+Hafiidz@users.noreply.github.com> Date: Thu, 20 Jul 2023 12:25:59 +0800 Subject: [PATCH 08/23] Flatten UI Style properties that use Size + remove Size & MeasureFunc improvements Chore: Migration 0.10 to 0.11 1. Flatten UI Style properties that use Size + remove Size 2. MeasureFunc improvements Need second eye especially on line 92 to 111 (pub struct ContentSize .... ) --- bevy_proto_backend/src/impls/bevy_impls/ui.rs | 100 ++++++++++++------ 1 file changed, 69 insertions(+), 31 deletions(-) diff --git a/bevy_proto_backend/src/impls/bevy_impls/ui.rs b/bevy_proto_backend/src/impls/bevy_impls/ui.rs index 49583a7..dfd58cf 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/ui.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/ui.rs @@ -3,9 +3,10 @@ use bevy::math::{Rect, Vec2}; use bevy::prelude::{BackgroundColor, Button, Label}; use bevy::reflect::{std_traits::ReflectDefault, Reflect}; use bevy::ui::{ - AlignContent, AlignItems, AlignSelf, CalculatedClip, Direction, Display, - FlexDirection, FlexWrap, FocusPolicy, Interaction, JustifyContent, Node, Overflow, - PositionType, RelativeCursorPosition, Style, UiImage, UiRect, Val, ZIndex, + AlignContent, AlignItems, AlignSelf, CalculatedClip, ContentSize, Direction, Display, + FlexDirection, FlexWrap, FocusPolicy, GridAutoFlow, GridPlacement, GridTrack, Interaction, + JustifyContent, JustifyItems, JustifySelf, Node, Overflow, PositionType, + RelativeCursorPosition, RepeatedGridTrack, Style, UiImage, UiRect, Val, ZIndex, }; use crate::impls::macros::{from_to, from_to_default, register_schematic}; @@ -18,6 +19,7 @@ pub(super) fn register(app: &mut App) { BackgroundColor, Button, CalculatedClip, + ContentSize, FocusPolicy, Interaction, Label, @@ -38,8 +40,6 @@ pub(super) fn register(app: &mut App) { .register_type::() .register_type::() .register_type::() - .register_type::() - .register_type::() .register_type::() .register_type::(); } @@ -89,6 +89,26 @@ impl_external_schematic! { } } +impl_external_schematic! { + #[schematic(from = ContentSizeInput)] + struct ContentSize {} + // --- + #[derive(Reflect)] + #[reflect(Default)] + pub struct ContentSizeInput { + pub size: Vec2, + pub preserve_aspect_ratio: bool, + } + from_to_default! { + ContentSize, + ContentSizeInput, + |value: Input| Self { + size: value.size, + preserve_aspect_ratio: value.preserve_aspect_ratio, + } + } +} + impl_external_schematic! { #[schematic(from = FocusPolicyInput)] enum FocusPolicy {} @@ -189,6 +209,7 @@ impl_external_schematic! { pub struct StyleInput { pub display: DisplayInput, pub position_type: PositionTypeInput, + pub overflow: OverflowInput, pub direction: DirectionInput, pub flex_direction: FlexDirectionInput, pub flex_wrap: FlexWrapInput, @@ -196,19 +217,34 @@ impl_external_schematic! { pub align_self: AlignSelfInput, pub align_content: AlignContentInput, pub justify_content: JustifyContentInput, - pub position: UiRectInput, + pub justify_self: JustifySelf, + pub justify_items: JustifyItems, pub margin: UiRectInput, pub padding: UiRectInput, pub border: UiRectInput, pub flex_grow: f32, pub flex_shrink: f32, pub flex_basis: ValInput, - pub size: SizeInput, - pub min_size: SizeInput, - pub max_size: SizeInput, pub aspect_ratio: Option, - pub overflow: OverflowInput, - pub gap: SizeInput, + pub left: Val, + pub right: Val, + pub top: Val, + pub bottom: Val, + pub width: Val, + pub min_width: Val, + pub max_width: Val, + pub height: Val, + pub min_height: Val, + pub max_height: Val, + pub row_gap: Val, + pub column_gap: Val, + pub grid_auto_flow: GridAutoFlow, + pub grid_template_rows: Vec, + pub grid_template_columns: Vec, + pub grid_auto_rows: Vec, + pub grid_auto_columns: Vec, + pub grid_row: GridPlacement, + pub grid_column: GridPlacement, } from_to_default! { Style, @@ -216,6 +252,7 @@ impl_external_schematic! { |value: Input| Self { display: value.display.into(), position_type: value.position_type.into(), + overflow: value.overflow.into(), direction: value.direction.into(), flex_direction: value.flex_direction.into(), flex_wrap: value.flex_wrap.into(), @@ -223,19 +260,34 @@ impl_external_schematic! { align_self: value.align_self.into(), align_content: value.align_content.into(), justify_content: value.justify_content.into(), - position: value.position.into(), + justify_self: value.justify_self.into(), + justify_items: value.justify_items.into(), margin: value.margin.into(), padding: value.padding.into(), border: value.border.into(), flex_grow: value.flex_grow, flex_shrink: value.flex_shrink, flex_basis: value.flex_basis.into(), - size: value.size.into(), - min_size: value.min_size.into(), - max_size: value.max_size.into(), aspect_ratio: value.aspect_ratio, - overflow: value.overflow.into(), - gap: value.gap.into(), + left: value.left.into(), + right: value.right.into(), + top: value.top.into(), + bottom: value.bottom.into(), + width: value.width.into(), + min_width: value.min_width.into(), + max_width: value.max_width.into(), + height: value.height.into(), + min_height: value.min_height.into(), + max_height: value.max_height.into(), + row_gap: value.row_gap.into(), + column_gap: value.column_gap.into(), + grid_auto_flow: value.grid_auto_flow.into(), + grid_template_rows: value.grid_template_rows.into(), + grid_template_columns: value.grid_template_columns.into(), + grid_auto_rows: value.grid_auto_rows.into(), + grid_auto_columns: value.grid_auto_columns.into(), + grid_row: value.grid_row.into(), + grid_column: value.grid_column.into(), } } @@ -445,20 +497,6 @@ impl_external_schematic! { } } - #[derive(Reflect)] - #[reflect(Default)] - pub struct SizeInput { - pub width: ValInput, - pub height: ValInput, - } - from_to_default! { - Size, - SizeInput, - |value: Input| Self { - width: value.width.into(), - height: value.height.into(), - } - } #[derive(Reflect)] #[reflect(Default)] From b38efd179e0c772935e5708b28011f8ad2608a8f Mon Sep 17 00:00:00 2001 From: Hafiidz <3688500+Hafiidz@users.noreply.github.com> Date: Mon, 17 Jul 2023 16:58:05 +0800 Subject: [PATCH 09/23] Rename Interaction::Clicked > Interaction::Pressed --- bevy_proto_backend/src/impls/bevy_impls/ui.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bevy_proto_backend/src/impls/bevy_impls/ui.rs b/bevy_proto_backend/src/impls/bevy_impls/ui.rs index dfd58cf..893f933 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/ui.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/ui.rs @@ -136,7 +136,7 @@ impl_external_schematic! { #[derive(Reflect)] #[reflect(Default)] pub enum InteractionInput { - Clicked, + Pressed, Hovered, None, } @@ -144,7 +144,7 @@ impl_external_schematic! { Interaction, InteractionInput, |value: Input| match value { - Input::Clicked => Self::Clicked, + Input::Pressed => Self::Pressed, Input::Hovered => Self::Hovered, Input::None => Self::None, } From 5cae089b1f4fc7ce90f89222a2b58308184c5588 Mon Sep 17 00:00:00 2001 From: Hafiidz <3688500+Hafiidz@users.noreply.github.com> Date: Thu, 20 Jul 2023 13:10:06 +0800 Subject: [PATCH 10/23] Ui Node Borders #7795 https://github.com/bevyengine/bevy/pull/7795 --- bevy_proto_backend/src/impls/bevy_impls/ui.rs | 20 ++++++++++++++++--- src/custom.rs | 3 +++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/bevy_proto_backend/src/impls/bevy_impls/ui.rs b/bevy_proto_backend/src/impls/bevy_impls/ui.rs index 893f933..7369838 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/ui.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/ui.rs @@ -3,9 +3,9 @@ use bevy::math::{Rect, Vec2}; use bevy::prelude::{BackgroundColor, Button, Label}; use bevy::reflect::{std_traits::ReflectDefault, Reflect}; use bevy::ui::{ - AlignContent, AlignItems, AlignSelf, CalculatedClip, ContentSize, Direction, Display, - FlexDirection, FlexWrap, FocusPolicy, GridAutoFlow, GridPlacement, GridTrack, Interaction, - JustifyContent, JustifyItems, JustifySelf, Node, Overflow, PositionType, + AlignContent, AlignItems, AlignSelf, BorderColor, CalculatedClip, ContentSize, Direction, + Display, FlexDirection, FlexWrap, FocusPolicy, GridAutoFlow, GridPlacement, GridTrack, + Interaction, JustifyContent, JustifyItems, JustifySelf, Node, Overflow, PositionType, RelativeCursorPosition, RepeatedGridTrack, Style, UiImage, UiRect, Val, ZIndex, }; @@ -58,6 +58,20 @@ impl_external_schematic! { } } +impl_external_schematic! { + #[schematic(from = BorderColorInput)] + struct BorderColor(); + // --- + #[derive(Reflect)] + #[reflect(Default)] + pub struct BorderColorInput(pub ProtoColor); + from_to_default! { + BorderColor, + BorderColorInput, + |value: Input| Self(value.0.into()) + } +} + impl_external_schematic! { #[schematic(from = ButtonInput)] struct Button; diff --git a/src/custom.rs b/src/custom.rs index ecf290f..48088c8 100644 --- a/src/custom.rs +++ b/src/custom.rs @@ -531,6 +531,8 @@ pub struct ButtonBundle { #[reflect(default)] pub background_color: bevy_impls::ui::BackgroundColorInput, #[reflect(default)] + pub background_color: bevy_impls::ui::BorderColorInput, + #[reflect(default)] pub image: bevy_impls::ui::UiImageInput, #[reflect(default)] pub transform: Transform, @@ -554,6 +556,7 @@ impl FromSchematicInput for bevy::ui::node_bundles::ButtonBundle { interaction: input.interaction.into(), focus_policy: input.focus_policy.into(), background_color: input.background_color.into(), + border_color: input.border_color.into(), image: bevy::ui::UiImage::from_input(input.image, context), transform: input.transform, global_transform: input.global_transform, From 7ef1337882ef04eb2bebb1747324ca1504a3f570 Mon Sep 17 00:00:00 2001 From: Hafiidz <3688500+Hafiidz@users.noreply.github.com> Date: Thu, 20 Jul 2023 13:12:26 +0800 Subject: [PATCH 11/23] typo background_color -> border_color --- src/custom.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/custom.rs b/src/custom.rs index 48088c8..18c75e6 100644 --- a/src/custom.rs +++ b/src/custom.rs @@ -531,7 +531,7 @@ pub struct ButtonBundle { #[reflect(default)] pub background_color: bevy_impls::ui::BackgroundColorInput, #[reflect(default)] - pub background_color: bevy_impls::ui::BorderColorInput, + pub border_color: bevy_impls::ui::BorderColorInput, #[reflect(default)] pub image: bevy_impls::ui::UiImageInput, #[reflect(default)] From 566204eece485b74e1f9e35f8ab391dfec22b22a Mon Sep 17 00:00:00 2001 From: "kaosat.dev" Date: Sat, 22 Jul 2023 22:35:10 +0200 Subject: [PATCH 12/23] fix(ImageBundle): added missing image_size field --- src/custom.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/custom.rs b/src/custom.rs index 18c75e6..3ed598f 100644 --- a/src/custom.rs +++ b/src/custom.rs @@ -9,6 +9,7 @@ use bevy::app::App; use bevy::asset::Handle; use bevy::prelude::{Component, GlobalTransform, Transform}; use bevy::reflect::{std_traits::ReflectDefault, FromReflect, Reflect}; +use bevy::ui::widget::UiImageSize; use bevy_proto_backend::impls::bevy_impls; use bevy_proto_backend::{from, from_to_default, from_to_input}; @@ -597,6 +598,8 @@ pub struct ImageBundle { pub computed_visibility: bevy::render::view::ComputedVisibility, #[reflect(default)] pub z_index: bevy_impls::ui::ZIndexInput, + #[reflect(ignore, default)] + pub image_size: UiImageSize } #[cfg(feature = "bevy_ui")] @@ -614,6 +617,7 @@ impl FromSchematicInput for bevy::ui::node_bundles::ImageBundle { visibility: input.visibility, computed_visibility: input.computed_visibility, z_index: input.z_index.into(), + image_size: UiImageSize::default() // this field is set automatically by Bevy normally } } } From 0becab55b16eb1fdec0a0117463c6536d274f7e8 Mon Sep 17 00:00:00 2001 From: "kaosat.dev" Date: Sat, 22 Jul 2023 22:38:00 +0200 Subject: [PATCH 13/23] chore(from_reflect): removed obsoleted from_reflect imports --- bevy_proto_backend/src/impls/bevy_impls/core.rs | 2 +- bevy_proto_backend/src/impls/bevy_impls/window.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bevy_proto_backend/src/impls/bevy_impls/core.rs b/bevy_proto_backend/src/impls/bevy_impls/core.rs index 2145428..ee18b70 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/core.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/core.rs @@ -1,6 +1,6 @@ use bevy::app::App; use bevy::core::Name; -use bevy::reflect::{FromReflect, Reflect}; +use bevy::reflect::Reflect; use crate::impls::macros::register_schematic; use bevy_proto_derive::impl_external_schematic; diff --git a/bevy_proto_backend/src/impls/bevy_impls/window.rs b/bevy_proto_backend/src/impls/bevy_impls/window.rs index 2c0ffd8..dcd9536 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/window.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/window.rs @@ -1,5 +1,5 @@ use bevy::app::App; -use bevy::reflect::{FromReflect, Reflect}; +use bevy::reflect::Reflect; use bevy::window::{PrimaryWindow, Window}; use crate::impls::macros::register_schematic; From e899c10884ca7e1de07e80c9e2461ec24b7961c8 Mon Sep 17 00:00:00 2001 From: Gino Valente Date: Sat, 22 Jul 2023 16:06:24 -0700 Subject: [PATCH 14/23] Add some more fixes --- .../src/impls/bevy_impls/asset.rs | 7 +- .../src/impls/bevy_impls/pbr.rs | 7 +- .../src/impls/bevy_impls/text.rs | 63 ++++++++- bevy_proto_backend/src/impls/bevy_impls/ui.rs | 61 +++++---- bevy_proto_backend/src/plugin.rs | 4 +- bevy_proto_backend/src/tree/entity_tree.rs | 2 +- bevy_proto_derive/src/schematic/input.rs | 8 +- src/custom.rs | 127 ++++++++---------- src/plugin.rs | 2 +- src/proto/prototype.rs | 4 +- 10 files changed, 161 insertions(+), 124 deletions(-) diff --git a/bevy_proto_backend/src/impls/bevy_impls/asset.rs b/bevy_proto_backend/src/impls/bevy_impls/asset.rs index 349f5ac..f8f241f 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/asset.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/asset.rs @@ -13,12 +13,7 @@ pub(super) fn register(app: &mut App) { register_schematic!(app, Handle); #[cfg(feature = "bevy_audio")] - register_schematic!( - app, - Handle, - Handle, - Handle, - ); + register_schematic!(app, Handle,); #[cfg(feature = "bevy_gltf")] register_schematic!( diff --git a/bevy_proto_backend/src/impls/bevy_impls/pbr.rs b/bevy_proto_backend/src/impls/bevy_impls/pbr.rs index f957dc9..2dc625d 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/pbr.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/pbr.rs @@ -2,7 +2,7 @@ use bevy::app::App; use bevy::math::{UVec3, Vec3}; use bevy::pbr::wireframe::Wireframe; use bevy::pbr::{ - AlphaMode, CascadeShadowConfig, CascadeShadowConfigBuilder, ClusterConfig, ClusterZConfig, + CascadeShadowConfig, CascadeShadowConfigBuilder, ClusterConfig, ClusterZConfig, DirectionalLight, EnvironmentMapLight, FogFalloff, FogSettings, NotShadowCaster, NotShadowReceiver, PointLight, SpotLight, }; @@ -15,7 +15,6 @@ use bevy_proto_derive::impl_external_schematic; pub(super) fn register(app: &mut App) { register_schematic!( app, - AlphaMode, CascadeShadowConfig, ClusterConfig, DirectionalLight, @@ -32,10 +31,6 @@ pub(super) fn register(app: &mut App) { app.register_type::(); } -impl_external_schematic! { - enum AlphaMode {} -} - impl_external_schematic! { #[schematic(from = CascadeShadowConfigInput)] struct CascadeShadowConfig {} diff --git a/bevy_proto_backend/src/impls/bevy_impls/text.rs b/bevy_proto_backend/src/impls/bevy_impls/text.rs index af148c8..17d6dd1 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/text.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/text.rs @@ -1,7 +1,10 @@ use bevy::app::App; use bevy::math::Vec2; use bevy::reflect::{std_traits::ReflectDefault, Reflect}; -use bevy::text::{BreakLineOn, Text, Text2dBounds, TextAlignment, TextSection, TextStyle}; +use bevy::text::{ + BreakLineOn, GlyphAtlasInfo, PositionedGlyph, Text, Text2dBounds, TextAlignment, + TextLayoutInfo, TextSection, TextStyle, +}; use crate::impls::macros::{from_to, from_to_default, from_to_input, register_schematic}; use crate::proto::{ProtoAsset, ProtoColor}; @@ -107,6 +110,7 @@ impl_external_schematic! { pub enum BreakLineOnInput { WordBoundary, AnyCharacter, + NoWrap, } from_to! { BreakLineOn, @@ -114,6 +118,7 @@ impl_external_schematic! { |value: Input| match value { Input::WordBoundary => Self::WordBoundary, Input::AnyCharacter => Self::AnyCharacter, + Input::NoWrap => Self::NoWrap, } } } @@ -135,3 +140,59 @@ impl_external_schematic! { } } } + +#[derive(Reflect, Default)] +#[reflect(Default)] +pub struct TextLayoutInfoInput { + pub glyphs: Vec, + pub size: Vec2, +} + +impl FromSchematicInput for TextLayoutInfo { + fn from_input(input: TextLayoutInfoInput, context: &mut SchematicContext) -> Self { + Self { + glyphs: input + .glyphs + .into_iter() + .map(|glyph| FromSchematicInput::from_input(glyph, context)) + .collect(), + size: input.size, + } + } +} + +#[derive(Reflect)] +pub struct PositionedGlyphInput { + pub position: Vec2, + pub size: Vec2, + pub atlas_info: GlyphAtlasInfoInput, + pub section_index: usize, + pub byte_index: usize, +} + +impl FromSchematicInput for PositionedGlyph { + fn from_input(input: PositionedGlyphInput, context: &mut SchematicContext) -> Self { + Self { + position: input.position, + size: input.size, + atlas_info: FromSchematicInput::from_input(input.atlas_info, context), + section_index: input.section_index, + byte_index: input.byte_index, + } + } +} + +#[derive(Reflect)] +pub struct GlyphAtlasInfoInput { + pub texture_atlas: ProtoAsset, + pub glyph_index: usize, +} + +impl FromSchematicInput for GlyphAtlasInfo { + fn from_input(input: GlyphAtlasInfoInput, context: &mut SchematicContext) -> Self { + Self { + texture_atlas: FromSchematicInput::from_input(input.texture_atlas, context), + glyph_index: input.glyph_index, + } + } +} diff --git a/bevy_proto_backend/src/impls/bevy_impls/ui.rs b/bevy_proto_backend/src/impls/bevy_impls/ui.rs index 7369838..c8e0454 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/ui.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/ui.rs @@ -2,11 +2,12 @@ use bevy::app::App; use bevy::math::{Rect, Vec2}; use bevy::prelude::{BackgroundColor, Button, Label}; use bevy::reflect::{std_traits::ReflectDefault, Reflect}; +use bevy::ui::widget::TextFlags; use bevy::ui::{ AlignContent, AlignItems, AlignSelf, BorderColor, CalculatedClip, ContentSize, Direction, Display, FlexDirection, FlexWrap, FocusPolicy, GridAutoFlow, GridPlacement, GridTrack, - Interaction, JustifyContent, JustifyItems, JustifySelf, Node, Overflow, PositionType, - RelativeCursorPosition, RepeatedGridTrack, Style, UiImage, UiRect, Val, ZIndex, + Interaction, JustifyContent, JustifyItems, JustifySelf, Node, Overflow, OverflowAxis, + PositionType, RelativeCursorPosition, RepeatedGridTrack, Style, UiImage, UiRect, Val, ZIndex, }; use crate::impls::macros::{from_to, from_to_default, register_schematic}; @@ -19,13 +20,13 @@ pub(super) fn register(app: &mut App) { BackgroundColor, Button, CalculatedClip, - ContentSize, FocusPolicy, Interaction, Label, Node, RelativeCursorPosition, Style, + TextFlags, UiImage, ); @@ -104,23 +105,7 @@ impl_external_schematic! { } impl_external_schematic! { - #[schematic(from = ContentSizeInput)] struct ContentSize {} - // --- - #[derive(Reflect)] - #[reflect(Default)] - pub struct ContentSizeInput { - pub size: Vec2, - pub preserve_aspect_ratio: bool, - } - from_to_default! { - ContentSize, - ContentSizeInput, - |value: Input| Self { - size: value.size, - preserve_aspect_ratio: value.preserve_aspect_ratio, - } - } } impl_external_schematic! { @@ -308,6 +293,7 @@ impl_external_schematic! { #[derive(Reflect)] #[reflect(Default)] pub enum AlignContentInput { + Default, Start, End, FlexStart, @@ -322,6 +308,7 @@ impl_external_schematic! { AlignContent, AlignContentInput, |value: Input| match value { + Input::Default => Self::Default, Input::Start => Self::Start, Input::End => Self::End, Input::FlexStart => Self::FlexStart, @@ -337,6 +324,7 @@ impl_external_schematic! { #[derive(Reflect)] #[reflect(Default)] pub enum AlignItemsInput { + Default, Start, End, FlexStart, @@ -349,6 +337,7 @@ impl_external_schematic! { AlignItems, AlignItemsInput, |value: Input| match value { + Input::Default => Self::Default, Input::Start => Self::Start, Input::End => Self::End, Input::FlexStart => Self::FlexStart, @@ -406,15 +395,17 @@ impl_external_schematic! { #[derive(Reflect)] #[reflect(Default)] pub enum DisplayInput { - None, Flex, + Grid, + None, } from_to_default! { Display, DisplayInput, |value: Input| match value { - Input::None => Self::None, Input::Flex => Self::Flex, + Input::Grid => Self::Grid, + Input::None => Self::None, } } @@ -457,6 +448,7 @@ impl_external_schematic! { #[derive(Reflect)] #[reflect(Default)] pub enum JustifyContentInput { + Default, Start, End, FlexStart, @@ -470,6 +462,7 @@ impl_external_schematic! { JustifyContent, JustifyContentInput, |value: Input| match value { + Input::Default => Self::Default, Input::Start => Self::Start, Input::End => Self::End, Input::FlexStart => Self::FlexStart, @@ -483,16 +476,16 @@ impl_external_schematic! { #[derive(Reflect)] #[reflect(Default)] - pub enum OverflowInput { - Visible, - Hidden, + pub struct OverflowInput { + pub x: OverflowAxis, + pub y: OverflowAxis, } from_to_default! { Overflow, OverflowInput, - |value: Input| match value { - Input::Visible => Self::Visible, - Input::Hidden => Self::Hidden, + |value: Input| Self { + x: value.x.into(), + y: value.y.into(), } } @@ -534,23 +527,33 @@ impl_external_schematic! { #[derive(Reflect)] #[reflect(Default)] pub enum ValInput { - Undefined, Auto, Px(f32), Percent(f32), + Vw(f32), + Vh(f32), + VMin(f32), + VMax(f32), } from_to_default! { Val, ValInput, |value: Input| match value { - Input::Undefined => Self::Undefined, Input::Auto => Self::Auto, Input::Px(value) => Self::Px(value), Input::Percent(value) => Self::Percent(value), + Input::Vw(value) => Self::Vw(value), + Input::Vh(value) => Self::Vh(value), + Input::VMin(value) => Self::VMin(value), + Input::VMax(value) => Self::VMax(value), } } } +impl_external_schematic! { + pub struct TextFlags {} +} + impl_external_schematic! { #[schematic(input(vis = pub))] pub struct UiImage { diff --git a/bevy_proto_backend/src/plugin.rs b/bevy_proto_backend/src/plugin.rs index 2772d1d..3f5a415 100644 --- a/bevy_proto_backend/src/plugin.rs +++ b/bevy_proto_backend/src/plugin.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use bevy::app::{App, Plugin}; use bevy::asset::AddAsset; -use bevy::prelude::FromWorld; +use bevy::prelude::{FromWorld, Update}; use parking_lot::Mutex; use crate::impls; @@ -79,7 +79,7 @@ impl, C: Config> Plugin for ProtoBackendPlugin< app.add_event::>(); // === Systems === // - app.add_system(on_proto_asset_event::); + app.add_systems(Update, on_proto_asset_event::); } } diff --git a/bevy_proto_backend/src/tree/entity_tree.rs b/bevy_proto_backend/src/tree/entity_tree.rs index 2b54ef2..faf5675 100644 --- a/bevy_proto_backend/src/tree/entity_tree.rs +++ b/bevy_proto_backend/src/tree/entity_tree.rs @@ -199,7 +199,7 @@ impl<'a> EntityTree<'a> { let entity = world.spawn(instance).id(); if let Some(parent) = parent { - Command::write( + Command::apply( AddChild { parent, child: entity, diff --git a/bevy_proto_derive/src/schematic/input.rs b/bevy_proto_derive/src/schematic/input.rs index 63093a2..823800b 100644 --- a/bevy_proto_derive/src/schematic/input.rs +++ b/bevy_proto_derive/src/schematic/input.rs @@ -145,7 +145,7 @@ impl<'a> ToTokens for Input<'a> { let from_impl = make_from_impl(quote!(Self)); tokens.extend(quote! { - #[derive(#bevy_crate::prelude::Reflect, #bevy_crate::prelude::FromReflect)] + #[derive(#bevy_crate::prelude::Reflect)] #vis struct #input_ty_def #where_clause; #from_impl @@ -168,7 +168,7 @@ impl<'a> ToTokens for Input<'a> { }); tokens.extend(quote! { - #[derive(#bevy_crate::prelude::Reflect, #bevy_crate::prelude::FromReflect)] + #[derive(#bevy_crate::prelude::Reflect)] #vis struct #input_ty_def ( #(#filtered,)* #phantom_ty @@ -196,7 +196,7 @@ impl<'a> ToTokens for Input<'a> { }); tokens.extend(quote! { - #[derive(#bevy_crate::prelude::Reflect, #bevy_crate::prelude::FromReflect)] + #[derive(#bevy_crate::prelude::Reflect)] #vis struct #input_ty_def #where_clause { #(#filtered,)* #phantom_ty @@ -224,7 +224,7 @@ impl<'a> ToTokens for Input<'a> { }); tokens.extend(quote! { - #[derive(#bevy_crate::prelude::Reflect, #bevy_crate::prelude::FromReflect)] + #[derive(#bevy_crate::prelude::Reflect)] #vis enum #input_ty_def #where_clause { #(#variants,)* #phantom_ty diff --git a/src/custom.rs b/src/custom.rs index 3ed598f..e298f5f 100644 --- a/src/custom.rs +++ b/src/custom.rs @@ -49,7 +49,7 @@ pub(crate) fn register_custom_schematics(app: &mut App) { /// A [`Schematic`] implementation of [`TransformBundle`]. /// /// [`TransformBundle`]: bevy::prelude::TransformBundle -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic, Default)] #[schematic(into = bevy::prelude::TransformBundle)] pub struct TransformBundle { @@ -70,7 +70,7 @@ from_to_default! { /// /// [`SpatialBundle`]: bevy::prelude::SpatialBundle #[cfg(feature = "bevy_render")] -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic, Default)] #[schematic(into = bevy::render::prelude::SpatialBundle)] pub struct SpatialBundle { @@ -97,7 +97,7 @@ from_to_default! { /// /// [`VisibilityBundle`]: bevy::prelude::VisibilityBundle #[cfg(feature = "bevy_render")] -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic, Default)] #[schematic(into = bevy::prelude::VisibilityBundle)] pub struct VisibilityBundle { @@ -192,7 +192,7 @@ from!( /// /// [`Camera2dBundle`]: bevy::core_pipeline::core_2d::Camera2dBundle #[cfg(feature = "bevy_core_pipeline")] -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic, Default)] #[schematic(into = bevy::prelude::Camera2dBundle)] pub struct Camera2dBundle { @@ -232,7 +232,7 @@ from_to_default! { /// /// [`Camera3dBundle`]: bevy::core_pipeline::core_3d::Camera3dBundle #[cfg(feature = "bevy_core_pipeline")] -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic, Default)] #[schematic(into = bevy::prelude::Camera3dBundle)] pub struct Camera3dBundle { @@ -274,7 +274,7 @@ from_to_default! { /// /// [`DirectionalLightBundle`]: bevy::pbr::DirectionalLightBundle #[cfg(feature = "bevy_pbr")] -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic, Default)] #[schematic(into = bevy::pbr::DirectionalLightBundle)] pub struct DirectionalLightBundle { @@ -332,7 +332,7 @@ impl Default for DirectionalLightBundle { /// /// [`PointLightBundle`]: bevy::pbr::PointLightBundle #[cfg(feature = "bevy_pbr")] -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic, Default)] #[schematic(into = bevy::pbr::PointLightBundle)] pub struct PointLightBundle { @@ -367,7 +367,7 @@ from_to_default!( /// /// [`SpotLightBundle`]: bevy::pbr::SpotLightBundle #[cfg(feature = "bevy_pbr")] -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic, Default)] #[schematic(into = bevy::pbr::SpotLightBundle)] pub struct SpotLightBundle { @@ -464,49 +464,40 @@ from!(bevy::scene::SceneBundle, SceneBundle, |value: Input| Self { /// /// [`Text2dBundle`]: bevy::text::Text2dBundle #[cfg(feature = "bevy_text")] -#[derive(Component, Schematic, Reflect, FromReflect)] -#[reflect(Schematic, Default)] +#[derive(Component, Schematic, Reflect)] +#[reflect(Schematic)] #[schematic(into = bevy::text::Text2dBundle)] pub struct Text2dBundle { + #[reflect(default)] pub text: bevy_impls::text::TextInput, + #[reflect(default)] pub text_anchor: bevy::sprite::Anchor, + #[reflect(default)] pub text_2d_bounds: bevy_impls::text::Text2dBoundsInput, + #[reflect(default)] pub transform: Transform, + #[reflect(default)] pub global_transform: GlobalTransform, + #[reflect(default)] pub visibility: bevy::render::view::Visibility, #[reflect(ignore)] pub computed_visibility: bevy::render::view::ComputedVisibility, + #[reflect(default)] + pub text_layout_info: bevy_impls::text::TextLayoutInfoInput, } #[cfg(feature = "bevy_text")] -from_to_input!( - bevy::text::Text2dBundle, - Text2dBundle, - |input: Input, context| { +impl FromSchematicInput for bevy::text::Text2dBundle { + fn from_input(input: Text2dBundle, context: &mut SchematicContext) -> Self { Self { text: FromSchematicInput::from_input(input.text, context), text_anchor: input.text_anchor, - text_2d_bounds: input.text_2d_bounds.into(), + text_2d_bounds: FromSchematicInput::from_input(input.text_2d_bounds, context), transform: input.transform, global_transform: input.global_transform, visibility: input.visibility, computed_visibility: input.computed_visibility, - } - } -); - -#[cfg(feature = "bevy_text")] -impl Default for Text2dBundle { - fn default() -> Self { - let base = bevy::text::Text2dBundle::default(); - Self { - text: Default::default(), - text_anchor: base.text_anchor, - text_2d_bounds: base.text_2d_bounds.into(), - transform: base.transform, - global_transform: base.global_transform, - visibility: base.visibility, - computed_visibility: base.computed_visibility, + text_layout_info: FromSchematicInput::from_input(input.text_layout_info, context), } } } @@ -515,7 +506,7 @@ impl Default for Text2dBundle { /// /// [`ButtonBundle`]: bevy::ui::node_bundles::ButtonBundle #[cfg(feature = "bevy_ui")] -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic)] #[schematic(into = bevy::ui::node_bundles::ButtonBundle)] pub struct ButtonBundle { @@ -572,7 +563,7 @@ impl FromSchematicInput for bevy::ui::node_bundles::ButtonBundle { /// /// [`ImageBundle`]: bevy::ui::node_bundles::ImageBundle #[cfg(feature = "bevy_ui")] -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic)] #[schematic(into = bevy::ui::node_bundles::ImageBundle)] pub struct ImageBundle { @@ -581,8 +572,6 @@ pub struct ImageBundle { #[reflect(default)] pub style: bevy_impls::ui::StyleInput, #[reflect(default)] - pub calculated_size: bevy_impls::ui::CalculatedSizeInput, - #[reflect(default)] pub background_color: bevy_impls::ui::BackgroundColorInput, #[reflect(default)] pub image: bevy_impls::ui::UiImageInput, @@ -599,7 +588,7 @@ pub struct ImageBundle { #[reflect(default)] pub z_index: bevy_impls::ui::ZIndexInput, #[reflect(ignore, default)] - pub image_size: UiImageSize + pub image_size: UiImageSize, } #[cfg(feature = "bevy_ui")] @@ -608,7 +597,7 @@ impl FromSchematicInput for bevy::ui::node_bundles::ImageBundle { Self { node: input.node.into(), style: input.style.into(), - calculated_size: input.calculated_size.into(), + calculated_size: Default::default(), background_color: input.background_color.into(), image: bevy::ui::UiImage::from_input(input.image, context), focus_policy: input.focus_policy.into(), @@ -617,7 +606,7 @@ impl FromSchematicInput for bevy::ui::node_bundles::ImageBundle { visibility: input.visibility, computed_visibility: input.computed_visibility, z_index: input.z_index.into(), - image_size: UiImageSize::default() // this field is set automatically by Bevy normally + image_size: UiImageSize::default(), // this field is set automatically by Bevy normally } } } @@ -626,7 +615,7 @@ impl FromSchematicInput for bevy::ui::node_bundles::ImageBundle { /// /// [`NodeBundle`]: bevy::ui::node_bundles::NodeBundle #[cfg(feature = "bevy_ui")] -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic, Default)] #[schematic(into = bevy::ui::node_bundles::NodeBundle)] pub struct NodeBundle { @@ -663,61 +652,55 @@ from_to_default!( /// /// [`TextBundle`]: bevy::ui::node_bundles::TextBundle #[cfg(feature = "bevy_ui")] -#[derive(Component, Schematic, Reflect, FromReflect)] -#[reflect(Schematic, Default)] +#[derive(Component, Schematic, Reflect)] +#[reflect(Schematic)] #[schematic(into = bevy::ui::node_bundles::TextBundle)] pub struct TextBundle { + #[reflect(default)] pub node: bevy_impls::ui::NodeInput, + #[reflect(default)] pub style: bevy_impls::ui::StyleInput, + #[reflect(default)] pub text: bevy_impls::text::TextInput, - pub calculated_size: bevy_impls::ui::CalculatedSizeInput, + #[reflect(default)] + pub text_layout_info: bevy_impls::text::TextLayoutInfoInput, + #[reflect(default)] + pub text_flags: bevy::ui::widget::TextFlags, + #[reflect(ignore)] + pub calculated_size: bevy::ui::ContentSize, + #[reflect(default)] pub focus_policy: bevy_impls::ui::FocusPolicyInput, + #[reflect(default)] pub transform: Transform, + #[reflect(default)] pub global_transform: GlobalTransform, + #[reflect(default)] pub visibility: bevy::render::view::Visibility, #[reflect(ignore)] pub computed_visibility: bevy::render::view::ComputedVisibility, + #[reflect(default)] pub z_index: bevy_impls::ui::ZIndexInput, + #[reflect(default)] pub background_color: bevy_impls::ui::BackgroundColorInput, } #[cfg(feature = "bevy_ui")] -from_to_input!( - bevy::ui::node_bundles::TextBundle, - TextBundle, - |input: Input, context| { +impl FromSchematicInput for bevy::ui::node_bundles::TextBundle { + fn from_input(input: TextBundle, context: &mut SchematicContext) -> Self { Self { - node: input.node.into(), - style: input.style.into(), + node: FromSchematicInput::from_input(input.node, context), + style: FromSchematicInput::from_input(input.style, context), text: FromSchematicInput::from_input(input.text, context), - calculated_size: input.calculated_size.into(), - focus_policy: input.focus_policy.into(), + text_layout_info: FromSchematicInput::from_input(input.text_layout_info, context), + text_flags: input.text_flags, + calculated_size: input.calculated_size, + focus_policy: FromSchematicInput::from_input(input.focus_policy, context), transform: input.transform, global_transform: input.global_transform, visibility: input.visibility, computed_visibility: input.computed_visibility, - z_index: input.z_index.into(), - background_color: input.background_color.into(), - } - } -); - -#[cfg(feature = "bevy_ui")] -impl Default for TextBundle { - fn default() -> Self { - let base = bevy::ui::node_bundles::TextBundle::default(); - Self { - node: base.node.into(), - style: base.style.into(), - text: Default::default(), - calculated_size: base.calculated_size.into(), - focus_policy: base.focus_policy.into(), - transform: base.transform, - global_transform: base.global_transform, - visibility: base.visibility, - computed_visibility: base.computed_visibility, - z_index: base.z_index.into(), - background_color: base.background_color.into(), + z_index: FromSchematicInput::from_input(input.z_index, context), + background_color: FromSchematicInput::from_input(input.background_color, context), } } } diff --git a/src/plugin.rs b/src/plugin.rs index fa81ca9..dd5815d 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -100,7 +100,7 @@ impl, C: Config> Plugin for ProtoPlugin { plugin = plugin.with_loader(loader); } - app.add_plugin(plugin); + app.add_plugins(plugin); #[cfg(feature = "custom_schematics")] crate::custom::register_custom_schematics(app); diff --git a/src/proto/prototype.rs b/src/proto/prototype.rs index 2c6acc8..ef6bc50 100644 --- a/src/proto/prototype.rs +++ b/src/proto/prototype.rs @@ -1,5 +1,5 @@ use crate::proto::ProtoChild; -use bevy::reflect::TypeUuid; +use bevy::reflect::{TypePath, TypeUuid}; use bevy_proto_backend::children::Children; use bevy_proto_backend::deps::Dependencies; use bevy_proto_backend::path::ProtoPath; @@ -8,7 +8,7 @@ use bevy_proto_backend::schematics::Schematics; use bevy_proto_backend::templates::Templates; /// The core asset type used to create easily-configurable entity trees. -#[derive(Debug, TypeUuid)] +#[derive(Debug, TypeUuid, TypePath)] #[uuid = "cbc85a87-723a-4e61-83c7-26e96e54fe9f"] pub struct Prototype { pub(crate) id: String, From 403dfec35a30925e4de0c3f4e8149a547967067f Mon Sep 17 00:00:00 2001 From: Gino Valente Date: Thu, 27 Jul 2023 20:00:21 -0700 Subject: [PATCH 15/23] Fix generics causing compile error --- bevy_proto_derive/src/schematic/input.rs | 6 ++--- src/custom.rs | 33 ++++++++++++------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/bevy_proto_derive/src/schematic/input.rs b/bevy_proto_derive/src/schematic/input.rs index 823800b..2694b92 100644 --- a/bevy_proto_derive/src/schematic/input.rs +++ b/bevy_proto_derive/src/schematic/input.rs @@ -162,7 +162,7 @@ impl<'a> ToTokens for Input<'a> { let phantom_ty = phantom_ty.map(|phantom_ty| { quote! { - #[reflect(ignore, default)] + #[reflect(ignore)] #phantom_ty } }); @@ -190,7 +190,7 @@ impl<'a> ToTokens for Input<'a> { let phantom_ty = phantom_ty.map(|phantom_ty| { quote! { - #[reflect(ignore, default)] + #[reflect(ignore)] __phantom_ty__: #phantom_ty } }); @@ -219,7 +219,7 @@ impl<'a> ToTokens for Input<'a> { let phantom_ty = phantom_ty.map(|phantom_ty| { quote! { - _Phantom(#[reflect(ignore, default)] #phantom_ty) + _Phantom(#[reflect(ignore)] #phantom_ty) } }); diff --git a/src/custom.rs b/src/custom.rs index e298f5f..db01323 100644 --- a/src/custom.rs +++ b/src/custom.rs @@ -8,10 +8,10 @@ use bevy::app::App; use bevy::asset::Handle; use bevy::prelude::{Component, GlobalTransform, Transform}; -use bevy::reflect::{std_traits::ReflectDefault, FromReflect, Reflect}; +use bevy::reflect::{std_traits::ReflectDefault, Reflect}; use bevy::ui::widget::UiImageSize; use bevy_proto_backend::impls::bevy_impls; -use bevy_proto_backend::{from, from_to_default, from_to_input}; +use bevy_proto_backend::{from, from_to_default}; use bevy_proto_backend::schematics::{ FromSchematicInput, ReflectSchematic, Schematic, SchematicContext, @@ -134,7 +134,7 @@ pub struct SpriteBundle { pub texture: Handle, #[reflect(default)] pub visibility: bevy::render::view::Visibility, - #[reflect(ignore, default)] + #[reflect(ignore)] pub computed_visibility: bevy::render::view::ComputedVisibility, } @@ -168,7 +168,7 @@ pub struct SpriteSheetBundle { pub global_transform: GlobalTransform, #[reflect(default)] pub visibility: bevy::render::view::Visibility, - #[reflect(ignore, default)] + #[reflect(ignore)] pub computed_visibility: bevy::render::view::ComputedVisibility, } @@ -414,7 +414,7 @@ pub struct DynamicSceneBundle { pub global_transform: GlobalTransform, #[reflect(default)] pub visibility: bevy::render::view::Visibility, - #[reflect(ignore, default)] + #[reflect(ignore)] pub computed_visibility: bevy::render::view::ComputedVisibility, } @@ -447,7 +447,7 @@ pub struct SceneBundle { pub global_transform: GlobalTransform, #[reflect(default)] pub visibility: bevy::render::view::Visibility, - #[reflect(ignore, default)] + #[reflect(ignore)] pub computed_visibility: bevy::render::view::ComputedVisibility, } @@ -532,7 +532,7 @@ pub struct ButtonBundle { pub global_transform: GlobalTransform, #[reflect(default)] pub visibility: bevy::render::view::Visibility, - #[reflect(ignore, default)] + #[reflect(ignore)] pub computed_visibility: bevy::render::view::ComputedVisibility, #[reflect(default)] pub z_index: bevy_impls::ui::ZIndexInput, @@ -583,11 +583,11 @@ pub struct ImageBundle { pub global_transform: GlobalTransform, #[reflect(default)] pub visibility: bevy::render::view::Visibility, - #[reflect(ignore, default)] + #[reflect(ignore)] pub computed_visibility: bevy::render::view::ComputedVisibility, #[reflect(default)] pub z_index: bevy_impls::ui::ZIndexInput, - #[reflect(ignore, default)] + #[reflect(ignore)] pub image_size: UiImageSize, } @@ -622,6 +622,7 @@ pub struct NodeBundle { pub node: bevy_impls::ui::NodeInput, pub style: bevy_impls::ui::StyleInput, pub background_color: bevy_impls::ui::BackgroundColorInput, + pub border_color: bevy::ui::BorderColor, pub focus_policy: bevy_impls::ui::FocusPolicyInput, pub transform: Transform, pub global_transform: GlobalTransform, @@ -639,6 +640,7 @@ from_to_default!( node: value.node.into(), style: value.style.into(), background_color: value.background_color.into(), + border_color: value.border_color, focus_policy: value.focus_policy.into(), transform: value.transform, global_transform: value.global_transform, @@ -714,12 +716,12 @@ impl FromSchematicInput for bevy::ui::node_bundles::TextBundle { #[reflect(Schematic)] #[schematic(into = bevy::pbr::MaterialMeshBundle)] pub struct MaterialMeshBundle { - #[reflect( - default = "bevy_proto_backend::proto::ProtoAsset::default_handle_id::" - )] + // #[reflect( + // default = "bevy_proto_backend::proto::ProtoAsset::default_handle_id::" + // )] #[schematic(asset(lazy))] pub mesh: Handle, - #[reflect(default = "bevy_proto_backend::proto::ProtoAsset::default_handle_id::")] + // #[reflect(default = "bevy_proto_backend::proto::ProtoAsset::default_handle_id::")] #[schematic(asset(lazy))] pub material: Handle, #[reflect(default)] @@ -728,7 +730,7 @@ pub struct MaterialMeshBundle { pub global_transform: GlobalTransform, #[reflect(default)] pub visibility: bevy::render::view::Visibility, - #[reflect(ignore, default)] + #[reflect(ignore)] pub computed_visibility: bevy::render::view::ComputedVisibility, } @@ -757,7 +759,6 @@ impl From> for bevy::pbr::Material pub struct MaterialMesh2dBundle { #[reflect(default)] pub mesh: bevy_impls::sprite::Mesh2dHandleInput, - #[reflect(default = "bevy_proto_backend::proto::ProtoAsset::default_handle_id::")] #[schematic(asset(lazy))] pub material: Handle, #[reflect(default)] @@ -766,7 +767,7 @@ pub struct MaterialMesh2dBundle { pub global_transform: GlobalTransform, #[reflect(default)] pub visibility: bevy::render::view::Visibility, - #[reflect(ignore, default)] + #[reflect(ignore)] pub computed_visibility: bevy::render::view::ComputedVisibility, } From 759061dff1b3eec00da5437baefbc9e860178d7c Mon Sep 17 00:00:00 2001 From: Gino Valente Date: Thu, 27 Jul 2023 20:45:27 -0700 Subject: [PATCH 16/23] Update examples --- assets/examples/bevy/ui/Blue.prototype.ron | 19 +++--- assets/examples/bevy/ui/Left.prototype.ron | 10 +--- assets/examples/bevy/ui/Red.prototype.ron | 60 +++++++------------ assets/examples/bevy/ui/Right.prototype.ron | 12 ++-- assets/examples/bevy/ui/Root.prototype.ron | 6 +- .../examples/bevy/ui/Scrollbox.prototype.ron | 17 +++--- .../src/impls/bevy_impls/core_pipeline.rs | 2 +- bevy_proto_backend/src/impls/bevy_impls/ui.rs | 47 ++++++++------- bevy_proto_backend/src/load/asset_loader.rs | 2 +- bevy_proto_backend/src/proto/color.rs | 4 +- .../src/schematics/schematic.rs | 2 +- examples/basic_schematic.rs | 27 ++++----- examples/bevy/ui.rs | 25 +++++--- examples/custom_config.rs | 28 +++++---- examples/custom_loader.rs | 19 +++--- examples/custom_schematic.rs | 14 +++-- examples/cycles.rs | 17 +++--- examples/derive_schematic.rs | 59 +++++++++++------- examples/hierarchy.rs | 49 ++++++++------- examples/hot_reload.rs | 21 ++++--- examples/loading.rs | 13 ++-- examples/templates.rs | 20 ++++--- src/custom.rs | 11 +++- src/schematics.rs | 4 +- 24 files changed, 251 insertions(+), 237 deletions(-) diff --git a/assets/examples/bevy/ui/Blue.prototype.ron b/assets/examples/bevy/ui/Blue.prototype.ron index 0e3d2a9..a2ab8f1 100644 --- a/assets/examples/bevy/ui/Blue.prototype.ron +++ b/assets/examples/bevy/ui/Blue.prototype.ron @@ -3,15 +3,11 @@ schematics: { "bevy_proto::custom::NodeBundle": ( style: ( - size: ( - width: Px(200.0), - height: Px(200.0), - ), + width: Px(200.0), + height: Px(200.0), position_type: Absolute, - position: ( - left: Px(210.0), - bottom: Px(10.0), - ), + left: Px(210.0), + bottom: Px(10.0), border: ( left: Px(20.0), right: Px(20.0), @@ -19,6 +15,7 @@ bottom: Px(20.0), ), ), + border_color: (Green), background_color: (Rgba( red: 0.4, green: 0.4, @@ -33,10 +30,8 @@ schematics: { "bevy_proto::custom::NodeBundle": ( style: ( - size: ( - width: Percent(100.0), - height: Percent(100.0), - ), + width: Percent(100.0), + height: Percent(100.0), ), background_color: (Rgba( red: 0.8, diff --git a/assets/examples/bevy/ui/Left.prototype.ron b/assets/examples/bevy/ui/Left.prototype.ron index 55ea2f5..81a89bf 100644 --- a/assets/examples/bevy/ui/Left.prototype.ron +++ b/assets/examples/bevy/ui/Left.prototype.ron @@ -3,10 +3,7 @@ schematics: { "bevy_proto::custom::NodeBundle": ( style: ( - size: ( - width: Px(200.0), - height: Auto, - ), + width: Px(200.0), border: ( left: Px(2.0), right: Px(2.0), @@ -28,10 +25,7 @@ schematics: { "bevy_proto::custom::NodeBundle": ( style: ( - size: ( - width: Percent(100.0), - height: Auto, - ), + width: Percent(100.0), ), background_color: (Rgba( red: 0.15, diff --git a/assets/examples/bevy/ui/Red.prototype.ron b/assets/examples/bevy/ui/Red.prototype.ron index ae1e5a2..b726e3a 100644 --- a/assets/examples/bevy/ui/Red.prototype.ron +++ b/assets/examples/bevy/ui/Red.prototype.ron @@ -3,10 +3,8 @@ schematics: { "bevy_proto::custom::NodeBundle": ( style: ( - size: ( - width: Percent(100.0), - height: Percent(100.0), - ), + width: Percent(100.0), + height: Percent(100.0), position_type: Absolute, align_items: Center, justify_content: Center, @@ -19,10 +17,8 @@ schematics: { "bevy_proto::custom::NodeBundle": ( style: ( - size: ( - width: Px(100.0), - height: Px(100.0), - ), + width: Px(100.0), + height: Px(100.0), ), background_color: (Red), ) @@ -34,15 +30,11 @@ schematics: { "bevy_proto::custom::NodeBundle": ( style: ( - size: ( - width: Percent(100.0), - height: Percent(100.0), - ), + width: Percent(100.0), + height: Percent(100.0), position_type: Absolute, - position: ( - left: Px(20.0), - bottom: Px(20.0), - ), + left: Px(20.0), + bottom: Px(20.0), ), background_color: (Rgba( red: 1.0, @@ -60,15 +52,11 @@ schematics: { "bevy_proto::custom::NodeBundle": ( style: ( - size: ( - width: Percent(100.0), - height: Percent(100.0), - ), + width: Percent(100.0), + height: Percent(100.0), position_type: Absolute, - position: ( - left: Px(40.0), - bottom: Px(40.0), - ), + left: Px(40.0), + bottom: Px(40.0), ), background_color: (Rgba( red: 1.0, @@ -86,15 +74,11 @@ schematics: { "bevy_proto::custom::NodeBundle": ( style: ( - size: ( - width: Percent(100.0), - height: Percent(100.0), - ), + width: Percent(100.0), + height: Percent(100.0), position_type: Absolute, - position: ( - left: Px(60.0), - bottom: Px(60.0), - ), + left: Px(60.0), + bottom: Px(60.0), ), background_color: (Rgba( red: 1.0, @@ -112,15 +96,11 @@ schematics: { "bevy_proto::custom::NodeBundle": ( style: ( - size: ( - width: Percent(100.0), - height: Percent(100.0), - ), + width: Percent(100.0), + height: Percent(100.0), position_type: Absolute, - position: ( - left: Px(80.0), - bottom: Px(80.0), - ), + left: Px(80.0), + bottom: Px(80.0), ), background_color: (Rgba( red: 1.0, diff --git a/assets/examples/bevy/ui/Right.prototype.ron b/assets/examples/bevy/ui/Right.prototype.ron index 4413b40..d5c15e4 100644 --- a/assets/examples/bevy/ui/Right.prototype.ron +++ b/assets/examples/bevy/ui/Right.prototype.ron @@ -6,10 +6,8 @@ flex_direction: Column, justify_content: Center, align_items: Center, - size: ( - width: Px(200.0), - height: Auto, - ), + width: Px(200.0), + height: Auto, ), background_color: (Rgba( red: 0.15, @@ -35,10 +33,8 @@ )] ), style: ( - size: ( - width: Auto, - height: Px(25.0), - ) + width: Auto, + height: Px(25.0), ), ), "bevy_ui::widget::label::Label": () diff --git a/assets/examples/bevy/ui/Root.prototype.ron b/assets/examples/bevy/ui/Root.prototype.ron index 3991597..461e937 100644 --- a/assets/examples/bevy/ui/Root.prototype.ron +++ b/assets/examples/bevy/ui/Root.prototype.ron @@ -3,10 +3,8 @@ schematics: { "bevy_proto::custom::NodeBundle": ( style: ( - size: ( - width: Percent(100.0), - height: Percent(100.0), - ), + width: Percent(100.0), + height: Percent(100.0), justify_content: SpaceBetween, ) ) diff --git a/assets/examples/bevy/ui/Scrollbox.prototype.ron b/assets/examples/bevy/ui/Scrollbox.prototype.ron index 5f8c9e4..bde9ef8 100644 --- a/assets/examples/bevy/ui/Scrollbox.prototype.ron +++ b/assets/examples/bevy/ui/Scrollbox.prototype.ron @@ -5,11 +5,12 @@ style: ( flex_direction: Column, align_self: Stretch, - size: ( - width: Auto, - height: Percent(50.0), - ), - overflow: Hidden + width: Auto, + height: Percent(50.0), + overflow: ( + x: Clip, + y: Clip, + ) ), background_color: (Rgba( red: 0.10, @@ -26,10 +27,8 @@ "bevy_proto::custom::NodeBundle": ( style: ( flex_direction: Column, - max_size: ( - width: Undefined, - height: Undefined, - ), + max_width: Auto, + max_height: Auto, align_items: Center, ), ), diff --git a/bevy_proto_backend/src/impls/bevy_impls/core_pipeline.rs b/bevy_proto_backend/src/impls/bevy_impls/core_pipeline.rs index b313dc3..35b1201 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/core_pipeline.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/core_pipeline.rs @@ -121,7 +121,7 @@ impl_external_schematic! { Camera3d, Camera3dInput, |value: Input| Self { - depth_texture_usages: value.depth_texture_usages.into(), + depth_texture_usages: value.depth_texture_usages, clear_color: value.clear_color.into(), depth_load_op: value.depth_load_op.into() } diff --git a/bevy_proto_backend/src/impls/bevy_impls/ui.rs b/bevy_proto_backend/src/impls/bevy_impls/ui.rs index c8e0454..23a0b3c 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/ui.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/ui.rs @@ -34,6 +34,7 @@ pub(super) fn register(app: &mut App) { app.register_type::() .register_type::() .register_type::() + .register_type::() .register_type::() .register_type::() .register_type::() @@ -259,8 +260,8 @@ impl_external_schematic! { align_self: value.align_self.into(), align_content: value.align_content.into(), justify_content: value.justify_content.into(), - justify_self: value.justify_self.into(), - justify_items: value.justify_items.into(), + justify_self: value.justify_self, + justify_items: value.justify_items, margin: value.margin.into(), padding: value.padding.into(), border: value.border.into(), @@ -268,25 +269,25 @@ impl_external_schematic! { flex_shrink: value.flex_shrink, flex_basis: value.flex_basis.into(), aspect_ratio: value.aspect_ratio, - left: value.left.into(), - right: value.right.into(), - top: value.top.into(), - bottom: value.bottom.into(), - width: value.width.into(), - min_width: value.min_width.into(), - max_width: value.max_width.into(), - height: value.height.into(), - min_height: value.min_height.into(), - max_height: value.max_height.into(), - row_gap: value.row_gap.into(), - column_gap: value.column_gap.into(), - grid_auto_flow: value.grid_auto_flow.into(), - grid_template_rows: value.grid_template_rows.into(), - grid_template_columns: value.grid_template_columns.into(), - grid_auto_rows: value.grid_auto_rows.into(), - grid_auto_columns: value.grid_auto_columns.into(), - grid_row: value.grid_row.into(), - grid_column: value.grid_column.into(), + left: value.left, + right: value.right, + top: value.top, + bottom: value.bottom, + width: value.width, + min_width: value.min_width, + max_width: value.max_width, + height: value.height, + min_height: value.min_height, + max_height: value.max_height, + row_gap: value.row_gap, + column_gap: value.column_gap, + grid_auto_flow: value.grid_auto_flow, + grid_template_rows: value.grid_template_rows, + grid_template_columns: value.grid_template_columns, + grid_auto_rows: value.grid_auto_rows, + grid_auto_columns: value.grid_auto_columns, + grid_row: value.grid_row, + grid_column: value.grid_column, } } @@ -484,8 +485,8 @@ impl_external_schematic! { Overflow, OverflowInput, |value: Input| Self { - x: value.x.into(), - y: value.y.into(), + x: value.x, + y: value.y, } } diff --git a/bevy_proto_backend/src/load/asset_loader.rs b/bevy_proto_backend/src/load/asset_loader.rs index 717de01..3ade55d 100644 --- a/bevy_proto_backend/src/load/asset_loader.rs +++ b/bevy_proto_backend/src/load/asset_loader.rs @@ -1,8 +1,8 @@ use std::marker::PhantomData; use std::sync::Arc; -use bevy::ecs::reflect::AppTypeRegistry; use bevy::asset::{AssetLoader, AssetPath, BoxedFuture, LoadContext, LoadedAsset}; +use bevy::ecs::reflect::AppTypeRegistry; use bevy::prelude::{Handle, World}; use parking_lot::RwLock; diff --git a/bevy_proto_backend/src/proto/color.rs b/bevy_proto_backend/src/proto/color.rs index 76f897a..46244dc 100644 --- a/bevy_proto_backend/src/proto/color.rs +++ b/bevy_proto_backend/src/proto/color.rs @@ -1,6 +1,4 @@ -use bevy::reflect::{ - std_traits::ReflectDefault, Reflect, ReflectDeserialize, ReflectSerialize, -}; +use bevy::reflect::{std_traits::ReflectDefault, Reflect, ReflectDeserialize, ReflectSerialize}; use bevy::render::color::Color; use serde::{Deserialize, Serialize}; diff --git a/bevy_proto_backend/src/schematics/schematic.rs b/bevy_proto_backend/src/schematics/schematic.rs index 66c170e..1857eb8 100644 --- a/bevy_proto_backend/src/schematics/schematic.rs +++ b/bevy_proto_backend/src/schematics/schematic.rs @@ -16,7 +16,7 @@ use crate::schematics::SchematicContext; /// ``` /// use bevy::prelude::{Component, FromReflect, Reflect}; /// use bevy_proto_backend::schematics::{Schematic, SchematicContext}; -/// #[derive(Component, Reflect, FromReflect)] +/// #[derive(Component, Reflect)] /// struct PlayerId(usize); /// /// impl Schematic for PlayerId { diff --git a/examples/basic_schematic.rs b/examples/basic_schematic.rs index e93d522..112580b 100644 --- a/examples/basic_schematic.rs +++ b/examples/basic_schematic.rs @@ -7,7 +7,7 @@ use bevy_proto::prelude::*; fn main() { App::new() - .add_plugins(DefaultPlugins) + .add_plugins((DefaultPlugins, ProtoPlugin::new())) // =============== // // Make sure to register your types! .register_type::() @@ -17,16 +17,18 @@ fn main() { .register_type::() .register_type_data::() // =============== // - .add_plugin(ProtoPlugin::new()) .add_systems(Startup, (setup, load)) - .add_systems(Update, ( - spawn.run_if( - prototype_ready("Player") - .and_then(prototype_ready("PlayerConfig")) - .and_then(run_once()), + .add_systems( + Update, + ( + spawn.run_if( + prototype_ready("Player") + .and_then(prototype_ready("PlayerConfig")) + .and_then(run_once()), + ), + inspect, ), - inspect, - )) + ) .run(); } @@ -37,15 +39,12 @@ fn main() { // First thing's first, we need to derive `Reflect` so that we can register // this type to the registry (speaking of, don't forget to do that!): #[derive(Reflect)] -// For the basic schematic types we also need to derive `FromReflect` so that -// we can convert the deserialized data into a real instance of our type: -#[derive(FromReflect)] // Lastly, we need to register `ReflectSchematic`, which can do like this: #[reflect(Schematic)] struct Playable; /// The derive also works for enums! -#[derive(Component, Schematic, Reflect, FromReflect, Debug)] +#[derive(Component, Schematic, Reflect, Debug)] #[reflect(Schematic)] enum Alignment { Good, @@ -60,7 +59,7 @@ enum Alignment { /// /// Note that when a schematic is applied, it will replace the current instance /// of the resource in the world. -#[derive(Resource, Schematic, Reflect, FromReflect)] +#[derive(Resource, Schematic, Reflect)] #[schematic(kind = "resource")] struct MaxPlayers(u8); diff --git a/examples/bevy/ui.rs b/examples/bevy/ui.rs index 90f1a0c..d94a5da 100644 --- a/examples/bevy/ui.rs +++ b/examples/bevy/ui.rs @@ -9,34 +9,41 @@ //! //! [`ui`]: https://github.com/bevyengine/bevy/blob/v0.10.1/examples/ui/ui.rs +use bevy::asset::ChangeWatcher; use bevy::input::mouse::{MouseScrollUnit, MouseWheel}; use bevy::prelude::*; use bevy_proto::prelude::*; +use std::time::Duration; const ROOT: &str = "Root"; fn main() { App::new() - .add_plugins(DefaultPlugins.set(AssetPlugin { - watch_for_changes: true, - ..default() - })) - .add_plugin(ProtoPlugin::new()) + .add_plugins(( + DefaultPlugins.set(AssetPlugin { + watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)), + ..default() + }), + ProtoPlugin::new(), + )) // The original example sets the update mode to `desktop_app`, // but this doesn't play nice with hot-reloading. // .insert_resource(bevy::winit::WinitSettings::desktop_app()) .register_type::() .register_type::() .add_systems(Startup, (setup, load)) - .add_systems(Update, (spawn.run_if(prototype_ready(ROOT)), inspect, mouse_scroll)) + .add_systems( + Update, + (spawn.run_if(prototype_ready(ROOT)), inspect, mouse_scroll), + ) .run(); } -#[derive(Component, Default, Reflect, FromReflect)] +#[derive(Component, Default, Reflect)] #[reflect(Schematic)] struct ScrollText(String); -#[derive(Component, Reflect, FromReflect, Schematic)] +#[derive(Component, Reflect, Schematic)] #[reflect(Schematic)] struct ScrollingList { #[reflect(default)] @@ -62,7 +69,7 @@ fn mouse_scroll( scrolling_list.position += dy; scrolling_list.position = scrolling_list.position.clamp(-max_scroll, 0.); - style.position.top = Val::Px(scrolling_list.position); + style.top = Val::Px(scrolling_list.position); } } } diff --git a/examples/custom_config.rs b/examples/custom_config.rs index 09c3f28..9beb79c 100644 --- a/examples/custom_config.rs +++ b/examples/custom_config.rs @@ -19,11 +19,11 @@ fn main() { .add_plugins(DefaultPlugins) // =============== // // Be sure to add `ProtoPlugin` with the custom config: - .add_plugin(ProtoPlugin::new_with_config(MyConfig::default())) + .add_plugins(ProtoPlugin::new_with_config(MyConfig::default())) // Note: If you don't need to define your own type/resource, // you can also just add some callbacks to the default `ProtoConfig`: // - // .add_plugin( + // .add_plugins( // ProtoPlugin::new().with_config(ProtoConfig::default().on_register_prototype(Box::new( // |prototype, _handle| { // println!("Registered: {:?}", prototype.id()); @@ -33,16 +33,20 @@ fn main() { // // =============== // .add_systems(Startup, load) - .add_systems(Update, ( - // =============== // - // For custom configs we also need to use `ProtoCondition::::prototype_ready` - // instead of the default `prototype_ready` for our run condition: - spawn - .run_if(ProtoCondition::::prototype_ready("Player").and_then(run_once())), - // =============== // - on_config_change, - inspect, - )) + .add_systems( + Update, + ( + // =============== // + // For custom configs we also need to use `ProtoCondition::::prototype_ready` + // instead of the default `prototype_ready` for our run condition: + spawn.run_if( + ProtoCondition::::prototype_ready("Player").and_then(run_once()), + ), + // =============== // + on_config_change, + inspect, + ), + ) .run(); } diff --git a/examples/custom_loader.rs b/examples/custom_loader.rs index 754e54f..bc2a005 100644 --- a/examples/custom_loader.rs +++ b/examples/custom_loader.rs @@ -22,16 +22,19 @@ fn main() { .add_plugins(DefaultPlugins) // =============== // // Be sure to add `ProtoPlugin` with the custom loader: - .add_plugin(ProtoPlugin::new_with_loader(MyLoader::default())) + .add_plugins(ProtoPlugin::new_with_loader(MyLoader::default())) // =============== // .register_type::() .register_type::() .register_type::() .add_systems(Startup, load) - .add_systems(Update, ( - spawn.run_if(prototype_ready("Player").and_then(run_once())), - inspect, - )) + .add_systems( + Update, + ( + spawn.run_if(prototype_ready("Player").and_then(run_once())), + inspect, + ), + ) .run(); } @@ -96,15 +99,15 @@ impl Loader for MyLoader { } } -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic)] struct Player; -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic)] struct Health(i32); -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic)] struct Mana(i32); diff --git a/examples/custom_schematic.rs b/examples/custom_schematic.rs index c7e6b5f..0b36494 100644 --- a/examples/custom_schematic.rs +++ b/examples/custom_schematic.rs @@ -7,17 +7,19 @@ use bevy_proto::prelude::*; fn main() { App::new() - .add_plugins(DefaultPlugins) - .add_plugin(ProtoPlugin::new()) + .add_plugins((DefaultPlugins, ProtoPlugin::new())) // =============== // // Make sure to register your types! .register_type::() // ================ // .add_systems(Startup, load) - .add_systems(Update, ( - spawn.run_if(prototype_ready("CustomSchematic").and_then(run_once())), - inspect, - )) + .add_systems( + Update, + ( + spawn.run_if(prototype_ready("CustomSchematic").and_then(run_once())), + inspect, + ), + ) .run(); } diff --git a/examples/cycles.rs b/examples/cycles.rs index 8d69b51..5c55add 100644 --- a/examples/cycles.rs +++ b/examples/cycles.rs @@ -26,20 +26,23 @@ use bevy_proto_backend::cycles::CycleResponse; fn main() { App::new() - .add_plugins(DefaultPlugins) - .add_plugin( + .add_plugins(( + DefaultPlugins, ProtoPlugin::new().with_config(ProtoConfig::default().on_cycle(Box::new(|cycle| { println!("Handling cycle: {:?}", cycle); // Here we can configure what CycleResponse is returned. // For debug builds, the default behavior is to panic. CycleResponse::Panic }))), - ) - .add_systems(Startup, load) - .add_systems(Update, ( - spawn.run_if(prototype_ready("CycleA").and_then(run_once())), - inspect, )) + .add_systems(Startup, load) + .add_systems( + Update, + ( + spawn.run_if(prototype_ready("CycleA").and_then(run_once())), + inspect, + ), + ) .run(); } diff --git a/examples/derive_schematic.rs b/examples/derive_schematic.rs index 2610842..1986873 100644 --- a/examples/derive_schematic.rs +++ b/examples/derive_schematic.rs @@ -20,6 +20,7 @@ //! For more details, check out the documentation on the derive macro. use bevy::prelude::*; +use bevy::reflect::TypePath; use std::marker::PhantomData; use bevy_proto::prelude::*; @@ -38,7 +39,7 @@ fn main() { /// To see what this generated input type looks like, scroll to the bottom of this file. #[derive(Component, Schematic, Reflect)] #[reflect(Schematic)] -struct Foo { +struct Foo { /// Assets can be loaded by marking any `Handle` field like so: #[schematic(asset)] lazy_asset: Handle, @@ -69,7 +70,7 @@ struct Foo { complex_from: EntityGroup, /// As a side note, all reflection attributes get passed to the generated /// input type. - #[reflect(ignore, default)] + #[reflect(ignore)] _phantom: PhantomData, } @@ -132,27 +133,35 @@ impl From for Bar { // // ----------------------------------------------------------------------- // const _: () = { -// #[derive(::bevy::prelude::Reflect, ::bevy::prelude::FromReflect)] -// pub struct FooInput { +// #[derive(::bevy::prelude::Reflect)] +// pub struct FooInput { // lazy_asset: ::bevy_proto_backend::proto::ProtoAsset, // preloaded_asset: ::bevy_proto_backend::proto::ProtoAsset, // entity: ::bevy_proto_backend::tree::EntityAccess, // optional_entity: ::bevy_proto_backend::tree::EntityAccess, // simple_from: [f32; 3], // complex_from: String, -// #[reflect(ignore, default)] +// #[reflect(ignore)] // _phantom: PhantomData, -// #[reflect(ignore, default)] +// #[reflect(ignore)] // __phantom_ty__: ::core::marker::PhantomData (T)>, // } -// impl ::bevy_proto_backend::schematics::FromSchematicInput> for Foo { +// impl ::bevy_proto_backend::schematics::FromSchematicInput> +// for Foo +// { // fn from_input( // __input__: FooInput, // __context__: &mut ::bevy_proto_backend::schematics::SchematicContext, // ) -> Self { // Self { -// lazy_asset: __context__.world().resource::<::bevy::asset::AssetServer>().load(__input__.lazy_asset.to_asset_path().expect("ProtoAsset should contain an asset path")), -// preloaded_asset: __context__.world().resource::<::bevy::asset::AssetServer>().load(__input__.preloaded_asset.to_asset_path().expect("ProtoAsset should contain an asset path")), +// lazy_asset: match __input__.lazy_asset { +// ::bevy_proto_backend::proto::ProtoAsset::AssetPath(ref path) => { __context__.world().resource::<::bevy::asset::AssetServer>().load(path) } +// ::bevy_proto_backend::proto::ProtoAsset::HandleId(handle_id) => { __context__.world().resource::<::bevy::asset::AssetServer>().get_handle(handle_id) } +// }, +// preloaded_asset: match __input__.preloaded_asset { +// ::bevy_proto_backend::proto::ProtoAsset::AssetPath(ref path) => { __context__.world().resource::<::bevy::asset::AssetServer>().load(path) } +// ::bevy_proto_backend::proto::ProtoAsset::HandleId(handle_id) => { __context__.world().resource::<::bevy::asset::AssetServer>().get_handle(handle_id) } +// }, // entity: >::from_input(__input__.entity, __context__), // optional_entity: as ::bevy_proto_backend::schematics::FromSchematicInput<::bevy_proto_backend::tree::EntityAccess>>::from_input(__input__.optional_entity, __context__), // simple_from: >::from_input(__input__.simple_from, __context__), @@ -161,7 +170,7 @@ impl From for Bar { // } // } // } -// impl ::bevy_proto_backend::schematics::Schematic for Foo { +// impl ::bevy_proto_backend::schematics::Schematic for Foo { // type Input = FooInput; // fn apply( // __input__: &Self::Input, @@ -170,12 +179,12 @@ impl From for Bar { // let __input__ = ::from_reflect( // &*::bevy::reflect::Reflect::clone_value(__input__), // ) -// .unwrap_or_else(|| { -// panic!( -// "{} should have a functioning `FromReflect` impl", -// std::any::type_name::() -// ) -// }); +// .unwrap_or_else(|| { +// panic!( +// "{} should have a functioning `FromReflect` impl", +// std::any::type_name::() +// ) +// }); // let __input__ = >::from_input(__input__, __context__); @@ -207,14 +216,18 @@ impl From for Bar { // __input__: &mut Self::Input, // __dependencies__: &mut ::bevy_proto_backend::deps::DependenciesBuilder, // ) { -// let _: Handle = __dependencies__.add_dependency( -// __input__ -// .preloaded_asset -// .to_asset_path() -// .expect("ProtoAsset should contain an asset path") -// .to_owned(), -// ); +// match __input__.preloaded_asset { +// ::bevy_proto_backend::proto::ProtoAsset::AssetPath(ref path) => { +// let _: Handle = __dependencies__.add_dependency(path.to_owned()); +// } +// ::bevy_proto_backend::proto::ProtoAsset::HandleId(handle_id) => { +// panic!("expected `ProtoAsset::AssetPath` in field `{}` of `{}`, but found `ProtoAsset::HandleId`", "preloaded_asset", ::core::any::type_name::()); +// } +// } // } // } +// const _: () = { +// mod Assertions {} +// }; // }; // ----------------------------------------------------------------------- diff --git a/examples/hierarchy.rs b/examples/hierarchy.rs index c121d7c..b267460 100644 --- a/examples/hierarchy.rs +++ b/examples/hierarchy.rs @@ -32,31 +32,36 @@ use bevy_proto_backend::tree::EntityAccess; fn main() { App::new() - .add_plugins(DefaultPlugins) - .add_plugin(ProtoPlugin::new().with_config( - ProtoConfig::default().on_before_apply_prototype(Box::new(|prototype, context| { - // To see the end result of our hierarchy, let's inspect the generated - // `EntityTree` for the `Parent` prototype. - if prototype.id() == "Parent" { - println!("{:#?}", context.tree()); - - // We can also directly access the generated entities - // (check out the docs for `EntityAccess` for details): - let key_entity = context.find_entity(&EntityAccess::from("/OtherChild/@0")); - println!("🔑 Key Entity: {:?}", key_entity.unwrap()); - } - })), + .add_plugins(( + DefaultPlugins, + ProtoPlugin::new().with_config(ProtoConfig::default().on_before_apply_prototype( + Box::new(|prototype, context| { + // To see the end result of our hierarchy, let's inspect the generated + // `EntityTree` for the `Parent` prototype. + if prototype.id() == "Parent" { + println!("{:#?}", context.tree()); + + // We can also directly access the generated entities + // (check out the docs for `EntityAccess` for details): + let key_entity = context.find_entity(&EntityAccess::from("/OtherChild/@0")); + println!("🔑 Key Entity: {:?}", key_entity.unwrap()); + } + }), + )), + ShapePlugin, )) - .add_plugin(ShapePlugin) .register_type::() .register_type::() .register_type::() .add_systems(Startup, (setup, load)) - .add_systems(Update, ( - spawn.run_if(prototype_ready("Parent").and_then(run_once())), - inspect, - draw_relations, - )) + .add_systems( + Update, + ( + spawn.run_if(prototype_ready("Parent").and_then(run_once())), + inspect, + draw_relations, + ), + ) .run(); } @@ -77,12 +82,12 @@ struct Opens( ); /// Marker component opting into the drawing of relationships. -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic)] struct DrawRelations; /// Marker component indicating a hat is present. -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic)] struct HasHat; diff --git a/examples/hot_reload.rs b/examples/hot_reload.rs index 0c3c0ca..a209a4e 100644 --- a/examples/hot_reload.rs +++ b/examples/hot_reload.rs @@ -13,20 +13,27 @@ //! //! Just run the example and try it out for yourself! +use bevy::asset::ChangeWatcher; use bevy::prelude::*; +use std::time::Duration; use bevy_proto::prelude::*; fn main() { App::new() - .add_plugins(DefaultPlugins.set(AssetPlugin { - // Enable hot-reloading of assets: - watch_for_changes: true, - ..default() - })) - .add_plugin(ProtoPlugin::new()) + .add_plugins(( + DefaultPlugins.set(AssetPlugin { + // Enable hot-reloading of assets: + watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)), + ..default() + }), + ProtoPlugin::new(), + )) .add_systems(Startup, (setup, load)) - .add_systems(Update, (spawn.run_if(prototype_ready("ReloadableSprite")), inspect)) + .add_systems( + Update, + (spawn.run_if(prototype_ready("ReloadableSprite")), inspect), + ) .run(); } diff --git a/examples/loading.rs b/examples/loading.rs index bf2fd25..939fe79 100644 --- a/examples/loading.rs +++ b/examples/loading.rs @@ -9,12 +9,15 @@ fn main() { .add_plugins(DefaultPlugins) // The `ProtoPlugin` adds all the necessary systems and resources // to load and spawn prototype assets. - .add_plugin(ProtoPlugin::new()) + .add_plugins(ProtoPlugin::new()) .add_systems(Startup, (setup, load)) - .add_systems(Update, ( - spawn.run_if(prototype_ready("Player").and_then(run_once())), - inspect, - )) + .add_systems( + Update, + ( + spawn.run_if(prototype_ready("Player").and_then(run_once())), + inspect, + ), + ) .run(); } diff --git a/examples/templates.rs b/examples/templates.rs index ca98f75..2d42519 100644 --- a/examples/templates.rs +++ b/examples/templates.rs @@ -28,26 +28,28 @@ use bevy_proto::prelude::*; fn main() { App::new() - .add_plugins(DefaultPlugins) - .add_plugin(ProtoPlugin::new()) + .add_plugins((DefaultPlugins, ProtoPlugin::new())) .register_type::() .register_type::() .add_systems(Startup, (load, setup)) - .add_systems(Update, ( - spawn.run_if(prototype_ready("Player").and_then(run_once())), - on_spawn, - inspect, - )) + .add_systems( + Update, + ( + spawn.run_if(prototype_ready("Player").and_then(run_once())), + on_spawn, + inspect, + ), + ) .run(); } /// A component used to tint a sprite. -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic)] struct Colored(Color); /// A component used to scale a sprite. -#[derive(Component, Schematic, Reflect, FromReflect)] +#[derive(Component, Schematic, Reflect)] #[reflect(Schematic)] struct Scaled(f32); diff --git a/src/custom.rs b/src/custom.rs index db01323..1acd3f8 100644 --- a/src/custom.rs +++ b/src/custom.rs @@ -11,6 +11,7 @@ use bevy::prelude::{Component, GlobalTransform, Transform}; use bevy::reflect::{std_traits::ReflectDefault, Reflect}; use bevy::ui::widget::UiImageSize; use bevy_proto_backend::impls::bevy_impls; +use bevy_proto_backend::proto::ProtoColor; use bevy_proto_backend::{from, from_to_default}; use bevy_proto_backend::schematics::{ @@ -622,7 +623,7 @@ pub struct NodeBundle { pub node: bevy_impls::ui::NodeInput, pub style: bevy_impls::ui::StyleInput, pub background_color: bevy_impls::ui::BackgroundColorInput, - pub border_color: bevy::ui::BorderColor, + pub border_color: bevy_impls::ui::BorderColorInput, pub focus_policy: bevy_impls::ui::FocusPolicyInput, pub transform: Transform, pub global_transform: GlobalTransform, @@ -640,7 +641,7 @@ from_to_default!( node: value.node.into(), style: value.style.into(), background_color: value.background_color.into(), - border_color: value.border_color, + border_color: value.border_color.into(), focus_policy: value.focus_policy.into(), transform: value.transform, global_transform: value.global_transform, @@ -682,10 +683,14 @@ pub struct TextBundle { pub computed_visibility: bevy::render::view::ComputedVisibility, #[reflect(default)] pub z_index: bevy_impls::ui::ZIndexInput, - #[reflect(default)] + #[reflect(default = "transparent_background_color")] pub background_color: bevy_impls::ui::BackgroundColorInput, } +fn transparent_background_color() -> bevy_impls::ui::BackgroundColorInput { + bevy_impls::ui::BackgroundColorInput(ProtoColor::None) +} + #[cfg(feature = "bevy_ui")] impl FromSchematicInput for bevy::ui::node_bundles::TextBundle { fn from_input(input: TextBundle, context: &mut SchematicContext) -> Self { diff --git a/src/schematics.rs b/src/schematics.rs index 68256c1..1c7a860 100644 --- a/src/schematics.rs +++ b/src/schematics.rs @@ -86,13 +86,13 @@ impl<'de, 'a> DeserializeSeed<'de> for SchematicsDeserializer<'a> { #[cfg(test)] mod tests { use bevy::prelude::Component; - use bevy::reflect::{FromReflect, Reflect, TypeRegistryInternal}; + use bevy::reflect::{Reflect, TypeRegistryInternal}; use bevy_proto_backend::schematics::Schematic; use super::*; - #[derive(Reflect, FromReflect, Component, Schematic, Eq, PartialEq, Debug)] + #[derive(Reflect, Component, Schematic, Eq, PartialEq, Debug)] struct MySchematic { foo: usize, } From 5f189fe542755f0a046c53df81c6e138a7d4ed3f Mon Sep 17 00:00:00 2001 From: Gino Valente Date: Thu, 27 Jul 2023 20:47:04 -0700 Subject: [PATCH 17/23] Change bevy version --- Cargo.toml | 2 +- bevy_proto_backend/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9683bdc..1525a2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -100,7 +100,7 @@ bevy_ui = [ [dependencies] bevy_proto_backend = { version = "0.4", path = "./bevy_proto_backend", default-features = false } -bevy = { version = ">=0.11.0", default-features = false, features = ["bevy_asset"] } +bevy = { version = "0.11", default-features = false, features = ["bevy_asset"] } anyhow = "1.0" serde = "1.0" thiserror = "1.0" diff --git a/bevy_proto_backend/Cargo.toml b/bevy_proto_backend/Cargo.toml index 3a6dd38..3b6692a 100644 --- a/bevy_proto_backend/Cargo.toml +++ b/bevy_proto_backend/Cargo.toml @@ -63,7 +63,7 @@ bevy_ui = [ [dependencies] bevy_proto_derive = { version = "0.5", path = "../bevy_proto_derive" } -bevy = { version = ">=0.11.0", default-features = false, features = ["bevy_asset"] } +bevy = { version = "0.11", default-features = false, features = ["bevy_asset"] } anyhow = "1.0" serde = "1.0" thiserror = "1.0" From ece4b16dc828c775ad72d35955e6de6035f6e1f4 Mon Sep 17 00:00:00 2001 From: Gino Valente Date: Thu, 27 Jul 2023 20:59:38 -0700 Subject: [PATCH 18/23] Fix clippy --- bevy_proto_backend/src/impls/bevy_impls/ui.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bevy_proto_backend/src/impls/bevy_impls/ui.rs b/bevy_proto_backend/src/impls/bevy_impls/ui.rs index 23a0b3c..28723ab 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/ui.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/ui.rs @@ -173,7 +173,7 @@ impl_external_schematic! { from_to!( Node, NodeInput, - |_: Input| Self::default() + |_: Input| Self ); impl Default for NodeInput { fn default() -> Self { From a0539790f258391a6b676e48aa2babdc15400143 Mon Sep 17 00:00:00 2001 From: Gino Valente Date: Thu, 27 Jul 2023 20:59:38 -0700 Subject: [PATCH 19/23] Fix clippy --- bevy_proto_backend/src/impls/bevy_impls/ui.rs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/bevy_proto_backend/src/impls/bevy_impls/ui.rs b/bevy_proto_backend/src/impls/bevy_impls/ui.rs index 28723ab..7953b97 100644 --- a/bevy_proto_backend/src/impls/bevy_impls/ui.rs +++ b/bevy_proto_backend/src/impls/bevy_impls/ui.rs @@ -10,7 +10,7 @@ use bevy::ui::{ PositionType, RelativeCursorPosition, RepeatedGridTrack, Style, UiImage, UiRect, Val, ZIndex, }; -use crate::impls::macros::{from_to, from_to_default, register_schematic}; +use crate::impls::macros::{from_to_default, register_schematic}; use crate::proto::{ProtoAsset, ProtoColor}; use bevy_proto_derive::impl_external_schematic; @@ -170,11 +170,19 @@ impl_external_schematic! { // --- #[derive(Reflect)] pub struct NodeInput; - from_to!( - Node, - NodeInput, - |_: Input| Self - ); + + impl From for NodeInput { + fn from(_: Node) -> Self { + Self + } + } + + impl From for Node { + fn from(_: NodeInput) -> Self { + Self::default() + } + } + impl Default for NodeInput { fn default() -> Self { Self From c395e520fbdb18bdb0f578da87b0bac47e53623d Mon Sep 17 00:00:00 2001 From: Gino Valente Date: Thu, 27 Jul 2023 21:11:57 -0700 Subject: [PATCH 20/23] Fix clippy (some more) --- examples/custom_loader.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/custom_loader.rs b/examples/custom_loader.rs index bc2a005..b5c7486 100644 --- a/examples/custom_loader.rs +++ b/examples/custom_loader.rs @@ -22,7 +22,7 @@ fn main() { .add_plugins(DefaultPlugins) // =============== // // Be sure to add `ProtoPlugin` with the custom loader: - .add_plugins(ProtoPlugin::new_with_loader(MyLoader::default())) + .add_plugins(ProtoPlugin::new_with_loader(MyLoader)) // =============== // .register_type::() .register_type::() From d6c35d692f17edd3c5423c7e393fc7372c5e9ed1 Mon Sep 17 00:00:00 2001 From: Gino Valente Date: Fri, 28 Jul 2023 14:54:17 -0700 Subject: [PATCH 21/23] Update color defaults --- src/custom.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/custom.rs b/src/custom.rs index 1acd3f8..a43c760 100644 --- a/src/custom.rs +++ b/src/custom.rs @@ -47,6 +47,14 @@ pub(crate) fn register_custom_schematics(app: &mut App) { .register_type::(); } +fn transparent_background_color() -> bevy_impls::ui::BackgroundColorInput { + bevy_impls::ui::BackgroundColorInput(ProtoColor::None) +} + +fn transparent_border_color() -> bevy_impls::ui::BorderColorInput { + bevy_impls::ui::BorderColorInput(ProtoColor::None) +} + /// A [`Schematic`] implementation of [`TransformBundle`]. /// /// [`TransformBundle`]: bevy::prelude::TransformBundle @@ -523,7 +531,7 @@ pub struct ButtonBundle { pub focus_policy: bevy_impls::ui::FocusPolicyInput, #[reflect(default)] pub background_color: bevy_impls::ui::BackgroundColorInput, - #[reflect(default)] + #[reflect(default = "transparent_border_color")] pub border_color: bevy_impls::ui::BorderColorInput, #[reflect(default)] pub image: bevy_impls::ui::UiImageInput, @@ -687,10 +695,6 @@ pub struct TextBundle { pub background_color: bevy_impls::ui::BackgroundColorInput, } -fn transparent_background_color() -> bevy_impls::ui::BackgroundColorInput { - bevy_impls::ui::BackgroundColorInput(ProtoColor::None) -} - #[cfg(feature = "bevy_ui")] impl FromSchematicInput for bevy::ui::node_bundles::TextBundle { fn from_input(input: TextBundle, context: &mut SchematicContext) -> Self { From 7e49ee456343596f695880ec27d487d128a92d2a Mon Sep 17 00:00:00 2001 From: Gino Valente Date: Fri, 28 Jul 2023 16:24:53 -0700 Subject: [PATCH 22/23] Reset version --- bevy_proto_backend/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bevy_proto_backend/Cargo.toml b/bevy_proto_backend/Cargo.toml index 3b6692a..475bd8e 100644 --- a/bevy_proto_backend/Cargo.toml +++ b/bevy_proto_backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_proto_backend" -version = "0.4.0" +version = "0.3.0" edition = "2021" authors = ["Gino Valente "] description = "Backend crate for bevy_proto" From 62a8e50e1962005e3707c387218b40eb9b4f9174 Mon Sep 17 00:00:00 2001 From: Gino Valente Date: Fri, 28 Jul 2023 16:26:18 -0700 Subject: [PATCH 23/23] Reset dep version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1525a2e..7545179 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -99,7 +99,7 @@ bevy_ui = [ ] [dependencies] -bevy_proto_backend = { version = "0.4", path = "./bevy_proto_backend", default-features = false } +bevy_proto_backend = { version = "0.3", path = "./bevy_proto_backend", default-features = false } bevy = { version = "0.11", default-features = false, features = ["bevy_asset"] } anyhow = "1.0" serde = "1.0"