cnmo_parse/
lib.rs

1#![warn(missing_docs)]
2//! A all-encompasing CNM Online lparse and cnma data format parser.
3//!
4//! This crate allows one to load .cnmb/.cnms/.cnma files.
5//! - .cnmb/.cnms files are binary .lparse files and start with the bytes "CNML"
6//! - .cnma files are text files with a special format, kind of like .ini files
7//! 
8//! By default this crate only allows one to edit these files at the
9//! very lowest level (besides for cnma files which can already load
10//! in game configs), so if you want to load a cnm level file from an
11//! lparse file, you will need to specify certain crate features.
12//! 
13//! These features are:
14//! - "level_data" which adds in structs that represent all aspects
15//!     of a CNM online level file, and has functions to save and load
16//!     them from their respective .cnmb and .cnms lparse files.
17//! - "serde" which adds serde traits for said level data structs
18//!     so that the level data can also additionally be saved to any
19//!     other format that you want. This is NOT a serde implementation
20//!     for lparse or cnma files (and you need "level_data" feature
21//!     enabled already).
22//! 
23//! Heres the [`Github Link`]
24//! 
25//! [`Github Link`]: https://github.com/wyatt-radkiewicz/cnm-online-editor/tree/main/cnmo-parse
26
27/// Loading and saving lparse (level) files
28pub mod lparse;
29/// Loading and saving cnm config files
30pub mod cnma;
31
32/// A generic rectangle struct that CNM Online uses internally
33#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
34#[derive(Debug, Clone, Copy, PartialEq, Eq)]
35pub struct Rect {
36    /// X position of the rect
37    pub x: i32,
38    /// Y position of the rect
39    pub y: i32,
40    /// Width of the rect. Negative values are undefined and might crash CNM Online. These
41    /// are i32's because in the CNM Online source code and lparse files they are i32's.
42    pub w: i32,
43    /// Height of the rect. Negative values are undefined and might crash CNM Online. These
44    /// are i32's because in the CNM Online source code and lparse files they are i32's.
45    pub h: i32,
46}
47
48impl Rect {
49    /// Creates a new rectangle
50    /// 
51    /// # Example
52    /// 
53    /// ```
54    /// # use cnmo_parse::Rect;
55    /// let rect = Rect::new(0, 0, 100, 100);
56    /// ```
57    pub fn new(x: i32, y: i32, w: i32, h: i32) -> Self {
58        Self { x, y, w, h }
59    }
60}
61
62impl std::fmt::Display for Rect {
63    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
64        f.write_str("")
65    }
66}