Add editor operator lifecycle bridge
CI / Format, lint, test, build (push) Waiting to run

This commit is contained in:
Rbanh committed 2026-06-06 04:07:58 -04:00
1 parent 2054fa2558
commit d77cc6a40e
8 files changed
+447 -8

No files matched your search

+29
View File
@@ -149,3 +149,32 @@ pub enum EditorCommand {
snapshot: EditorEntitySnapshot,
},
}
impl EditorCommand {
pub fn label(&self) -> &'static str {
match self {
EditorCommand::Spawn { .. } => "Spawn",
EditorCommand::Despawn { .. } => "Delete",
EditorCommand::Duplicate { .. } => "Duplicate",
EditorCommand::Rename { .. } => "Rename",
EditorCommand::SetTransform { .. } => "Move",
EditorCommand::SetMaterial { .. } => "Set Material",
EditorCommand::SetMaterialOverride { .. } => "Set Material Override",
EditorCommand::SetLight { .. } => "Set Light",
EditorCommand::SetPhysics { .. } => "Set Physics",
EditorCommand::SetRigidBody { .. } => "Set Rigid Body",
EditorCommand::SetCollider { .. } => "Set Collider",
EditorCommand::SetPrimitive { .. } => "Set Primitive",
EditorCommand::SetStaticMeshRenderer { .. } => "Set Static Mesh Renderer",
EditorCommand::SetPostProcessVolume { .. } => "Set Post Process Volume",
EditorCommand::SetTransformGroup { .. } => "Move Selection",
EditorCommand::Reparent { .. } => "Reparent",
EditorCommand::SetActorKind { .. } => "Set Actor Kind",
EditorCommand::ReorderSibling { .. } => "Reorder Hierarchy",
EditorCommand::SetEditorVisibility { .. } => "Set Visibility",
EditorCommand::SetInspectorOrder { .. } => "Set Component Order",
EditorCommand::AddComponent { .. } => "Add Component",
EditorCommand::RemoveComponent { .. } => "Remove Component",
}
}
}
+18 -1
View File
@@ -27,9 +27,10 @@ pub struct EditorHistory {
impl EditorHistory {
pub fn push(&mut self, command: EditorCommand) {
let label = command.label();
self.undo_stack.push(command);
self.redo_stack.clear();
self.status = format!("Undo: {} command(s), redo cleared", self.undo_stack.len());
self.status = format!("Undo: {label}");
}
pub fn can_undo(&self) -> bool {
@@ -40,6 +41,18 @@ impl EditorHistory {
!self.redo_stack.is_empty()
}
pub fn undo_depth(&self) -> usize {
self.undo_stack.len()
}
pub fn set_undo_status(&mut self, label: impl Into<String>) {
self.status = format!("Undo: {}", label.into());
}
fn set_redo_status(&mut self, label: impl Into<String>) {
self.status = format!("Redo: {}", label.into());
}
fn pop_undo(&mut self) -> Option<EditorCommand> {
self.undo_stack.pop()
}
@@ -695,8 +708,10 @@ pub fn apply_command_undo(world: &mut World) {
let Some(mut command) = world.resource_mut::<EditorHistory>().pop_undo() else {
return;
};
let label = command.label();
undo_command(world, &mut command);
world.resource_mut::<EditorHistory>().push_redo(command);
world.resource_mut::<EditorHistory>().set_redo_status(label);
mark_dirty(world);
}
@@ -704,8 +719,10 @@ pub fn apply_command_redo(world: &mut World) {
let Some(mut command) = world.resource_mut::<EditorHistory>().pop_redo() else {
return;
};
let label = command.label();
redo_command(world, &mut command);
world.resource_mut::<EditorHistory>().push_undo(command);
world.resource_mut::<EditorHistory>().set_undo_status(label);
mark_dirty(world);
}