From 970a6eb500ddf32186e70f75a1a422bd91eb0dfd Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Wed, 23 Jun 2021 16:05:29 -0400 Subject: [PATCH] Add component_mut function to entity descriptor trait --- src/techblox/block_group_entity.rs | 5 +++++ src/techblox/blocks/block_entity.rs | 15 +++++++++++++++ src/techblox/blocks/engine.rs | 6 ++++++ src/techblox/blocks/joint.rs | 4 ++++ src/techblox/blocks/passenger_seat.rs | 6 ++++++ src/techblox/blocks/pilot_seat.rs | 6 ++++++ src/techblox/blocks/spring.rs | 14 ++++++++++++++ src/techblox/blocks/tyre.rs | 4 ++++ src/techblox/blocks/wheel_rig.rs | 13 +++++++++++++ src/techblox/blocks/wire_entity.rs | 8 ++++++++ src/techblox/camera.rs | 8 ++++++++ src/techblox/entity_traits.rs | 2 ++ 12 files changed, 91 insertions(+) diff --git a/src/techblox/block_group_entity.rs b/src/techblox/block_group_entity.rs index c8015a3..e72ce65 100644 --- a/src/techblox/block_group_entity.rs +++ b/src/techblox/block_group_entity.rs @@ -22,6 +22,11 @@ impl SerializedEntityDescriptor for BlockGroupEntity { &self.block_group_transform] } + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> { + vec![&mut self.saved_block_group_id, + &mut self.block_group_transform] + } + fn hash_name(&self) -> u32 { Self::hash("BlockGroupEntityDescriptorV0") } diff --git a/src/techblox/blocks/block_entity.rs b/src/techblox/blocks/block_entity.rs index 1cd6524..926400a 100644 --- a/src/techblox/blocks/block_entity.rs +++ b/src/techblox/blocks/block_entity.rs @@ -56,6 +56,21 @@ impl SerializedEntityDescriptor for BlockEntity { &self.group_component] } + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> { + vec![&mut self.db_component, + &mut self.pos_component, + &mut self.scale_component, + &mut self.rot_component, + &mut self.skew_component, + &mut self.grid_component, + &mut self.grid_conn_component, + &mut self.placement_component, + &mut self.material_component, + &mut self.uscale_component, + &mut self.colour_component, + &mut self.group_component] + } + fn hash_name(&self) -> u32 { Self::hash("StandardBlockEntityDescriptorV4") // 1357220432 } diff --git a/src/techblox/blocks/engine.rs b/src/techblox/blocks/engine.rs index 176750f..35f6bde 100644 --- a/src/techblox/blocks/engine.rs +++ b/src/techblox/blocks/engine.rs @@ -22,6 +22,12 @@ impl SerializedEntityDescriptor for EngineBlockEntity { return c; } + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> { + let mut c = self.block.components_mut(); + c.push(&mut self.tweak_component); + return c; + } + fn hash_name(&self) -> u32 { Self::hash("EngineBlockEntityDescriptor") // 1757314505 } diff --git a/src/techblox/blocks/joint.rs b/src/techblox/blocks/joint.rs index eb14a01..14ca192 100644 --- a/src/techblox/blocks/joint.rs +++ b/src/techblox/blocks/joint.rs @@ -18,6 +18,10 @@ impl SerializedEntityDescriptor for JointBlockEntity { self.block.components() } + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> { + self.block.components_mut() + } + fn hash_name(&self) -> u32 { Self::hash("JointBlockEntityDescriptorV3") // 3586818581 } diff --git a/src/techblox/blocks/passenger_seat.rs b/src/techblox/blocks/passenger_seat.rs index 00269de..9110a15 100644 --- a/src/techblox/blocks/passenger_seat.rs +++ b/src/techblox/blocks/passenger_seat.rs @@ -22,6 +22,12 @@ impl SerializedEntityDescriptor for PassengerSeatEntity { return c; } + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> { + let mut c = self.block.components_mut(); + c.push(&mut self.cam_component); + return c; + } + fn hash_name(&self) -> u32 { Self::hash("PassengerSeatEntityDescriptorV4") // 1360086092 } diff --git a/src/techblox/blocks/pilot_seat.rs b/src/techblox/blocks/pilot_seat.rs index cdff457..c454c3e 100644 --- a/src/techblox/blocks/pilot_seat.rs +++ b/src/techblox/blocks/pilot_seat.rs @@ -21,6 +21,12 @@ impl SerializedEntityDescriptor for PilotSeatEntity { return c; } + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> { + let mut c = self.block.components_mut(); + c.push(&mut self.cam_component); + return c; + } + fn hash_name(&self) -> u32 { Self::hash("PilotSeatEntityDescriptorV4") // 2281299333 } diff --git a/src/techblox/blocks/spring.rs b/src/techblox/blocks/spring.rs index e6a153f..fb888a6 100644 --- a/src/techblox/blocks/spring.rs +++ b/src/techblox/blocks/spring.rs @@ -25,6 +25,13 @@ impl SerializedEntityDescriptor for DampedAngularSpringEntity { return c; } + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> { + let mut c = self.block.components_mut(); + c.push(&mut self.tweak_component); + c.push(&mut self.spring_component); + return c; + } + fn hash_name(&self) -> u32 { Self::hash("DampedAngularSpringEntityDescriptorV4") // 3789998433 } @@ -53,6 +60,13 @@ impl SerializedEntityDescriptor for DampedSpringEntity { return c; } + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> { + let mut c = self.block.components_mut(); + c.push(&mut self.tweak_component); + c.push(&mut self.spring_component); + return c; + } + fn hash_name(&self) -> u32 { Self::hash("DampedSpringEntityDescriptorV5") // 2892049599 } diff --git a/src/techblox/blocks/tyre.rs b/src/techblox/blocks/tyre.rs index e7a179c..bc6a248 100644 --- a/src/techblox/blocks/tyre.rs +++ b/src/techblox/blocks/tyre.rs @@ -18,6 +18,10 @@ impl SerializedEntityDescriptor for TyreEntity { self.block.components() } + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> { + self.block.components_mut() + } + fn hash_name(&self) -> u32 { Self::hash("TyreEntityDescriptorV1") // 1517625162 } diff --git a/src/techblox/blocks/wheel_rig.rs b/src/techblox/blocks/wheel_rig.rs index e3f3888..9622eef 100644 --- a/src/techblox/blocks/wheel_rig.rs +++ b/src/techblox/blocks/wheel_rig.rs @@ -25,6 +25,13 @@ impl SerializedEntityDescriptor for WheelRigEntity { return c; } + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> { + let mut c = self.block.components_mut(); + c.push(&mut self.tweak_component); + c.push(&mut self.joint_component); + return c; + } + fn hash_name(&self) -> u32 { Self::hash("WheelRigEntityDescriptor") // 1156723746 } @@ -50,6 +57,12 @@ impl SerializedEntityDescriptor for WheelRigSteerableEntity { return c; } + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> { + let mut c = self.block.components_mut(); + c.push(&mut self.tweak_component); + return c; + } + fn hash_name(&self) -> u32 { Self::hash("WheelRigSteerableEntityDescriptor") // 1864425618 } diff --git a/src/techblox/blocks/wire_entity.rs b/src/techblox/blocks/wire_entity.rs index 6f39dce..7fc1500 100644 --- a/src/techblox/blocks/wire_entity.rs +++ b/src/techblox/blocks/wire_entity.rs @@ -18,6 +18,10 @@ impl SerializedEntityDescriptor for SerializedWireEntity { vec![&self.save_data_component] } + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> { + vec![&mut self.save_data_component] + } + fn hash_name(&self) -> u32 { Self::hash("WireEntityDescriptorMock") // 1818308818 } @@ -54,6 +58,10 @@ impl SerializedEntityDescriptor for SerializedGlobalWireSettingsEntity { vec![&self.settings_component] } + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> { + vec![&mut self.settings_component] + } + fn hash_name(&self) -> u32 { Self::hash("GlobalWireSettingsEntityDescriptor") // 1820064641 } diff --git a/src/techblox/camera.rs b/src/techblox/camera.rs index 3e51643..cb20bb0 100644 --- a/src/techblox/camera.rs +++ b/src/techblox/camera.rs @@ -18,6 +18,10 @@ impl SerializedEntityDescriptor for SerializedFlyCamEntity { vec![&self.rb_component] } + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> { + vec![&mut self.rb_component] + } + fn hash_name(&self) -> u32 { Self::hash("FlyCamEntityDescriptorV0") // 252528354 } @@ -48,6 +52,10 @@ impl SerializedEntityDescriptor for SerializedPhysicsCameraEntity { vec![&self.cam_component] } + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> { + vec![&mut self.cam_component] + } + fn hash_name(&self) -> u32 { Self::hash("CharacterCameraEntityDescriptorV1") // 3850144645 } diff --git a/src/techblox/entity_traits.rs b/src/techblox/entity_traits.rs index e332143..407310d 100644 --- a/src/techblox/entity_traits.rs +++ b/src/techblox/entity_traits.rs @@ -14,6 +14,8 @@ pub trait SerializedEntityDescriptor: Parsable { fn serialized_components() -> u8 where Self: Sized; /// Components that this entity is comprised of fn components<'a>(&'a self) -> Vec<&'a dyn SerializedEntityComponent>; + /// Components that this entity is comprised of, for modification + fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent>; /// Hash of descriptor name fn hash_name(&self) -> u32; /// Hash of descriptor name