1use serde::{Serialize, Deserialize};
2use crate::parser::serde_util::{string_to_u16, date_to_timestamp};
3use crate::color::Color;
4use super::Parsable;
5
6#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
7pub struct Project {
8 #[serde(rename = "sc_id")]
9 #[serde(with = "string_to_u16")]
10 pub id: u16,
11
12 #[serde(rename = "my_app_name")]
13 pub app_name: String,
14
15 #[serde(rename = "my_ws_name")]
16 pub workspace_name: String,
17
18 #[serde(rename = "my_sc_pkg_name")]
19 pub package_name: String,
20
21 #[serde(rename = "sc_ver_code")]
22 #[serde(with = "string_to_u16")]
23 pub version_code: u16,
24
25 #[serde(rename = "sc_ver_name")]
26 pub version_name: String,
27
28 #[serde(rename = "my_sc_reg_dt")]
29 #[serde(with = "date_to_timestamp")]
30 pub date_created: u64,
31 pub custom_icon: bool,
32
33 #[serde(flatten)]
34 pub color_palette: ProjectColorPalette,
35
36 #[serde(rename = "sketchware_ver")]
37 pub sketchware_version: u8,
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
41pub struct ProjectColorPalette {
42 pub color_primary: Color,
43 pub color_primary_dark: Color,
44 pub color_accent: Color,
45 pub color_control_normal: Color,
46 pub color_control_highlight: Color,
47}
48
49impl Default for ProjectColorPalette {
50 fn default() -> Self {
51 ProjectColorPalette {
52 color_primary: 0xff008dcd.into(),
53 color_primary_dark: 0xff0084c2.into(),
54 color_accent: 0xff008dcd.into(),
55 color_control_normal: 0xff57beee.into(),
56 color_control_highlight: 0x20008dcd.into()
57 }
58 }
59}
60
61impl Parsable for Project {
62 type ParseError = serde_json::Error;
63 type ReconstructionError = serde_json::Error;
64
65 fn parse(project: &str) -> Result<Project, Self::ParseError> {
66 serde_json::from_str(project)
67 }
68
69 fn reconstruct(&self) -> Result<String, Self::ReconstructionError> {
70 serde_json::to_string(self)
71 }
72}