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.

33 lines
1.1KB

  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. /// Hash of descriptor name
  16. fn hash_name(&self) -> u32;
  17. /// Hash of descriptor name
  18. fn hash(s: &str) -> u32 where Self: Sized {
  19. crate::techblox::hashname(s)
  20. }
  21. }
  22. /// Serializable entity component.
  23. /// Components are the atomic unit of entities.
  24. pub trait SerializedEntityComponent: Parsable {
  25. /// Raw size of struct, in bytes.
  26. fn size() -> usize where Self: Sized {
  27. std::mem::size_of::<Self>()
  28. }
  29. }