Skip to content

Commit

Permalink
Merge pull request #295 from rewin123/issue-279-last-pr
Browse files Browse the repository at this point in the history
Issue 279 last pr
  • Loading branch information
rewin123 authored Apr 11, 2024
2 parents b678b6c + c9ee43f commit 23b9fb2
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 33 deletions.
6 changes: 5 additions & 1 deletion crates/editor_core/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ use space_shared::{toast::ToastMessage, *};
use crate::EditorLoader;

pub fn load_listener(world: &mut World) {
// AppTypeRegistry and are injected in Startup

Check warning on line 7 in crates/editor_core/src/load.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_core/src/load.rs#L7

Added line #L7 was not covered by tests
let app_registry = world.resource::<AppTypeRegistry>().clone();
let load_server = world.resource::<EditorLoader>().clone();
let Some(load_server) = world.get_resource::<EditorLoader>().cloned() else {
error!("Failed to get Editor Loader");
return;

Check warning on line 11 in crates/editor_core/src/load.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_core/src/load.rs#L9-L11

Added lines #L9 - L11 were not covered by tests
};
let mut prefab;
{
let assets = world.resource::<Assets<DynamicScene>>();
Expand Down
20 changes: 16 additions & 4 deletions crates/editor_ui/src/camera_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ fn create_camera_image(width: u32, height: u32) -> Image {
impl EditorTab for CameraViewTab {
fn ui(&mut self, ui: &mut bevy_egui::egui::Ui, commands: &mut Commands, world: &mut World) {
if self.real_camera.is_none() {
if world.resource::<GameModeSettings>().is_3d() {
if world
.get_resource::<GameModeSettings>()
.map_or(false, |mode| mode.is_3d())
{

Check warning on line 81 in crates/editor_ui/src/camera_view.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/camera_view.rs#L78-L81

Added lines #L78 - L81 were not covered by tests
self.real_camera = Some(
commands
.spawn((
Expand All @@ -95,7 +98,10 @@ impl EditorTab for CameraViewTab {
))
.id(),
);
} else if world.resource::<GameModeSettings>().is_2d() {
} else if world
.get_resource::<GameModeSettings>()
.map_or(false, |mode| mode.is_2d())
{

Check warning on line 104 in crates/editor_ui/src/camera_view.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/camera_view.rs#L101-L104

Added lines #L101 - L104 were not covered by tests
self.real_camera = Some(
commands
.spawn((
Expand Down Expand Up @@ -152,7 +158,10 @@ impl EditorTab for CameraViewTab {
ui.spacing();
ui.separator();
ui.spacing();
if world.resource::<GameModeSettings>().is_3d() {
if world
.get_resource::<GameModeSettings>()
.map_or(false, |mode| mode.is_3d())

Check warning on line 163 in crates/editor_ui/src/camera_view.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/camera_view.rs#L161-L163

Added lines #L161 - L163 were not covered by tests
{
ui.spacing();
if ui.button("Add 3D Playmode Camera").clicked() {
commands.spawn((
Expand Down Expand Up @@ -212,7 +221,10 @@ impl EditorTab for CameraViewTab {
);
world.send_event(ToastMessage::new(&msg, toast::ToastKind::Success));
} else if let Some(handle) = &self.target_image {
if let Some(image) = world.resource::<Assets<Image>>().get(handle) {
if let Some(image) = world
.get_resource::<Assets<Image>>()
.and_then(|asset| asset.get(handle))

Check warning on line 226 in crates/editor_ui/src/camera_view.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/camera_view.rs#L224-L226

Added lines #L224 - L226 were not covered by tests
{
if image.texture_descriptor.size.width != clipped.width() as u32
|| image.texture_descriptor.size.height != clipped.height() as u32
{
Expand Down
5 changes: 4 additions & 1 deletion crates/editor_ui/src/change_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ impl EditorTab for ChangeChainView {
_commands: &mut bevy::prelude::Commands,
world: &mut bevy::prelude::World,
) {
let change_chain = world.resource::<ChangeChain>();
let Some(change_chain) = world.get_resource::<ChangeChain>() else {
error!("Failed to get Change Chain");
return;

Check warning on line 28 in crates/editor_ui/src/change_chain.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/change_chain.rs#L26-L28

Added lines #L26 - L28 were not covered by tests
};

for change in change_chain.changes.iter() {
ui.label(change.debug_text());
Expand Down
2 changes: 1 addition & 1 deletion crates/editor_ui/src/editor_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ impl TabStyle for EditorStyle {
}

Check warning on line 38 in crates/editor_ui/src/editor_style.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/editor_style.rs#L16-L38

Added lines #L16 - L38 were not covered by tests

fn text_size(&self, world: &World) -> f32 {
world.resource::<Sizing>().text
world.get_resource::<Sizing>().map_or(12., |size| size.text)
}

Check warning on line 42 in crates/editor_ui/src/editor_style.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/editor_style.rs#L40-L42

Added lines #L40 - L42 were not covered by tests
}
9 changes: 6 additions & 3 deletions crates/editor_ui/src/inspector/components_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ impl ComponentsPriority for App {
if !self.world.contains_resource::<ComponentsOrder>() {
self.insert_resource(ComponentsOrder::default());
}
let component_name = pretty_type_name::pretty_type_name::<T>();
let mut order = self.world.resource_mut::<ComponentsOrder>();
order.components.insert(component_name, priority);
if let Some(mut order) = self.world.get_resource_mut::<ComponentsOrder>() {
let component_name = pretty_type_name::pretty_type_name::<T>();
order.components.insert(component_name, priority);
} else {
error!("Failed to configure components order");

Check warning on line 30 in crates/editor_ui/src/inspector/components_order.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/inspector/components_order.rs#L26-L30

Added lines #L26 - L30 were not covered by tests
}

self
}
Expand Down
8 changes: 7 additions & 1 deletion crates/editor_ui/src/inspector/events_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ impl EditorTab for EventDispatcherTab {
}

pub fn inspect(ui: &mut egui::Ui, world: &mut World, open_events: &mut HashMap<String, bool>) {
let events = &mut world.resource::<EditorRegistry>().send_events.clone();
let Some(events) = &world.get_resource::<EditorRegistry>() else {
error!("Failed to get event registry");
return;

Check warning on line 26 in crates/editor_ui/src/inspector/events_dispatcher.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/inspector/events_dispatcher.rs#L24-L26

Added lines #L24 - L26 were not covered by tests
};
let mut events = events.send_events.clone();

Check warning on line 29 in crates/editor_ui/src/inspector/events_dispatcher.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/inspector/events_dispatcher.rs#L28-L29

Added lines #L28 - L29 were not covered by tests
events.sort_by(|a, b| a.name().cmp(b.name()));

if events.is_empty() {
ui.label(egui::RichText::new("No events registered").color(ERROR_COLOR));
} else {
// Safe as was injected by Bevy

Check warning on line 35 in crates/editor_ui/src/inspector/events_dispatcher.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/inspector/events_dispatcher.rs#L35

Added line #L35 was not covered by tests
let type_registry = world.resource::<AppTypeRegistry>().clone();
let type_registry = type_registry.read();

Expand Down
20 changes: 15 additions & 5 deletions crates/editor_ui/src/inspector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ pub struct InspectorTab {

impl EditorTab for InspectorTab {
fn ui(&mut self, ui: &mut egui::Ui, _: &mut Commands, world: &mut World) {
let sizing = world.resource::<Sizing>().clone();
// Defaults in case it is missing
let sizing = world.get_resource::<Sizing>().cloned().unwrap_or_default();

Check warning on line 75 in crates/editor_ui/src/inspector/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/inspector/mod.rs#L74-L75

Added lines #L74 - L75 were not covered by tests
let selected_entity = world
.query_filtered::<Entity, With<Selected>>()
.get_single(world);
Expand All @@ -88,8 +89,12 @@ impl EditorTab for InspectorTab {
let app_registry = app_registry_handle.read();
let mut disable_pan_orbit = false;

//Collet data about all components
let components_priority = world.resource::<ComponentsOrder>().clone().components;
//Collet data about all components | empty if missing
let components_priority = world
.get_resource::<ComponentsOrder>()
.cloned()
.unwrap_or_default()
.components;

Check warning on line 97 in crates/editor_ui/src/inspector/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/inspector/mod.rs#L92-L97

Added lines #L92 - L97 were not covered by tests
let mut components_id = Vec::new();
if self.show_all_components {
for reg in app_registry.iter() {
Expand Down Expand Up @@ -352,8 +357,13 @@ impl EditorTab for InspectorTab {

state.commands = commands;

if disable_pan_orbit {
world.resource_mut::<crate::EditorCameraEnabled>().0 = false;
if let (Some(mut editor_camera_enabled), true) = (
world.get_resource_mut::<crate::EditorCameraEnabled>(),
disable_pan_orbit,
) {
editor_camera_enabled.0 = false;
} else {
error!("Failed to get editor camera config");

Check warning on line 366 in crates/editor_ui/src/inspector/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/inspector/mod.rs#L360-L366

Added lines #L360 - L366 were not covered by tests
}
}

Expand Down
9 changes: 6 additions & 3 deletions crates/editor_ui/src/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ impl Plugin for EditorPickingPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(bevy_mod_picking::DefaultPickingPlugins);

app.world
.resource_mut::<bevy_mod_picking::backends::raycast::RaycastBackendSettings>()
.require_markers = true;
if let Some(mut raycast_backend) =
app.world
.get_resource_mut::<bevy_mod_picking::backends::raycast::RaycastBackendSettings>()
{
raycast_backend.require_markers = true;
}

Check warning on line 15 in crates/editor_ui/src/selection.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/selection.rs#L10-L15

Added lines #L10 - L15 were not covered by tests

app.add_systems(
PostUpdate,
Expand Down
12 changes: 9 additions & 3 deletions crates/editor_ui/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ impl RegisterSettingsBlockExt for App {

impl EditorTab for SettingsWindow {
fn ui(&mut self, ui: &mut egui::Ui, commands: &mut Commands, world: &mut World) {
let game_mode_setting = &world.resource::<GameModeSettings>();
let Some(game_mode_setting) = &world.get_resource::<GameModeSettings>() else {
error!("Game Mode settings not available");
return;

Check warning on line 151 in crates/editor_ui/src/settings.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/settings.rs#L149-L151

Added lines #L149 - L151 were not covered by tests
};
if let Some(new_game_mode) = game_mode_setting.ui(ui) {
info!("Game Mode changed: {:?}", new_game_mode);
*world.resource_mut::<GameModeSettings>() = new_game_mode;
Expand All @@ -162,8 +165,11 @@ impl EditorTab for SettingsWindow {

ui.add_space(12.);
ui.heading("New Tab Behaviour");
let new_window_settings = &mut world.resource_mut::<NewWindowSettings>();
new_window_settings.ui(ui);
if let Some(new_window_settings) = &mut world.get_resource_mut::<NewWindowSettings>() {
new_window_settings.ui(ui);
} else {
error!("New window settings not available");

Check warning on line 171 in crates/editor_ui/src/settings.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/settings.rs#L168-L171

Added lines #L168 - L171 were not covered by tests
}

ui.add_space(12.);
ui.heading("Default Sizing");
Expand Down
9 changes: 5 additions & 4 deletions crates/editor_ui/src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ impl ToolExt for App {
where
T: EditorTool + Send + Sync + 'static,
{
self.world
.resource_mut::<GameViewTab>()
.tools
.push(Box::new(tool));
if let Some(mut game_view) = self.world.get_resource_mut::<GameViewTab>() {
game_view.tools.push(Box::new(tool));
} else {
error!("Game View tab not loaded");

Check warning on line 44 in crates/editor_ui/src/tool.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/tool.rs#L41-L44

Added lines #L41 - L44 were not covered by tests
}
}
}
10 changes: 8 additions & 2 deletions crates/editor_ui/src/tools/gizmo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ impl Plugin for GizmoToolPlugin {
fn build(&self, app: &mut App) {
app.editor_tool(GizmoTool::default());

app.world.resource_mut::<GameViewTab>().active_tool = Some(0);
if let Some(mut game_view_tab) = app.world.get_resource_mut::<GameViewTab>() {
game_view_tab.active_tool = Some(0);
}

Check warning on line 23 in crates/editor_ui/src/tools/gizmo.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/tools/gizmo.rs#L21-L23

Added lines #L21 - L23 were not covered by tests
app.init_resource::<MultipleCenter>();

app.editor_hotkey(GizmoHotkey::Translate, vec![KeyCode::KeyG]);
Expand Down Expand Up @@ -95,6 +97,7 @@ impl EditorTool for GizmoTool {
// If SHIFT+ALT pressed, then all selected entities will be cloned at interact
// All hotkeys can be changes in editor ui

// Not much we can do

Check warning on line 100 in crates/editor_ui/src/tools/gizmo.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/tools/gizmo.rs#L100

Added line #L100 was not covered by tests
let sizing = world.resource::<Sizing>();

ui.spacing();
Expand All @@ -119,7 +122,10 @@ impl EditorTool for GizmoTool {
}
});

let input = world.resource::<ButtonInput<GizmoHotkey>>();
let Some(input) = world.get_resource::<ButtonInput<GizmoHotkey>>() else {
warn!("Failed to retrieve gizmos hotkey button input");
return;

Check warning on line 127 in crates/editor_ui/src/tools/gizmo.rs

View check run for this annotation

Codecov / codecov/patch

crates/editor_ui/src/tools/gizmo.rs#L125-L127

Added lines #L125 - L127 were not covered by tests
};

let mut del = false;
let mut clone_pressed = false;
Expand Down
11 changes: 6 additions & 5 deletions modules/bevy_xpbd_plugin/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ impl Plugin for BevyXpbdPlugin {
if app.is_plugin_added::<space_editor_ui::ui_plugin::EditorUiCore>() {
app.register_settings_block("Bevy XPBD 3D", |ui, _, world| {
ui.checkbox(
&mut world
.resource_mut::<GizmoConfigStore>()
.config_mut::<PhysicsGizmos>()
.1
.hide_meshes,
&mut world.get_resource_mut::<GizmoConfigStore>().map_or(
false,
|mut gizmos_config| {
gizmos_config.config_mut::<PhysicsGizmos>().1.hide_meshes
},
),

Check warning on line 87 in modules/bevy_xpbd_plugin/src/registry.rs

View check run for this annotation

Codecov / codecov/patch

modules/bevy_xpbd_plugin/src/registry.rs#L82-L87

Added lines #L82 - L87 were not covered by tests
"Hide debug meshes",
);
});
Expand Down

0 comments on commit 23b9fb2

Please sign in to comment.