summaryrefslogtreecommitdiffstats
path: root/src/timeman.rs
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2026-04-15 16:53:58 -0400
committerJon Santmyer <jon@jonsantmyer.com>2026-04-15 16:53:58 -0400
commitb5ced3af46c96ceb959fbbf1addfeba3bd4f76d5 (patch)
tree06d06fc9562dc99eede655b53635576f67c37e3b /src/timeman.rs
downloadsystemic4x-b5ced3af46c96ceb959fbbf1addfeba3bd4f76d5.tar.gz
systemic4x-b5ced3af46c96ceb959fbbf1addfeba3bd4f76d5.tar.bz2
systemic4x-b5ced3af46c96ceb959fbbf1addfeba3bd4f76d5.zip
first commit. working body rendering
Diffstat (limited to 'src/timeman.rs')
-rw-r--r--src/timeman.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/timeman.rs b/src/timeman.rs
new file mode 100644
index 0000000..9d17999
--- /dev/null
+++ b/src/timeman.rs
@@ -0,0 +1,69 @@
+use std::cell::RefCell;
+use std::time::Duration;
+use std::{fmt::Display, string};
+use std::error::Error;
+
+use crate::GameState;
+use crate::window::ui::GameWindowUiState;
+
+pub type Second = u64;
+
+pub struct TimeMan
+{
+ time: Second,
+ auto_tick: Option<Second>
+}
+
+impl TimeMan
+{
+ pub fn new(time: Second)
+ -> Self {
+ Self {
+ time,
+ auto_tick: None
+ }
+ }
+
+ pub fn seconds(&self)
+ -> Second {
+ self.time
+ }
+
+ pub fn advance(
+ &mut self,
+ by: Second)
+ {
+ self.time += by;
+ }
+
+ pub fn update(
+ &mut self)
+ {
+ match self.auto_tick {
+ Some(advance) => { self.time += advance; },
+ None => {}
+ }
+ }
+
+ pub fn format_duration(time: Second) -> String
+ {
+ let seconds = time % 60;
+ let minutes = (time / 60) % 60;
+ let hours = (time / (60 * 60)) % 24;
+ let days = (time / (60 * 60 * 24)) % 365;
+ let years = time / (60 * 60 * 24 * 365);
+
+ if time == 0 {
+ return "0s".to_string();
+ }
+
+ format!("{}{}{}{}{}",
+ if seconds > 0 { format!("{}s", seconds) } else { format!("") },
+ if minutes > 0 { format!("{}m", minutes) } else { format!("") },
+ if hours > 0 { format!("{}h", hours) } else { format!("") },
+ if days > 0 { format!("{}d", days) } else { format!("") },
+ if years > 0 { format!("{}y", years) } else { format!("") })
+ }
+
+
+} //impl TimeMan