Group brush CSG history edits
This commit is contained in:
1 parent
1b9fbebda1
commit
3f85d25cc7
3 files changed
+115
-11
No files matched your search
@@ -7,9 +7,7 @@ use shared::{
|
||||
BrushDesc, LevelObject,
|
||||
};
|
||||
|
||||
use crate::history::{
|
||||
delete_entities_with_history, set_brush_with_history, set_transform_with_history,
|
||||
};
|
||||
use crate::history::apply_brush_csg_with_history;
|
||||
use crate::scene_io::SceneIo;
|
||||
use crate::ui::UiState;
|
||||
|
||||
@@ -241,17 +239,18 @@ fn commit_csg_preview(world: &mut World, pending: PendingBrushCsg) {
|
||||
return;
|
||||
}
|
||||
let new_brush = BrushDesc::cuboid(pending.result.size());
|
||||
apply_bounds_result(world, primary, pending.result, new_brush);
|
||||
if matches!(pending.op, BrushCsgOp::Merge | BrushCsgOp::Intersect) {
|
||||
let to_delete: Vec<_> = pending
|
||||
let to_delete: Vec<_> = if matches!(pending.op, BrushCsgOp::Merge | BrushCsgOp::Intersect) {
|
||||
pending
|
||||
.selected
|
||||
.iter()
|
||||
.skip(1)
|
||||
.copied()
|
||||
.filter(|entity| world.get::<BrushDesc>(*entity).is_some())
|
||||
.collect();
|
||||
delete_entities_with_history(world, &to_delete);
|
||||
}
|
||||
.collect()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
apply_bounds_result(world, primary, pending.result, new_brush, &to_delete);
|
||||
set_status(
|
||||
world,
|
||||
match pending.op {
|
||||
@@ -318,6 +317,7 @@ fn apply_bounds_result(
|
||||
entity: Entity,
|
||||
bounds: BrushBounds,
|
||||
new_brush: BrushDesc,
|
||||
delete_entities: &[Entity],
|
||||
) {
|
||||
let center = bounds.center();
|
||||
let old_transform = world.get::<Transform>(entity).copied().unwrap_or_default();
|
||||
@@ -325,8 +325,7 @@ fn apply_bounds_result(
|
||||
new_transform.translation = center;
|
||||
new_transform.rotation = Quat::IDENTITY;
|
||||
new_transform.scale = Vec3::ONE;
|
||||
set_transform_with_history(world, entity, old_transform, new_transform);
|
||||
set_brush_with_history(world, entity, new_brush);
|
||||
apply_brush_csg_with_history(world, entity, new_transform, new_brush, delete_entities);
|
||||
}
|
||||
|
||||
fn brush_world_bounds(world: &World, entity: Entity) -> Option<BrushBounds> {
|
||||
@@ -398,6 +397,7 @@ fn set_status(world: &mut World, status: impl Into<String>) {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::history::EditorCommand;
|
||||
|
||||
fn bounds(min: Vec3, max: Vec3) -> BrushBounds {
|
||||
BrushBounds { min, max }
|
||||
@@ -418,4 +418,18 @@ mod tests {
|
||||
assert_eq!(result.min, Vec3::new(1.0, 0.0, 0.0));
|
||||
assert_eq!(result.max, source.max);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn csg_history_command_is_grouped() {
|
||||
let command = EditorCommand::ApplyBrushCsg {
|
||||
primary: Entity::PLACEHOLDER,
|
||||
old_transform: Transform::default(),
|
||||
new_transform: Transform::from_translation(Vec3::X),
|
||||
old_brush: Some(BrushDesc::default()),
|
||||
new_brush: BrushDesc::default(),
|
||||
deleted: Vec::new(),
|
||||
};
|
||||
|
||||
assert_eq!(command.label(), "Brush CSG");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user