diff options
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | src/character.rs | 8 | ||||
-rw-r--r-- | src/dl_list.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 12 | ||||
-rw-r--r-- | src/tags.rs | 2 |
5 files changed, 21 insertions, 7 deletions
@@ -7,3 +7,7 @@ authors = ["jan <jan@ruken.pw>"] | |||
7 | regex = "0.1" | 7 | regex = "0.1" |
8 | walkdir = "0.1" | 8 | walkdir = "0.1" |
9 | yaml-rust = "0.3" | 9 | yaml-rust = "0.3" |
10 | |||
11 | serde = "0.8" | ||
12 | serde_derive = "0.8" | ||
13 | serde_json = "0.8" | ||
diff --git a/src/character.rs b/src/character.rs index b0322dd..c1d3829 100644 --- a/src/character.rs +++ b/src/character.rs | |||
@@ -9,26 +9,26 @@ use super::tiles; | |||
9 | 9 | ||
10 | use std::collections::HashMap; | 10 | use std::collections::HashMap; |
11 | 11 | ||
12 | #[derive(Debug)] | 12 | #[derive(Debug, Serialize)] |
13 | pub struct Names { | 13 | pub struct Names { |
14 | pub romaji: String, | 14 | pub romaji: String, |
15 | pub japanese: String, | 15 | pub japanese: String, |
16 | pub aliases: Vec<String>, | 16 | pub aliases: Vec<String>, |
17 | } | 17 | } |
18 | 18 | ||
19 | #[derive(Debug)] | 19 | #[derive(Debug, Serialize)] |
20 | pub struct Images { | 20 | pub struct Images { |
21 | pub thumb: String, | 21 | pub thumb: String, |
22 | pub full: String, | 22 | pub full: String, |
23 | } | 23 | } |
24 | 24 | ||
25 | #[derive(Debug)] | 25 | #[derive(Debug, Serialize)] |
26 | pub struct Traits { | 26 | pub struct Traits { |
27 | pub official: Vec<DLListItem>, | 27 | pub official: Vec<DLListItem>, |
28 | pub indexed: Vec<DLListItem>, | 28 | pub indexed: Vec<DLListItem>, |
29 | } | 29 | } |
30 | 30 | ||
31 | #[derive(Debug)] | 31 | #[derive(Debug, Serialize)] |
32 | pub struct Character { | 32 | pub struct Character { |
33 | pub name: Names, | 33 | pub name: Names, |
34 | pub image: Images, | 34 | pub image: Images, |
diff --git a/src/dl_list.rs b/src/dl_list.rs index 979c332..3327388 100644 --- a/src/dl_list.rs +++ b/src/dl_list.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use super::regex::Regex; | 1 | use super::regex::Regex; |
2 | 2 | ||
3 | #[derive(Debug)] | 3 | #[derive(Debug, Serialize)] |
4 | pub struct DLListItem { | 4 | pub struct DLListItem { |
5 | name: String, | 5 | name: String, |
6 | value: String, | 6 | value: String, |
diff --git a/src/main.rs b/src/main.rs index ea89b02..a7f1f9d 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,3 +1,7 @@ | |||
1 | #![feature(rustc_macro)] | ||
2 | #[macro_use] extern crate serde_derive; | ||
3 | extern crate serde_json; | ||
4 | |||
1 | extern crate regex; | 5 | extern crate regex; |
2 | extern crate yaml_rust; | 6 | extern crate yaml_rust; |
3 | 7 | ||
@@ -21,7 +25,9 @@ mod tiles; | |||
21 | 25 | ||
22 | fn main() { | 26 | fn main() { |
23 | let raw_files = env::var("RAW_FILES").unwrap_or("characters".into()); | 27 | let raw_files = env::var("RAW_FILES").unwrap_or("characters".into()); |
28 | let out_files = env::var("OUT").unwrap_or("json".into()); | ||
24 | let base_path = Path::new(&raw_files); | 29 | let base_path = Path::new(&raw_files); |
30 | let out_path = Path::new(&out_files); | ||
25 | 31 | ||
26 | 32 | ||
27 | for entry in WalkDir::new(base_path).min_depth(1).into_iter().filter_map(|e| e.ok()) { | 33 | for entry in WalkDir::new(base_path).min_depth(1).into_iter().filter_map(|e| e.ok()) { |
@@ -36,6 +42,10 @@ fn main() { | |||
36 | 42 | ||
37 | let mut char = Character::new(); | 43 | let mut char = Character::new(); |
38 | char.parse(&buf); | 44 | char.parse(&buf); |
39 | println!("{:?}", char); | 45 | |
46 | let json = serde_json::to_string(&char).unwrap(); | ||
47 | |||
48 | let mut o = File::create(out_path.join(entry.file_name())).unwrap(); | ||
49 | o.write_all(json.as_bytes()).unwrap(); | ||
40 | } | 50 | } |
41 | } | 51 | } |
diff --git a/src/tags.rs b/src/tags.rs index 0fdf815..561c54d 100644 --- a/src/tags.rs +++ b/src/tags.rs | |||
@@ -2,7 +2,7 @@ use super::regex::Regex; | |||
2 | 2 | ||
3 | use std::str::FromStr; | 3 | use std::str::FromStr; |
4 | 4 | ||
5 | #[derive(Debug)] | 5 | #[derive(Debug, Serialize)] |
6 | pub struct Tag { | 6 | pub struct Tag { |
7 | pub id: u32, | 7 | pub id: u32, |
8 | pub name: String, | 8 | pub name: String, |