Crates.io | ticktime |
lib.rs | ticktime |
version | 0.1.0 |
source | src |
created_at | 2020-12-10 22:07:04.64406 |
updated_at | 2021-02-27 22:21:09.003767 |
description | Provides a ticktime struct to convert a tick to an in game date time |
homepage | |
repository | https://github.com/grzi/ticktime-rs/ |
max_upload_size | |
id | 321617 |
size | 43,280 |
A utilities to convert tick number to a date time to use in game. It was first made to fulfill the need of city building games but can also be used in any game that needs date time handled from ticks.
// Initialize a lunar ticktime where one tick is 3600 seconds
let mut ticktime = TickTime::init(
0, TickTimeOptions {
tick_time_type: TickTimeType::EarthLike { seconds_per_tick: 3600, month_type: EarthLikeMonthType::Lunar },
compute_events: false,
}
).unwrap();
// Calling tick to simulate 40 days
for _ in 0..(24*40) {
ticktime.tick();
}
println!("{}", ticktime.to_string()); // Month 1, Day 10
// Initialize a real ticktime where one tick is 3600 seconds
let mut ticktime = TickTime::init(
0, TickTimeOptions {
tick_time_type: TickTimeType::EarthLike { seconds_per_tick: 3600, month_type: EarthLikeMonthType::Real },
compute_events: false,
}
).unwrap();
// Calling tick to simulate 40 days
for _ in 0..(24*40) {
ticktime.tick();
}
println!("{}", ticktime.to_string()); // Month 1, Day 9
// Initialize a custom ticktime where one tick is 3600 seconds
// where each day is 12 hours long
// and year are composed of 4 months with 1 day
let mut ticktime = TickTime::init(
0, TickTimeOptions {
tick_time_type:
TickTimeType::Custom {
seconds_per_tick: 3600,
hours_in_a_day: 12,
months_durations: vec![1, 1, 1, 1],
seasons_durations: vec![4],
week_duration: 7,
},
compute_events: false,
},
).unwrap();
// Calling tick to simulate 40 days
for _ in 0..(24*40) {
ticktime.tick();
}
println!("{}", ticktime.to_string()); // Year 20, Month 0, Day 0
See the examples for more use cases.
As in any OS project, contributions are welcome. Issues or PR. Please check the issues to know if you can get involved in existing demands.