An unofficial collection of APIs used in FreeJam games and mods
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.9KB

  1. use std::convert::AsRef;
  2. use crate::techblox::{SerializedEntityDescriptor, Parsable, SerializedEntityComponent,
  3. blocks::{BlockEntity, TweakableJointDampingComponent, Block}};
  4. use libfj_parsable_macro_derive::*;
  5. /// Wheel rig entity descriptor
  6. #[derive(Copy, Clone, Parsable)]
  7. pub struct WheelRigEntity {
  8. /// parent block entity
  9. pub block: BlockEntity,
  10. /// Wheel tweakables component
  11. pub tweak_component: WheelRigTweakableStruct,
  12. /// Joint tweakables component
  13. pub joint_component: TweakableJointDampingComponent,
  14. }
  15. impl SerializedEntityDescriptor for WheelRigEntity {
  16. fn serialized_components() -> u8 {
  17. BlockEntity::serialized_components() + 2
  18. }
  19. fn components<'a>(&'a self) -> Vec<&'a dyn SerializedEntityComponent> {
  20. let mut c = self.block.components();
  21. c.push(&self.tweak_component);
  22. c.push(&self.joint_component);
  23. return c;
  24. }
  25. fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> {
  26. let mut c = self.block.components_mut();
  27. c.push(&mut self.tweak_component);
  28. c.push(&mut self.joint_component);
  29. return c;
  30. }
  31. fn hash_name(&self) -> u32 {
  32. Self::hash("WheelRigEntityDescriptor") // 1156723746
  33. }
  34. }
  35. impl AsRef<BlockEntity> for WheelRigEntity {
  36. fn as_ref(&self) -> &BlockEntity {
  37. &self.block
  38. }
  39. }
  40. impl Block for WheelRigEntity {}
  41. /// Wheel rig entity descriptor
  42. #[derive(Copy, Clone, Parsable)]
  43. pub struct WheelRigSteerableEntity {
  44. /// parent wheel rig entity
  45. pub block: WheelRigEntity,
  46. /// Steering tweakables component
  47. pub tweak_component: WheelRigSteerableTweakableStruct,
  48. }
  49. impl SerializedEntityDescriptor for WheelRigSteerableEntity {
  50. fn serialized_components() -> u8 {
  51. WheelRigEntity::serialized_components() + 1
  52. }
  53. fn components<'a>(&'a self) -> Vec<&'a dyn SerializedEntityComponent> {
  54. let mut c = self.block.components();
  55. c.push(&self.tweak_component);
  56. return c;
  57. }
  58. fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> {
  59. let mut c = self.block.components_mut();
  60. c.push(&mut self.tweak_component);
  61. return c;
  62. }
  63. fn hash_name(&self) -> u32 {
  64. Self::hash("WheelRigSteerableEntityDescriptor") // 1864425618
  65. }
  66. }
  67. impl AsRef<BlockEntity> for WheelRigSteerableEntity {
  68. fn as_ref(&self) -> &BlockEntity {
  69. &self.block.as_ref()
  70. }
  71. }
  72. impl Block for WheelRigSteerableEntity {}
  73. /// Wheel rig settings entity component.
  74. #[derive(Copy, Clone, Parsable)]
  75. pub struct WheelRigTweakableStruct {
  76. /// Brake force (percent?)
  77. pub braking_strength: f32,
  78. }
  79. impl SerializedEntityComponent for WheelRigTweakableStruct {}
  80. /// Steering wheel rig settings entity component.
  81. #[derive(Copy, Clone, Parsable)]
  82. pub struct WheelRigSteerableTweakableStruct {
  83. /// Wheel steering angle (max?)
  84. pub steer_angle: f32,
  85. }
  86. impl SerializedEntityComponent for WheelRigSteerableTweakableStruct {}