Upgrade to Bevy 0.19 and harden editor workflows
CI / Format, lint, test, build (push) Has been cancelled
CI / Format, lint, test, build (push) Has been cancelled
This commit is contained in:
1 parent
3f85d25cc7
commit
b5e561904c
204 files changed
+6972
-29907
No files matched your search
@@ -35,6 +35,12 @@ pub struct EditorCommandRegistry {
|
||||
commands: Vec<Box<dyn EditorCommand>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct EditorCommandEntry {
|
||||
pub name: String,
|
||||
pub label: String,
|
||||
}
|
||||
|
||||
impl EditorCommandRegistry {
|
||||
pub fn register(&mut self, command: Box<dyn EditorCommand>) {
|
||||
self.commands.push(command);
|
||||
@@ -47,6 +53,16 @@ impl EditorCommandRegistry {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn entries(&self) -> Vec<EditorCommandEntry> {
|
||||
self.commands
|
||||
.iter()
|
||||
.map(|command| EditorCommandEntry {
|
||||
name: command.name().to_string(),
|
||||
label: command.label().to_string(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn command_state(&self, world: &World, name: &str) -> Option<(String, Option<String>)> {
|
||||
self.commands
|
||||
.iter()
|
||||
@@ -249,6 +265,10 @@ impl EditorCommand for TogglePlayCommand {
|
||||
"play.toggle"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Toggle Play / Edit"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
toggle_play_mode(world);
|
||||
}
|
||||
@@ -261,6 +281,15 @@ impl EditorCommand for TogglePlayPausedCommand {
|
||||
"play.toggle_pause"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Pause / Resume Simulation"
|
||||
}
|
||||
|
||||
fn disabled_reason(&self, world: &World) -> Option<String> {
|
||||
(*world.resource::<State<EditorMode>>().get() != EditorMode::Playing)
|
||||
.then(|| "Enter Play mode before pausing the simulation".to_string())
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
toggle_play_paused(world);
|
||||
}
|
||||
@@ -273,6 +302,10 @@ impl EditorCommand for TogglePossessionCommand {
|
||||
"play.toggle_possession"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Possess / Eject Player"
|
||||
}
|
||||
|
||||
fn disabled_reason(&self, world: &World) -> Option<String> {
|
||||
(*world.resource::<State<EditorMode>>().get() != EditorMode::Playing)
|
||||
.then(|| "Enter Play mode before toggling possession".to_string())
|
||||
@@ -294,6 +327,10 @@ impl EditorCommand for ResetLightingCommand {
|
||||
"scene.reset_lighting"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Reset Scene Lighting"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
reset_scene_lighting_to_project_defaults(world);
|
||||
}
|
||||
@@ -306,6 +343,10 @@ impl EditorCommand for GroupSelectionCommand {
|
||||
"selection.group"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Group Selection"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
let selected: Vec<Entity> = world
|
||||
.resource::<UiState>()
|
||||
@@ -323,6 +364,10 @@ impl EditorCommand for FocusSelectionCommand {
|
||||
"selection.focus"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Focus Selection"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
focus_editor_camera_on_selection(world);
|
||||
}
|
||||
@@ -335,6 +380,10 @@ impl EditorCommand for ResetSelectionTransformCommand {
|
||||
"selection.reset_transform"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Reset Selection Transform"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
reset_selected_transforms(world);
|
||||
}
|
||||
@@ -428,6 +477,10 @@ impl EditorCommand for CreatePostProcessVolumeCommand {
|
||||
"rendering.create_volume"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Create Post-process Volume"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
crate::rendering_diagnostics::spawn_post_process_volume_at_camera(world);
|
||||
}
|
||||
@@ -440,6 +493,10 @@ impl EditorCommand for FocusActiveVolumesCommand {
|
||||
"rendering.focus_active_volumes"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Focus Active Post-process Volumes"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
crate::rendering_diagnostics::select_volumes_at_camera(world);
|
||||
focus_editor_camera_on_selection(world);
|
||||
@@ -453,6 +510,10 @@ impl EditorCommand for SelectVolumesAtCameraCommand {
|
||||
"rendering.select_volumes_at_camera"
|
||||
}
|
||||
|
||||
fn label(&self) -> &str {
|
||||
"Select Volumes at Camera"
|
||||
}
|
||||
|
||||
fn execute(&self, world: &mut World) {
|
||||
crate::rendering_diagnostics::select_volumes_at_camera(world);
|
||||
}
|
||||
@@ -471,6 +532,7 @@ fn command_palette_ui(
|
||||
|
||||
if ctx.input(|input| input.modifiers.command && input.key_pressed(egui::Key::P)) {
|
||||
palette.open = true;
|
||||
palette.filter.clear();
|
||||
palette.focus_filter = true;
|
||||
palette.selected_index = 0;
|
||||
}
|
||||
@@ -480,19 +542,20 @@ fn command_palette_ui(
|
||||
}
|
||||
|
||||
let mut open = palette.open;
|
||||
let palette_width = (ctx.content_rect().width() - 32.0).clamp(320.0, 520.0);
|
||||
egui::Window::new("Command Palette")
|
||||
.open(&mut open)
|
||||
.default_width(400.0)
|
||||
.frame(egui::Frame::window(&ctx.style()).fill(PANEL_BG))
|
||||
.anchor(egui::Align2::CENTER_TOP, egui::vec2(0.0, 64.0))
|
||||
.collapsible(false)
|
||||
.resizable(false)
|
||||
.default_width(palette_width)
|
||||
.min_width(palette_width)
|
||||
.max_width(palette_width)
|
||||
.frame(egui::Frame::window(&ctx.global_style()).fill(PANEL_BG))
|
||||
.show(ctx, |ui| {
|
||||
ui.label(
|
||||
egui::RichText::new("Ctrl+P — filter and run commands")
|
||||
.color(TEXT_DIM)
|
||||
.small(),
|
||||
);
|
||||
let filter_response = ui.add(
|
||||
egui::TextEdit::singleline(&mut palette.filter)
|
||||
.hint_text("Type to filter...")
|
||||
.hint_text("Search commands...")
|
||||
.desired_width(f32::INFINITY),
|
||||
);
|
||||
if palette.focus_filter {
|
||||
@@ -503,35 +566,30 @@ fn command_palette_ui(
|
||||
palette.selected_index = 0;
|
||||
}
|
||||
|
||||
let filter = palette.filter.to_lowercase();
|
||||
let filtered_names: Vec<String> = registry
|
||||
.names()
|
||||
.into_iter()
|
||||
.filter(|name| filter.is_empty() || name.to_lowercase().contains(&filter))
|
||||
.collect();
|
||||
if !filtered_names.is_empty() {
|
||||
palette.selected_index = palette.selected_index.min(filtered_names.len() - 1);
|
||||
let filtered_entries = filtered_command_entries(®istry, &palette.filter);
|
||||
if !filtered_entries.is_empty() {
|
||||
palette.selected_index = palette.selected_index.min(filtered_entries.len() - 1);
|
||||
} else {
|
||||
palette.selected_index = 0;
|
||||
}
|
||||
|
||||
if ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::ArrowDown))
|
||||
&& !filtered_names.is_empty()
|
||||
&& !filtered_entries.is_empty()
|
||||
{
|
||||
palette.selected_index = (palette.selected_index + 1) % filtered_names.len();
|
||||
palette.selected_index = (palette.selected_index + 1) % filtered_entries.len();
|
||||
}
|
||||
if ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::ArrowUp))
|
||||
&& !filtered_names.is_empty()
|
||||
&& !filtered_entries.is_empty()
|
||||
{
|
||||
palette.selected_index = if palette.selected_index == 0 {
|
||||
filtered_names.len() - 1
|
||||
filtered_entries.len() - 1
|
||||
} else {
|
||||
palette.selected_index - 1
|
||||
};
|
||||
}
|
||||
if ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::Enter)) {
|
||||
if let Some(name) = filtered_names.get(palette.selected_index) {
|
||||
palette.pending_run = Some(name.clone());
|
||||
if let Some(entry) = filtered_entries.get(palette.selected_index) {
|
||||
palette.pending_run = Some(entry.name.clone());
|
||||
palette.open = false;
|
||||
ui.close();
|
||||
}
|
||||
@@ -543,18 +601,23 @@ fn command_palette_ui(
|
||||
|
||||
ui.separator();
|
||||
egui::ScrollArea::vertical()
|
||||
.max_height(280.0)
|
||||
.max_height(320.0)
|
||||
.show(ui, |ui| {
|
||||
for (index, name) in filtered_names.iter().enumerate() {
|
||||
if filtered_entries.is_empty() {
|
||||
ui.weak("No matching commands");
|
||||
}
|
||||
for (index, entry) in filtered_entries.iter().enumerate() {
|
||||
let selected = index == palette.selected_index;
|
||||
let response =
|
||||
ui.selectable_label(selected, egui::RichText::new(name).color(TEXT));
|
||||
let response = ui.add_sized(
|
||||
[ui.available_width(), 40.0],
|
||||
egui::Button::selectable(selected, command_palette_row(entry)),
|
||||
);
|
||||
if selected {
|
||||
response.scroll_to_me(Some(egui::Align::Center));
|
||||
}
|
||||
if response.clicked() {
|
||||
palette.selected_index = index;
|
||||
palette.pending_run = Some(name.clone());
|
||||
palette.pending_run = Some(entry.name.clone());
|
||||
palette.open = false;
|
||||
ui.close();
|
||||
}
|
||||
@@ -565,3 +628,73 @@ fn command_palette_ui(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn filtered_command_entries(
|
||||
registry: &EditorCommandRegistry,
|
||||
filter: &str,
|
||||
) -> Vec<EditorCommandEntry> {
|
||||
let filter = filter.trim().to_lowercase();
|
||||
registry
|
||||
.entries()
|
||||
.into_iter()
|
||||
.filter(|entry| {
|
||||
filter.is_empty()
|
||||
|| entry.name.to_lowercase().contains(&filter)
|
||||
|| entry.label.to_lowercase().contains(&filter)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn command_palette_row(entry: &EditorCommandEntry) -> egui::WidgetText {
|
||||
let mut job = egui::text::LayoutJob::default();
|
||||
job.append(
|
||||
&entry.label,
|
||||
0.0,
|
||||
egui::TextFormat {
|
||||
font_id: egui::FontId::new(13.0, egui::FontFamily::Proportional),
|
||||
color: TEXT,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
job.append(
|
||||
&format!("\n{}", entry.name),
|
||||
0.0,
|
||||
egui::TextFormat {
|
||||
font_id: egui::FontId::new(11.0, egui::FontFamily::Monospace),
|
||||
color: TEXT_DIM,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
job.into()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn command_filter_matches_human_label_and_stable_id() {
|
||||
let mut registry = EditorCommandRegistry::default();
|
||||
registry.register(Box::new(TogglePlayCommand));
|
||||
registry.register(Box::new(ResetLightingCommand));
|
||||
|
||||
let by_label = filtered_command_entries(®istry, "scene lighting");
|
||||
assert_eq!(by_label.len(), 1);
|
||||
assert_eq!(by_label[0].name, "scene.reset_lighting");
|
||||
|
||||
let by_id = filtered_command_entries(®istry, "play.toggle");
|
||||
assert_eq!(by_id.len(), 1);
|
||||
assert_eq!(by_id[0].label, "Toggle Play / Edit");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_command_filter_preserves_registration_order() {
|
||||
let mut registry = EditorCommandRegistry::default();
|
||||
registry.register(Box::new(TogglePlayCommand));
|
||||
registry.register(Box::new(ResetLightingCommand));
|
||||
|
||||
let entries = filtered_command_entries(®istry, " ");
|
||||
assert_eq!(entries[0].name, "play.toggle");
|
||||
assert_eq!(entries[1].name, "scene.reset_lighting");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user