-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.rs
86 lines (76 loc) · 2.09 KB
/
ui.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use std::{
path::PathBuf,
sync::mpsc::{Receiver, Sender},
};
use anyhow::Result;
use serde::{Deserialize, Serialize};
use crate::{
calendar::TimeOfTheYear,
export::{Cancel, Elevation, ExportParams, Progress},
FromDwarfFortress,
};
/// Command line interface
pub mod cli;
/// Graphical user interface
#[cfg(feature = "gui")]
pub mod gui;
/// Serializable application state
#[derive(Serialize, Deserialize)]
#[serde(default)]
pub struct State {
low_elevation: Elevation,
high_elevation: Elevation,
time: TimeOfTheYear,
#[serde(skip)]
error: Option<String>,
#[serde(skip)]
progress: Option<(Progress, Receiver<Progress>, Sender<Cancel>)>,
#[serde(skip)]
exported_path: Option<PathBuf>,
#[serde(skip)]
#[cfg(feature = "self-update")]
update_status: CheckUpdateStatus,
}
#[cfg(feature = "self-update")]
enum CheckUpdateStatus {
NotDone,
Doing(Receiver<Result<crate::update::UpdateStatus>>),
Done(crate::update::UpdateStatus),
}
impl Default for State {
fn default() -> Self {
Self {
low_elevation: Elevation(0),
high_elevation: Elevation(10),
time: Default::default(),
error: Default::default(),
progress: Default::default(),
exported_path: Default::default(),
#[cfg(feature = "self-update")]
update_status: Default::default(),
}
}
}
impl State {
fn export_params(&self, path: PathBuf) -> ExportParams {
ExportParams {
elevation_low: self.low_elevation,
elevation_high: self.high_elevation,
time: self.time,
path,
}
}
}
#[cfg(feature = "self-update")]
impl Default for CheckUpdateStatus {
fn default() -> Self {
Self::NotDone
}
}
impl FromDwarfFortress for TimeOfTheYear {
fn read_from_df(&mut self, _df: &mut dfhack_remote::Client) -> Result<()> {
// todo: refine for better display
*self = TimeOfTheYear::Current;
Ok(())
}
}