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.

90 lines
3.1KB

  1. use std::convert::AsRef;
  2. use crate::techblox::{SerializedEntityDescriptor, Parsable, SerializedEntityComponent};
  3. use crate::techblox::blocks::{DBEntityStruct, PositionEntityStruct, ScalingEntityStruct, RotationEntityStruct,
  4. SkewComponent, GridRotationStruct, SerializedGridConnectionsEntityStruct, SerializedBlockPlacementInfoStruct,
  5. SerializedCubeMaterialStruct, SerializedUniformBlockScaleEntityStruct, SerializedColourParameterEntityStruct,
  6. BlockGroupEntityComponent};
  7. use libfj_parsable_macro_derive::*;
  8. /// Block entity descriptor.
  9. #[derive(Copy, Clone, Parsable)]
  10. pub struct BlockEntity {
  11. /// Database component
  12. pub db_component: DBEntityStruct,
  13. /// Position component
  14. pub pos_component: PositionEntityStruct,
  15. /// Scale component
  16. pub scale_component: ScalingEntityStruct,
  17. /// Rotation component
  18. pub rot_component: RotationEntityStruct,
  19. /// Skew matrix component
  20. pub skew_component: SkewComponent,
  21. /// Grid component
  22. pub grid_component: GridRotationStruct,
  23. // GridConnectionsEntityStruct is not serialized to disk
  24. /// No-op serializer (this has no data!)
  25. pub grid_conn_component: SerializedGridConnectionsEntityStruct,
  26. // BlockPlacementInfoStruct has a disk serializer that does nothing (?)
  27. /// No-op serializer (this has no data!)
  28. pub placement_component: SerializedBlockPlacementInfoStruct,
  29. /// Cube material component
  30. pub material_component: SerializedCubeMaterialStruct,
  31. /// Uniform scale component
  32. pub uscale_component: SerializedUniformBlockScaleEntityStruct,
  33. /// Colour component
  34. pub colour_component: SerializedColourParameterEntityStruct,
  35. /// Group component
  36. pub group_component: BlockGroupEntityComponent,
  37. }
  38. impl SerializedEntityDescriptor for BlockEntity {
  39. fn serialized_components() -> u8 {
  40. 12
  41. }
  42. fn components<'a>(&'a self) -> Vec<&'a dyn SerializedEntityComponent> {
  43. vec![&self.db_component,
  44. &self.pos_component,
  45. &self.scale_component,
  46. &self.rot_component,
  47. &self.skew_component,
  48. &self.grid_component,
  49. &self.grid_conn_component,
  50. &self.placement_component,
  51. &self.material_component,
  52. &self.uscale_component,
  53. &self.colour_component,
  54. &self.group_component]
  55. }
  56. fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent> {
  57. vec![&mut self.db_component,
  58. &mut self.pos_component,
  59. &mut self.scale_component,
  60. &mut self.rot_component,
  61. &mut self.skew_component,
  62. &mut self.grid_component,
  63. &mut self.grid_conn_component,
  64. &mut self.placement_component,
  65. &mut self.material_component,
  66. &mut self.uscale_component,
  67. &mut self.colour_component,
  68. &mut self.group_component]
  69. }
  70. fn hash_name(&self) -> u32 {
  71. Self::hash("StandardBlockEntityDescriptorV4") // 1357220432
  72. }
  73. }
  74. impl AsRef<BlockEntity> for BlockEntity {
  75. fn as_ref(&self) -> &Self {
  76. self
  77. }
  78. }
  79. pub trait Block: SerializedEntityDescriptor + AsRef<BlockEntity> {}
  80. impl Block for BlockEntity {}