maikor_platform/models/
mod.rs

1pub mod layer_header;
2pub mod layer_tile;
3pub mod sprite;
4
5use crate::constants::TILES_PER_LAYER;
6use std::io;
7use std::io::ErrorKind;
8
9#[derive(Debug, Clone, Default, Eq, PartialEq)]
10pub struct Sprite {
11    pub x: usize,
12    pub y: usize,
13    pub id: usize,
14    pub flip_v: bool,
15    pub flip_h: bool,
16    pub palette: usize,
17    pub large: bool,
18    pub order: usize,
19    pub half_alpha: bool,
20    pub rotated: bool,
21    pub atlas: usize,
22    pub enabled: bool,
23}
24
25#[derive(Debug, Clone)]
26pub struct Layer {
27    pub header: LayerHeader,
28    pub content: [LayerTile; TILES_PER_LAYER],
29}
30
31impl Layer {
32    pub fn new(header: LayerHeader, content: [LayerTile; TILES_PER_LAYER]) -> Self {
33        Self { header, content }
34    }
35}
36
37#[derive(Debug, Clone, Default, Eq, PartialEq)]
38pub struct LayerHeader {
39    pub x: isize,
40    pub y: isize,
41    pub enabled: bool,
42    pub atlas: usize,
43    pub order: usize,
44}
45
46#[derive(Debug, Clone, Default, Eq, PartialEq)]
47pub struct LayerTile {
48    pub id: usize,
49    pub flip_v: bool,
50    pub flip_h: bool,
51    pub palette: usize,
52    pub half_alpha: bool,
53    pub rotated: bool,
54}
55
56pub trait Byteable {
57    const SIZE: usize;
58
59    fn try_from_bytes(bytes: &[u8]) -> Result<Self, io::Error>
60    where
61        Self: Sized,
62    {
63        if bytes.len() < Self::SIZE {
64            Err(io::Error::from(ErrorKind::UnexpectedEof))
65        } else {
66            Ok(Self::from_bytes(bytes))
67        }
68    }
69
70    fn from_bytes(bytes: &[u8]) -> Self;
71
72    fn to_bytes(&self) -> Vec<u8>;
73}