mirror of
https://github.com/bevyengine/bevy
synced 2024-11-27 07:00:18 +00:00
address comments
`failure_mode` and `FailureMode` are now `failure_handling_mode` and `FailureHandlingMode`
This commit is contained in:
parent
1916616cdc
commit
b129f1ff41
2 changed files with 73 additions and 63 deletions
|
@ -16,7 +16,7 @@ use crate::{
|
||||||
system::{input::SystemInput, RunSystemWithInput, SystemId},
|
system::{input::SystemInput, RunSystemWithInput, SystemId},
|
||||||
world::{
|
world::{
|
||||||
command_queue::RawCommandQueue, unsafe_world_cell::UnsafeWorldCell, Command, CommandQueue,
|
command_queue::RawCommandQueue, unsafe_world_cell::UnsafeWorldCell, Command, CommandQueue,
|
||||||
EntityWorldMut, FailureMode, FromWorld, SpawnBatchIter, World,
|
EntityWorldMut, FailureHandlingMode, FromWorld, SpawnBatchIter, World,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use bevy_ptr::OwningPtr;
|
use bevy_ptr::OwningPtr;
|
||||||
|
@ -77,7 +77,7 @@ pub use parallel_scope::*;
|
||||||
pub struct Commands<'w, 's> {
|
pub struct Commands<'w, 's> {
|
||||||
queue: InternalQueue<'s>,
|
queue: InternalQueue<'s>,
|
||||||
entities: &'w Entities,
|
entities: &'w Entities,
|
||||||
pub(crate) failure_mode: FailureMode,
|
pub(crate) failure_handling_mode: FailureHandlingMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
// SAFETY: All commands [`Command`] implement [`Send`]
|
// SAFETY: All commands [`Command`] implement [`Send`]
|
||||||
|
@ -173,7 +173,7 @@ const _: () = {
|
||||||
Commands {
|
Commands {
|
||||||
queue: InternalQueue::CommandQueue(f0),
|
queue: InternalQueue::CommandQueue(f0),
|
||||||
entities: f1,
|
entities: f1,
|
||||||
failure_mode: FailureMode::default(),
|
failure_handling_mode: FailureHandlingMode::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ impl<'w, 's> Commands<'w, 's> {
|
||||||
Self {
|
Self {
|
||||||
queue: InternalQueue::CommandQueue(Deferred(queue)),
|
queue: InternalQueue::CommandQueue(Deferred(queue)),
|
||||||
entities,
|
entities,
|
||||||
failure_mode: FailureMode::default(),
|
failure_handling_mode: FailureHandlingMode::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ impl<'w, 's> Commands<'w, 's> {
|
||||||
Self {
|
Self {
|
||||||
queue: InternalQueue::RawCommandQueue(queue),
|
queue: InternalQueue::RawCommandQueue(queue),
|
||||||
entities,
|
entities,
|
||||||
failure_mode: FailureMode::default(),
|
failure_handling_mode: FailureHandlingMode::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ impl<'w, 's> Commands<'w, 's> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
entities: self.entities,
|
entities: self.entities,
|
||||||
failure_mode: self.failure_mode,
|
failure_handling_mode: self.failure_handling_mode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ impl<'w, 's> Commands<'w, 's> {
|
||||||
/// - [`warn_on_error`](Self::warn_on_error)
|
/// - [`warn_on_error`](Self::warn_on_error)
|
||||||
/// - [`panic_on_error`](Self::panic_on_error)
|
/// - [`panic_on_error`](Self::panic_on_error)
|
||||||
pub fn ignore_on_error(&mut self) -> &mut Self {
|
pub fn ignore_on_error(&mut self) -> &mut Self {
|
||||||
self.failure_mode = FailureMode::Ignore;
|
self.failure_handling_mode = FailureHandlingMode::Ignore;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ impl<'w, 's> Commands<'w, 's> {
|
||||||
/// - [`warn_on_error`](Self::warn_on_error)
|
/// - [`warn_on_error`](Self::warn_on_error)
|
||||||
/// - [`panic_on_error`](Self::panic_on_error)
|
/// - [`panic_on_error`](Self::panic_on_error)
|
||||||
pub fn log_on_error(&mut self) -> &mut Self {
|
pub fn log_on_error(&mut self) -> &mut Self {
|
||||||
self.failure_mode = FailureMode::Log;
|
self.failure_handling_mode = FailureHandlingMode::Log;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ impl<'w, 's> Commands<'w, 's> {
|
||||||
/// - [`log_on_error`](Self::log_on_error) (default)
|
/// - [`log_on_error`](Self::log_on_error) (default)
|
||||||
/// - [`panic_on_error`](Self::panic_on_error)
|
/// - [`panic_on_error`](Self::panic_on_error)
|
||||||
pub fn warn_on_error(&mut self) -> &mut Self {
|
pub fn warn_on_error(&mut self) -> &mut Self {
|
||||||
self.failure_mode = FailureMode::Warn;
|
self.failure_handling_mode = FailureHandlingMode::Warn;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ impl<'w, 's> Commands<'w, 's> {
|
||||||
/// - [`log_on_error`](Self::log_on_error) (default)
|
/// - [`log_on_error`](Self::log_on_error) (default)
|
||||||
/// - [`warn_on_error`](Self::warn_on_error)
|
/// - [`warn_on_error`](Self::warn_on_error)
|
||||||
pub fn panic_on_error(&mut self) -> &mut Self {
|
pub fn panic_on_error(&mut self) -> &mut Self {
|
||||||
self.failure_mode = FailureMode::Panic;
|
self.failure_handling_mode = FailureHandlingMode::Panic;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,8 +458,8 @@ impl<'w, 's> Commands<'w, 's> {
|
||||||
|
|
||||||
/// Returns the [`EntityCommands`] for the requested [`Entity`].
|
/// Returns the [`EntityCommands`] for the requested [`Entity`].
|
||||||
///
|
///
|
||||||
/// This method does not guarantee that `EntityCommands` will be successfully applied,
|
/// This method does not guarantee that commands queued by the `EntityCommands`
|
||||||
/// since another command in the queue may delete the entity before them.
|
/// will be successful, since the entity could be despawned before they are executed.
|
||||||
///
|
///
|
||||||
/// # Fallible
|
/// # Fallible
|
||||||
///
|
///
|
||||||
|
@ -503,11 +503,11 @@ impl<'w, 's> Commands<'w, 's> {
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn entity(&mut self, entity: Entity) -> EntityCommands {
|
pub fn entity(&mut self, entity: Entity) -> EntityCommands {
|
||||||
if !self.entities.contains(entity) {
|
if !self.entities.contains(entity) {
|
||||||
match self.failure_mode {
|
match self.failure_handling_mode {
|
||||||
FailureMode::Ignore => (),
|
FailureHandlingMode::Ignore => (),
|
||||||
FailureMode::Log => info!("Attempted to create an EntityCommands for Entity {entity:?}, which doesn't exist; returned invalid EntityCommands"),
|
FailureHandlingMode::Log => info!("Attempted to create an EntityCommands for entity {entity}, which doesn't exist; returned invalid EntityCommands"),
|
||||||
FailureMode::Warn => warn!("Attempted to create an EntityCommands for Entity {entity:?}, which doesn't exist; returned invalid EntityCommands"),
|
FailureHandlingMode::Warn => warn!("Attempted to create an EntityCommands for entity {entity}, which doesn't exist; returned invalid EntityCommands"),
|
||||||
FailureMode::Panic => panic!("Attempted to create an EntityCommands for Entity {entity:?}, which doesn't exist"),
|
FailureHandlingMode::Panic => panic!("Attempted to create an EntityCommands for entity {entity}, which doesn't exist"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
EntityCommands {
|
EntityCommands {
|
||||||
|
@ -520,8 +520,8 @@ impl<'w, 's> Commands<'w, 's> {
|
||||||
///
|
///
|
||||||
/// Returns `None` if the entity does not exist.
|
/// Returns `None` if the entity does not exist.
|
||||||
///
|
///
|
||||||
/// This method does not guarantee that `EntityCommands` will be successfully applied,
|
/// This method does not guarantee that commands queued by the `EntityCommands`
|
||||||
/// since another command in the queue may delete the entity before them.
|
/// will be successful, since the entity could be despawned before they are executed.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
|
@ -706,7 +706,7 @@ impl<'w, 's> Commands<'w, 's> {
|
||||||
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
|
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
|
||||||
B: Bundle,
|
B: Bundle,
|
||||||
{
|
{
|
||||||
self.queue(insert_batch(batch, self.failure_mode));
|
self.queue(insert_batch(batch, self.failure_handling_mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pushes a [`Command`] to the queue for adding a [`Bundle`] type to a batch of [`Entities`](Entity).
|
/// Pushes a [`Command`] to the queue for adding a [`Bundle`] type to a batch of [`Entities`](Entity).
|
||||||
|
@ -736,7 +736,7 @@ impl<'w, 's> Commands<'w, 's> {
|
||||||
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
|
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
|
||||||
B: Bundle,
|
B: Bundle,
|
||||||
{
|
{
|
||||||
self.queue(insert_batch_if_new(batch, self.failure_mode));
|
self.queue(insert_batch_if_new(batch, self.failure_handling_mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pushes a [`Command`] to the queue for adding a [`Bundle`] type to a batch of [`Entities`](Entity).
|
/// Pushes a [`Command`] to the queue for adding a [`Bundle`] type to a batch of [`Entities`](Entity).
|
||||||
|
@ -1162,7 +1162,7 @@ pub trait EntityCommand<Marker = ()>: Send + 'static {
|
||||||
/// footprint than `(Entity, Self)`.
|
/// footprint than `(Entity, Self)`.
|
||||||
/// In most cases the provided implementation is sufficient.
|
/// In most cases the provided implementation is sufficient.
|
||||||
#[must_use = "commands do nothing unless applied to a `World`"]
|
#[must_use = "commands do nothing unless applied to a `World`"]
|
||||||
fn with_entity(self, entity: Entity, failure_mode: FailureMode) -> impl Command
|
fn with_entity(self, entity: Entity, failure_handling_mode: FailureHandlingMode) -> impl Command
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
|
@ -1170,16 +1170,16 @@ pub trait EntityCommand<Marker = ()>: Send + 'static {
|
||||||
if world.entities.contains(entity) {
|
if world.entities.contains(entity) {
|
||||||
self.apply(entity, world);
|
self.apply(entity, world);
|
||||||
} else {
|
} else {
|
||||||
match failure_mode {
|
match failure_handling_mode {
|
||||||
FailureMode::Ignore => (),
|
FailureHandlingMode::Ignore => (),
|
||||||
FailureMode::Log => {
|
FailureHandlingMode::Log => {
|
||||||
info!("Could not execute EntityCommand because its Entity {entity:?} was missing");
|
info!("Could not execute EntityCommand because its entity {entity} was missing");
|
||||||
}
|
}
|
||||||
FailureMode::Warn => {
|
FailureHandlingMode::Warn => {
|
||||||
warn!("Could not execute EntityCommand because its Entity {entity:?} was missing");
|
warn!("Could not execute EntityCommand because its entity {entity} was missing");
|
||||||
}
|
}
|
||||||
FailureMode::Panic => {
|
FailureHandlingMode::Panic => {
|
||||||
panic!("Could not execute EntityCommand because its Entity {entity:?} was missing");
|
panic!("Could not execute EntityCommand because its entity {entity} was missing");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1237,7 +1237,8 @@ impl<'a> EntityCommands<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the [`EntityCommands`] instance to ignore commands if the entity doesn't exist.
|
/// Sets the [`EntityCommands`] instance to ignore commands if the entity doesn't exist
|
||||||
|
/// when a command is executed.
|
||||||
///
|
///
|
||||||
/// # See also:
|
/// # See also:
|
||||||
/// - [`log_if_missing`](Self::log_if_missing) (default)
|
/// - [`log_if_missing`](Self::log_if_missing) (default)
|
||||||
|
@ -1248,7 +1249,8 @@ impl<'a> EntityCommands<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the [`EntityCommands`] instance to log if the entity doesn't exist when a command is executed.
|
/// Sets the [`EntityCommands`] instance to log if the entity doesn't exist
|
||||||
|
/// when a command is executed.
|
||||||
///
|
///
|
||||||
/// This is the default setting.
|
/// This is the default setting.
|
||||||
///
|
///
|
||||||
|
@ -1261,7 +1263,8 @@ impl<'a> EntityCommands<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the [`EntityCommands`] instance to warn if the entity doesn't exist when a command is executed.
|
/// Sets the [`EntityCommands`] instance to warn if the entity doesn't exist
|
||||||
|
/// when a command is executed.
|
||||||
///
|
///
|
||||||
/// # See also:
|
/// # See also:
|
||||||
/// - [`ignore_if_missing`](Self::ignore_if_missing)
|
/// - [`ignore_if_missing`](Self::ignore_if_missing)
|
||||||
|
@ -1272,7 +1275,8 @@ impl<'a> EntityCommands<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the [`EntityCommands`] instance to panic if the entity doesn't exist when a command is executed.
|
/// Sets the [`EntityCommands`] instance to panic if the entity doesn't exist
|
||||||
|
/// when a command is executed.
|
||||||
///
|
///
|
||||||
/// # See also:
|
/// # See also:
|
||||||
/// - [`ignore_if_missing`](Self::ignore_if_missing)
|
/// - [`ignore_if_missing`](Self::ignore_if_missing)
|
||||||
|
@ -1472,7 +1476,7 @@ impl<'a> EntityCommands<'a> {
|
||||||
/// # Note
|
/// # Note
|
||||||
///
|
///
|
||||||
/// [`Self::insert`] used to panic if the entity was missing, and this was the non-panicking version.
|
/// [`Self::insert`] used to panic if the entity was missing, and this was the non-panicking version.
|
||||||
/// `EntityCommands` no longer need to handle missing entities individually, so just use [`Self::insert`]
|
/// `EntityCommands` no longer need to handle missing entities individually, so just use [`Self::insert`].
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
|
@ -1567,7 +1571,7 @@ impl<'a> EntityCommands<'a> {
|
||||||
/// # Note
|
/// # Note
|
||||||
///
|
///
|
||||||
/// [`Self::insert_if_new_and`] used to panic if the entity was missing, and this was the non-panicking version.
|
/// [`Self::insert_if_new_and`] used to panic if the entity was missing, and this was the non-panicking version.
|
||||||
/// `EntityCommands` no longer need to handle missing entities individually, so just use [`Self::insert_if_new_and`]
|
/// `EntityCommands` no longer need to handle missing entities individually, so just use [`Self::insert_if_new_and`].
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
|
@ -1612,7 +1616,7 @@ impl<'a> EntityCommands<'a> {
|
||||||
/// # Note
|
/// # Note
|
||||||
///
|
///
|
||||||
/// [`Self::insert_if_new`] used to panic if the entity was missing, and this was the non-panicking version.
|
/// [`Self::insert_if_new`] used to panic if the entity was missing, and this was the non-panicking version.
|
||||||
/// `EntityCommands` no longer need to handle missing entities individually, so just use [`Self::insert_if_new`]
|
/// `EntityCommands` no longer need to handle missing entities individually, so just use [`Self::insert_if_new`].
|
||||||
pub fn try_insert_if_new(&mut self, bundle: impl Bundle) -> &mut Self {
|
pub fn try_insert_if_new(&mut self, bundle: impl Bundle) -> &mut Self {
|
||||||
self.queue(try_insert(bundle, InsertMode::Keep))
|
self.queue(try_insert(bundle, InsertMode::Keep))
|
||||||
}
|
}
|
||||||
|
@ -1731,7 +1735,7 @@ impl<'a> EntityCommands<'a> {
|
||||||
/// Despawns the entity.
|
/// Despawns the entity.
|
||||||
///
|
///
|
||||||
/// [`Self::despawn`] used to warn if the entity was missing, and this was the silent version.
|
/// [`Self::despawn`] used to warn if the entity was missing, and this was the silent version.
|
||||||
/// `EntityCommands` no longer need to handle missing entities individually, so just use [`Self::despawn`]
|
/// `EntityCommands` no longer need to handle missing entities individually, so just use [`Self::despawn`].
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn try_despawn(&mut self) {
|
pub fn try_despawn(&mut self) {
|
||||||
self.queue(try_despawn());
|
self.queue(try_despawn());
|
||||||
|
@ -1755,7 +1759,7 @@ impl<'a> EntityCommands<'a> {
|
||||||
/// ```
|
/// ```
|
||||||
pub fn queue<M: 'static>(&mut self, command: impl EntityCommand<M>) -> &mut Self {
|
pub fn queue<M: 'static>(&mut self, command: impl EntityCommand<M>) -> &mut Self {
|
||||||
self.commands
|
self.commands
|
||||||
.queue(command.with_entity(self.entity, self.commands.failure_mode));
|
.queue(command.with_entity(self.entity, self.commands.failure_handling_mode));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1843,7 +1847,8 @@ pub struct EntityEntryCommands<'a, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Component> EntityEntryCommands<'a, T> {
|
impl<'a, T: Component> EntityEntryCommands<'a, T> {
|
||||||
/// Sets the [`EntityEntryCommands`] instance to ignore commands if the entity doesn't exist.
|
/// Sets the [`EntityEntryCommands`] instance to ignore commands if the entity doesn't exist
|
||||||
|
/// when a command is executed.
|
||||||
///
|
///
|
||||||
/// # See also:
|
/// # See also:
|
||||||
/// - [`log_if_missing`](Self::log_if_missing) (default)
|
/// - [`log_if_missing`](Self::log_if_missing) (default)
|
||||||
|
@ -1854,7 +1859,8 @@ impl<'a, T: Component> EntityEntryCommands<'a, T> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the [`EntityEntryCommands`] instance to log if the entity doesn't exist when a command is executed.
|
/// Sets the [`EntityEntryCommands`] instance to log if the entity doesn't exist
|
||||||
|
/// when a command is executed.
|
||||||
///
|
///
|
||||||
/// This is the default setting.
|
/// This is the default setting.
|
||||||
///
|
///
|
||||||
|
@ -1867,7 +1873,8 @@ impl<'a, T: Component> EntityEntryCommands<'a, T> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the [`EntityEntryCommands`] instance to warn if the entity doesn't exist when a command is executed.
|
/// Sets the [`EntityEntryCommands`] instance to warn if the entity doesn't exist
|
||||||
|
/// when a command is executed.
|
||||||
///
|
///
|
||||||
/// # See also:
|
/// # See also:
|
||||||
/// - [`ignore_if_missing`](Self::ignore_if_missing)
|
/// - [`ignore_if_missing`](Self::ignore_if_missing)
|
||||||
|
@ -1878,7 +1885,8 @@ impl<'a, T: Component> EntityEntryCommands<'a, T> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the [`EntityEntryCommands`] instance to panic if the entity doesn't exist when a command is executed.
|
/// Sets the [`EntityEntryCommands`] instance to panic if the entity doesn't exist
|
||||||
|
/// when a command is executed.
|
||||||
///
|
///
|
||||||
/// # See also:
|
/// # See also:
|
||||||
/// - [`ignore_if_missing`](Self::ignore_if_missing)
|
/// - [`ignore_if_missing`](Self::ignore_if_missing)
|
||||||
|
@ -1913,7 +1921,7 @@ impl<'a, T: Component> EntityEntryCommands<'a, T> {
|
||||||
/// [Insert](EntityCommands::insert) `default` into this entity, if `T` is not already present.
|
/// [Insert](EntityCommands::insert) `default` into this entity, if `T` is not already present.
|
||||||
///
|
///
|
||||||
/// [`Self::or_insert`] used to panic if the entity was missing, and this was the non-panicking version.
|
/// [`Self::or_insert`] used to panic if the entity was missing, and this was the non-panicking version.
|
||||||
/// `EntityCommands` no longer need to handle missing entities individually, so just use [`Self::or_insert`]
|
/// `EntityCommands` no longer need to handle missing entities individually, so just use [`Self::or_insert`].
|
||||||
///
|
///
|
||||||
/// See also [`or_insert_with`](Self::or_insert_with).
|
/// See also [`or_insert_with`](Self::or_insert_with).
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
|
@ -1934,7 +1942,7 @@ impl<'a, T: Component> EntityEntryCommands<'a, T> {
|
||||||
/// [Insert](EntityCommands::insert) the value returned from `default` into this entity, if `T` is not already present.
|
/// [Insert](EntityCommands::insert) the value returned from `default` into this entity, if `T` is not already present.
|
||||||
///
|
///
|
||||||
/// [`Self::or_insert_with`] used to panic if the entity was missing, and this was the non-panicking version.
|
/// [`Self::or_insert_with`] used to panic if the entity was missing, and this was the non-panicking version.
|
||||||
/// `EntityCommands` no longer need to handle missing entities individually, so just use [`Self::or_insert_with`]
|
/// `EntityCommands` no longer need to handle missing entities individually, so just use [`Self::or_insert_with`].
|
||||||
///
|
///
|
||||||
/// See also [`or_insert`](Self::or_insert) and [`or_try_insert`](Self::or_try_insert).
|
/// See also [`or_insert`](Self::or_insert) and [`or_try_insert`](Self::or_try_insert).
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
|
@ -2045,11 +2053,12 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [`Command`] that consumes an iterator to add a series of [`Bundles`](Bundle) to a set of entities.
|
/// A [`Command`] that consumes an iterator to add a series of [`Bundles`](Bundle) to a set of entities.
|
||||||
/// If any entities do not exist in the world, this command will fail according to `failure_mode`.
|
/// If any entities do not exist in the world, this command will fail according to
|
||||||
|
/// `failure_handling_mode`.
|
||||||
///
|
///
|
||||||
/// This is more efficient than inserting the bundles individually.
|
/// This is more efficient than inserting the bundles individually.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn insert_batch<I, B>(batch: I, failure_mode: FailureMode) -> impl Command
|
fn insert_batch<I, B>(batch: I, failure_handling_mode: FailureHandlingMode) -> impl Command
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
|
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
|
||||||
B: Bundle,
|
B: Bundle,
|
||||||
|
@ -2060,7 +2069,7 @@ where
|
||||||
world.insert_batch_with_caller(
|
world.insert_batch_with_caller(
|
||||||
batch,
|
batch,
|
||||||
InsertMode::Replace,
|
InsertMode::Replace,
|
||||||
failure_mode,
|
failure_handling_mode,
|
||||||
#[cfg(feature = "track_change_detection")]
|
#[cfg(feature = "track_change_detection")]
|
||||||
caller,
|
caller,
|
||||||
);
|
);
|
||||||
|
@ -2068,11 +2077,12 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [`Command`] that consumes an iterator to add a series of [`Bundles`](Bundle) to a set of entities.
|
/// A [`Command`] that consumes an iterator to add a series of [`Bundles`](Bundle) to a set of entities.
|
||||||
/// If any entities do not exist in the world, this command will fail according to `failure_mode`.
|
/// If any entities do not exist in the world, this command will fail according to
|
||||||
|
/// `failure_handling_mode`.
|
||||||
///
|
///
|
||||||
/// This is more efficient than inserting the bundles individually.
|
/// This is more efficient than inserting the bundles individually.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn insert_batch_if_new<I, B>(batch: I, failure_mode: FailureMode) -> impl Command
|
fn insert_batch_if_new<I, B>(batch: I, failure_handling_mode: FailureHandlingMode) -> impl Command
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
|
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
|
||||||
B: Bundle,
|
B: Bundle,
|
||||||
|
@ -2083,7 +2093,7 @@ where
|
||||||
world.insert_batch_with_caller(
|
world.insert_batch_with_caller(
|
||||||
batch,
|
batch,
|
||||||
InsertMode::Keep,
|
InsertMode::Keep,
|
||||||
failure_mode,
|
failure_handling_mode,
|
||||||
#[cfg(feature = "track_change_detection")]
|
#[cfg(feature = "track_change_detection")]
|
||||||
caller,
|
caller,
|
||||||
);
|
);
|
||||||
|
|
|
@ -2491,7 +2491,7 @@ impl World {
|
||||||
self.insert_batch_with_caller(
|
self.insert_batch_with_caller(
|
||||||
batch,
|
batch,
|
||||||
InsertMode::Replace,
|
InsertMode::Replace,
|
||||||
FailureMode::Panic,
|
FailureHandlingMode::Panic,
|
||||||
#[cfg(feature = "track_change_detection")]
|
#[cfg(feature = "track_change_detection")]
|
||||||
Location::caller(),
|
Location::caller(),
|
||||||
);
|
);
|
||||||
|
@ -2522,7 +2522,7 @@ impl World {
|
||||||
self.insert_batch_with_caller(
|
self.insert_batch_with_caller(
|
||||||
batch,
|
batch,
|
||||||
InsertMode::Keep,
|
InsertMode::Keep,
|
||||||
FailureMode::Panic,
|
FailureHandlingMode::Panic,
|
||||||
#[cfg(feature = "track_change_detection")]
|
#[cfg(feature = "track_change_detection")]
|
||||||
Location::caller(),
|
Location::caller(),
|
||||||
);
|
);
|
||||||
|
@ -2540,7 +2540,7 @@ impl World {
|
||||||
&mut self,
|
&mut self,
|
||||||
iter: I,
|
iter: I,
|
||||||
insert_mode: InsertMode,
|
insert_mode: InsertMode,
|
||||||
failure_mode: FailureMode,
|
failure_handling_mode: FailureHandlingMode,
|
||||||
#[cfg(feature = "track_change_detection")] caller: &'static Location,
|
#[cfg(feature = "track_change_detection")] caller: &'static Location,
|
||||||
) where
|
) where
|
||||||
I: IntoIterator,
|
I: IntoIterator,
|
||||||
|
@ -2561,20 +2561,20 @@ impl World {
|
||||||
}
|
}
|
||||||
|
|
||||||
let insert_batch_fail = |entity: Entity| {
|
let insert_batch_fail = |entity: Entity| {
|
||||||
match failure_mode {
|
match failure_handling_mode {
|
||||||
FailureMode::Ignore => (),
|
FailureHandlingMode::Ignore => (),
|
||||||
FailureMode::Log => info!(
|
FailureHandlingMode::Log => info!(
|
||||||
"error[B0003]: Could not insert a bundle (of type `{}`) for entity {:?} because it doesn't exist in this World. See: https://bevyengine.org/learn/errors/b0003",
|
"error[B0003]: Could not insert a bundle (of type `{}`) for entity {} because it doesn't exist in this World. See: https://bevyengine.org/learn/errors/b0003",
|
||||||
core::any::type_name::<B>(),
|
core::any::type_name::<B>(),
|
||||||
entity,
|
entity,
|
||||||
),
|
),
|
||||||
FailureMode::Warn => warn!(
|
FailureHandlingMode::Warn => warn!(
|
||||||
"error[B0003]: Could not insert a bundle (of type `{}`) for entity {:?} because it doesn't exist in this World. See: https://bevyengine.org/learn/errors/b0003",
|
"error[B0003]: Could not insert a bundle (of type `{}`) for entity {} because it doesn't exist in this World. See: https://bevyengine.org/learn/errors/b0003",
|
||||||
core::any::type_name::<B>(),
|
core::any::type_name::<B>(),
|
||||||
entity,
|
entity,
|
||||||
),
|
),
|
||||||
FailureMode::Panic => panic!(
|
FailureHandlingMode::Panic => panic!(
|
||||||
"error[B0003]: Could not insert a bundle (of type `{}`) for entity {:?} because it doesn't exist in this World. See: https://bevyengine.org/learn/errors/b0003",
|
"error[B0003]: Could not insert a bundle (of type `{}`) for entity {} because it doesn't exist in this World. See: https://bevyengine.org/learn/errors/b0003",
|
||||||
core::any::type_name::<B>(),
|
core::any::type_name::<B>(),
|
||||||
entity,
|
entity,
|
||||||
),
|
),
|
||||||
|
@ -3812,7 +3812,7 @@ impl<T: Default> FromWorld for T {
|
||||||
|
|
||||||
/// How to respond if a function fails
|
/// How to respond if a function fails
|
||||||
#[derive(Default, Clone, Copy, PartialEq, Eq)]
|
#[derive(Default, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum FailureMode {
|
pub enum FailureHandlingMode {
|
||||||
/// Do nothing
|
/// Do nothing
|
||||||
Ignore,
|
Ignore,
|
||||||
/// Send a benign message to the log
|
/// Send a benign message to the log
|
||||||
|
|
Loading…
Reference in a new issue