1use crate::error::Error;
2use binrw::{binrw, io::Cursor, BinRead};
3use serde_derive::{Deserialize, Serialize};
4
5#[binrw]
6#[brw(little, magic = b"TNAM")]
7#[derive(Debug, Clone, Deserialize, Serialize)]
8pub struct TNAM {
9 pub size: u16,
10
11 #[br(count = size)]
12 pub data: Vec<u8>,
13}
14
15#[binrw]
16#[brw(little)]
17#[derive(Debug, Clone, Deserialize, Serialize)]
18pub struct SunAndMoons {
19 pub sunrise_begin: u8,
20 pub sunrise_end: u8,
21 pub sunset_begin: u8,
22 pub sunset_end: u8,
23 pub volatility: u8,
24 pub moons: u8,
25}
26
27impl TryInto<SunAndMoons> for TNAM {
28 type Error = Error;
29
30 fn try_into(self) -> Result<SunAndMoons, Error> {
31 Ok(SunAndMoons::read_le(&mut Cursor::new(&self.data))?)
32 }
33}