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.

56 lines
1.6KB

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