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.

91 lines
2.6KB

  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 hash_name(&self) -> u32 {
  25. Self::hash("DampedAngularSpringEntityDescriptorV4") // 3789998433
  26. }
  27. }
  28. /// Damped spring entity descriptor
  29. #[derive(Copy, Clone, Parsable)]
  30. pub struct DampedSpringEntity {
  31. /// parent block entity
  32. pub block: BlockEntity,
  33. /// Joint tweakables component
  34. pub tweak_component: TweakableJointDampingComponent,
  35. /// Spring tweakables component
  36. pub spring_component: DampedSpringROStruct,
  37. }
  38. impl SerializedEntityDescriptor for DampedSpringEntity {
  39. fn serialized_components() -> u8 {
  40. BlockEntity::serialized_components() + 2
  41. }
  42. fn components<'a>(&'a self) -> Vec<&'a dyn SerializedEntityComponent> {
  43. let mut c = self.block.components();
  44. c.push(&self.tweak_component);
  45. c.push(&self.spring_component);
  46. return c;
  47. }
  48. fn hash_name(&self) -> u32 {
  49. Self::hash("DampedSpringEntityDescriptorV5") // 2892049599
  50. }
  51. }
  52. /// Joint settings entity component.
  53. #[derive(Copy, Clone, Parsable)]
  54. pub struct TweakableJointDampingComponent {
  55. /// Joint stiffness (percent?)
  56. pub stiffness: f32,
  57. /// Force damping (percent?)
  58. pub damping: f32,
  59. }
  60. impl SerializedEntityComponent for TweakableJointDampingComponent {}
  61. /// Damped angular spring settings entity component.
  62. #[derive(Copy, Clone, Parsable)]
  63. pub struct DampedSpringROStruct {
  64. /// Maximum spring extension
  65. pub max_extension: f32,
  66. }
  67. impl SerializedEntityComponent for DampedSpringROStruct {}
  68. /// Damped angular spring settings entity component.
  69. #[derive(Copy, Clone, Parsable)]
  70. pub struct DampedAngularSpringROStruct {
  71. /// Minimum sprint extension
  72. pub joint_min: f32,
  73. /// Maximum sprint extension
  74. pub joint_max: f32,
  75. }
  76. impl SerializedEntityComponent for DampedAngularSpringROStruct {}