Ship production navigation authoring workflow
This commit is contained in:
1 parent
0798aa5d57
commit
b4aa61e394
35 files changed
+3898
-602
No files matched your search
@@ -319,6 +319,7 @@ pub fn clear_level_objects(world: &mut World) {
|
||||
}
|
||||
|
||||
pub fn spawn_with_history(world: &mut World, mut snapshot: EditorEntitySnapshot) -> Entity {
|
||||
assign_missing_actor_ids(&mut snapshot);
|
||||
snapshot.hierarchy_sibling_index = next_sibling_index(world, None);
|
||||
let entity = spawn_snapshot(world, &snapshot);
|
||||
push_history(
|
||||
@@ -340,6 +341,9 @@ pub fn spawn_many_with_history(
|
||||
if snapshots.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
for snapshot in &mut snapshots {
|
||||
assign_missing_actor_ids(snapshot);
|
||||
}
|
||||
for (sibling_index, snapshot) in (next_sibling_index(world, None)..).zip(snapshots.iter_mut()) {
|
||||
snapshot.hierarchy_sibling_index = sibling_index;
|
||||
}
|
||||
@@ -421,12 +425,37 @@ pub fn duplicate_entities_with_history(world: &mut World, entities: &[Entity]) {
|
||||
}
|
||||
|
||||
fn assign_fresh_actor_ids(snapshot: &mut EditorEntitySnapshot) {
|
||||
snapshot.actor_id = Some(new_actor_id());
|
||||
let actor_id = new_actor_id();
|
||||
if let Some(bounds) = &mut snapshot.navigation_bounds {
|
||||
bounds.artifact_path = shared::navigation_artifact_path_for_actor(&actor_id.0);
|
||||
}
|
||||
snapshot.actor_id = Some(actor_id);
|
||||
for child in &mut snapshot.children {
|
||||
assign_fresh_actor_ids(child);
|
||||
}
|
||||
}
|
||||
|
||||
fn assign_missing_actor_ids(snapshot: &mut EditorEntitySnapshot) {
|
||||
let existing_actor_id = snapshot
|
||||
.actor_id
|
||||
.clone()
|
||||
.filter(|id| !id.0.trim().is_empty());
|
||||
let assigned_new_id = existing_actor_id.is_none();
|
||||
let actor_id = existing_actor_id.unwrap_or_else(new_actor_id);
|
||||
if let Some(bounds) = &mut snapshot.navigation_bounds {
|
||||
if assigned_new_id
|
||||
|| bounds.artifact_path == NavigationBounds::default().artifact_path
|
||||
|| shared::navigation_generated_artifact_path(&bounds.artifact_path).is_err()
|
||||
{
|
||||
bounds.artifact_path = shared::navigation_artifact_path_for_actor(&actor_id.0);
|
||||
}
|
||||
}
|
||||
snapshot.actor_id = Some(actor_id);
|
||||
for child in &mut snapshot.children {
|
||||
assign_missing_actor_ids(child);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rename_entity_with_history(world: &mut World, entity: Entity, new_name: String) {
|
||||
if !is_mutable_level_object(world, entity) {
|
||||
return;
|
||||
@@ -2825,8 +2854,10 @@ mod tests {
|
||||
#[test]
|
||||
fn snapshots_preserve_component_order_and_independent_active_state() {
|
||||
let mut world = World::new();
|
||||
let mut order = InspectorOrder::default();
|
||||
order.component_ids = vec![shared::AUTHORING_COMPONENT_LIGHT.to_string()];
|
||||
let order = InspectorOrder {
|
||||
component_ids: vec![shared::AUTHORING_COMPONENT_LIGHT.to_string()],
|
||||
..Default::default()
|
||||
};
|
||||
let mut states = AuthoringComponentStates::default();
|
||||
states.set_component_active(shared::COMPONENT_LIGHT_DESC, false);
|
||||
let entity = world
|
||||
@@ -3516,6 +3547,73 @@ mod tests {
|
||||
assert_eq!(unique.len(), ids.len(), "duplicated actors need fresh IDs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_navigation_bounds_gets_actor_owned_artifact_path() {
|
||||
let mut world = World::new();
|
||||
world.init_resource::<EditorHistory>();
|
||||
world.init_resource::<SceneIo>();
|
||||
world.init_resource::<SelectedEntity>();
|
||||
let original_id = ActorId::new("navigation-bounds-original");
|
||||
let original_bounds = NavigationBounds::for_actor(&original_id.0);
|
||||
let original = world
|
||||
.spawn((
|
||||
LevelObject,
|
||||
ActorKind::Navigation,
|
||||
original_id,
|
||||
Transform::IDENTITY,
|
||||
original_bounds.clone(),
|
||||
))
|
||||
.id();
|
||||
|
||||
duplicate_entities_with_history(&mut world, &[original]);
|
||||
|
||||
let (duplicate_id, duplicate_bounds) = world
|
||||
.query::<(Entity, &ActorId, &NavigationBounds)>()
|
||||
.iter(&world)
|
||||
.find_map(|(entity, actor_id, bounds)| {
|
||||
(entity != original).then_some((actor_id.clone(), bounds.clone()))
|
||||
})
|
||||
.expect("duplicated navigation bounds should exist");
|
||||
assert_ne!(
|
||||
duplicate_bounds.artifact_path,
|
||||
original_bounds.artifact_path
|
||||
);
|
||||
assert_eq!(
|
||||
duplicate_bounds.artifact_path,
|
||||
shared::navigation_artifact_path_for_actor(&duplicate_id.0)
|
||||
);
|
||||
|
||||
apply_command_undo(&mut world);
|
||||
apply_command_redo(&mut world);
|
||||
let redone = world
|
||||
.query::<(&ActorId, &NavigationBounds)>()
|
||||
.iter(&world)
|
||||
.find(|(actor_id, _)| **actor_id == duplicate_id)
|
||||
.expect("redo should preserve the duplicate actor identity");
|
||||
assert_eq!(redone.1, &duplicate_bounds);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn existing_navigation_snapshot_keeps_deliberate_generated_path() {
|
||||
let mut world = World::new();
|
||||
let mut bounds = NavigationBounds::for_actor("bounds-existing");
|
||||
bounds.artifact_path = "assets/navigation/generated/custom-zone.nav.ron".into();
|
||||
let entity = world
|
||||
.spawn((
|
||||
LevelObject,
|
||||
ActorKind::Navigation,
|
||||
ActorId::new("bounds-existing"),
|
||||
Transform::IDENTITY,
|
||||
bounds.clone(),
|
||||
))
|
||||
.id();
|
||||
let mut snapshot = snapshot_entity(&world, entity).unwrap();
|
||||
|
||||
assign_missing_actor_ids(&mut snapshot);
|
||||
|
||||
assert_eq!(snapshot.navigation_bounds.as_ref(), Some(&bounds));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn linked_members_reject_direct_history_mutations() {
|
||||
let mut world = World::new();
|
||||
|
||||
Reference in new issue
Block a user