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.

46 lines
1.4KB

  1. use crate::techblox::{SerializedEntityDescriptor, Parsable, SerializedEntityComponent,
  2. blocks::{BlockEntity}};
  3. use libfj_parsable_macro_derive::*;
  4. /// Engine entity descriptor
  5. #[derive(Copy, Clone, Parsable)]
  6. pub struct EngineBlockEntity {
  7. /// parent block entity
  8. pub block: BlockEntity,
  9. /// Engine tweakables component
  10. pub tweak_component: EngineBlockTweakableComponent,
  11. }
  12. impl SerializedEntityDescriptor for EngineBlockEntity {
  13. fn serialized_components() -> u8 {
  14. BlockEntity::serialized_components() + 1
  15. }
  16. fn components<'a>(&'a self) -> Vec<&'a dyn SerializedEntityComponent> {
  17. let mut c = self.block.components();
  18. c.push(&self.tweak_component);
  19. return c;
  20. }
  21. fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> {
  22. let mut c = self.block.components_mut();
  23. c.push(&mut self.tweak_component);
  24. return c;
  25. }
  26. fn hash_name(&self) -> u32 {
  27. Self::hash("EngineBlockEntityDescriptor") // 1757314505
  28. }
  29. }
  30. /// Engine settings entity component.
  31. #[derive(Copy, Clone, Parsable)]
  32. pub struct EngineBlockTweakableComponent {
  33. /// Engine power (percent?)
  34. pub power: f32,
  35. /// Is the engine's transmission automatic? (bool)
  36. pub automatic_gears: u32, // why is this not stored as u8 like the other bools?
  37. }
  38. impl SerializedEntityComponent for EngineBlockTweakableComponent {}