chiark / gitweb /
docs: wip document shapelibs, move from shapelib-toml
[otter.git] / src / shapelib-toml.rs
1 // Copyright 2020-2021 Ian Jackson and contributors to Otter
2 // SPDX-License-Identifier: AGPL-3.0-or-later
3 // There is NO WARRANTY.
4
5 pub use crate::prelude::*;
6
7 #[doc(hidden)] pub type LLE = shapelib::LibraryLoadError;
8
9 // At the implementation level, each loaded item contains an
10 // `Arc<GroupDetails>`, which is simply stored directly.  The
11 // `GroupDefn` is processed.
12 #[derive(Debug,Deserialize)]
13 pub struct GroupDefn {
14   pub files: FileList,
15   #[serde(default)] pub item_prefix: String,
16   #[serde(default)] pub item_suffix: String,
17   #[serde(default)] pub sort: String,
18   #[serde(flatten)] pub d: GroupDetails,
19 }
20
21 #[derive(Debug,Deserialize)]
22 pub struct GroupDetails {
23   #[cfg(doc)]inherit: String, // handled specially
24   pub size: Vec<f64>,  // scaled when put into GroupData
25   #[serde(default)] pub orig_size: Vec<f64>,
26   #[serde(default)] pub centre: Option<[f64; 2]>,
27   #[serde(default)] pub flip: bool,
28   #[serde(default)] pub back: Option<Box <dyn PieceSpec>>,
29   #[serde(default="num_traits::identities::One::one")] pub scale: f64,
30   #[serde(default)] pub colours: HashMap<String, RecolourData>,
31   pub desc_template: Option<String>,
32   pub occulted: Option<OccultationMethod>,
33
34   /// One of `"Circle"` or `"Rect"`, to define the outline shape.
35   /// The size is taken from `size`.
36   ///
37   /// This value is a string, not some weird Rust type, despite
38   /// what you see here.
39   #[serde(flatten)] pub outline: Box<dyn shapelib::OutlineDefn>,
40 }
41
42 #[derive(Deserialize,Clone,Debug)]
43 #[serde(tag="method")]
44 pub enum OccultationMethod {
45   ByColour {
46     colour: ColourSpec,
47   },
48   ByBack {
49     ilk: OccultIlkName,
50   },
51 }
52
53 #[derive(Debug,Deserialize)]
54 pub struct RecolourData {
55   pub abbrev: String,
56   #[cfg(doc)] pub map: HashMap<String, String>,
57 }
58
59 #[doc(hidden)]
60 #[derive(Deserialize,Debug)]
61 #[serde(try_from="String")]
62 pub struct FileList(pub Vec<FileData>);
63
64 #[derive(Deserialize,Debug)]
65 pub struct FileData {
66   pub item_spec: String,
67   pub src_file_spec: String,
68   pub extra_fields: HashMap<String, String>,
69   pub desc: String,
70 }
71
72 #[cfg(doc)]
73 /// `scraper`, specifying where and how to get updated piece SVGs.
74 pub struct Scraper {
75   /// Determines which scraper is run and the rest of the table
76   /// [`scraper`](LibraryTomlFile::scraper) is interpreted.
77   ///
78   /// There are two methods available:
79   ///
80   ///  * `"none"`: Do not scrape anything.  The SVGs in the Otter
81   ///  source tree are hand-edited.  The 2nd field in each
82   ///  [`files`](GroupDefn::files) line
83   ///  ([`r_file_spec`](FileData::r_file_spec)) is ignored.
84   ///
85   ///  * `"wikimedia"`: Scrape a site that uses Mediawiki the way that
86   ///  Wikimedia does.  In this case
87   ///  [`scraper`](LibraryTomlFile::scraper) is a table containing the
88   ///  fields of [`WikimediaScraper`], not just `method`.
89   ///
90   ///  * `"cards-oxymoron`": Special for that subdirectory.
91   pub method: String,
92 }
93
94 #[cfg(doc)]
95 /// Settings to go alongside `scraper = "wikimedia"`
96 ///
97 /// TODO: Most fields here yet to be documented!
98 pub struct WikimediaScraper {
99   /// See [`method` in `Scraper`](Scraper::method).  `"wikimedia"`
100   pub method: String,
101
102 }
103