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.

123 lines
3.5KB

  1. use std::convert::AsRef;
  2. use crate::techblox::{SerializedEntityDescriptor, Parsable, SerializedEntityComponent,
  3. blocks::{BlockEntity, Block}};
  4. use libfj_parsable_macro_derive::*;
  5. /// Damped angular spring entity descriptor
  6. #[derive(Copy, Clone, Parsable)]
  7. pub struct DampedAngularSpringEntity {
  8. /// parent block entity
  9. pub block: BlockEntity,
  10. /// Joint tweakables component
  11. pub tweak_component: TweakableJointDampingComponent,
  12. /// Spring tweakables component
  13. pub spring_component: DampedAngularSpringROStruct,
  14. }
  15. impl SerializedEntityDescriptor for DampedAngularSpringEntity {
  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.spring_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.spring_component);
  29. return c;
  30. }
  31. fn hash_name(&self) -> u32 {
  32. Self::hash("DampedAngularSpringEntityDescriptorV4") // 3789998433
  33. }
  34. }
  35. impl AsRef<BlockEntity> for DampedAngularSpringEntity {
  36. fn as_ref(&self) -> &BlockEntity {
  37. &self.block
  38. }
  39. }
  40. impl Block for DampedAngularSpringEntity {}
  41. /// Damped spring entity descriptor
  42. #[derive(Copy, Clone, Parsable)]
  43. pub struct DampedSpringEntity {
  44. /// parent block entity
  45. pub block: BlockEntity,
  46. /// Joint tweakables component
  47. pub tweak_component: TweakableJointDampingComponent,
  48. /// Spring tweakables component
  49. pub spring_component: DampedSpringROStruct,
  50. }
  51. impl SerializedEntityDescriptor for DampedSpringEntity {
  52. fn serialized_components() -> u8 {
  53. BlockEntity::serialized_components() + 2
  54. }
  55. fn components<'a>(&'a self) -> Vec<&'a dyn SerializedEntityComponent> {
  56. let mut c = self.block.components();
  57. c.push(&self.tweak_component);
  58. c.push(&self.spring_component);
  59. return c;
  60. }
  61. fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> {
  62. let mut c = self.block.components_mut();
  63. c.push(&mut self.tweak_component);
  64. c.push(&mut self.spring_component);
  65. return c;
  66. }
  67. fn hash_name(&self) -> u32 {
  68. Self::hash("DampedSpringEntityDescriptorV5") // 2892049599
  69. }
  70. }
  71. impl AsRef<BlockEntity> for DampedSpringEntity {
  72. fn as_ref(&self) -> &BlockEntity {
  73. &self.block
  74. }
  75. }
  76. impl Block for DampedSpringEntity {}
  77. /// Joint settings entity component.
  78. #[derive(Copy, Clone, Parsable)]
  79. pub struct TweakableJointDampingComponent {
  80. /// Joint stiffness (percent?)
  81. pub stiffness: f32,
  82. /// Force damping (percent?)
  83. pub damping: f32,
  84. }
  85. impl SerializedEntityComponent for TweakableJointDampingComponent {}
  86. /// Damped angular spring settings entity component.
  87. #[derive(Copy, Clone, Parsable)]
  88. pub struct DampedSpringROStruct {
  89. /// Maximum spring extension
  90. pub max_extension: f32,
  91. }
  92. impl SerializedEntityComponent for DampedSpringROStruct {}
  93. /// Damped angular spring settings entity component.
  94. #[derive(Copy, Clone, Parsable)]
  95. pub struct DampedAngularSpringROStruct {
  96. /// Minimum sprint extension
  97. pub joint_min: f32,
  98. /// Maximum sprint extension
  99. pub joint_max: f32,
  100. }
  101. impl SerializedEntityComponent for DampedAngularSpringROStruct {}