Improve quick brush creation workflow

This commit is contained in:
Rbanh committed 2026-06-06 14:16:12 -04:00
1 parent f09d35e54e
commit 48b1448c57
9 files changed
+701 -61

No files matched your search

+5
View File
@@ -50,6 +50,10 @@ pub enum EditorCommand {
snapshot: EditorEntitySnapshot,
entity: Option<Entity>,
},
SpawnMany {
snapshots: Vec<EditorEntitySnapshot>,
entities: Vec<Entity>,
},
Despawn {
snapshot: EditorEntitySnapshot,
entity: Option<Entity>,
@@ -160,6 +164,7 @@ impl EditorCommand {
pub fn label(&self) -> &'static str {
match self {
EditorCommand::Spawn { .. } => "Spawn",
EditorCommand::SpawnMany { .. } => "Spawn Brushes",
EditorCommand::Despawn { .. } => "Delete",
EditorCommand::Duplicate { .. } => "Duplicate",
EditorCommand::Rename { .. } => "Rename",
+45
View File
@@ -274,6 +274,34 @@ pub fn spawn_with_history(world: &mut World, mut snapshot: EditorEntitySnapshot)
entity
}
pub fn spawn_many_with_history(
world: &mut World,
snapshots: impl IntoIterator<Item = EditorEntitySnapshot>,
) -> Vec<Entity> {
let mut snapshots: Vec<EditorEntitySnapshot> = snapshots.into_iter().collect();
if snapshots.is_empty() {
return Vec::new();
}
let mut sibling_index = next_sibling_index(world, None);
for snapshot in &mut snapshots {
snapshot.hierarchy_sibling_index = sibling_index;
sibling_index += 1;
}
let entities: Vec<Entity> = snapshots
.iter()
.map(|snapshot| spawn_snapshot(world, snapshot))
.collect();
push_history(
world,
EditorCommand::SpawnMany {
snapshots,
entities: entities.clone(),
},
);
select_many(world, &entities);
entities
}
pub fn delete_entities_with_history(world: &mut World, entities: &[Entity]) {
let mut deleted = Vec::new();
for entity in entities {
@@ -752,6 +780,12 @@ fn undo_command(world: &mut World, command: &mut EditorCommand) {
despawn_entity(world, entity.take());
clear_selection(world);
}
EditorCommand::SpawnMany { entities, .. } => {
for entity in std::mem::take(entities) {
despawn_entity(world, Some(entity));
}
clear_selection(world);
}
EditorCommand::Despawn { snapshot, entity } => {
let spawned = spawn_snapshot(world, snapshot);
*entity = Some(spawned);
@@ -847,6 +881,17 @@ fn redo_command(world: &mut World, command: &mut EditorCommand) {
*entity = Some(spawned);
select_one(world, spawned);
}
EditorCommand::SpawnMany {
snapshots,
entities,
} => {
let spawned: Vec<Entity> = snapshots
.iter()
.map(|snapshot| spawn_snapshot(world, snapshot))
.collect();
*entities = spawned.clone();
select_many(world, &spawned);
}
EditorCommand::Despawn { entity, .. } => {
despawn_entity(world, entity.take());
clear_selection(world);