Adding duplicate entity checks as well

attempt/001
Elijah Voigt 1 year ago
parent b44147604d
commit 07b5fbce1a

@ -1 +1,2 @@
00/a.entity 00/a.entity
00/a.entity

@ -1,2 +1 @@
name "Hello world" name "Hello world"
name "Hello bevy"

@ -100,7 +100,6 @@ impl SaveEntity {
); );
} }
}); });
// Check for duplicate component types and emit an error // Check for duplicate component types and emit an error
// TODO: It would be nice if this emitted a line refernece instead of a parsed struct! // TODO: It would be nice if this emitted a line refernece instead of a parsed struct!
let l = entity.components.len(); let l = entity.components.len();
@ -111,12 +110,20 @@ impl SaveEntity {
let c2 = &entity.components[j]; let c2 = &entity.components[j];
let t1 = c1.type_id; let t1 = c1.type_id;
let t2 = c2.type_id; let t2 = c2.type_id;
if t1 == t2 { if cfg!(debug_assertions) {
debug_assert!(
t1 != t2,
"Duplicate components in {:?}: \n\t{:?}\n\t{:?}",
load_context.asset_path(),
c1.data,
c2.data
);
} else {
error!( error!(
"Duplicate components in {:?}: \n\t{:?}\n\t{:?}", "Duplicate components in {:?}: \n\t{:?}\n\t{:?}",
load_context.asset_path(), load_context.asset_path(),
c1.data, c1.data,
c2.data, c2.data
); );
} }
} }
@ -198,6 +205,37 @@ impl AssetLoader for SaveSceneLoader {
.map(|path| load_context.load(path)) .map(|path| load_context.load(path))
.collect(); .collect();
// Assert there are no duplicate entities in the file
{
let l = entities.len();
(0..l).for_each(|i| {
(i..l).for_each(|j| {
if i != j {
let e1 = &entities[i];
let e2 = &entities[j];
if cfg!(debug_assertions) {
debug_assert!(
e1 != e2,
"Duplicate entities in scene {:?}:\n\t{:?}\n\t{:?}",
load_context.asset_path(),
e1,
e2
);
} else {
if e1 == e2 {
error!(
"Duplicate entities in scene {:?}:\n\t{:?}\n\t{:?}",
load_context.asset_path(),
e1,
e2
)
}
}
}
});
});
}
Ok(SaveScene { entities }) Ok(SaveScene { entities })
} }

Loading…
Cancel
Save