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
@@ -9,6 +9,7 @@ mod migrate;
|
||||
pub mod navigation;
|
||||
mod prefab;
|
||||
mod project_validation;
|
||||
pub mod sample_pack;
|
||||
mod upgrade;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
@@ -13,7 +13,7 @@ use shared::{
|
||||
AudioSourceDesc, BrushDesc, ColliderDesc, ColliderShapeDesc, EditorAssetRef, MaterialAsset,
|
||||
MaterialDesc, MaterialInstanceAsset, MaterialOverride, ModelRef, PostProcessEffectAsset,
|
||||
PostProcessVolumeDesc, PrefabInstance, PrefabRef, RendererMaterialSet, ShaderSchemaAsset,
|
||||
SkinnedMeshRenderer, StaticMeshRenderer, ANIMATION_MANIFEST_SCHEMA_VERSION,
|
||||
SkinnedMeshRenderer, StaticMeshRenderer, TerrainDesc, ANIMATION_MANIFEST_SCHEMA_VERSION,
|
||||
AUDIO_CLIP_SUB_ASSET_ID, COMPONENT_ANIMATION_CONTROLLER_DESC, COMPONENT_SKINNED_MESH_RENDERER,
|
||||
NAVIGATION_GENERATED_ARTIFACT_DIRECTORY,
|
||||
};
|
||||
@@ -25,6 +25,7 @@ const MATERIAL_DESC: &str = "shared::components::MaterialDesc";
|
||||
const MATERIAL_OVERRIDE: &str = "shared::components::MaterialOverride";
|
||||
const STATIC_MESH_RENDERER: &str = "shared::components::StaticMeshRenderer";
|
||||
const BRUSH_DESC: &str = "shared::components::BrushDesc";
|
||||
const TERRAIN_DESC: &str = "shared::components::TerrainDesc";
|
||||
const COLLIDER_DESC: &str = "shared::components::ColliderDesc";
|
||||
const POST_PROCESS_VOLUME: &str = "shared::components::PostProcessVolumeDesc";
|
||||
const PREFAB_INSTANCE: &str = "shared::components::PrefabInstance";
|
||||
@@ -1905,6 +1906,53 @@ fn collect_component_references(
|
||||
}
|
||||
}
|
||||
}
|
||||
TERRAIN_DESC => match ron::from_str::<TerrainDesc>(&component.ron) {
|
||||
Ok(terrain) => {
|
||||
if let Err(error) = terrain.validate() {
|
||||
report.findings.push(ProjectValidationFinding {
|
||||
severity: ValidationSeverity::Error,
|
||||
code: "terrain.invalid".into(),
|
||||
source_path: source_path.to_string(),
|
||||
owner_actor_id: actor_id.map(str::to_string),
|
||||
reference: None,
|
||||
message: error,
|
||||
repair: "Repair the terrain dimensions, samples, layers, and chunk settings in the Inspector."
|
||||
.into(),
|
||||
});
|
||||
}
|
||||
if let Some(material) = &terrain.base_material {
|
||||
collect_terrain_material_ref(
|
||||
project_root,
|
||||
report,
|
||||
source_path,
|
||||
actor_id,
|
||||
"TerrainDesc.base_material",
|
||||
material,
|
||||
);
|
||||
}
|
||||
for (index, layer) in terrain.material_layers.iter().enumerate() {
|
||||
if let Some(material) = &layer.material {
|
||||
collect_terrain_material_ref(
|
||||
project_root,
|
||||
report,
|
||||
source_path,
|
||||
actor_id,
|
||||
&format!("TerrainDesc.material_layers[{index}].material"),
|
||||
material,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error) => report.findings.push(ProjectValidationFinding {
|
||||
severity: ValidationSeverity::Error,
|
||||
code: "terrain.malformed".into(),
|
||||
source_path: source_path.to_string(),
|
||||
owner_actor_id: actor_id.map(str::to_string),
|
||||
reference: None,
|
||||
message: format!("could not parse TerrainDesc: {error}"),
|
||||
repair: "Remove and recreate the Terrain component with the current editor.".into(),
|
||||
}),
|
||||
},
|
||||
COLLIDER_DESC => validate_collider(
|
||||
project_root,
|
||||
report,
|
||||
@@ -2736,6 +2784,64 @@ fn collect_material(
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_terrain_material_ref(
|
||||
project_root: &Path,
|
||||
report: &mut ProjectValidationReport,
|
||||
source_path: &str,
|
||||
actor_id: Option<&str>,
|
||||
property: &str,
|
||||
reference: &EditorAssetRef,
|
||||
) {
|
||||
let Some(path) = reference
|
||||
.source_path
|
||||
.as_deref()
|
||||
.filter(|path| !path.trim().is_empty())
|
||||
else {
|
||||
report.findings.push(ProjectValidationFinding {
|
||||
severity: ValidationSeverity::Error,
|
||||
code: "terrain.material_ref_unresolved".into(),
|
||||
source_path: source_path.to_string(),
|
||||
owner_actor_id: actor_id.map(str::to_string),
|
||||
reference: Some(property.to_string()),
|
||||
message: format!("{property} has no loadable project source path"),
|
||||
repair:
|
||||
"Assign an existing project Material or Material Instance in the Terrain inspector."
|
||||
.into(),
|
||||
});
|
||||
return;
|
||||
};
|
||||
let path_value = Path::new(path);
|
||||
if path_value.is_absolute()
|
||||
|| path_value == Path::new("assets")
|
||||
|| !path_value.starts_with("assets")
|
||||
|| !path_value
|
||||
.components()
|
||||
.all(|component| matches!(component, Component::Normal(_)))
|
||||
{
|
||||
report.findings.push(ProjectValidationFinding {
|
||||
severity: ValidationSeverity::Error,
|
||||
code: "terrain.material_ref_invalid".into(),
|
||||
source_path: source_path.to_string(),
|
||||
owner_actor_id: actor_id.map(str::to_string),
|
||||
reference: Some(path.to_string()),
|
||||
message: format!(
|
||||
"{property} source path must be a normalized project-relative path below assets/"
|
||||
),
|
||||
repair: "Reassign the terrain layer from a project Material or Material Instance."
|
||||
.into(),
|
||||
});
|
||||
return;
|
||||
}
|
||||
add_reference(
|
||||
project_root,
|
||||
report,
|
||||
source_path,
|
||||
actor_id,
|
||||
"terrain_material",
|
||||
path,
|
||||
);
|
||||
}
|
||||
|
||||
fn collect_asset_ref(
|
||||
project_root: &Path,
|
||||
report: &mut ProjectValidationReport,
|
||||
@@ -3888,6 +3994,132 @@ mod tests {
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
fn write_terrain_scene(root: &Path, terrain: &TerrainDesc) {
|
||||
let terrain = ron::to_string(terrain).unwrap();
|
||||
std::fs::write(
|
||||
root.join("assets/levels/main.scn.ron"),
|
||||
format!(
|
||||
"(schema_version:4,resources:{{}},entities:{{1:(components:{{\"shared::components::ActorId\":(\"terrain-owner\"),\"{TERRAIN_DESC}\":{terrain},}})}})"
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn terrain_material_references_are_actor_owned_dependencies() {
|
||||
let root = fixture_root();
|
||||
let mut terrain = TerrainDesc::flat(3);
|
||||
terrain.base_material = Some(
|
||||
EditorAssetRef::new("base-id", "material:instance", "Base")
|
||||
.with_source_path("assets/materials/base.ron"),
|
||||
);
|
||||
terrain.material_layers = vec![shared::TerrainMaterialLayer {
|
||||
material: Some(
|
||||
EditorAssetRef::new("layer-id", "material:source", "Layer")
|
||||
.with_source_path("assets/materials/layer.ron"),
|
||||
),
|
||||
uv_scale: 4.0,
|
||||
}];
|
||||
write_terrain_scene(&root, &terrain);
|
||||
|
||||
let report = validate_project(&root);
|
||||
let dependencies = report
|
||||
.dependencies
|
||||
.iter()
|
||||
.filter(|dependency| dependency.kind == "terrain_material")
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(dependencies.len(), 2, "{:?}", report.dependencies);
|
||||
assert!(dependencies
|
||||
.iter()
|
||||
.all(|dependency| dependency.owner_actor_id.as_deref() == Some("terrain-owner")));
|
||||
assert_eq!(
|
||||
report
|
||||
.findings
|
||||
.iter()
|
||||
.filter(|finding| finding.code == "asset.missing")
|
||||
.count(),
|
||||
2
|
||||
);
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn terrain_material_references_require_runtime_source_paths() {
|
||||
let root = fixture_root();
|
||||
let mut terrain = TerrainDesc::flat(3);
|
||||
terrain.base_material = Some(
|
||||
EditorAssetRef::new("empty-path-id", "material:source", "Empty")
|
||||
.with_source_path(" "),
|
||||
);
|
||||
terrain.material_layers = vec![
|
||||
shared::TerrainMaterialLayer {
|
||||
material: Some(EditorAssetRef::new(
|
||||
"source-less-id",
|
||||
"material:source",
|
||||
"Source-less",
|
||||
)),
|
||||
uv_scale: 4.0,
|
||||
},
|
||||
shared::TerrainMaterialLayer {
|
||||
material: Some(
|
||||
EditorAssetRef::new("missing-id", "material:source", "Missing")
|
||||
.with_source_path("assets/materials/missing.ron"),
|
||||
),
|
||||
uv_scale: 8.0,
|
||||
},
|
||||
];
|
||||
write_terrain_scene(&root, &terrain);
|
||||
|
||||
let report = validate_project(&root);
|
||||
let unresolved = report
|
||||
.findings
|
||||
.iter()
|
||||
.filter(|finding| finding.code == "terrain.material_ref_unresolved")
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(unresolved.len(), 2, "{:?}", report.findings);
|
||||
assert!(unresolved
|
||||
.iter()
|
||||
.all(|finding| finding.owner_actor_id.as_deref() == Some("terrain-owner")));
|
||||
assert!(report.findings.iter().any(|finding| {
|
||||
finding.code == "asset.missing"
|
||||
&& finding.owner_actor_id.as_deref() == Some("terrain-owner")
|
||||
&& finding.reference.as_deref() == Some("assets/materials/missing.ron")
|
||||
}));
|
||||
assert!(report.dependencies.iter().any(|dependency| {
|
||||
dependency.kind == "terrain_material"
|
||||
&& dependency.reference == "assets/materials/missing.ron"
|
||||
}));
|
||||
assert!(!report.dependencies.iter().any(|dependency| {
|
||||
dependency.kind == "generated_manifest"
|
||||
&& (dependency.reference.contains("empty-path-id")
|
||||
|| dependency.reference.contains("source-less-id"))
|
||||
}));
|
||||
assert!(!report.is_release_ready());
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_terrain_descriptor_blocks_project_validation() {
|
||||
let root = fixture_root();
|
||||
let mut terrain = TerrainDesc::flat(3);
|
||||
terrain.heights.pop();
|
||||
write_terrain_scene(&root, &terrain);
|
||||
|
||||
let report = validate_project(&root);
|
||||
let finding = report
|
||||
.findings
|
||||
.iter()
|
||||
.find(|finding| finding.code == "terrain.invalid")
|
||||
.expect("invalid terrain should block release validation");
|
||||
|
||||
assert_eq!(finding.owner_actor_id.as_deref(), Some("terrain-owner"));
|
||||
assert!(finding.message.contains("requires 9 height samples"));
|
||||
assert!(!report.is_release_ready());
|
||||
std::fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn project_default_level_must_be_in_the_audited_levels_tree() {
|
||||
let root = fixture_root();
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user