Skip to main content

rm2k/
engine.rs

1//! Which RPG Maker produced the file.
2//!
3//! Changes the wire format, not just metadata. Roughly 90 schema fields exist only in 2003 and are
4//! skipped when writing 2000. Other fields have per-engine defaults; the writer elides fields
5//! equal to their default, so those matter too. Flag bundles suffer most: skipping a 2003-only
6//! flag shifts every later bit.
7
8/// The engine a file targets.
9#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
10pub enum Engine {
11    R2K,
12    R2K3,
13}
14
15impl Engine {
16    #[must_use]
17    #[inline]
18    pub const fn is_2k3(self) -> bool {
19        matches!(self, Self::R2K3)
20    }
21
22    /// Pick between a 2000 value and a 2003 value.
23    ///
24    /// This is what the schema macro's `engine!(a, b)` default expands to.
25    #[must_use]
26    #[inline]
27    pub const fn pick<T: Copy>(self, r2k: T, r2k3: T) -> T {
28        match self {
29            Self::R2K => r2k,
30            Self::R2K3 => r2k3,
31        }
32    }
33
34    /// Classify a database's `system.ldb_id`.
35    #[must_use]
36    #[inline]
37    pub const fn from_ldb_id(ldb_id: i32) -> Self {
38        if ldb_id == 2003 { Self::R2K3 } else { Self::R2K }
39    }
40}
41
42impl Default for Engine {
43    #[inline]
44    fn default() -> Self {
45        Self::R2K
46    }
47}
48
49/// Options affecting how a file is written.
50#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
51pub struct SaveOpt {
52    /// Keep the header bytes exactly as they were read rather than regenerating them.
53    pub preserve_header: bool,
54}