Working timer
This commit is contained in:
parent
8254e6f0e0
commit
cfffd3f98f
36
src/main.rs
36
src/main.rs
|
|
@ -76,21 +76,33 @@ impl FromWorld for ForgeTimer {
|
||||||
|
|
||||||
impl ForgeTimer {
|
impl ForgeTimer {
|
||||||
fn to_str(&mut self) -> String {
|
fn to_str(&mut self) -> String {
|
||||||
let t = self.time_current.elapsed_seconds_f64() as isize;
|
|
||||||
self.time_current.update();
|
self.time_current.update();
|
||||||
let remaining = self.time_target - t;
|
let t = self.time_current.elapsed_seconds_f64();
|
||||||
let actual_remaining = self.time_target - self.time_offset - t;
|
let show_timer = self.time_target
|
||||||
// let scaled_remaining = remaining*
|
- ((t * self.time_target as f64) / (self.time_target - self.time_offset) as f64)
|
||||||
// let time_warp = (self.time_target - self.time_offset) * remaining / self.time_target;
|
as isize;
|
||||||
let percent = actual_remaining * 100 / self.time_target;
|
// format!(
|
||||||
// sec_to_str(remaining)
|
// "Target: {} T-Offs: {} Current: {} Shown: {} Ell: {}",
|
||||||
format!("{}", percent)
|
// self.time_target,
|
||||||
|
// self.time_target - self.time_offset,
|
||||||
|
// self.time_target - t,
|
||||||
|
// show_timer,
|
||||||
|
// t
|
||||||
|
// )
|
||||||
|
if show_timer > 0 {
|
||||||
|
format!("{}", sec_to_str(show_timer as isize))
|
||||||
|
} else {
|
||||||
|
format!(
|
||||||
|
"{}",
|
||||||
|
sec_to_str(self.time_target - self.time_offset - t as isize)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sec_to_str(time: isize) -> String {
|
fn sec_to_str(time: isize) -> String {
|
||||||
// let time = time.as_secs();
|
// let time = time.as_secs();
|
||||||
let sign = if time < 0 { "-" } else { "" };
|
let (sign, time) = if time < 0 { ("-", -time) } else { ("", time) };
|
||||||
let s = time % 60;
|
let s = time % 60;
|
||||||
let m = (time / 60) % 3600;
|
let m = (time / 60) % 3600;
|
||||||
let h = time / 3600;
|
let h = time / 3600;
|
||||||
|
|
@ -132,11 +144,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_timer(
|
fn update_timer(mut tmr: ResMut<ForgeTimer>, mut query: Query<&mut Text, With<ShowTimer>>) {
|
||||||
time: Res<Time>,
|
|
||||||
mut tmr: ResMut<ForgeTimer>,
|
|
||||||
mut query: Query<&mut Text, With<ShowTimer>>,
|
|
||||||
) {
|
|
||||||
for mut text in &mut query {
|
for mut text in &mut query {
|
||||||
text.sections[1].value = format!("{}", tmr.to_str()); //sec_to_time(time.elapsed_wrapped());
|
text.sections[1].value = format!("{}", tmr.to_str()); //sec_to_time(time.elapsed_wrapped());
|
||||||
// text.sections[1].value = format!("{:?}", tmr);
|
// text.sections[1].value = format!("{:?}", tmr);
|
||||||
|
|
|
||||||
Reference in New Issue