Make AssetMetaCheck a field on the asset plugin (#13177)

# Objective

There's a TODO comment above the `AssetMetaCheck` enum mentioning this
should have been done in 0.13

## Solution

Do it in 0.14

## Testing

I've checked that all the asset tests compile. I've also run the
asset_processing and asset_settings tests and they both work.

---

## Changelog

### Changed
-
[`AssetMetaCheck`](https://docs.rs/bevy/latest/bevy/asset/enum.AssetMetaCheck.html)
is no longer a resource and is now a field on the
[`AssetPlugin`](https://docs.rs/bevy/latest/bevy/asset/struct.AssetPlugin.html).

## Migration Guide

Changes to how bevy handles asset meta files now need to be specified
when inserting the `AssetPlugin`.
This commit is contained in:
Brezak 2024-05-08 01:52:30 +02:00 committed by GitHub
parent 03f4cc5dde
commit 4350ad0bd1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -55,7 +55,6 @@ use bevy_app::{App, Last, Plugin, PreUpdate};
use bevy_ecs::{
reflect::AppTypeRegistry,
schedule::{IntoSystemConfigs, IntoSystemSetConfigs, SystemSet},
system::Resource,
world::FromWorld,
};
use bevy_reflect::{FromReflect, GetTypeRegistration, Reflect, TypePath};
@ -90,6 +89,8 @@ pub struct AssetPlugin {
pub watch_for_changes_override: Option<bool>,
/// The [`AssetMode`] to use for this server.
pub mode: AssetMode,
/// How/If asset meta files should be checked.
pub meta_check: AssetMetaCheck,
}
#[derive(Debug)]
@ -118,8 +119,7 @@ pub enum AssetMode {
/// Configures how / if meta files will be checked. If an asset's meta file is not checked, the default meta for the asset
/// will be used.
// TODO: To avoid breaking Bevy 0.12 users in 0.12.1, this is a Resource. In Bevy 0.13 this should be changed to a field on AssetPlugin (if it is still needed).
#[derive(Debug, Default, Clone, Resource)]
#[derive(Debug, Default, Clone)]
pub enum AssetMetaCheck {
/// Always check if assets have meta files. If the meta does not exist, the default meta will be used.
#[default]
@ -137,6 +137,7 @@ impl Default for AssetPlugin {
file_path: Self::DEFAULT_UNPROCESSED_FILE_PATH.to_string(),
processed_file_path: Self::DEFAULT_PROCESSED_FILE_PATH.to_string(),
watch_for_changes_override: None,
meta_check: AssetMetaCheck::default(),
}
}
}
@ -171,16 +172,11 @@ impl Plugin for AssetPlugin {
AssetMode::Unprocessed => {
let mut builders = app.world_mut().resource_mut::<AssetSourceBuilders>();
let sources = builders.build_sources(watch, false);
let meta_check = app
.world()
.get_resource::<AssetMetaCheck>()
.cloned()
.unwrap_or_else(AssetMetaCheck::default);
app.insert_resource(AssetServer::new_with_meta_check(
sources,
AssetServerMode::Unprocessed,
meta_check,
self.meta_check.clone(),
watch,
));
}