Skip to content

Commit

Permalink
Make public API consistent independent of enabled features
Browse files Browse the repository at this point in the history
  • Loading branch information
superdump committed Jan 15, 2022
1 parent 9a2f4ca commit 1cfdadf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
9 changes: 1 addition & 8 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,7 @@ mod test {
handle_to_path: Default::default(),
asset_lifecycles: Default::default(),
task_pool: Default::default(),
asset_io: Box::new(FileAssetIo::new(
asset_path,
#[cfg(all(
feature = "filesystem_watcher",
all(not(target_arch = "wasm32"), not(target_os = "android"))
))]
false,
)),
asset_io: Box::new(FileAssetIo::new(asset_path, false)),
}),
}
}
Expand Down
16 changes: 11 additions & 5 deletions crates/bevy_asset/src/io/file_asset_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,23 @@ pub struct FileAssetIo {
}

impl FileAssetIo {
pub fn new<P: AsRef<Path>>(
path: P,
#[cfg(feature = "filesystem_watcher")] watch_for_changes: bool,
) -> Self {
pub fn new<P: AsRef<Path>>(path: P, watch_for_changes: bool) -> Self {
let file_asset_io = FileAssetIo {
#[cfg(feature = "filesystem_watcher")]
filesystem_watcher: Default::default(),
root_path: Self::get_root_path().join(path.as_ref()),
};
#[cfg(feature = "filesystem_watcher")]
if watch_for_changes {
#[cfg(any(
not(feature = "filesystem_watcher"),
target_arch = "wasm32",
target_os = "android"
))]
panic!(
"Watch for changes requires the filesystem_watcher feature and cannot be used on \
wasm32 / android targets"
);
#[cfg(feature = "filesystem_watcher")]
file_asset_io.watch_for_changes().unwrap();
}
file_asset_io
Expand Down
16 changes: 3 additions & 13 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,15 @@ pub struct AssetPlugin;

pub struct AssetServerSettings {
pub asset_folder: String,
#[cfg(all(
feature = "filesystem_watcher",
all(not(target_arch = "wasm32"), not(target_os = "android"))
))]
/// Whether to watch for changes in asset files. Requires the `filesystem_watcher` feature,
/// and cannot be supported on the wasm32 arch nor android os.
pub watch_for_changes: bool,
}

impl Default for AssetServerSettings {
fn default() -> Self {
Self {
asset_folder: "assets".to_string(),
#[cfg(all(
feature = "filesystem_watcher",
all(not(target_arch = "wasm32"), not(target_os = "android"))
))]
watch_for_changes: false,
}
}
Expand All @@ -74,11 +68,7 @@ pub fn create_platform_default_asset_io(app: &mut App) -> Box<dyn AssetIo> {
.get_resource_or_insert_with(AssetServerSettings::default);

#[cfg(all(not(target_arch = "wasm32"), not(target_os = "android")))]
let source = FileAssetIo::new(
&settings.asset_folder,
#[cfg(feature = "filesystem_watcher")]
settings.watch_for_changes,
);
let source = FileAssetIo::new(&settings.asset_folder, settings.watch_for_changes);
#[cfg(target_arch = "wasm32")]
let source = WasmAssetIo::new(&settings.asset_folder);
#[cfg(target_os = "android")]
Expand Down

0 comments on commit 1cfdadf

Please sign in to comment.