Skip to content

Commit 4c4ab71

Browse files
committed
docs(project): doc-comment every public struct and it's fields
1 parent 0ad8849 commit 4c4ab71

File tree

2 files changed

+98
-11
lines changed

2 files changed

+98
-11
lines changed

examples/boonga.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@
2020
],
2121
"meta": {
2222
"app": "http://www.aseprite.org/",
23-
"version": "1.1.6-dev",
24-
"image": "boonga.png",
23+
"version": "1.3.4-x64",
2524
"format": "RGBA8888",
2625
"size": { "w": 32, "h": 16 },
27-
"scale": "1"
26+
"scale": "1",
27+
"frameTags": [
28+
],
29+
"layers": [
30+
{ "name": "Layer 1", "opacity": 255, "blendMode": "normal" }
31+
],
32+
"slices": [
33+
]
2834
}
2935
}

src/lib.rs

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,51 @@
1616
//! This has been tested to work with aseprite 1.1.6 and 1.2.25; other
1717
//! versions have not been tested.
1818
19+
use std::ops::{Deref, DerefMut};
20+
1921
use serde::{Deserialize, Serialize};
2022

23+
/// 2D Rectangle with a position and a size.
2124
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Copy)]
2225
pub struct Rect {
26+
/// X coordinate.
2327
pub x: u32,
28+
/// Y coordinate.
2429
pub y: u32,
30+
/// Width.
2531
pub w: u32,
32+
/// Height.
2633
pub h: u32,
2734
}
2835

36+
/// 2D point is space.
2937
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Copy)]
3038
pub struct Point {
39+
/// X coordinate.
3140
pub x: u32,
41+
/// Y coordinate.
3242
pub y: u32,
3343
}
3444

45+
/// 2D size.
3546
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Copy)]
3647
pub struct Dimensions {
48+
/// Width.
3749
pub w: u32,
50+
/// Height.
3851
pub h: u32,
3952
}
4053

54+
/// RGBA color.
4155
#[derive(PartialEq, Eq, Clone, Copy)]
4256
pub struct Color {
57+
/// Red component.
4358
pub r: u8,
59+
/// Green component.
4460
pub g: u8,
61+
/// Blue component.
4562
pub b: u8,
63+
/// Alpha component.
4664
pub a: u8,
4765
}
4866

@@ -53,15 +71,15 @@ impl std::fmt::Debug for Color {
5371
}
5472
}
5573

56-
impl serde::Serialize for Color {
74+
impl Serialize for Color {
5775
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
5876
format!("{:?}", self).serialize(serializer)
5977
}
6078
}
6179

62-
impl<'de> serde::Deserialize<'de> for Color {
80+
impl<'de> Deserialize<'de> for Color {
6381
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
64-
let s: String = serde::Deserialize::deserialize(deserializer)?;
82+
let s: String = Deserialize::deserialize(deserializer)?;
6583
if !s.starts_with('#') {
6684
Err(serde::de::Error::custom("color doesn't start with '#'"))
6785
} else if !s.len() == 7 {
@@ -80,35 +98,51 @@ impl<'de> serde::Deserialize<'de> for Color {
8098
}
8199
}
82100

101+
/// A single frame as part of an animation.
102+
///
103+
/// Contains timing and position information.
83104
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
84105
pub struct Frame {
106+
/// Local path on disk.
85107
pub filename: String,
108+
/// Data for this frame.
86109
#[serde(flatten)]
87110
pub data: FrameData,
88111
}
89112

90-
impl std::ops::Deref for Frame {
113+
impl Deref for Frame {
91114
type Target = FrameData;
92115
fn deref(&self) -> &Self::Target {
93116
&self.data
94117
}
95118
}
96119

97-
impl std::ops::DerefMut for Frame {
120+
impl DerefMut for Frame {
98121
fn deref_mut(&mut self) -> &mut Self::Target {
99122
&mut self.data
100123
}
101124
}
102125

126+
/// Data for a single frame as part of an animation.
103127
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
104128
#[serde(rename_all = "camelCase")]
105129
#[non_exhaustive]
106130
pub struct FrameData {
131+
/// Rectangle on the sprite sheet for this sprite including padding.
132+
///
133+
/// If `trimmed` is true and coordinates are zero this is exactly the same as `sprite_source_size`.
107134
pub frame: Rect,
135+
/// Whether the sprite is rotated.
108136
pub rotated: bool,
137+
/// Whether the sprite is trimmed, meaning whether empty pixels from the edge have been removed.
109138
pub trimmed: bool,
139+
/// Trimmed rectangle on the sprite sheet for this sprite.
140+
///
141+
/// If `trimmed` is true and coordinates are zero this is exactly the same as `frame`.
110142
pub sprite_source_size: Rect,
143+
/// Actual frame size.
111144
pub source_size: Dimensions,
145+
/// Frame duration in milliseconds.
112146
pub duration: u32,
113147
}
114148

@@ -149,28 +183,40 @@ fn deserialize_frames<'de, D: serde::Deserializer<'de>>(de: D) -> Result<Vec<Fra
149183
de.deserialize_any(FramesVisitor)
150184
}
151185

186+
/// Frame animation direction.
152187
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Copy)]
153188
#[serde(rename_all = "camelCase")]
154189
#[non_exhaustive]
155190
pub enum Direction {
191+
/// Normal animation direction.
156192
Forward,
193+
/// Reversed animation direction.
157194
Reverse,
195+
/// Animation is played forward and then backward and so on.
158196
Pingpong,
159197
}
160198

199+
/// Tagged frame group.
200+
///
201+
/// This is a way to define a single animation within the sprite sheet.
161202
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
162203
#[serde(rename_all = "camelCase")]
163204
#[non_exhaustive]
164205
pub struct Frametag {
206+
/// Tag name.
165207
pub name: String,
208+
/// Frame start number.
166209
pub from: u32,
210+
/// Frame end number.
167211
pub to: u32,
212+
/// Animation direction.
168213
pub direction: Direction,
169214
}
170215

171216
// These are listed at:
172217
// https://github.com/aseprite/aseprite/blob/51b038ac024dd99902ab5b0c0d61524c48856b93/src/doc/blend_mode.cpp#L18-L37
173218

219+
/// Layer blend modes.
174220
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Copy)]
175221
#[serde(rename_all = "snake_case")]
176222
#[non_exhaustive]
@@ -229,50 +275,85 @@ pub struct Layer {
229275
pub data: Option<String>,
230276
}
231277

278+
/// Slice within the sprite.
232279
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
233280
#[serde(rename_all = "camelCase")]
234281
#[non_exhaustive]
235282
pub struct Slice {
283+
/// Slice name.
236284
pub name: String,
285+
/// Color with which the slice frame is displayed in Aseprite.
237286
pub color: Color,
238-
pub data: Option<String>,
287+
/// List of slice keys.
239288
pub keys: Vec<SliceKey>,
289+
/// Custom data.
290+
pub data: Option<String>,
240291
}
241292

293+
/// Define the slice rectangle in a specific frame.
242294
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
243295
#[serde(rename_all = "camelCase")]
244296
#[non_exhaustive]
245297
pub struct SliceKey {
298+
/// Frame number.
246299
pub frame: u32,
300+
/// Outer slice bounds within the frame.
247301
pub bounds: Rect,
302+
/// Pivot point within the slice.
248303
pub pivot: Option<Point>,
304+
/// Center area of a nine-patch slice.
249305
pub center: Option<Rect>,
250306
}
251307

308+
/// Sprite sheet metadata.
252309
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
253310
#[serde(rename_all = "camelCase")]
254311
#[non_exhaustive]
255312
pub struct Metadata {
313+
/// Which application produced the sprite sheet.
256314
pub app: String,
315+
/// Version of the application used to produce the sprite sheet.
257316
pub version: String,
317+
/// Pixel format of the image file.
258318
pub format: String,
319+
/// Pixel dimensions of the image file.
259320
pub size: Dimensions,
260-
pub scale: String, // Surely this should be a number?
321+
/// Scale of the image.
322+
///
323+
/// Usually this is `1`.
324+
///
325+
/// Unclear why this is a string, most likely to be compatible with the application the JSON is formatted after.
326+
pub scale: String,
327+
/// Relative path to the image file.
328+
pub image: Option<String>,
329+
/// List of tags.
330+
///
331+
/// Only present when "Meta: Tags" is enabled when exporting in Aseprite.
261332
#[serde(default)]
262333
pub frame_tags: Vec<Frametag>,
334+
/// List of layers.
335+
///
336+
/// Only present when "Meta: Layers" is enabled when exporting in Aseprite.
263337
#[serde(default)]
264338
pub layers: Vec<Layer>,
265-
pub image: Option<String>,
339+
/// List of slices.
340+
///
341+
/// Only present when "Meta: Slices" is enabled when exporting in Aseprite.
266342
#[serde(default)]
267343
pub slices: Vec<Slice>,
268344
}
269345

346+
/// Aseprite sprite sheet.
347+
///
348+
/// Root type in an Aseprite JSON file.
270349
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
271350
#[serde(rename_all = "camelCase")]
272351
#[non_exhaustive]
273352
pub struct SpritesheetData {
353+
/// List with sprite frame definitions.
274354
#[serde(deserialize_with = "deserialize_frames")]
275355
pub frames: Vec<Frame>,
356+
/// Meta data.
276357
pub meta: Metadata,
277358
}
278359

0 commit comments

Comments
 (0)