use std::path::PathBuf; use bevy::prelude::*; use shared::{ ActorId, ActorKind, ActorName, AnimationControllerDesc, AudioListenerDesc, AudioSourceDesc, AuthoringComponentStates, BrushDesc, ColliderDesc, EditorVisibility, InspectorOrder, LightDesc, MaterialDesc, MaterialOverride, ModelRef, NavigationArea, NavigationBounds, NavigationLink, NavigationObstacle, ObjectiveMarker, PhysicsBody, PostProcessVolumeDesc, PrefabInstance, PrefabRef, Primitive, RigidBodyDesc, SceneComposition, SkinnedMeshRenderer, StaticMeshRenderer, TeamSpawn, TriggerVolume, WeaponSpawn, }; #[derive(Debug, Clone)] pub struct EditorEntitySnapshot { pub actor_id: Option, pub actor_kind: ActorKind, pub actor_name: Option, pub name: Option, pub transform: Transform, pub primitive: Option, pub brush: Option, pub static_mesh_renderer: Option, pub skinned_mesh_renderer: Option, pub material: Option, pub material_override: Option, pub rigid_body: Option, pub collider: Option, pub physics: Option, pub light: Option, pub animation_controller: Option, pub audio_source: Option, pub audio_listener: Option, pub player_spawn: bool, pub model: Option, pub prefab: Option, pub prefab_instance: Option, pub weapon_spawn: Option, pub trigger_volume: Option, pub post_process_volume: Option, pub team_spawn: Option, pub objective: Option, pub navigation_bounds: Option, pub navigation_obstacle: Option, pub navigation_area: Option, pub navigation_link: Option, pub hierarchy_sibling_index: i32, pub editor_visibility: EditorVisibility, pub inspector_order: Option, pub component_states: Option, pub children: Vec, } /// One reflected component value used by registry-driven editor transactions. /// `component_id` is stable; `type_path` is retained only to resolve Bevy's /// reflection adapter for this build. #[derive(Debug, Clone, PartialEq, Eq)] pub struct ReflectedComponentValue { pub component_id: String, pub type_path: String, pub ron: String, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct ComponentDelta { pub component_id: String, pub type_path: String, pub before: Option, pub after: Option, } /// An atomic add/remove/reset/paste operation. Requirements, dependent removals, /// and the derived ActorKind hint can be represented as additional deltas. #[derive(Debug, Clone, PartialEq, Eq)] pub struct ComponentTransaction { pub entity: Entity, pub label: &'static str, pub deltas: Vec, } #[derive(Debug, Clone, Default, PartialEq)] pub struct NavigationComponentState { pub bounds: Option, pub obstacle: Option, pub area: Option, pub link: Option, } #[derive(Debug, Clone)] pub struct SiblingChange { pub entity: Entity, pub old_parent: Option, pub new_parent: Option, pub old_index: i32, pub new_index: i32, pub old_transform: Option, pub new_transform: Option, } #[derive(Debug, Clone, PartialEq)] pub struct PrefabEditState { pub instance: Option, pub prefab_ref: Option, pub blocked_reason: Option, pub transform: Option, pub material: Option, } #[derive(Debug, Clone)] pub enum EditorCommand { GroupSelection { snapshot: EditorEntitySnapshot, group: Option, changes: Vec, }, Spawn { snapshot: EditorEntitySnapshot, entity: Option, }, SpawnMany { snapshots: Vec, entities: Vec, }, Despawn { snapshot: EditorEntitySnapshot, entity: Option, }, Duplicate { snapshots: Vec, entities: Vec, }, Rename { entity: Entity, old: String, new: String, }, SetTransform { entity: Entity, old: Transform, new: Transform, }, SetMaterial { entity: Entity, old: Option, new: MaterialDesc, }, SetMaterialGroup { entities: Vec, olds: Vec>, news: Vec, }, SetMaterialOverride { entity: Entity, old: Option, new: MaterialOverride, }, SetLight { entity: Entity, old: Option, new: LightDesc, }, SetLightGroup { entities: Vec, olds: Vec>, news: Vec>, label: &'static str, }, SetAnimationController { entity: Entity, old: Option, new: AnimationControllerDesc, }, SetAudioSource { entity: Entity, old: Option, new: AudioSourceDesc, }, SetAudioListener { entity: Entity, old: Option, new: AudioListenerDesc, }, SetPhysics { entity: Entity, old: Option, new: PhysicsBody, }, SetRigidBody { entity: Entity, old: Option, new: RigidBodyDesc, }, SetCollider { entity: Entity, old: Option, new: ColliderDesc, }, SetPrimitive { entity: Entity, old: Option, new: Primitive, }, SetBrush { entity: Entity, old: Option, new: BrushDesc, }, SetBrushTransform { entity: Entity, old_transform: Transform, new_transform: Transform, old_brush: Option, new_brush: BrushDesc, }, ApplyBrushCsg { primary: Entity, old_transform: Transform, new_transform: Transform, old_brush: Option, new_brush: BrushDesc, deleted: Vec<(EditorEntitySnapshot, Option)>, }, SetStaticMeshRenderer { entity: Entity, old: Option, new: StaticMeshRenderer, }, SetPostProcessVolume { entity: Entity, old: Option, new: PostProcessVolumeDesc, }, SetNavigation { entity: Entity, old: NavigationComponentState, new: NavigationComponentState, }, SetTransformGroup { entities: Vec, olds: Vec, news: Vec, }, Reparent { entity: Entity, old_parent: Option, new_parent: Option, }, SetActorKind { entity: Entity, old: ActorKind, new: ActorKind, }, ReorderSibling { changes: Vec, }, SetEditorVisibility { entity: Entity, old: EditorVisibility, new: EditorVisibility, }, SetInspectorOrder { entity: Entity, old: Option, new: InspectorOrder, }, SetSceneComposition { old: SceneComposition, new: SceneComposition, }, SetPrefabState { entity: Entity, old: PrefabEditState, new: PrefabEditState, }, ApplyPrefabToSource { entity: Entity, source_path: PathBuf, before_source: String, after_source: String, old: PrefabEditState, new: PrefabEditState, }, UnpackPrefab { entity: Entity, instance: PrefabInstance, prefab_ref: PrefabRef, linked_actor_kind: ActorKind, fully_local: bool, linked_local_snapshots: Vec, linked_local_roots: Vec, unpacked_snapshots: Vec, unpacked_parented_to_anchor: Vec, unpacked_roots: Vec, }, AddComponent { entity: Entity, snapshot: EditorEntitySnapshot, }, RemoveComponent { entity: Entity, snapshot: EditorEntitySnapshot, }, ComponentTransaction(ComponentTransaction), } impl EditorCommand { pub fn label(&self) -> &'static str { match self { EditorCommand::GroupSelection { .. } => "Group Selection", EditorCommand::Spawn { .. } => "Spawn", EditorCommand::SpawnMany { .. } => "Spawn Brushes", EditorCommand::Despawn { .. } => "Delete", EditorCommand::Duplicate { .. } => "Duplicate", EditorCommand::Rename { .. } => "Rename", EditorCommand::SetTransform { .. } => "Move", EditorCommand::SetMaterial { .. } => "Set Material", EditorCommand::SetMaterialGroup { .. } => "Apply Material to Selection", EditorCommand::SetMaterialOverride { .. } => "Set Material Override", EditorCommand::SetLight { .. } => "Set Light", EditorCommand::SetLightGroup { label, .. } => label, EditorCommand::SetAnimationController { .. } => "Set Animation Controller", EditorCommand::SetAudioSource { .. } => "Set Audio Source", EditorCommand::SetAudioListener { .. } => "Set Audio Listener", EditorCommand::SetPhysics { .. } => "Set Physics", EditorCommand::SetRigidBody { .. } => "Set Rigid Body", EditorCommand::SetCollider { .. } => "Set Collider", EditorCommand::SetPrimitive { .. } => "Set Primitive", EditorCommand::SetBrush { .. } => "Set Brush", EditorCommand::SetBrushTransform { .. } => "Clip Brush", EditorCommand::ApplyBrushCsg { .. } => "Brush CSG", EditorCommand::SetStaticMeshRenderer { .. } => "Set Static Mesh Renderer", EditorCommand::SetPostProcessVolume { .. } => "Set Post Process Volume", EditorCommand::SetNavigation { .. } => "Set Navigation", 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::SetSceneComposition { .. } => "Set Scene Composition", EditorCommand::SetPrefabState { .. } => "Edit Prefab Instance", EditorCommand::ApplyPrefabToSource { .. } => "Apply Prefab to Source", EditorCommand::UnpackPrefab { fully_local: true, .. } => "Convert Prefab to Local", EditorCommand::UnpackPrefab { fully_local: false, .. } => "Unpack Prefab Layer", EditorCommand::AddComponent { .. } => "Add Component", EditorCommand::RemoveComponent { .. } => "Remove Component", EditorCommand::ComponentTransaction(transaction) => transaction.label, } } }