Skip to content

Commit

Permalink
add panic message if plugin was added after default plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobhellermann committed Nov 5, 2023
1 parent ea772a6 commit 6b49d2c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions crates/bevy-inspector-egui/src/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{marker::PhantomData, sync::Mutex};

use bevy_app::{Plugin, Update};
use bevy_asset::Asset;
use bevy_core::TypeRegistrationPlugin;
use bevy_ecs::{
component::Tick, prelude::*, query::ReadOnlyWorldQuery, schedule::BoxedCondition,
system::ReadOnlySystem, world::unsafe_world_cell::UnsafeWorldCell,
Expand Down Expand Up @@ -60,6 +61,8 @@ impl WorldInspectorPlugin {

impl Plugin for WorldInspectorPlugin {
fn build(&self, app: &mut bevy_app::App) {
check_default_plugins(app, "WorldInspectorPlugin");

if !app.is_plugin_added::<DefaultInspectorConfigPlugin>() {
app.add_plugins(DefaultInspectorConfigPlugin);
}
Expand Down Expand Up @@ -156,6 +159,8 @@ impl<T> ResourceInspectorPlugin<T> {

impl<T: Resource + Reflect> Plugin for ResourceInspectorPlugin<T> {
fn build(&self, app: &mut bevy_app::App) {
check_default_plugins(app, "ResourceInspectorPlugin");

if !app.is_plugin_added::<DefaultInspectorConfigPlugin>() {
app.add_plugins(DefaultInspectorConfigPlugin);
}
Expand Down Expand Up @@ -249,6 +254,8 @@ impl<T> StateInspectorPlugin<T> {

impl<T: States + Reflect> Plugin for StateInspectorPlugin<T> {
fn build(&self, app: &mut bevy_app::App) {
check_default_plugins(app, "StateInspectorPlugin");

if !app.is_plugin_added::<DefaultInspectorConfigPlugin>() {
app.add_plugins(DefaultInspectorConfigPlugin);
}
Expand Down Expand Up @@ -331,6 +338,8 @@ impl<A> AssetInspectorPlugin<A> {

impl<A: Asset + Reflect> Plugin for AssetInspectorPlugin<A> {
fn build(&self, app: &mut bevy_app::App) {
check_default_plugins(app, "AssetInspectorPlugin");

if !app.is_plugin_added::<DefaultInspectorConfigPlugin>() {
app.add_plugins(DefaultInspectorConfigPlugin);
}
Expand Down Expand Up @@ -411,6 +420,8 @@ where
F: ReadOnlyWorldQuery,
{
fn build(&self, app: &mut bevy_app::App) {
check_default_plugins(app, "FilterQueryInspectorPlugin");

if !app.is_plugin_added::<DefaultInspectorConfigPlugin>() {
app.add_plugins(DefaultInspectorConfigPlugin);
}
Expand Down Expand Up @@ -506,3 +517,15 @@ impl System for BoxedConditionHelper {
self.0.set_last_run(last_run)
}
}

fn check_default_plugins(app: &bevy_app::App, name: &str) {
if !app.is_plugin_added::<TypeRegistrationPlugin>() {
panic!(
r#"`{name}` should be added after the default plugins:
.add_plugins(DefaultPlugins)
.add_plugins({name}::default())
"#,
name = name,
);
}
}

0 comments on commit 6b49d2c

Please sign in to comment.