This commit is contained in:
1 parent
9a67a25a15
commit
1ab3886028
24 files changed
+1836
-311
No files matched your search
@@ -469,6 +469,86 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_actor_material_assignment_is_one_undo_group() {
|
||||
let mut world = World::new();
|
||||
world.init_resource::<ActiveOperator>();
|
||||
world.init_resource::<EditorHistory>();
|
||||
world.init_resource::<SceneIo>();
|
||||
let material_path = std::env::temp_dir().join(format!(
|
||||
"blacksite-material-operator-{}.material.ron",
|
||||
uuid::Uuid::new_v4()
|
||||
));
|
||||
let fixture = shared::MaterialAsset {
|
||||
schema_version: shared::MATERIAL_ASSET_SCHEMA_VERSION,
|
||||
label: "Concrete".into(),
|
||||
shader: None,
|
||||
shader_ref: None,
|
||||
render_state: Default::default(),
|
||||
material: MaterialDesc {
|
||||
roughness: 0.85,
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
std::fs::write(
|
||||
&material_path,
|
||||
ron::ser::to_string_pretty(&fixture, ron::ser::PrettyConfig::default()).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
let material_path = material_path.to_string_lossy().into_owned();
|
||||
world.insert_resource(AssetRegistry {
|
||||
records: vec![AssetRecord {
|
||||
id: AssetId::new(),
|
||||
path: material_path.clone(),
|
||||
label: "Concrete".into(),
|
||||
kind_tag: "Material".into(),
|
||||
import_settings: Default::default(),
|
||||
dependencies: Vec::new(),
|
||||
}],
|
||||
index_dirty: false,
|
||||
});
|
||||
let first = world.spawn((LevelObject, MaterialDesc::default())).id();
|
||||
let second = world.spawn((LevelObject, MaterialDesc::default())).id();
|
||||
let mut selected = SelectedEntities::default();
|
||||
selected.select_replace(first);
|
||||
selected.select_maybe_add(second, true);
|
||||
let asset = EditorAsset {
|
||||
label: "Concrete".to_string(),
|
||||
path: Some(material_path.clone()),
|
||||
folder_path: "assets/materials".to_string(),
|
||||
kind: super::super::EditorAssetKind::Material,
|
||||
};
|
||||
super::super::materials::material_desc_from_asset(&material_path)
|
||||
.expect("committed material fixture should resolve");
|
||||
let harness = OperatorInvariantHarness::capture(&mut world);
|
||||
let read_materials = move |world: &mut World| {
|
||||
[first, second]
|
||||
.into_iter()
|
||||
.map(|entity| {
|
||||
world
|
||||
.get::<MaterialDesc>(entity)
|
||||
.and_then(|material| material.material_asset_path.clone())
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
|
||||
let applied = apply_material_operator(&mut world, asset, &selected);
|
||||
assert!(
|
||||
applied,
|
||||
"material operator failed: {:?}",
|
||||
world.resource::<ActiveOperator>().status
|
||||
);
|
||||
|
||||
harness.assert_committed(&mut world, 1, 0);
|
||||
assert_undo_redo_round_trip(
|
||||
&mut world,
|
||||
vec![None, None],
|
||||
vec![Some(material_path.clone()), Some(material_path.clone())],
|
||||
read_materials,
|
||||
);
|
||||
let _ = std::fs::remove_file(material_path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_subasset_commit_cancels_without_side_effects() {
|
||||
let mut world = World::new();
|
||||
@@ -533,4 +613,59 @@ mod tests {
|
||||
|
||||
harness.assert_blocked(&mut world);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn material_assignment_without_authored_selection_is_blocked() {
|
||||
let mut world = World::new();
|
||||
world.init_resource::<ActiveOperator>();
|
||||
world.init_resource::<EditorHistory>();
|
||||
world.init_resource::<SceneIo>();
|
||||
let harness = OperatorInvariantHarness::capture(&mut world);
|
||||
let asset = EditorAsset {
|
||||
label: "Concrete".to_string(),
|
||||
path: Some("assets/materials/concrete.ron".to_string()),
|
||||
folder_path: "assets/materials".to_string(),
|
||||
kind: super::super::EditorAssetKind::Material,
|
||||
};
|
||||
|
||||
assert!(!apply_material_operator(
|
||||
&mut world,
|
||||
asset,
|
||||
&SelectedEntities::default()
|
||||
));
|
||||
|
||||
harness.assert_blocked(&mut world);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn audio_and_animation_assignment_reject_incompatible_actors() {
|
||||
let mut world = World::new();
|
||||
world.init_resource::<ActiveOperator>();
|
||||
world.init_resource::<EditorHistory>();
|
||||
world.init_resource::<SceneIo>();
|
||||
let entity = world.spawn(LevelObject).id();
|
||||
let audio = EditorAsset {
|
||||
label: "Impact".into(),
|
||||
path: Some("assets/audio/impact.ogg".into()),
|
||||
folder_path: "assets/audio".into(),
|
||||
kind: super::super::EditorAssetKind::AudioClip,
|
||||
};
|
||||
let audio_harness = OperatorInvariantHarness::capture(&mut world);
|
||||
|
||||
assert!(!assign_audio_clip_operator(&mut world, audio, entity));
|
||||
audio_harness.assert_blocked(&mut world);
|
||||
|
||||
let animation_harness = OperatorInvariantHarness::capture(&mut world);
|
||||
let selection = AssetSelection::SubAsset {
|
||||
parent_path: "assets/models/missing.glb".into(),
|
||||
sub_asset_id: "animation:missing".into(),
|
||||
label: "Missing".into(),
|
||||
kind: super::super::AssetSubAssetKind::AnimationClip,
|
||||
source_path: None,
|
||||
};
|
||||
assert!(!assign_animation_clip_operator(
|
||||
&mut world, selection, entity
|
||||
));
|
||||
animation_harness.assert_blocked(&mut world);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user