Build production-ready editor authoring workflows
CI / Format, lint, test, build (push) Waiting to run
CI / Format, lint, test, build (push) Waiting to run
This commit is contained in:
1 parent
cc1fa6ea3b
commit
0553a85220
163 files changed
+34547
-1565
No files matched your search
@@ -8,6 +8,7 @@ use shared::{
|
||||
};
|
||||
|
||||
use crate::history::apply_brush_csg_with_history;
|
||||
use crate::operators::{ActiveOperator, OperatorPhase, OperatorStatus};
|
||||
use crate::scene_io::SceneIo;
|
||||
use crate::ui::UiState;
|
||||
|
||||
@@ -189,14 +190,13 @@ fn run_bounds_csg(world: &mut World, op: BrushCsgOp) {
|
||||
selected,
|
||||
result,
|
||||
});
|
||||
set_status(
|
||||
world,
|
||||
match op {
|
||||
BrushCsgOp::Intersect => "Brush intersect preview: Enter commits, Esc cancels",
|
||||
BrushCsgOp::Merge => "Brush convex merge preview: Enter commits, Esc cancels",
|
||||
BrushCsgOp::Subtract => "Brush subtract preview: Enter commits, Esc cancels",
|
||||
},
|
||||
);
|
||||
let hint = match op {
|
||||
BrushCsgOp::Intersect => "Brush intersect preview: Enter commits, Esc cancels",
|
||||
BrushCsgOp::Merge => "Brush convex merge preview: Enter commits, Esc cancels",
|
||||
BrushCsgOp::Subtract => "Brush subtract preview: Enter commits, Esc cancels",
|
||||
};
|
||||
set_status(world, hint);
|
||||
set_csg_operator_status(world, OperatorPhase::Preview, hint);
|
||||
}
|
||||
|
||||
fn brush_csg_preview_input(world: &mut World) {
|
||||
@@ -210,14 +210,7 @@ fn brush_csg_preview_input(world: &mut World) {
|
||||
return;
|
||||
}
|
||||
if escape {
|
||||
if world
|
||||
.resource_mut::<BrushCsgPreview>()
|
||||
.pending
|
||||
.take()
|
||||
.is_some()
|
||||
{
|
||||
set_status(world, "Brush CSG preview canceled");
|
||||
}
|
||||
cancel_csg_preview(world);
|
||||
return;
|
||||
}
|
||||
let Some(pending) = world.resource_mut::<BrushCsgPreview>().pending.take() else {
|
||||
@@ -226,9 +219,26 @@ fn brush_csg_preview_input(world: &mut World) {
|
||||
commit_csg_preview(world, pending);
|
||||
}
|
||||
|
||||
fn cancel_csg_preview(world: &mut World) {
|
||||
if world
|
||||
.resource_mut::<BrushCsgPreview>()
|
||||
.pending
|
||||
.take()
|
||||
.is_some()
|
||||
{
|
||||
set_status(world, "Brush CSG preview canceled");
|
||||
set_csg_operator_status(world, OperatorPhase::Canceled, "Canceled");
|
||||
}
|
||||
}
|
||||
|
||||
fn commit_csg_preview(world: &mut World, pending: PendingBrushCsg) {
|
||||
let Some(primary) = pending.selected.first().copied() else {
|
||||
set_status(world, "Brush CSG commit failed: missing primary brush");
|
||||
set_csg_operator_status(
|
||||
world,
|
||||
OperatorPhase::Blocked,
|
||||
"Commit failed: missing primary brush",
|
||||
);
|
||||
return;
|
||||
};
|
||||
if world.get::<BrushDesc>(primary).is_none() {
|
||||
@@ -236,6 +246,11 @@ fn commit_csg_preview(world: &mut World, pending: PendingBrushCsg) {
|
||||
world,
|
||||
"Brush CSG commit failed: primary brush no longer exists",
|
||||
);
|
||||
set_csg_operator_status(
|
||||
world,
|
||||
OperatorPhase::Blocked,
|
||||
"Commit failed: primary brush no longer exists",
|
||||
);
|
||||
return;
|
||||
}
|
||||
let new_brush = BrushDesc::cuboid(pending.result.size());
|
||||
@@ -251,14 +266,13 @@ fn commit_csg_preview(world: &mut World, pending: PendingBrushCsg) {
|
||||
Vec::new()
|
||||
};
|
||||
apply_bounds_result(world, primary, pending.result, new_brush, &to_delete);
|
||||
set_status(
|
||||
world,
|
||||
match pending.op {
|
||||
BrushCsgOp::Intersect => "Brush intersect committed",
|
||||
BrushCsgOp::Merge => "Brush convex merge committed",
|
||||
BrushCsgOp::Subtract => "Brush subtract committed",
|
||||
},
|
||||
);
|
||||
let hint = match pending.op {
|
||||
BrushCsgOp::Intersect => "Brush intersect committed",
|
||||
BrushCsgOp::Merge => "Brush convex merge committed",
|
||||
BrushCsgOp::Subtract => "Brush subtract committed",
|
||||
};
|
||||
set_status(world, hint);
|
||||
set_csg_operator_status(world, OperatorPhase::Committed, hint);
|
||||
}
|
||||
|
||||
fn draw_brush_csg_preview(preview: Res<BrushCsgPreview>, mut gizmos: Gizmos) {
|
||||
@@ -394,10 +408,24 @@ fn set_status(world: &mut World, status: impl Into<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_csg_operator_status(world: &mut World, phase: OperatorPhase, hint: impl Into<String>) {
|
||||
if let Some(mut active) = world.get_resource_mut::<ActiveOperator>() {
|
||||
active.status = Some(OperatorStatus {
|
||||
id: "brush.csg".to_string(),
|
||||
label: "Brush CSG".to_string(),
|
||||
phase,
|
||||
hint: hint.into(),
|
||||
warnings: Vec::new(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::history::EditorCommand;
|
||||
use crate::history::{EditorCommand, EditorHistory};
|
||||
use crate::operators::test_harness::{assert_undo_redo_round_trip, OperatorInvariantHarness};
|
||||
use crate::selection::SelectedEntity;
|
||||
|
||||
fn bounds(min: Vec3, max: Vec3) -> BrushBounds {
|
||||
BrushBounds { min, max }
|
||||
@@ -432,4 +460,62 @@ mod tests {
|
||||
|
||||
assert_eq!(command.label(), "Brush CSG");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn csg_preview_cancel_clears_pending_without_authored_side_effects() {
|
||||
let mut world = World::new();
|
||||
world.init_resource::<ActiveOperator>();
|
||||
world.init_resource::<EditorHistory>();
|
||||
world.init_resource::<SceneIo>();
|
||||
world.init_resource::<BrushCsgPreview>();
|
||||
world.resource_mut::<BrushCsgPreview>().pending = Some(PendingBrushCsg {
|
||||
op: BrushCsgOp::Merge,
|
||||
selected: vec![Entity::PLACEHOLDER],
|
||||
result: bounds(Vec3::ZERO, Vec3::ONE),
|
||||
});
|
||||
set_csg_operator_status(
|
||||
&mut world,
|
||||
OperatorPhase::Preview,
|
||||
"Enter commits, Esc cancels",
|
||||
);
|
||||
let harness = OperatorInvariantHarness::capture(&mut world);
|
||||
|
||||
cancel_csg_preview(&mut world);
|
||||
|
||||
harness.assert_canceled(&mut world);
|
||||
assert!(world.resource::<BrushCsgPreview>().pending.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn csg_merge_commit_is_one_undo_group_and_round_trips_deleted_brush() {
|
||||
let mut world = World::new();
|
||||
world.init_resource::<ActiveOperator>();
|
||||
world.init_resource::<EditorHistory>();
|
||||
world.init_resource::<SceneIo>();
|
||||
world.init_resource::<SelectedEntity>();
|
||||
let primary = world
|
||||
.spawn((LevelObject, BrushDesc::default(), Transform::default()))
|
||||
.id();
|
||||
let secondary = world
|
||||
.spawn((
|
||||
LevelObject,
|
||||
BrushDesc::default(),
|
||||
Transform::from_translation(Vec3::new(0.5, 0.0, 0.0)),
|
||||
))
|
||||
.id();
|
||||
let harness = OperatorInvariantHarness::capture(&mut world);
|
||||
let pending = PendingBrushCsg {
|
||||
op: BrushCsgOp::Merge,
|
||||
selected: vec![primary, secondary],
|
||||
result: bounds(Vec3::new(-0.5, -0.5, -0.5), Vec3::new(1.0, 0.5, 0.5)),
|
||||
};
|
||||
|
||||
commit_csg_preview(&mut world, pending);
|
||||
|
||||
harness.assert_committed(&mut world, 1, -1);
|
||||
assert_undo_redo_round_trip(&mut world, 2, 1, |world| {
|
||||
let mut query = world.query_filtered::<Entity, With<LevelObject>>();
|
||||
query.iter(world).count()
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user