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.

27 lines
962B

  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. }
  16. /// Serializable entity component.
  17. /// Components are the atomic unit of entities.
  18. pub trait SerializedEntityComponent: Parsable {
  19. /// Raw size of struct, in bytes.
  20. fn size() -> usize where Self: Sized {
  21. std::mem::size_of::<Self>()
  22. }
  23. }