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.

35 lines
1.3KB

  1. use std::io::{Read, Write};
  2. /// Standard trait for parsing Techblox game save data.
  3. pub trait Parsable {
  4. /// Process information from raw data.
  5. fn parse(reader: &mut dyn Read) -> std::io::Result<Self> where Self: Sized;
  6. /// Convert struct data back into raw bytes
  7. fn dump(&self, writer: &mut dyn Write) -> std::io::Result<usize>;
  8. }
  9. /// Entity descriptor containing serialized components.
  10. pub trait SerializedEntityDescriptor: Parsable {
  11. /// Count of entity components that this descriptor contains
  12. fn serialized_components() -> u8 where Self: Sized;
  13. /// Components that this entity is comprised of
  14. fn components<'a>(&'a self) -> Vec<&'a dyn SerializedEntityComponent>;
  15. /// Components that this entity is comprised of, for modification
  16. fn components_mut<'a>(&'a mut self) -> Vec<&'a mut dyn SerializedEntityComponent>;
  17. /// Hash of descriptor name
  18. fn hash_name(&self) -> u32;
  19. /// Hash of descriptor name
  20. fn hash(s: &str) -> u32 where Self: Sized {
  21. crate::techblox::hashname(s)
  22. }
  23. }
  24. /// Serializable entity component.
  25. /// Components are the atomic unit of entities.
  26. pub trait SerializedEntityComponent: Parsable {
  27. /// Raw size of struct, in bytes.
  28. fn size() -> usize where Self: Sized {
  29. std::mem::size_of::<Self>()
  30. }
  31. }