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.

105 lines
3.1KB

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