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.

88 lines
2.6KB

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