1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
use crate::binel::serialize::*;
use crate::binel::*;

/// A `Level`'s "stylegrounds," or complexly animated backgrounds.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
#[celeste_name = "Style"]
pub struct Stylegrounds {
    pub foregrounds: Foregrounds,
    pub backgrounds: Backgrounds // TODO: implement stylegrounds
}

/// Foreground stylegrounds. Currently not deserialized, instead just being a newtype over `BinEl`.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
#[celeste_name = "Foregrounds"]
pub struct Foregrounds(BinEl);

/// Background stylegrounds. Currently not deserialized, instead just being a newtype over `BinEl`.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
#[celeste_name = "Backgrounds"]
pub struct Backgrounds(BinEl);

/// The tilesets used in the `Level`'s background.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
#[celeste_name = "bgtiles"]
pub struct BGTiles {
    /// The tileset. Seems to always be "Scenery," but this may change.
    pub tileset: String
}

/// The tilesets used in the `Level`'s foreground.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
#[celeste_name = "fgtiles"]
pub struct FGTiles {
    /// The tileset. Seems to always be "Scenery," but this may change.
    pub tileset: String
}

/// The solid tiles in the `Level`'s foreground.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
pub struct Solids {
    /// The actual tiles, stored as a string.
    #[celeste_name = "innerText"]
    pub contents: String
}

/// The tiles in the `Level`'s background.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
#[celeste_name = "bg"]
pub struct BGSolids {
    #[celeste_name = "innerText"]
    pub contents: String
}

/// Decals, or image assets in a `Level`.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
pub struct Decal {
    /// The pixel (8 per tile) location in the `Level`.
    x: i32,
    /// The pixel (8 per tile) location in the `Level`.
    y: i32,
    /// Horizontal stretching of the `Decal`.
    scale_x: i32,
    /// Vertical stretching of the `Decal`.
    scale_y: i32,
    /// The texture of the `Decal`, within the Gameplay atlas.
    texture: String
}

/// Background decals, or image assets in a `Level`.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
#[celeste_name = "bgdecals"]
pub struct BGDecals {
    /// The "tileset". Seems to always be "Scenery," but this may change. Unclear what this is used
    /// for.
    pub tileset: String,
    /// The decals.
    #[celeste_child_vec]
    pub decals: Vec<Decal>
}

/// Foreground decals, or image assets in a `Level`.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
#[celeste_name = "fgdecals"]
pub struct FGDecals {
    /// The "tileset". Seems to always be "Scenery," but this may change. Unclear what this is used
    /// for.
    pub tileset: String,
    /// The decals.
    #[celeste_child_vec]
    pub decals: Vec<Decal>
}

/// Entities, or objects in the `Level` with associated code.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
pub struct Entities {
    /// The actual entities. May be one of over 100 elements, so currently parsed as a raw BinEl.
    #[celeste_child_vec]
    pub entities: Vec<BinEl>
}

/// Triggers, or regions in the `Level` with associated code.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
pub struct Triggers {
    /// The actual triggers. May be one of over 50 elements, so currently parsed as a raw BinEl.
    #[celeste_child_vec]
    pub triggers: Vec<BinEl>
}

/// Object tiles. Poorly documented.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
pub struct ObjTiles {
    #[celeste_name = "innerText"]
    pub tiles: String
}

/// Filler regions in the map. An alternate way of storing rooms filled with a single tile and no
/// other assets. Not currently parsed, as they are not necessary for most use cases. The `Map`'s
/// behavior shouldn't change if you remove these.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
#[celeste_name = "Filler"]
pub struct Filler(BinEl); // TODO: parse filler

/// Undocumented (apart from source) Everest extension, for storing the `Map`'s name and icon.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
pub struct Meta(BinEl);

/// A room in a `Map`. Only confusingly named fields are documented.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
pub struct Level {
    pub name: String,
    pub x: i32,
    pub y: i32,
    pub width: i32,
    pub height: i32,
    pub music_layer_1: bool,
    pub music_layer_2: bool,
    pub music_layer_3: bool,
    pub music_layer_4: bool,
    pub music_progress: String,
    pub whisper: bool,
    pub underwater: bool,
    /// Unclear what this does.
    pub c: i32, // ???
    /// Unclear what this does, though I believe that it is the default music used by Music
    /// triggers.
    #[celeste_name = "alt_music"] // nice consistency there
    pub alt_music: String,
    /// Alternate gravity. Behavior may be unstable in different game versions.
    pub space: bool,
    pub wind_pattern: String,
    pub disable_down_transition: bool,
    /// Affects lighting shaders.
    pub dark: bool,
    pub fgdecals: FGDecals,
    pub bgdecals: BGDecals,
    pub fgtiles: FGTiles,
    pub bgtiles: BGTiles,
    pub solids: Solids,
    pub bg: BGSolids,
    pub entities: Entities,
    pub triggers: Triggers,
    /// Optional, as some serializers (such as older versions of Maple) don't include these.
    pub objtiles: Option<ObjTiles>,
    /// All children that failed to parse.
    #[celeste_child_vec]
    pub invalid: Vec<BinEl>
}

/// All `Level`s in a `Map`. Stored as a subelement for unknown reasons.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
pub struct Levels {
    #[celeste_child_vec]
    pub levels: Vec<Level>,
    /// All children that couldn't be parsed as `Level`s.
    #[celeste_child_vec]
    pub invalid_levels: Vec<BinEl>
}

/// A chapter, also known as an Area in the game's code. `Map` was chosen to avoid confusion.
/// Parsed via the `BinElType` trait.
#[derive(Clone, PartialEq, Debug, Default, BinElType)]
#[celeste_name = "Map"]
pub struct Map {
    pub style: Stylegrounds,
    pub levels: Levels,
    pub filler: Filler,
    /// Optional, as it is an Everest extension, and thus many maps do not include it.
    pub meta: Option<Meta>
}