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
@@ -8,6 +8,7 @@ description = "Shared reflectable authoring types and scene hydration for the FP
|
||||
[dependencies]
|
||||
avian3d.workspace = true
|
||||
bevy.workspace = true
|
||||
blake3 = "1"
|
||||
ron = "0.8"
|
||||
serde.workspace = true
|
||||
settings.workspace = true
|
||||
@@ -321,10 +321,26 @@ fn validate_navigation_actor(entity: EntityRef<'_>) -> Result<(), ActorValidatio
|
||||
.agent
|
||||
.validate()
|
||||
.map_err(|error| ActorValidationError::InvalidNavigation(error.into()))?;
|
||||
if bounds.artifact_path.trim().is_empty() {
|
||||
return Err(ActorValidationError::InvalidNavigation(
|
||||
"navigation artifact path must not be empty".into(),
|
||||
));
|
||||
crate::navigation_generated_artifact_path(&bounds.artifact_path)
|
||||
.map_err(|error| ActorValidationError::InvalidNavigation(error.into()))?;
|
||||
let mut sample_ids = HashSet::new();
|
||||
for sample in &bounds.validation_samples {
|
||||
let sample_id = sample.id.trim();
|
||||
if sample_id.is_empty() {
|
||||
return Err(ActorValidationError::InvalidNavigation(
|
||||
"navigation validation sample ID must not be empty".into(),
|
||||
));
|
||||
}
|
||||
if !sample_ids.insert(sample_id) {
|
||||
return Err(ActorValidationError::InvalidNavigation(format!(
|
||||
"navigation validation sample ID `{sample_id}` must be unique within its bounds"
|
||||
)));
|
||||
}
|
||||
if !sample.start.is_finite() || !sample.end.is_finite() || sample.start == sample.end {
|
||||
return Err(ActorValidationError::InvalidNavigation(format!(
|
||||
"navigation validation sample `{sample_id}` endpoints must be finite and distinct"
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(obstacle) = entity.get::<NavigationObstacle>() {
|
||||
@@ -832,4 +848,37 @@ mod tests {
|
||||
Err(ActorValidationError::AnimationControllerUnknownDefaultState)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn navigation_bounds_validate_generated_path_and_unique_samples() {
|
||||
let mut world = World::new();
|
||||
let mut bounds = NavigationBounds::for_actor("bounds-main");
|
||||
bounds.validation_samples.push(crate::NavigationPathSample {
|
||||
id: "entry-to-exit".into(),
|
||||
start: Vec3::new(-2.0, 0.0, 0.0),
|
||||
end: Vec3::new(2.0, 0.0, 0.0),
|
||||
enabled: true,
|
||||
});
|
||||
let entity = level_entity(&mut world, (ActorKind::Navigation, bounds.clone()));
|
||||
assert!(validate_actor(world.entity(entity)).is_ok());
|
||||
|
||||
bounds
|
||||
.validation_samples
|
||||
.push(bounds.validation_samples[0].clone());
|
||||
world.entity_mut(entity).insert(bounds.clone());
|
||||
assert!(matches!(
|
||||
validate_actor(world.entity(entity)),
|
||||
Err(ActorValidationError::InvalidNavigation(message))
|
||||
if message.contains("must be unique")
|
||||
));
|
||||
|
||||
bounds.validation_samples.pop();
|
||||
bounds.artifact_path = "assets/navigation/manual.nav.ron".into();
|
||||
world.entity_mut(entity).insert(bounds);
|
||||
assert!(matches!(
|
||||
validate_actor(world.entity(entity)),
|
||||
Err(ActorValidationError::InvalidNavigation(message))
|
||||
if message.contains("assets/navigation/generated/")
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -615,8 +615,8 @@ pub enum PrimitiveShape {
|
||||
}
|
||||
|
||||
/// Reflectable authoring primitive. Hydration turns this into `Mesh3d`.
|
||||
#[derive(Component, Reflect, Debug, Clone, Serialize, Deserialize)]
|
||||
#[reflect(Component, Default, Debug, Serialize, Deserialize)]
|
||||
#[derive(Component, Reflect, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[reflect(Component, Default, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Primitive {
|
||||
pub shape: PrimitiveShape,
|
||||
pub size: Vec3,
|
||||
|
||||
@@ -147,23 +147,20 @@ pub fn flush_level_object_hydration(world: &mut World) {
|
||||
Option<&InspectorOrder>,
|
||||
), With<LevelObject>>()
|
||||
.iter(world)
|
||||
.filter_map(|(entity, brush, material, collider, states, order)| {
|
||||
authoring_component_active(states, order, COMPONENT_BRUSH_DESC).then(|| {
|
||||
(
|
||||
entity,
|
||||
brush.clone(),
|
||||
material
|
||||
.filter(|_| {
|
||||
authoring_component_active(states, order, COMPONENT_MATERIAL_DESC)
|
||||
})
|
||||
.cloned(),
|
||||
collider
|
||||
.filter(|_| {
|
||||
authoring_component_active(states, order, COMPONENT_COLLIDER_DESC)
|
||||
})
|
||||
.cloned(),
|
||||
)
|
||||
})
|
||||
.filter(|(_, _, _, _, states, order)| {
|
||||
authoring_component_active(*states, *order, COMPONENT_BRUSH_DESC)
|
||||
})
|
||||
.map(|(entity, brush, material, collider, states, order)| {
|
||||
(
|
||||
entity,
|
||||
brush.clone(),
|
||||
material
|
||||
.filter(|_| authoring_component_active(states, order, COMPONENT_MATERIAL_DESC))
|
||||
.cloned(),
|
||||
collider
|
||||
.filter(|_| authoring_component_active(states, order, COMPONENT_COLLIDER_DESC))
|
||||
.cloned(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -190,34 +187,25 @@ pub fn flush_level_object_hydration(world: &mut World) {
|
||||
Option<&InspectorOrder>,
|
||||
), With<LevelObject>>()
|
||||
.iter(world)
|
||||
.filter_map(
|
||||
.filter(|(_, _, _, _, _, states, order)| {
|
||||
authoring_component_active(*states, *order, COMPONENT_STATIC_MESH_RENDERER)
|
||||
})
|
||||
.map(
|
||||
|(entity, renderer, material, material_override, collider, states, order)| {
|
||||
authoring_component_active(states, order, COMPONENT_STATIC_MESH_RENDERER).then(
|
||||
|| {
|
||||
(
|
||||
entity,
|
||||
renderer.clone(),
|
||||
material
|
||||
.filter(|_| {
|
||||
authoring_component_active(
|
||||
states,
|
||||
order,
|
||||
COMPONENT_MATERIAL_DESC,
|
||||
)
|
||||
})
|
||||
.cloned(),
|
||||
material_override.cloned(),
|
||||
collider
|
||||
.filter(|_| {
|
||||
authoring_component_active(
|
||||
states,
|
||||
order,
|
||||
COMPONENT_COLLIDER_DESC,
|
||||
)
|
||||
})
|
||||
.cloned(),
|
||||
)
|
||||
},
|
||||
(
|
||||
entity,
|
||||
renderer.clone(),
|
||||
material
|
||||
.filter(|_| {
|
||||
authoring_component_active(states, order, COMPONENT_MATERIAL_DESC)
|
||||
})
|
||||
.cloned(),
|
||||
material_override.cloned(),
|
||||
collider
|
||||
.filter(|_| {
|
||||
authoring_component_active(states, order, COMPONENT_COLLIDER_DESC)
|
||||
})
|
||||
.cloned(),
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -361,6 +361,7 @@ pub fn despawn_static_mesh_parts(
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn material_for_entry(
|
||||
asset_server: &AssetServer,
|
||||
materials: &mut Assets<StandardMaterial>,
|
||||
|
||||
@@ -32,9 +32,10 @@ pub use material_asset::{
|
||||
pub use navigation::*;
|
||||
pub use post_process_effect_asset::{PostProcessEffectAsset, PostProcessEffectKind};
|
||||
pub use prefab_overrides::{
|
||||
apply_prefab_overrides_on_ready, decode_prefab_overrides, encode_prefab_overrides,
|
||||
PrefabActorPath, PrefabComponentOverride, PrefabOverrides, PrefabPropertyOverride,
|
||||
PrefabStructuralOverride, PREFAB_OVERRIDE_FORMAT_VERSION,
|
||||
apply_prefab_overrides_on_ready, apply_serialized_navigation_property_override,
|
||||
decode_prefab_overrides, encode_prefab_overrides, PrefabActorPath, PrefabComponentOverride,
|
||||
PrefabOverrides, PrefabPropertyOverride, PrefabStructuralOverride,
|
||||
PREFAB_OVERRIDE_FORMAT_VERSION,
|
||||
};
|
||||
pub use renderer_material::*;
|
||||
pub use rendering_profile_asset::RenderingProfileAsset;
|
||||
@@ -94,6 +95,7 @@ impl Plugin for SharedTypesPlugin {
|
||||
.register_type::<AnimationStateDesc>()
|
||||
.register_type::<AnimationControllerDesc>()
|
||||
.register_type::<NavigationAgentProfile>()
|
||||
.register_type::<NavigationPathSample>()
|
||||
.register_type::<NavigationBounds>()
|
||||
.register_type::<NavigationObstacle>()
|
||||
.register_type::<NavigationArea>()
|
||||
@@ -149,6 +151,7 @@ impl Plugin for SharedTypesPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn migrate_legacy_authoring_component_states(
|
||||
mut commands: Commands,
|
||||
mut legacy: Query<
|
||||
|
||||
@@ -191,6 +191,15 @@ pub struct ShaderSchemaAsset {
|
||||
pub default_textures: Vec<MaterialTextureBinding>,
|
||||
}
|
||||
|
||||
impl ShaderSchemaAsset {
|
||||
pub fn load_from_path(catalog_path: &str) -> Result<Self, String> {
|
||||
let text = std::fs::read_to_string(catalog_path)
|
||||
.map_err(|err| format!("could not read {catalog_path}: {err}"))?;
|
||||
ron::from_str(&text)
|
||||
.map_err(|err| format!("invalid shader schema RON in {catalog_path}: {err}"))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -262,12 +271,3 @@ mod tests {
|
||||
.any(|value| value.name == "edge_width"));
|
||||
}
|
||||
}
|
||||
|
||||
impl ShaderSchemaAsset {
|
||||
pub fn load_from_path(catalog_path: &str) -> Result<Self, String> {
|
||||
let text = std::fs::read_to_string(catalog_path)
|
||||
.map_err(|err| format!("could not read {catalog_path}: {err}"))?;
|
||||
ron::from_str(&text)
|
||||
.map_err(|err| format!("invalid shader schema RON in {catalog_path}: {err}"))
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
use bevy::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const NAVIGATION_GENERATED_ARTIFACT_DIRECTORY: &str = "assets/navigation/generated/";
|
||||
pub const COMPONENT_NAVIGATION_BOUNDS: &str = "shared::navigation::NavigationBounds";
|
||||
pub const COMPONENT_NAVIGATION_OBSTACLE: &str = "shared::navigation::NavigationObstacle";
|
||||
pub const COMPONENT_NAVIGATION_AREA: &str = "shared::navigation::NavigationArea";
|
||||
@@ -54,11 +55,24 @@ impl NavigationAgentProfile {
|
||||
if !self.max_slope_deg.is_finite() || !(0.0..90.0).contains(&self.max_slope_deg) {
|
||||
return Err("maximum slope must be finite and in [0, 90) degrees");
|
||||
}
|
||||
if !self.cell_size_fraction.is_finite() || self.cell_size_fraction <= 0.0 {
|
||||
return Err("cell size fraction must be finite and greater than zero");
|
||||
if !self.cell_size_fraction.is_finite() || !(1.0..=32.0).contains(&self.cell_size_fraction)
|
||||
{
|
||||
return Err("cell size fraction must be finite and in [1, 32]");
|
||||
}
|
||||
if !self.cell_height_fraction.is_finite() || self.cell_height_fraction <= 0.0 {
|
||||
return Err("cell height fraction must be finite and greater than zero");
|
||||
if !self.cell_height_fraction.is_finite()
|
||||
|| !(1.0..=64.0).contains(&self.cell_height_fraction)
|
||||
{
|
||||
return Err("cell height fraction must be finite and in [1, 64]");
|
||||
}
|
||||
let cell_height = self.radius / self.cell_height_fraction;
|
||||
if (self.height / cell_height).ceil() > f32::from(u16::MAX) {
|
||||
return Err("agent height requires more than 65535 vertical voxels");
|
||||
}
|
||||
if (self.max_climb / cell_height).floor() > f32::from(u16::MAX) {
|
||||
return Err("maximum climb requires more than 65535 vertical voxels");
|
||||
}
|
||||
if self.min_region_size > 255 || self.merge_region_size > 255 {
|
||||
return Err("navigation region sizes must not exceed 255 voxels");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -73,6 +87,8 @@ pub struct NavigationBounds {
|
||||
pub artifact_path: String,
|
||||
#[serde(default)]
|
||||
pub auto_bake: bool,
|
||||
#[serde(default)]
|
||||
pub validation_samples: Vec<NavigationPathSample>,
|
||||
}
|
||||
|
||||
impl Default for NavigationBounds {
|
||||
@@ -82,10 +98,111 @@ impl Default for NavigationBounds {
|
||||
agent: NavigationAgentProfile::default(),
|
||||
artifact_path: "assets/navigation/generated/main_humanoid.nav.ron".into(),
|
||||
auto_bake: false,
|
||||
validation_samples: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Named local-space start/end pair persisted for bake and packaged-runtime validation.
|
||||
#[derive(Reflect, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[reflect(Default, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct NavigationPathSample {
|
||||
pub id: String,
|
||||
pub start: Vec3,
|
||||
pub end: Vec3,
|
||||
#[serde(default = "default_true")]
|
||||
pub enabled: bool,
|
||||
}
|
||||
|
||||
impl Default for NavigationPathSample {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
id: "sample".into(),
|
||||
start: Vec3::new(-4.0, 0.0, 0.0),
|
||||
end: Vec3::new(4.0, 0.0, 0.0),
|
||||
enabled: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NavigationBounds {
|
||||
/// Creates bounds whose generated output is owned by one stable actor.
|
||||
pub fn for_actor(actor_id: &str) -> Self {
|
||||
Self {
|
||||
artifact_path: navigation_artifact_path_for_actor(actor_id),
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a readable, collision-resistant artifact path derived from a persisted actor ID.
|
||||
pub fn navigation_artifact_path_for_actor(actor_id: &str) -> String {
|
||||
let mut slug = String::with_capacity(32);
|
||||
let mut last_was_separator = false;
|
||||
for character in actor_id.trim().chars() {
|
||||
if slug.len() >= 32 {
|
||||
break;
|
||||
}
|
||||
let character = character.to_ascii_lowercase();
|
||||
if character.is_ascii_alphanumeric() || matches!(character, '-' | '_') {
|
||||
slug.push(character);
|
||||
last_was_separator = false;
|
||||
} else if !slug.is_empty() && !last_was_separator {
|
||||
slug.push('-');
|
||||
last_was_separator = true;
|
||||
}
|
||||
}
|
||||
while slug.ends_with('-') {
|
||||
slug.pop();
|
||||
}
|
||||
if slug.is_empty() {
|
||||
slug.push_str("actor");
|
||||
}
|
||||
|
||||
let digest = blake3::hash(actor_id.as_bytes()).to_hex();
|
||||
format!(
|
||||
"{NAVIGATION_GENERATED_ARTIFACT_DIRECTORY}{slug}-{}.nav.ron",
|
||||
&digest[..24]
|
||||
)
|
||||
}
|
||||
|
||||
/// Normalizes and validates a project-relative generated navigation artifact path.
|
||||
pub fn navigation_generated_artifact_path(path: &str) -> Result<String, &'static str> {
|
||||
let normalized = path.replace('\\', "/");
|
||||
let relative = std::path::Path::new(&normalized);
|
||||
if normalized.trim().is_empty()
|
||||
|| relative.is_absolute()
|
||||
|| relative.components().any(|component| {
|
||||
matches!(
|
||||
component,
|
||||
std::path::Component::CurDir
|
||||
| std::path::Component::ParentDir
|
||||
| std::path::Component::RootDir
|
||||
| std::path::Component::Prefix(_)
|
||||
)
|
||||
})
|
||||
{
|
||||
return Err("navigation artifacts must be project-relative files under assets/navigation/generated/");
|
||||
}
|
||||
let canonical = relative
|
||||
.components()
|
||||
.filter_map(|component| match component {
|
||||
std::path::Component::Normal(component) => component.to_str(),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("/");
|
||||
if !canonical.starts_with(NAVIGATION_GENERATED_ARTIFACT_DIRECTORY)
|
||||
|| canonical == NAVIGATION_GENERATED_ARTIFACT_DIRECTORY.trim_end_matches('/')
|
||||
|| !canonical.ends_with(".nav.ron")
|
||||
{
|
||||
return Err(
|
||||
"navigation artifacts must be .nav.ron files under assets/navigation/generated/",
|
||||
);
|
||||
}
|
||||
Ok(canonical)
|
||||
}
|
||||
|
||||
/// Axis-aligned volume carved from every overlapping navigation bake.
|
||||
#[derive(Component, Reflect, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[reflect(Component, Default, Debug, PartialEq, Serialize, Deserialize)]
|
||||
@@ -162,7 +279,10 @@ fn default_one() -> f32 {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::NavigationAgentProfile;
|
||||
use super::{
|
||||
navigation_artifact_path_for_actor, navigation_generated_artifact_path,
|
||||
NavigationAgentProfile, NAVIGATION_GENERATED_ARTIFACT_DIRECTORY,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn default_agent_profile_is_valid() {
|
||||
@@ -178,4 +298,59 @@ mod tests {
|
||||
Err("agent height must be finite and greater than twice its radius")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pathological_voxel_settings_are_rejected() {
|
||||
let profile = NavigationAgentProfile {
|
||||
cell_size_fraction: 1_000_000.0,
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(
|
||||
profile.validate(),
|
||||
Err("cell size fraction must be finite and in [1, 32]")
|
||||
);
|
||||
|
||||
let profile = NavigationAgentProfile {
|
||||
merge_region_size: 256,
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(
|
||||
profile.validate(),
|
||||
Err("navigation region sizes must not exceed 255 voxels")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generated_artifact_paths_are_stable_and_actor_specific() {
|
||||
let first = navigation_artifact_path_for_actor("Bounds / Main");
|
||||
assert_eq!(first, navigation_artifact_path_for_actor("Bounds / Main"));
|
||||
assert_ne!(first, navigation_artifact_path_for_actor("Bounds / Other"));
|
||||
assert!(first.starts_with(NAVIGATION_GENERATED_ARTIFACT_DIRECTORY));
|
||||
assert!(first.ends_with(".nav.ron"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generated_artifact_policy_rejects_escapes_and_other_directories() {
|
||||
assert_eq!(
|
||||
navigation_generated_artifact_path("assets\\navigation\\generated\\bounds.nav.ron"),
|
||||
Ok("assets/navigation/generated/bounds.nav.ron".into())
|
||||
);
|
||||
assert_eq!(
|
||||
navigation_generated_artifact_path(
|
||||
"assets/navigation/generated//nested///bounds.nav.ron"
|
||||
),
|
||||
Ok("assets/navigation/generated/nested/bounds.nav.ron".into())
|
||||
);
|
||||
assert!(navigation_generated_artifact_path("assets/navigation/bounds.nav.ron").is_err());
|
||||
assert!(
|
||||
navigation_generated_artifact_path("assets/navigation/generated/bounds.ron").is_err()
|
||||
);
|
||||
assert!(navigation_generated_artifact_path(
|
||||
"assets/navigation/generated/../bounds.nav.ron"
|
||||
)
|
||||
.is_err());
|
||||
assert!(
|
||||
navigation_generated_artifact_path(NAVIGATION_GENERATED_ARTIFACT_DIRECTORY).is_err()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ use bevy::prelude::*;
|
||||
use bevy::reflect::serde::TypedReflectDeserializer;
|
||||
use bevy::reflect::{GetPath, ParsedPath, ReflectPath};
|
||||
use bevy::world_serialization::{WorldInstanceReady, WorldInstanceSpawner};
|
||||
use serde::de::DeserializeSeed;
|
||||
use serde::de::{DeserializeOwned, DeserializeSeed};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{ActorId, EditorVisibility, HydratedPrefabMember, MaterialDesc, PrefabInstance};
|
||||
@@ -198,6 +198,61 @@ pub fn validate_prefab_overrides_payload(overrides: &PrefabOverrides) -> Result<
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Applies one reflected property path while preserving every other field in the current value.
|
||||
///
|
||||
/// Navigation baking consumes authored prefab overrides without instantiating a Bevy world. Keep
|
||||
/// its serialized merge behavior identical to the runtime override path, including enum variants.
|
||||
pub fn apply_serialized_navigation_property_override(
|
||||
component_type: &str,
|
||||
current_component_ron: &str,
|
||||
value_component_ron: &str,
|
||||
property_path: &str,
|
||||
) -> Result<String, String> {
|
||||
fn apply<T>(current: &str, value: &str, property_path: &str) -> Result<String, String>
|
||||
where
|
||||
T: Reflect + Serialize + DeserializeOwned,
|
||||
{
|
||||
let mut current = ron::from_str::<T>(current)
|
||||
.map_err(|error| format!("invalid current component value: {error}"))?;
|
||||
let value = ron::from_str::<T>(value)
|
||||
.map_err(|error| format!("invalid override component value: {error}"))?;
|
||||
let path = ParsedPath::parse(property_path)
|
||||
.map_err(|error| format!("invalid property path `{property_path}`: {error}"))?;
|
||||
let source_value = path
|
||||
.reflect_element(&value)
|
||||
.map_err(|error| format!("override value path `{property_path}` failed: {error}"))?;
|
||||
let target_value = current
|
||||
.reflect_path_mut(&path)
|
||||
.map_err(|error| format!("target property path `{property_path}` failed: {error}"))?;
|
||||
target_value
|
||||
.try_apply(source_value)
|
||||
.map_err(|error| format!("could not apply `{property_path}`: {error}"))?;
|
||||
ron::to_string(¤t)
|
||||
.map_err(|error| format!("could not encode merged component value: {error}"))
|
||||
}
|
||||
|
||||
macro_rules! apply_component {
|
||||
($ty:ty) => {
|
||||
if component_type == std::any::type_name::<$ty>() {
|
||||
return apply::<$ty>(current_component_ron, value_component_ron, property_path);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
apply_component!(Transform);
|
||||
apply_component!(crate::Primitive);
|
||||
apply_component!(crate::BrushDesc);
|
||||
apply_component!(crate::NavigationBounds);
|
||||
apply_component!(crate::NavigationObstacle);
|
||||
apply_component!(crate::NavigationArea);
|
||||
apply_component!(crate::NavigationLink);
|
||||
apply_component!(PrefabInstance);
|
||||
apply_component!(crate::PrefabRef);
|
||||
Err(format!(
|
||||
"component `{component_type}` is not supported by serialized authoring property overrides"
|
||||
))
|
||||
}
|
||||
|
||||
pub fn encode_prefab_overrides(overrides: &PrefabOverrides) -> Result<Option<String>, String> {
|
||||
if overrides == &PrefabOverrides::default() {
|
||||
Ok(None)
|
||||
@@ -572,6 +627,26 @@ mod tests {
|
||||
assert_ne!(first, second);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialized_property_merge_preserves_unrelated_fields_and_enum_identity() {
|
||||
let current = crate::Primitive::cuboid(Vec3::new(4.0, 0.2, 6.0));
|
||||
let value = crate::Primitive {
|
||||
shape: crate::PrimitiveShape::Sphere,
|
||||
size: Vec3::splat(99.0),
|
||||
};
|
||||
let merged = apply_serialized_navigation_property_override(
|
||||
std::any::type_name::<crate::Primitive>(),
|
||||
&ron::to_string(¤t).unwrap(),
|
||||
&ron::to_string(&value).unwrap(),
|
||||
"shape",
|
||||
)
|
||||
.unwrap();
|
||||
let merged: crate::Primitive = ron::from_str(&merged).unwrap();
|
||||
|
||||
assert_eq!(merged.shape, crate::PrimitiveShape::Sphere);
|
||||
assert_eq!(merged.size, current.size);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_inner_override_payload_is_rejected_during_decode() {
|
||||
let mut instance = PrefabInstance::new("prefab", "assets/prefabs/test.scn.ron");
|
||||
|
||||
Reference in new issue
Block a user