Commit c94d3c88 authored by Rahix's avatar Rahix 🦀
Browse files

heaven: Prevent integer underflow when player reaches max hours

When the player reaches 30 hours, we're currently getting a panic in
debug mode and an unhandled interger underflow in release mode.
Sidestep this by not performing the subtraction if the player has gained
enough hours.
parent b63b480c
......@@ -30,9 +30,15 @@ impl HeavenState {
utils::get_element_by_id::<web_sys::Element>("heaven-collected-hours")
.unwrap()
.set_inner_html(&format!("{}", player.collected_hours));
utils::get_element_by_id::<web_sys::Element>("heaven-needed-hours")
.unwrap()
.set_inner_html(&format!("{}", 30 - player.collected_hours));
if player.collected_hours < 30 {
utils::get_element_by_id::<web_sys::Element>("heaven-needed-hours")
.unwrap()
.set_inner_html(&format!("{}", 30 - player.collected_hours));
} else {
utils::get_element_by_id::<web_sys::Element>("heaven-needed-hours")
.unwrap()
.set_inner_html("None!");
}
// Assign a random shift
let assigned_shift = angel_shifts::generate_random_shift(&mut rand::thread_rng());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment