This commit is contained in:
1 parent
d77cc6a40e
commit
cc6acb188d
11 files changed
+548
-165
No files matched your search
@@ -4,6 +4,7 @@ pub mod asset_db;
|
||||
mod catalog;
|
||||
mod import;
|
||||
pub mod materials;
|
||||
pub mod operators;
|
||||
pub mod prefab_overrides;
|
||||
pub mod static_mesh;
|
||||
pub mod thumbnails;
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
//! Operator wrappers for asset placement and assignment workflows.
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_inspector_egui::bevy_inspector::hierarchy::SelectedEntities;
|
||||
|
||||
use crate::operators::{run_immediate_operator, OperatorAvailability};
|
||||
use crate::ui::helpers::{
|
||||
apply_material_asset_to_selection, apply_texture_to_selection, selected_level_entities,
|
||||
};
|
||||
|
||||
use super::{spawn_asset_at, spawn_subasset_at, AssetSelection, EditorAsset};
|
||||
|
||||
fn selection_availability(world: &World, selected: &SelectedEntities) -> OperatorAvailability {
|
||||
if selected_level_entities(world, selected).is_empty() {
|
||||
OperatorAvailability::Disabled("Select at least one authored actor".to_string())
|
||||
} else {
|
||||
OperatorAvailability::Ready
|
||||
}
|
||||
}
|
||||
|
||||
pub fn place_asset_operator(world: &mut World, asset: EditorAsset, translation: Vec3) -> bool {
|
||||
let label = format!("Place {}", asset.label);
|
||||
run_immediate_operator(
|
||||
world,
|
||||
"assets.place",
|
||||
&label,
|
||||
OperatorAvailability::Ready,
|
||||
move |world| {
|
||||
spawn_asset_at(world, &asset, translation)
|
||||
.map(|_| ())
|
||||
.ok_or_else(|| format!("Asset cannot be placed: {}", asset.label))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn place_subasset_operator(
|
||||
world: &mut World,
|
||||
selection: AssetSelection,
|
||||
translation: Vec3,
|
||||
) -> bool {
|
||||
let label = format!("Place {}", selection.display_label());
|
||||
run_immediate_operator(
|
||||
world,
|
||||
"assets.place_subasset",
|
||||
&label,
|
||||
OperatorAvailability::Ready,
|
||||
move |world| {
|
||||
spawn_subasset_at(world, &selection, translation)
|
||||
.map(|_| ())
|
||||
.ok_or_else(|| format!("Sub-asset cannot be placed: {}", selection.display_label()))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn apply_texture_operator(
|
||||
world: &mut World,
|
||||
asset: EditorAsset,
|
||||
selected: &SelectedEntities,
|
||||
) -> bool {
|
||||
let label = format!("Apply Texture {}", asset.label);
|
||||
let availability = selection_availability(world, selected);
|
||||
let selected = selected;
|
||||
run_immediate_operator(
|
||||
world,
|
||||
"assets.apply_texture",
|
||||
&label,
|
||||
availability,
|
||||
move |world| {
|
||||
apply_texture_to_selection(world, &asset, &selected);
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn apply_material_operator(
|
||||
world: &mut World,
|
||||
asset: EditorAsset,
|
||||
selected: &SelectedEntities,
|
||||
) -> bool {
|
||||
let label = format!("Apply Material {}", asset.label);
|
||||
let availability = selection_availability(world, selected);
|
||||
let selected = selected;
|
||||
run_immediate_operator(
|
||||
world,
|
||||
"assets.apply_material",
|
||||
&label,
|
||||
availability,
|
||||
move |world| {
|
||||
apply_material_asset_to_selection(world, &asset, &selected);
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user