1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4use serde_json::{Map, Value};
5
6use crate::Diagnostic;
7
8pub type JsonMap = Map<String, Value>;
9
10#[derive(Debug, Clone, PartialEq)]
11pub struct ParseReport {
12 pub catalog: AssetCatalog,
13 pub diagnostics: Vec<Diagnostic>,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq)]
17pub struct AssetReferenceIndex {
18 pub catalog_name: String,
19 pub source_path: PathBuf,
20 pub references: Vec<AssetReference>,
21 pub diagnostics: Vec<Diagnostic>,
22}
23
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub struct AssetReference {
26 pub kind: AssetReferenceKind,
27 pub lookup_name: String,
28 pub relative_path: PathBuf,
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum AssetReferenceKind {
33 Image,
34 Color,
35 AppIcon,
36}
37
38#[derive(Debug, Clone, PartialEq)]
39pub struct AssetCatalog {
40 pub name: String,
41 pub source_path: PathBuf,
42 pub files: Vec<PathBuf>,
43 pub raw_contents: Option<RawContents>,
44 pub contents: Option<FolderContents>,
45 pub children: Vec<Node>,
46}
47
48#[derive(Debug, Clone, PartialEq)]
49pub enum Node {
50 Group(GroupNode),
51 ImageSet(ImageSetNode),
52 ColorSet(ColorSetNode),
53 AppIconSet(AppIconSetNode),
54 Opaque(OpaqueNode),
55}
56
57#[derive(Debug, Clone, PartialEq)]
58pub struct FolderNode<T> {
59 pub name: String,
60 pub relative_path: PathBuf,
61 pub files: Vec<PathBuf>,
62 pub raw_contents: Option<RawContents>,
63 pub contents: Option<T>,
64 pub children: Vec<Node>,
65}
66
67pub type GroupNode = FolderNode<FolderContents>;
68pub type ImageSetNode = FolderNode<ImageSetContents>;
69pub type ColorSetNode = FolderNode<ColorSetContents>;
70pub type AppIconSetNode = FolderNode<AppIconSetContents>;
71
72#[derive(Debug, Clone, PartialEq)]
73pub struct OpaqueNode {
74 pub name: String,
75 pub relative_path: PathBuf,
76 pub folder_type: String,
77 pub files: Vec<PathBuf>,
78 pub raw_contents: Option<RawContents>,
79 pub children: Vec<Node>,
80}
81
82#[derive(Debug, Clone, PartialEq)]
83pub enum RawContents {
84 Json(Value),
85 InvalidJson(String),
86}
87
88#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
89pub struct FolderContents {
90 pub info: Option<ContentsInfo>,
91 #[serde(default)]
92 pub properties: FolderProperties,
93 #[serde(flatten, default)]
94 pub extras: JsonMap,
95}
96
97#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
98pub struct ImageSetContents {
99 pub info: Option<ContentsInfo>,
100 #[serde(default)]
101 pub properties: FolderProperties,
102 #[serde(default)]
103 pub images: Vec<ImageEntry>,
104 #[serde(flatten, default)]
105 pub extras: JsonMap,
106}
107
108#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
109pub struct ColorSetContents {
110 pub info: Option<ContentsInfo>,
111 #[serde(default)]
112 pub properties: FolderProperties,
113 #[serde(default)]
114 pub colors: Vec<ColorEntry>,
115 #[serde(flatten, default)]
116 pub extras: JsonMap,
117}
118
119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
120pub struct AppIconSetContents {
121 pub info: Option<ContentsInfo>,
122 #[serde(default)]
123 pub properties: FolderProperties,
124 #[serde(default)]
125 pub images: Vec<ImageEntry>,
126 #[serde(flatten, default)]
127 pub extras: JsonMap,
128}
129
130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
131pub struct ContentsInfo {
132 pub author: Option<String>,
133 pub version: Option<u64>,
134 #[serde(flatten, default)]
135 pub extras: JsonMap,
136}
137
138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
139pub struct FolderProperties {
140 #[serde(rename = "provides-namespace")]
141 pub provides_namespace: Option<bool>,
142 pub localizable: Option<bool>,
143 #[serde(rename = "template-rendering-intent")]
144 pub template_rendering_intent: Option<String>,
145 #[serde(flatten, default)]
146 pub extras: JsonMap,
147}
148
149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
150pub struct ImageEntry {
151 pub filename: Option<String>,
152 pub idiom: Option<String>,
153 pub scale: Option<String>,
154 #[serde(rename = "language-direction")]
155 pub language_direction: Option<String>,
156 #[serde(rename = "display-gamut")]
157 pub display_gamut: Option<String>,
158 pub platform: Option<String>,
159 pub size: Option<String>,
160 pub role: Option<String>,
161 pub subtype: Option<String>,
162 #[serde(rename = "matching-style")]
163 pub matching_style: Option<String>,
164 pub memory: Option<String>,
165 #[serde(rename = "graphics-feature-set")]
166 pub graphics_feature_set: Option<String>,
167 #[serde(rename = "screen-width")]
168 pub screen_width: Option<String>,
169 #[serde(rename = "width-class")]
170 pub width_class: Option<String>,
171 #[serde(rename = "height-class")]
172 pub height_class: Option<String>,
173 #[serde(default)]
174 pub appearances: Vec<Appearance>,
175 #[serde(flatten, default)]
176 pub extras: JsonMap,
177}
178
179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
180pub struct ColorEntry {
181 pub idiom: Option<String>,
182 #[serde(rename = "display-gamut")]
183 pub display_gamut: Option<String>,
184 pub color: Option<ColorValue>,
185 #[serde(default)]
186 pub appearances: Vec<Appearance>,
187 #[serde(flatten, default)]
188 pub extras: JsonMap,
189}
190
191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
192pub struct Appearance {
193 pub appearance: Option<String>,
194 pub value: Option<String>,
195 #[serde(flatten, default)]
196 pub extras: JsonMap,
197}
198
199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
200pub struct ColorValue {
201 #[serde(rename = "color-space")]
202 pub color_space: Option<String>,
203 #[serde(default)]
204 pub components: JsonMap,
205 #[serde(flatten, default)]
206 pub extras: JsonMap,
207}