Guard editor shutdown and track clean savepoints

This commit is contained in:
Rbanh committed 2026-07-13 05:12:43 -04:00
1 parent 62b538999d
commit 4b33f32357
19 files changed
+1944 -129

No files matched your search

+33 -7
View File
@@ -6,7 +6,7 @@ use bevy::app::PluginGroupBuilder;
use bevy::asset::AssetPlugin;
use bevy::log::{LogPlugin, DEFAULT_FILTER};
use bevy::prelude::*;
use bevy::window::{CompositeAlphaMode, PresentMode, WindowMode, WindowPlugin};
use bevy::window::{CompositeAlphaMode, ExitCondition, PresentMode, WindowMode, WindowPlugin};
/// Runtime switch for the HDR camera pass.
///
@@ -40,6 +40,27 @@ fn find_assets_directory(start: Option<PathBuf>) -> Option<String> {
}
pub fn default_plugins(title: impl Into<String>) -> PluginGroupBuilder {
configured_plugins(WindowPlugin {
primary_window: Some(primary_window(title)),
..default()
})
}
/// Default plugins for the editor, whose shutdown coordinator owns window-close handling.
pub fn editor_plugins(title: impl Into<String>) -> PluginGroupBuilder {
configured_plugins(editor_window_plugin(title))
}
fn editor_window_plugin(title: impl Into<String>) -> WindowPlugin {
WindowPlugin {
primary_window: Some(primary_window(title)),
exit_condition: ExitCondition::DontExit,
close_when_requested: false,
..default()
}
}
fn configured_plugins(window_plugin: WindowPlugin) -> PluginGroupBuilder {
DefaultPlugins
.set(LogPlugin {
// Blacksite intentionally replaces Bevy's `.scn.ron` loader with a
@@ -48,10 +69,7 @@ pub fn default_plugins(title: impl Into<String>) -> PluginGroupBuilder {
filter: format!("{DEFAULT_FILTER}bevy_asset::server::loaders=error"),
..default()
})
.set(WindowPlugin {
primary_window: Some(primary_window(title)),
..default()
})
.set(window_plugin)
.set(AssetPlugin {
file_path: resolve_assets_directory(),
..default()
@@ -86,8 +104,8 @@ pub fn hdr_enabled_from_env() -> bool {
#[cfg(test)]
mod tests {
use super::{primary_window, resolve_assets_directory};
use bevy::window::CompositeAlphaMode;
use super::{editor_window_plugin, primary_window, resolve_assets_directory};
use bevy::window::{CompositeAlphaMode, ExitCondition};
#[test]
fn primary_window_is_opaque() {
@@ -97,6 +115,14 @@ mod tests {
assert_eq!(window.composite_alpha_mode, CompositeAlphaMode::Opaque);
}
#[test]
fn editor_window_defers_close_and_exit_to_the_editor() {
let plugin = editor_window_plugin("test");
assert!(!plugin.close_when_requested);
assert!(matches!(plugin.exit_condition, ExitCondition::DontExit));
}
#[test]
fn resolve_assets_directory_finds_workspace_assets() {
let cwd = std::env::current_dir().expect("cwd");