Add editor sample regression pack
This commit is contained in:
1 parent
c55f34780f
commit
06010c5922
31 files changed
+3258
-110
No files matched your search
@@ -27,6 +27,7 @@ pub use project::diagnostics_bundle;
|
||||
pub use project::launcher;
|
||||
pub use project::native_dialog;
|
||||
pub use project::project_io;
|
||||
pub use project::samples;
|
||||
pub use project::session;
|
||||
pub use project::settings_ui;
|
||||
pub use scene::scene_io;
|
||||
@@ -74,6 +75,7 @@ use play::audio_preview::AudioPreviewPlugin;
|
||||
use play::PlaySessionPlugin;
|
||||
use project::collaboration::CollaborationPlugin;
|
||||
use project::native_dialog::NativeDialogPlugin;
|
||||
use project::samples::SampleCatalogPlugin;
|
||||
use project_io::ProjectIoPlugin;
|
||||
use render_view::RenderViewPlugin;
|
||||
use scene_io::SceneIoPlugin;
|
||||
@@ -98,6 +100,7 @@ impl PluginGroup for EditorPluginGroup {
|
||||
let group = PluginGroupBuilder::start::<Self>()
|
||||
.add(EditorInfraPlugin)
|
||||
.add(ProjectIoPlugin)
|
||||
.add(SampleCatalogPlugin)
|
||||
.add(NativeDialogPlugin)
|
||||
.add(scene_schema::SceneSchemaPlugin)
|
||||
.add(net_editor::NetEditorPlugin)
|
||||
|
||||
@@ -5,5 +5,6 @@ pub mod diagnostics_bundle;
|
||||
pub mod launcher;
|
||||
pub mod native_dialog;
|
||||
pub mod project_io;
|
||||
pub mod samples;
|
||||
pub mod session;
|
||||
pub mod settings_ui;
|
||||
@@ -0,0 +1,208 @@
|
||||
//! Cached project sample catalog used by editor scene-opening UI.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use bevy::prelude::*;
|
||||
use scene::sample_pack::{
|
||||
validate_editor_sample_pack, EditorSampleEntry, EDITOR_SAMPLE_MANIFEST_PATH,
|
||||
};
|
||||
|
||||
use super::project_io::ProjectWorkspace;
|
||||
|
||||
const VALIDATION_HINT: &str = "Run `cargo validate-samples --project .` for details.";
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct SampleCatalogEntry {
|
||||
pub id: String,
|
||||
pub label: String,
|
||||
pub scene_path: PathBuf,
|
||||
pub project_relative_scene: String,
|
||||
pub summary: String,
|
||||
pub checks: Vec<String>,
|
||||
}
|
||||
|
||||
impl SampleCatalogEntry {
|
||||
pub fn hover_text(&self) -> String {
|
||||
let mut lines = vec![self.summary.clone()];
|
||||
if !self.checks.is_empty() {
|
||||
lines.push(format!("Checks: {}", self.checks.join(", ")));
|
||||
}
|
||||
lines.push(self.project_relative_scene.clone());
|
||||
lines.join("\n")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Debug, Clone)]
|
||||
pub struct SampleCatalog {
|
||||
entries: Vec<SampleCatalogEntry>,
|
||||
unavailable_reason: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for SampleCatalog {
|
||||
fn default() -> Self {
|
||||
Self::unavailable("Sample catalog is loading")
|
||||
}
|
||||
}
|
||||
|
||||
impl SampleCatalog {
|
||||
pub fn entries(&self) -> &[SampleCatalogEntry] {
|
||||
&self.entries
|
||||
}
|
||||
|
||||
pub fn entry(&self, stable_id: &str) -> Option<&SampleCatalogEntry> {
|
||||
self.unavailable_reason
|
||||
.is_none()
|
||||
.then(|| self.entries.iter().find(|entry| entry.id == stable_id))
|
||||
.flatten()
|
||||
}
|
||||
|
||||
pub fn unavailable_reason(&self) -> Option<&str> {
|
||||
self.unavailable_reason.as_deref()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn available_entries(entries: Vec<SampleCatalogEntry>) -> Self {
|
||||
Self {
|
||||
entries,
|
||||
unavailable_reason: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn available(samples: Vec<EditorSampleEntry>) -> Self {
|
||||
Self {
|
||||
entries: samples.into_iter().map(catalog_entry).collect(),
|
||||
unavailable_reason: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn unavailable(reason: impl Into<String>) -> Self {
|
||||
Self {
|
||||
entries: Vec::new(),
|
||||
unavailable_reason: Some(reason.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn catalog_entry(entry: EditorSampleEntry) -> SampleCatalogEntry {
|
||||
SampleCatalogEntry {
|
||||
id: entry.id,
|
||||
label: entry.label,
|
||||
scene_path: PathBuf::from(&entry.scene),
|
||||
project_relative_scene: entry.scene,
|
||||
summary: entry.summary,
|
||||
checks: entry.checks,
|
||||
}
|
||||
}
|
||||
|
||||
fn load_catalog(project_root: &Path) -> SampleCatalog {
|
||||
let validation = validate_editor_sample_pack(project_root);
|
||||
if !validation.is_release_ready() {
|
||||
let first_error = validation
|
||||
.report
|
||||
.findings
|
||||
.iter()
|
||||
.find(|finding| finding.severity == scene::ValidationSeverity::Error)
|
||||
.map(|finding| finding.message.as_str())
|
||||
.unwrap_or("sample pack validation failed");
|
||||
return SampleCatalog::unavailable(format!(
|
||||
"Sample manifest `{EDITOR_SAMPLE_MANIFEST_PATH}` is invalid: {first_error}\n{VALIDATION_HINT}"
|
||||
));
|
||||
}
|
||||
if validation.samples.is_empty() {
|
||||
return SampleCatalog::unavailable(format!(
|
||||
"Sample manifest contains no scenes.\n{VALIDATION_HINT}"
|
||||
));
|
||||
}
|
||||
SampleCatalog::available(validation.samples)
|
||||
}
|
||||
|
||||
fn load_sample_catalog(world: &mut World) {
|
||||
let project_root = PathBuf::from(&world.resource::<ProjectWorkspace>().root);
|
||||
world.insert_resource(load_catalog(&project_root));
|
||||
}
|
||||
|
||||
pub struct SampleCatalogPlugin;
|
||||
|
||||
impl Plugin for SampleCatalogPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_resource::<SampleCatalog>()
|
||||
.add_systems(Startup, load_sample_catalog);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use scene::sample_pack::EditorSampleArea;
|
||||
|
||||
fn sample(id: &str, label: &str, scene: &str) -> EditorSampleEntry {
|
||||
EditorSampleEntry {
|
||||
id: id.into(),
|
||||
label: label.into(),
|
||||
area: EditorSampleArea::Brush,
|
||||
scene: scene.into(),
|
||||
summary: format!("Summary for {label}"),
|
||||
checks: vec!["selection".into(), "undo".into()],
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn available_catalog_preserves_manifest_order_and_resolves_paths() {
|
||||
let catalog = SampleCatalog::available(vec![
|
||||
sample(
|
||||
"terrain",
|
||||
"Terrain",
|
||||
"assets/levels/samples/terrain.scn.ron",
|
||||
),
|
||||
sample("brush", "Brush", "assets/levels/samples/brush.scn.ron"),
|
||||
]);
|
||||
|
||||
assert_eq!(
|
||||
catalog
|
||||
.entries()
|
||||
.iter()
|
||||
.map(|entry| entry.id.as_str())
|
||||
.collect::<Vec<_>>(),
|
||||
vec!["terrain", "brush"]
|
||||
);
|
||||
assert_eq!(
|
||||
catalog.entry("brush").unwrap().scene_path,
|
||||
PathBuf::from("assets/levels/samples/brush.scn.ron")
|
||||
);
|
||||
let hover = catalog.entry("brush").unwrap().hover_text();
|
||||
assert!(hover.contains("Summary for Brush"));
|
||||
assert!(hover.contains("Checks: selection, undo"));
|
||||
assert!(hover.contains("assets/levels/samples/brush.scn.ron"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unavailable_catalog_never_resolves_entries() {
|
||||
let catalog = SampleCatalog {
|
||||
entries: vec![catalog_entry(sample(
|
||||
"brush",
|
||||
"Brush",
|
||||
"assets/levels/samples/brush.scn.ron",
|
||||
))],
|
||||
unavailable_reason: Some("manifest invalid".into()),
|
||||
};
|
||||
|
||||
assert!(catalog.entry("brush").is_none());
|
||||
assert_eq!(catalog.unavailable_reason(), Some("manifest invalid"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_manifest_reports_repair_command() {
|
||||
let root = std::env::temp_dir().join(format!(
|
||||
"blacksite-missing-sample-catalog-{}",
|
||||
uuid::Uuid::new_v4()
|
||||
));
|
||||
std::fs::create_dir_all(&root).unwrap();
|
||||
|
||||
let catalog = load_catalog(&root);
|
||||
|
||||
let reason = catalog.unavailable_reason().unwrap();
|
||||
assert!(reason.contains(EDITOR_SAMPLE_MANIFEST_PATH));
|
||||
assert!(reason.contains("cargo validate-samples --project ."));
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ use crate::assets::{import_external_assets, EditorAssets, IMPORTABLE_ASSET_EXTEN
|
||||
use crate::history::{clear_level_objects, snapshot_entity, EditorHistory};
|
||||
use crate::native_dialog::NativeDialogBroker;
|
||||
use crate::project::collaboration::{publish_authored_file, FileSnapshot, FileWriteIntent};
|
||||
use crate::project::samples::SampleCatalog;
|
||||
use crate::scene::recovery::{
|
||||
default_state_root, discard_recovery_snapshots, latest_recovery_snapshot,
|
||||
write_recovery_snapshot,
|
||||
@@ -49,6 +50,7 @@ pub enum SceneIoRequest {
|
||||
SaveRecoveryCopyAs,
|
||||
DiscardRecovery,
|
||||
OpenRecent(usize),
|
||||
OpenSample(String),
|
||||
OpenPath(PathBuf),
|
||||
SwitchTab(usize),
|
||||
CloseTab(usize),
|
||||
@@ -313,6 +315,7 @@ fn process_scene_io_requests(world: &mut World) {
|
||||
SceneIoRequest::SaveRecoveryCopyAs => save_recovery_copy_with_dialog(world),
|
||||
SceneIoRequest::DiscardRecovery => discard_recovery(world),
|
||||
SceneIoRequest::OpenRecent(index) => open_recent(world, index),
|
||||
SceneIoRequest::OpenSample(stable_id) => open_sample(world, &stable_id),
|
||||
SceneIoRequest::OpenPath(path) => open_path(world, path),
|
||||
SceneIoRequest::SwitchTab(index) => switch_scene_tab(world, index),
|
||||
SceneIoRequest::CloseTab(index) => close_scene_tab(world, index),
|
||||
@@ -377,13 +380,72 @@ fn open_recent(world: &mut World, index: usize) -> String {
|
||||
open_path(world, path)
|
||||
}
|
||||
|
||||
fn open_sample(world: &mut World, stable_id: &str) -> String {
|
||||
let catalog_state = {
|
||||
let catalog = world.resource::<SampleCatalog>();
|
||||
(
|
||||
catalog.entry(stable_id).cloned(),
|
||||
catalog.unavailable_reason().map(str::to_string),
|
||||
)
|
||||
};
|
||||
match catalog_state {
|
||||
(Some(entry), _) => open_path(world, entry.scene_path),
|
||||
(None, Some(reason)) => format!("Open sample failed: {reason}"),
|
||||
(None, None) => format!("Open sample failed: unknown sample ID `{stable_id}`"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Comparison-only key. Stored paths remain unchanged because recovery and bookmarks use them.
|
||||
fn scene_path_identity(project_root: &Path, path: &Path) -> PathBuf {
|
||||
let candidate = if path.is_absolute() {
|
||||
path.to_path_buf()
|
||||
} else {
|
||||
project_root.join(path)
|
||||
};
|
||||
candidate.canonicalize().unwrap_or(candidate)
|
||||
}
|
||||
|
||||
fn scene_paths_share_identity(project_root: &Path, first: &Path, second: &Path) -> bool {
|
||||
scene_path_identity(project_root, first) == scene_path_identity(project_root, second)
|
||||
}
|
||||
|
||||
fn remember_persisted_scene_path(
|
||||
preferences: &mut crate::project_io::UserPreferences,
|
||||
project_root: &Path,
|
||||
path: &Path,
|
||||
) {
|
||||
preferences
|
||||
.recent_levels
|
||||
.retain(|recent| !scene_paths_share_identity(project_root, Path::new(recent), path));
|
||||
preferences
|
||||
.recent_levels
|
||||
.insert(0, path.display().to_string());
|
||||
preferences.recent_levels.truncate(8);
|
||||
}
|
||||
|
||||
fn open_path(world: &mut World, path: PathBuf) -> String {
|
||||
if let Some(index) = world
|
||||
.resource::<SceneIo>()
|
||||
.tabs
|
||||
.iter()
|
||||
.position(|tab| tab.path.as_ref() == Some(&path))
|
||||
{
|
||||
let project_root = PathBuf::from(
|
||||
world
|
||||
.resource::<crate::project_io::ProjectWorkspace>()
|
||||
.root
|
||||
.clone(),
|
||||
);
|
||||
let Ok(project_root) = project_root.canonicalize() else {
|
||||
return format!(
|
||||
"Open failed: could not resolve project root {}",
|
||||
project_root.display()
|
||||
);
|
||||
};
|
||||
let matching_tab = world.resource::<SceneIo>().tabs.iter().position(|tab| {
|
||||
tab.path
|
||||
.as_deref()
|
||||
.is_some_and(|tab_path| scene_paths_share_identity(&project_root, tab_path, &path))
|
||||
});
|
||||
if let Some(index) = matching_tab {
|
||||
let established_path = world.resource::<SceneIo>().tabs[index].path.clone();
|
||||
if let Some(established_path) = established_path {
|
||||
remember_path(world, established_path);
|
||||
}
|
||||
return switch_scene_tab(world, index);
|
||||
}
|
||||
if let Err(error) = capture_active_tab(world) {
|
||||
@@ -2160,15 +2222,24 @@ fn backfill_missing_actor_kinds(world: &mut World) {
|
||||
}
|
||||
|
||||
fn remember_path(world: &mut World, path: PathBuf) {
|
||||
let mut io = world.resource_mut::<SceneIo>();
|
||||
io.recent_paths.retain(|recent| recent != &path);
|
||||
io.recent_paths.insert(0, path.clone());
|
||||
io.recent_paths.truncate(8);
|
||||
let configured_root = PathBuf::from(
|
||||
world
|
||||
.resource::<crate::project_io::ProjectWorkspace>()
|
||||
.root
|
||||
.clone(),
|
||||
);
|
||||
let project_root = configured_root.canonicalize().unwrap_or(configured_root);
|
||||
{
|
||||
let mut io = world.resource_mut::<SceneIo>();
|
||||
io.recent_paths
|
||||
.retain(|recent| !scene_paths_share_identity(&project_root, recent, &path));
|
||||
io.recent_paths.insert(0, path.clone());
|
||||
io.recent_paths.truncate(8);
|
||||
}
|
||||
|
||||
if world.contains_resource::<crate::project_io::UserPreferences>() {
|
||||
let path_label = path.display().to_string();
|
||||
let mut prefs = world.resource_mut::<crate::project_io::UserPreferences>();
|
||||
crate::project_io::push_recent(&mut prefs.recent_levels, path_label, 8);
|
||||
remember_persisted_scene_path(&mut prefs, &project_root, &path);
|
||||
if let Err(error) = crate::project_io::write_user_preferences(&prefs) {
|
||||
warn!("Failed to save editor preferences: {error}");
|
||||
}
|
||||
@@ -3168,6 +3239,258 @@ mod tests {
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_sample_id_does_not_change_scene_state() {
|
||||
let known = crate::project::samples::SampleCatalogEntry {
|
||||
id: "known".into(),
|
||||
label: "Known Sample".into(),
|
||||
scene_path: PathBuf::from("assets/levels/samples/known.scn.ron"),
|
||||
project_relative_scene: "assets/levels/samples/known.scn.ron".into(),
|
||||
summary: "Known fixture".into(),
|
||||
checks: vec!["opens".into()],
|
||||
};
|
||||
let mut world = World::new();
|
||||
world.init_resource::<SceneIo>();
|
||||
world.insert_resource(SampleCatalog::available_entries(vec![known]));
|
||||
let original_tab_id = world.resource::<SceneIo>().tabs[0].id;
|
||||
|
||||
let status = open_sample(&mut world, "missing");
|
||||
|
||||
assert_eq!(status, "Open sample failed: unknown sample ID `missing`");
|
||||
let io = world.resource::<SceneIo>();
|
||||
assert_eq!(io.tabs.len(), 1);
|
||||
assert_eq!(io.tabs[0].id, original_tab_id);
|
||||
assert_eq!(io.active_path, None);
|
||||
assert!(!io.dirty);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn in_project_absolute_and_relative_scene_paths_share_one_canonical_key() {
|
||||
let root = std::env::temp_dir().join(format!(
|
||||
"blacksite-scene-path-identity-{}",
|
||||
uuid::Uuid::new_v4()
|
||||
));
|
||||
let scene = root.join("assets/levels/samples/alias.scn.ron");
|
||||
std::fs::create_dir_all(scene.parent().unwrap()).unwrap();
|
||||
std::fs::write(&scene, "(schema_version: 4, resources: {}, entities: {})").unwrap();
|
||||
let root = root.canonicalize().unwrap();
|
||||
|
||||
let expected = scene.canonicalize().unwrap();
|
||||
assert_eq!(scene_path_identity(&root, &scene), expected);
|
||||
assert_eq!(
|
||||
scene_path_identity(&root, Path::new("assets/levels/./samples/alias.scn.ron")),
|
||||
expected
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relative_and_absolute_scene_aliases_do_not_create_a_second_tab() {
|
||||
let root = std::env::temp_dir().join(format!(
|
||||
"blacksite-scene-tab-alias-{}",
|
||||
uuid::Uuid::new_v4()
|
||||
));
|
||||
let relative = PathBuf::from("assets/levels/samples/alias.scn.ron");
|
||||
let absolute = root.join(&relative);
|
||||
std::fs::create_dir_all(absolute.parent().unwrap()).unwrap();
|
||||
std::fs::write(
|
||||
&absolute,
|
||||
"(schema_version: 4, resources: {}, entities: {})",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut world = World::new();
|
||||
world.init_resource::<SceneIo>();
|
||||
world.insert_resource(crate::project_io::ProjectWorkspace {
|
||||
root: root.display().to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
{
|
||||
let mut io = world.resource_mut::<SceneIo>();
|
||||
io.active_path = Some(relative.clone());
|
||||
io.tabs[0].path = Some(relative.clone());
|
||||
io.recent_paths = vec![absolute.clone(), relative.clone()];
|
||||
}
|
||||
|
||||
let status = open_path(&mut world, absolute.clone());
|
||||
|
||||
assert_eq!(status, "Scene tab is already active");
|
||||
let io = world.resource::<SceneIo>();
|
||||
assert_eq!(io.tabs.len(), 1);
|
||||
assert_eq!(io.tabs[0].path.as_ref(), Some(&relative));
|
||||
assert_eq!(io.active_path.as_ref(), Some(&relative));
|
||||
assert_eq!(io.recent_paths, vec![relative.clone()]);
|
||||
let mut preferences = crate::project_io::UserPreferences {
|
||||
recent_levels: vec![
|
||||
absolute.display().to_string(),
|
||||
relative.display().to_string(),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
remember_persisted_scene_path(&mut preferences, &root, &relative);
|
||||
assert_eq!(
|
||||
preferences.recent_levels,
|
||||
vec![relative.display().to_string()]
|
||||
);
|
||||
|
||||
let mut world = World::new();
|
||||
world.init_resource::<SceneIo>();
|
||||
world.insert_resource(crate::project_io::ProjectWorkspace {
|
||||
root: root.display().to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
{
|
||||
let mut io = world.resource_mut::<SceneIo>();
|
||||
io.active_path = Some(absolute.clone());
|
||||
io.tabs[0].path = Some(absolute.clone());
|
||||
}
|
||||
|
||||
let status = open_path(&mut world, relative.clone());
|
||||
|
||||
assert_eq!(status, "Scene tab is already active");
|
||||
let io = world.resource::<SceneIo>();
|
||||
assert_eq!(io.tabs.len(), 1);
|
||||
assert_eq!(io.tabs[0].path.as_ref(), Some(&absolute));
|
||||
assert_eq!(io.active_path.as_ref(), Some(&absolute));
|
||||
let mut preferences = crate::project_io::UserPreferences {
|
||||
recent_levels: vec![
|
||||
relative.display().to_string(),
|
||||
absolute.display().to_string(),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
remember_persisted_scene_path(&mut preferences, &root, &absolute);
|
||||
assert_eq!(
|
||||
preferences.recent_levels,
|
||||
vec![absolute.display().to_string()]
|
||||
);
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_open_preserves_recovery_generation_and_camera_bookmark_keys() {
|
||||
let root = std::env::temp_dir().join(format!(
|
||||
"blacksite-scene-alias-state-{}",
|
||||
uuid::Uuid::new_v4()
|
||||
));
|
||||
std::fs::create_dir_all(&root).unwrap();
|
||||
let root = root.canonicalize().unwrap();
|
||||
let relative = PathBuf::from("assets/levels/samples/stateful.scn.ron");
|
||||
let absolute = root.join(&relative);
|
||||
std::fs::create_dir_all(absolute.parent().unwrap()).unwrap();
|
||||
std::fs::write(
|
||||
&absolute,
|
||||
"(schema_version: 4, resources: {}, entities: {})",
|
||||
)
|
||||
.unwrap();
|
||||
let state_root = root.join("editor-state");
|
||||
let first_recovery =
|
||||
write_recovery_snapshot(&state_root, &root, &absolute, b"first", 5).unwrap();
|
||||
let bookmark = Transform::from_xyz(7.0, 11.0, 13.0);
|
||||
let bookmark_key = absolute.display().to_string();
|
||||
let mut bookmarks = crate::viewport::CameraBookmarks::default();
|
||||
crate::viewport::save_camera_bookmark(&mut bookmarks, &bookmark_key, bookmark);
|
||||
|
||||
let mut world = World::new();
|
||||
world.init_resource::<SceneIo>();
|
||||
world.insert_resource(crate::project_io::ProjectWorkspace {
|
||||
root: root.display().to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
world.insert_resource(bookmarks);
|
||||
{
|
||||
let mut io = world.resource_mut::<SceneIo>();
|
||||
io.active_path = Some(absolute.clone());
|
||||
io.recovery_snapshot = Some(first_recovery.clone());
|
||||
io.tabs[0].path = Some(absolute.clone());
|
||||
io.tabs[0].recovery_snapshot = Some(first_recovery.clone());
|
||||
}
|
||||
|
||||
let status = open_path(&mut world, relative);
|
||||
|
||||
assert_eq!(status, "Scene tab is already active");
|
||||
let active_path = world
|
||||
.resource::<SceneIo>()
|
||||
.active_path
|
||||
.clone()
|
||||
.expect("active path must remain established");
|
||||
assert_eq!(active_path, absolute);
|
||||
assert_eq!(
|
||||
world.resource::<SceneIo>().recovery_snapshot.as_ref(),
|
||||
Some(&first_recovery)
|
||||
);
|
||||
let second_recovery =
|
||||
write_recovery_snapshot(&state_root, &root, &active_path, b"second", 5).unwrap();
|
||||
assert_eq!(first_recovery.parent(), second_recovery.parent());
|
||||
let active_key = active_path.display().to_string();
|
||||
assert_eq!(
|
||||
crate::viewport::recall_camera_bookmark(
|
||||
world.resource::<crate::viewport::CameraBookmarks>(),
|
||||
&active_key,
|
||||
),
|
||||
Some(bookmark)
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outside_project_scene_keeps_its_absolute_identity() {
|
||||
let root = std::env::temp_dir().join(format!(
|
||||
"blacksite-scene-path-root-{}",
|
||||
uuid::Uuid::new_v4()
|
||||
));
|
||||
let outside = std::env::temp_dir().join(format!(
|
||||
"blacksite-outside-scene-{}.scn.ron",
|
||||
uuid::Uuid::new_v4()
|
||||
));
|
||||
std::fs::create_dir_all(&root).unwrap();
|
||||
std::fs::write(&outside, "(schema_version: 4, resources: {}, entities: {})").unwrap();
|
||||
let root = root.canonicalize().unwrap();
|
||||
let outside = outside.canonicalize().unwrap();
|
||||
|
||||
assert_eq!(scene_path_identity(&root, &outside), outside);
|
||||
|
||||
std::fs::remove_file(outside).unwrap();
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_manifest_sample_typed_deserializes_without_a_gpu() {
|
||||
let project_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../..")
|
||||
.canonicalize()
|
||||
.unwrap();
|
||||
let manifest = scene::sample_pack::load_editor_sample_manifest(&project_root).unwrap();
|
||||
assert!(!manifest.samples.is_empty());
|
||||
let mut app = App::new();
|
||||
app.add_plugins(MinimalPlugins)
|
||||
.add_plugins(AssetPlugin::default())
|
||||
.add_plugins(bevy::pbr::MaterialPlugin::<StandardMaterial>::default())
|
||||
.init_asset::<Mesh>()
|
||||
.add_plugins(shared::SharedTypesPlugin);
|
||||
|
||||
for sample in manifest.samples {
|
||||
let path = project_root.join(&sample.scene);
|
||||
let text = std::fs::read_to_string(&path)
|
||||
.unwrap_or_else(|error| panic!("could not read sample `{}`: {error}", sample.id));
|
||||
let document = SceneDocument::from_ron_text(&text).unwrap_or_else(|error| {
|
||||
panic!(
|
||||
"sample `{}` is not a valid scene document: {error}",
|
||||
sample.id
|
||||
)
|
||||
});
|
||||
let bevy_ron = strip_schema_version(document.normalized_ron()).unwrap();
|
||||
deserialize_dynamic_scene(app.world_mut(), &bevy_ron).unwrap_or_else(|error| {
|
||||
panic!(
|
||||
"sample `{}` failed typed deserialization: {error}",
|
||||
sample.id
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scene_io_event_log_is_bounded_and_classifies_failures() {
|
||||
let mut io = SceneIo::default();
|
||||
|
||||
@@ -6,6 +6,7 @@ use bevy_inspector_egui::bevy_inspector::hierarchy::SelectedEntities;
|
||||
use egui_dock::DockState;
|
||||
|
||||
use crate::history::{apply_command_redo, apply_command_undo, EditorHistory};
|
||||
use crate::project::samples::{SampleCatalog, SampleCatalogEntry};
|
||||
use crate::scene_io::{SceneIo, SceneIoRequest};
|
||||
use crate::settings_ui::{open_project_settings_panel, ProjectSettingsPanel};
|
||||
use crate::state::{EditorMode, PlayPaused};
|
||||
@@ -19,6 +20,19 @@ use super::layout::reset_and_save_layout;
|
||||
use super::widgets::menu_item;
|
||||
use super::EditorTab;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
enum SampleMenuModel {
|
||||
Available(Vec<SampleCatalogEntry>),
|
||||
Unavailable(String),
|
||||
}
|
||||
|
||||
fn sample_menu_model(catalog: &SampleCatalog) -> SampleMenuModel {
|
||||
match catalog.unavailable_reason() {
|
||||
Some(reason) => SampleMenuModel::Unavailable(reason.to_string()),
|
||||
None => SampleMenuModel::Available(catalog.entries().to_vec()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn top_menu_bar(
|
||||
world: &mut World,
|
||||
root_ui: &mut egui::Ui,
|
||||
@@ -37,6 +51,25 @@ pub fn top_menu_bar(
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::Open);
|
||||
ui.close();
|
||||
}
|
||||
let sample_menu = sample_menu_model(world.resource::<SampleCatalog>());
|
||||
ui.menu_button("Open Sample", |ui| match sample_menu {
|
||||
SampleMenuModel::Available(entries) => {
|
||||
for entry in entries {
|
||||
if menu_item(ui, &entry.label, None, true)
|
||||
.on_hover_text(entry.hover_text())
|
||||
.clicked()
|
||||
{
|
||||
world.resource_mut::<SceneIo>().request =
|
||||
Some(SceneIoRequest::OpenSample(entry.id));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
SampleMenuModel::Unavailable(reason) => {
|
||||
menu_item(ui, "Sample pack unavailable", None, false)
|
||||
.on_disabled_hover_text(reason);
|
||||
}
|
||||
});
|
||||
if menu_item(ui, "Save", Some("Ctrl+S"), true).clicked() {
|
||||
world.resource_mut::<SceneIo>().request = Some(SceneIoRequest::Save);
|
||||
ui.close();
|
||||
@@ -287,3 +320,50 @@ pub fn top_menu_bar(
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn entry(id: &str, label: &str) -> SampleCatalogEntry {
|
||||
SampleCatalogEntry {
|
||||
id: id.into(),
|
||||
label: label.into(),
|
||||
scene_path: PathBuf::from(format!("assets/levels/samples/{id}.scn.ron")),
|
||||
project_relative_scene: format!("assets/levels/samples/{id}.scn.ron"),
|
||||
summary: format!("{label} summary"),
|
||||
checks: vec![format!("{label} check")],
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sample_menu_preserves_catalog_order_and_hover_details() {
|
||||
let catalog = SampleCatalog::available_entries(vec![
|
||||
entry("material", "Material Lab"),
|
||||
entry("terrain", "Terrain Sculpt"),
|
||||
]);
|
||||
|
||||
let SampleMenuModel::Available(rows) = sample_menu_model(&catalog) else {
|
||||
panic!("valid catalog must produce actionable menu rows");
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
rows.iter().map(|row| row.id.as_str()).collect::<Vec<_>>(),
|
||||
vec!["material", "terrain"]
|
||||
);
|
||||
assert!(rows[0].hover_text().contains("Material Lab summary"));
|
||||
assert!(rows[0].hover_text().contains("Material Lab check"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unavailable_catalog_produces_one_disabled_explanation() {
|
||||
let catalog = SampleCatalog::default();
|
||||
|
||||
assert_eq!(
|
||||
sample_menu_model(&catalog),
|
||||
SampleMenuModel::Unavailable("Sample catalog is loading".into())
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user