Skip to content

Commit 3817afc

Browse files
register missing reflect types (bevyengine#5747)
# Objective - While generating https://github.com/jakobhellermann/bevy_reflect_ts_type_export/blob/main/generated/types.ts, I noticed that some types that implement `Reflect` did not register themselves - `Viewport` isn't reflect but can be (there's a TODO) ## Solution - register all reflected types - derive `Reflect` for `Viewport` ## Changelog - more types are not registered in the type registry - remove `Serialize`, `Deserialize` impls from `Viewport` I also decided to remove the `Serialize, Deserialize` from the `Viewport`, since they were (AFAIK) only used for reflection, which now is done without serde. So this is technically a breaking change for people who relied on that impl directly. Personally I don't think that every bevy type should implement `Serialize, Deserialize`, as that would lead to a ton of code generation that mostly isn't necessary because we can do the same with `Reflect`, but if this is deemed controversial I can remove it from this PR. ## Migration Guide - `KeyCode` now implements `Reflect` not as `reflect_value`, but with proper struct reflection. The `Serialize` and `Deserialize` impls were removed, now that they are no longer required for scene serialization.
1 parent 5e2d9b4 commit 3817afc

File tree

9 files changed

+20
-7
lines changed

9 files changed

+20
-7
lines changed

crates/bevy_core/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub mod prelude {
1616

1717
use bevy_app::prelude::*;
1818
use bevy_ecs::entity::Entity;
19-
use bevy_utils::HashSet;
19+
use bevy_utils::{Duration, HashSet, Instant};
2020
use std::borrow::Cow;
2121
use std::ops::Range;
2222

@@ -45,7 +45,9 @@ fn register_rust_types(app: &mut App) {
4545
.register_type::<String>()
4646
.register_type::<HashSet<String>>()
4747
.register_type::<Option<String>>()
48-
.register_type::<Cow<'static, str>>();
48+
.register_type::<Cow<'static, str>>()
49+
.register_type::<Duration>()
50+
.register_type::<Instant>();
4951
}
5052

5153
fn register_math_types(app: &mut App) {

crates/bevy_core_pipeline/src/core_3d/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub struct Core3dPlugin;
4343
impl Plugin for Core3dPlugin {
4444
fn build(&self, app: &mut App) {
4545
app.register_type::<Camera3d>()
46+
.register_type::<Camera3dDepthLoadOp>()
4647
.add_plugin(ExtractComponentPlugin::<Camera3d>::default());
4748

4849
let render_app = match app.get_sub_app_mut(RenderApp) {

crates/bevy_core_pipeline/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ pub mod prelude {
1111
};
1212
}
1313

14-
use crate::{clear_color::ClearColor, core_2d::Core2dPlugin, core_3d::Core3dPlugin};
14+
use crate::{
15+
clear_color::{ClearColor, ClearColorConfig},
16+
core_2d::Core2dPlugin,
17+
core_3d::Core3dPlugin,
18+
};
1519
use bevy_app::{App, Plugin};
1620
use bevy_render::extract_resource::ExtractResourcePlugin;
1721

@@ -21,6 +25,7 @@ pub struct CorePipelinePlugin;
2125
impl Plugin for CorePipelinePlugin {
2226
fn build(&self, app: &mut App) {
2327
app.register_type::<ClearColor>()
28+
.register_type::<ClearColorConfig>()
2429
.init_resource::<ClearColor>()
2530
.add_plugin(ExtractResourcePlugin::<ClearColor>::default())
2631
.add_plugin(Core2dPlugin)

crates/bevy_input/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ bevy_app = { path = "../bevy_app", version = "0.9.0-dev" }
1818
bevy_ecs = { path = "../bevy_ecs", version = "0.9.0-dev" }
1919
bevy_math = { path = "../bevy_math", version = "0.9.0-dev" }
2020
bevy_utils = { path = "../bevy_utils", version = "0.9.0-dev" }
21+
bevy_reflect = { path = "../bevy_reflect", version = "0.9.0-dev" }
2122

2223
# other
2324
serde = { version = "1", features = ["derive"], optional = true }

crates/bevy_render/src/camera/camera.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use bevy_reflect::FromReflect;
2323
use bevy_transform::components::GlobalTransform;
2424
use bevy_utils::HashSet;
2525
use bevy_window::{WindowCreated, WindowId, WindowResized, Windows};
26-
use serde::{Deserialize, Serialize};
2726
use std::{borrow::Cow, ops::Range};
2827
use wgpu::Extent3d;
2928

@@ -32,9 +31,8 @@ use wgpu::Extent3d;
3231
/// The viewport defines the area on the render target to which the camera renders its image.
3332
/// You can overlay multiple cameras in a single window using viewports to create effects like
3433
/// split screen, minimaps, and character viewers.
35-
// TODO: remove reflect_value when possible
36-
#[derive(Reflect, FromReflect, Debug, Clone, Serialize, Deserialize)]
37-
#[reflect_value(Default, Serialize, Deserialize)]
34+
#[derive(Reflect, FromReflect, Debug, Clone)]
35+
#[reflect(Default)]
3836
pub struct Viewport {
3937
/// The physical position to render this viewport to within the [`RenderTarget`] of this [`Camera`].
4038
/// (0,0) corresponds to the top-left corner

crates/bevy_render/src/camera/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct CameraPlugin;
2121
impl Plugin for CameraPlugin {
2222
fn build(&self, app: &mut App) {
2323
app.register_type::<Camera>()
24+
.register_type::<Viewport>()
2425
.register_type::<Visibility>()
2526
.register_type::<ComputedVisibility>()
2627
.register_type::<VisibleEntities>()

crates/bevy_sprite/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ impl Plugin for SpritePlugin {
5757
shaders.set_untracked(SPRITE_SHADER_HANDLE, sprite_shader);
5858
app.add_asset::<TextureAtlas>()
5959
.register_type::<Sprite>()
60+
.register_type::<Anchor>()
6061
.register_type::<Mesh2dHandle>()
6162
.add_plugin(Mesh2dRenderPlugin)
6263
.add_plugin(ColorMaterialPlugin);

crates/bevy_text/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ impl Plugin for TextPlugin {
4343
app.add_asset::<Font>()
4444
.add_asset::<FontAtlasSet>()
4545
.register_type::<Text>()
46+
.register_type::<TextSection>()
47+
.register_type::<TextAlignment>()
4648
.register_type::<VerticalAlign>()
4749
.register_type::<HorizontalAlign>()
4850
.init_asset_loader::<FontLoader>()

crates/bevy_time/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ impl Plugin for TimePlugin {
3636
app.init_resource::<Time>()
3737
.init_resource::<FixedTimesteps>()
3838
.register_type::<Timer>()
39+
.register_type::<Time>()
40+
.register_type::<Stopwatch>()
3941
// time system is added as an "exclusive system" to ensure it runs before other systems
4042
// in CoreStage::First
4143
.add_system_to_stage(

0 commit comments

Comments
 (0)