Skip to content

Commit

Permalink
use a Resource instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherBiscardi committed Aug 3, 2024
1 parent fe4b1e1 commit 52b2a50
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 28 deletions.
2 changes: 1 addition & 1 deletion examples/cube3d/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() {
let mut app = App::new();

app.add_plugins(DefaultPlugins)
.add_plugins(VelloPlugin::default())
.add_plugins(VelloPlugin)
.add_systems(Startup, setup)
.add_systems(Update, cube_rotator_system)
.add_plugins(ExtractComponentPlugin::<VelloTarget>::default());
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
..default()
}))
.add_plugins(EguiPlugin)
.add_plugins(VelloPlugin::default())
.add_plugins(VelloPlugin)
.init_resource::<EmbeddedAssetRegistry>()
.add_plugins(bevy_pancam::PanCamPlugin)
.add_systems(Startup, setup_vector_graphics)
Expand Down
2 changes: 1 addition & 1 deletion examples/drag_n_drop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
meta_check: AssetMetaCheck::Never,
..default()
}))
.add_plugins(VelloPlugin::default())
.add_plugins(VelloPlugin)
.add_systems(Startup, setup_vector_graphics)
.add_systems(Update, drag_and_drop);
embedded_asset!(app, "assets/fountain.svg");
Expand Down
2 changes: 1 addition & 1 deletion examples/lottie/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
meta_check: AssetMetaCheck::Never,
..default()
}))
.add_plugins(VelloPlugin::default())
.add_plugins(VelloPlugin)
.add_systems(Startup, load_lottie);
embedded_asset!(app, "assets/Tiger.json");
app.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/render_layers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy_vello::{prelude::*, VelloPlugin};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(VelloPlugin::default())
.add_plugins(VelloPlugin)
.add_systems(Startup, (setup_animation, setup_background))
.add_systems(
Update,
Expand Down
2 changes: 1 addition & 1 deletion examples/scene/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bevy_vello::{
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(VelloPlugin::default())
.add_plugins(VelloPlugin)
.add_systems(Startup, setup_vector_graphics)
.add_systems(Update, simple_animation)
.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/scene_ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::f64::consts::{FRAC_PI_4, SQRT_2};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(VelloPlugin::default())
.add_plugins(VelloPlugin)
.add_systems(Startup, setup_ui)
.add_systems(Update, update_ui)
.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/svg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
meta_check: AssetMetaCheck::Never,
..default()
}))
.add_plugins(VelloPlugin::default())
.add_plugins(VelloPlugin)
.add_systems(Startup, load_svg);
embedded_asset!(app, "assets/fountain.svg");
app.run();
Expand Down
2 changes: 1 addition & 1 deletion examples/text/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
meta_check: AssetMetaCheck::Never,
..default()
}))
.add_plugins(VelloPlugin::default())
.add_plugins(VelloPlugin)
.add_systems(
Startup,
(setup_camera, setup_screenspace_text, setup_worldspace_text),
Expand Down
18 changes: 7 additions & 11 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@ use crate::{
debug::DebugVisualizationsPlugin, render::VelloRenderPlugin, text::VelloFontLoader, VelloAsset,
VelloFont,
};
use bevy::{asset::load_internal_binary_asset, prelude::*, render::view::RenderLayers};
use bevy::{asset::load_internal_binary_asset, prelude::*};

#[derive(Default)]
pub struct VelloPlugin {
pub canvas_render_layers: Option<RenderLayers>,
}
pub struct VelloPlugin;

impl Plugin for VelloPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(VelloRenderPlugin {
canvas_render_layers: self.canvas_render_layers.clone(),
})
.add_plugins(DebugVisualizationsPlugin)
.init_asset::<VelloAsset>()
.init_asset::<VelloFont>()
.init_asset_loader::<VelloFontLoader>();
app.add_plugins(VelloRenderPlugin)
.add_plugins(DebugVisualizationsPlugin)
.init_asset::<VelloAsset>()
.init_asset::<VelloFont>()
.init_asset_loader::<VelloFontLoader>();
#[cfg(feature = "svg")]
app.add_plugins(crate::integrations::svg::SvgIntegrationPlugin);
#[cfg(feature = "lottie")]
Expand Down
8 changes: 4 additions & 4 deletions src/render/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ use bevy::{
sprite::Material2dPlugin,
};

#[derive(Resource, Default, Clone)]
pub struct VelloRenderPlugin {
pub struct VelloRenderPlugin;

#[derive(Default, Resource, Clone)]
pub struct VelloRenderSettings {
/// the render layer that will be used for the vello canvas mesh
pub canvas_render_layers: Option<RenderLayers>,
}

impl Plugin for VelloRenderPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(self.clone());

load_internal_asset!(
app,
SSRT_SHADER_HANDLE,
Expand Down
9 changes: 5 additions & 4 deletions src/render/systems.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::{
extract::{ExtractedRenderAsset, ExtractedRenderText, SSRenderTarget},
plugin::VelloRenderSettings,
prepare::PreparedAffine,
VelloRenderPlugin, VelloRenderer,
VelloRenderer,
};
use crate::{
render::extract::ExtractedRenderScene, CoordinateSpace, VelloAsset, VelloCanvasMaterial,
Expand Down Expand Up @@ -282,7 +283,7 @@ pub fn setup_ss_rendertarget(
mut custom_materials: ResMut<Assets<VelloCanvasMaterial>>,
windows: Query<&Window>,
mut render_target_mesh_handle: Local<Option<Handle<Mesh>>>,
config: Res<VelloRenderPlugin>,
config: Option<Res<VelloRenderSettings>>,
) {
let Ok(window) = windows.get_single() else {
return;
Expand Down Expand Up @@ -331,8 +332,8 @@ pub fn setup_ss_rendertarget(
.insert(render_target)
.id();

if let Some(layer) = &config.canvas_render_layers {
commands.entity(entity).insert(layer.clone());
if let Some(layer) = config.and_then(|config| config.canvas_render_layers.clone()) {
commands.entity(entity).insert(layer);
}
}

Expand Down

0 comments on commit 52b2a50

Please sign in to comment.