rl_model/model/
progress.rs1use super::*;
2use crate::parser::{Position, RlError};
3use std::collections::HashMap;
4use std::time::Duration;
5
6#[derive(Debug, Clone)]
7pub struct Progress {
8 period: Duration,
9 message: Vec<Variable>,
10 position: Option<Position>,
11}
12
13impl Progress {
14 pub fn new(period: Duration, message: Vec<Variable>, position: Option<Position>) -> Self {
15 Self {
16 period,
17 message,
18 position,
19 }
20 }
21
22 pub fn period(&self) -> Duration {
23 self.period
24 }
25
26 pub fn message(&self) -> &Vec<Variable> {
27 &self.message
28 }
29
30 pub fn position(&self) -> Option<Position> {
31 self.position.clone()
32 }
33
34 pub fn resolve_type(&mut self, map: &HashMap<String, TypeId>) -> Result<(), RlError> {
37 for x in self.message.iter_mut() {
38 x.resolve_type(map)?;
39 }
40 Ok(())
41 }
42}
43
44impl ToLang for Progress {
45 fn to_lang(&self, skillset: &Skillset) -> String {
46 let mut s = String::from("\t\t\tprogress {\n");
47 s.push_str(&format!("\t\t\t\tperiod {} ms\n", self.period.as_millis()));
49 if !self.message.is_empty() {
51 s.push_str("\t\t\t\tmessage {\n");
52 for x in self.message.iter() {
53 s.push_str(&format!("\t\t\t\t\t{}\n", x.to_lang(skillset)))
54 }
55 s.push_str("\t\t\t\t}\n");
56 }
57 s.push_str("\t\t\t}\n");
59 s
60 }
61}
62
63impl std::fmt::Display for Progress {
64 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65 write!(f, "progress")
66 }
67}