ticktime 0.1.0

Provides a ticktime struct to convert a tick to an in game date time
Documentation
  • Coverage
  • 87.23%
    41 out of 47 items documented0 out of 18 items with examples
  • Size
  • Source code size: 42.75 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.35 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • jerthz/ticktime-rs
    3 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • grzi

TickTime-rs

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.

Features

  • Configurable calendar:
    • Earth-like real calendar: Computed time will be done following the real earth calendar rules
    • Earth-like lunar calendar: Computed time will be done with a lunar calendar of 12 months of 30 days
    • Custom calendar: Computed time will be be done by using custom unit time given at init.
  • Update event: Each tick will compute the time and, if enabled, will return an event with all the fields updated.

Examples

Earth-like lunar calendar

    // 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

Earth-like real calendar

    // 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

Custom calendar

    // 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.

Contributing

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.