Package dev.twilite.game.common
Class Clockwork
java.lang.Object
dev.twilite.game.common.Clockwork
Small mutable clock for measuring runtime, countdown windows, pauses, and rates.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordBuilder-style entry point for creating a clock. -
Method Summary
Modifier and TypeMethodDescriptionbooleanactive()Returns whether this clock is still inside its countdown window.age()Returns how long this clock has been running, excluding frozen time.ageText()Returns this clock's age asHH:mm:ss.booleanbounded()Returns whether this clock has a countdown window.static ClockworkCreates a countdown clock for the supplied duration.booleanexpired()Returns whether this clock has reached or passed its countdown limit.doublehourly(long value) Returns the value scaled to one hour based on this clock's age.leftText()Returns this clock's remaining countdown window asHH:mm:ss.voidmark()Re-marks this clock from now and preserves the current countdown window length.booleanReturns whether this clock's age is greater than the supplied duration.static Clockworkopen()Creates an open-ended clock using the system clock.origin()Returns when this clock was last marked.doubleReturns the value scaled to the supplied duration based on this clock's age.voidpause()Freezes this clock untilresume()is called.booleanpaused()Returns whether this clock is currently frozen.Returns the time left in this clock's countdown window, or zero when unbounded or expired.voidresume()Resumes this clock and shifts its origin and countdown limit by the frozen duration.static StringFormats a duration asHH:mm:ss.toString()static Clockwork.Seeduse()Begins building a clock using the system clock.static Clockwork.SeedBegins building a clock using a custom clock.static Clockwork.SeedBegins building a clock using a custom instant source.voidSets the countdown window from now.
-
Method Details
-
use
Begins building a clock using the system clock. -
use
Begins building a clock using a custom clock. -
use
Begins building a clock using a custom instant source. -
open
Creates an open-ended clock using the system clock. -
countdown
Creates a countdown clock for the supplied duration. -
origin
Returns when this clock was last marked. -
age
Returns how long this clock has been running, excluding frozen time. -
paused
public boolean paused()Returns whether this clock is currently frozen. -
bounded
public boolean bounded()Returns whether this clock has a countdown window. -
active
public boolean active()Returns whether this clock is still inside its countdown window. -
expired
public boolean expired()Returns whether this clock has reached or passed its countdown limit. -
olderThan
Returns whether this clock's age is greater than the supplied duration. -
mark
public void mark()Re-marks this clock from now and preserves the current countdown window length. -
window
Sets the countdown window from now. -
pause
public void pause()Freezes this clock untilresume()is called. -
resume
public void resume()Resumes this clock and shifts its origin and countdown limit by the frozen duration. -
remaining
Returns the time left in this clock's countdown window, or zero when unbounded or expired. -
pace
Returns the value scaled to the supplied duration based on this clock's age. -
hourly
public double hourly(long value) Returns the value scaled to one hour based on this clock's age. -
ageText
Returns this clock's age asHH:mm:ss. -
leftText
Returns this clock's remaining countdown window asHH:mm:ss. -
text
Formats a duration asHH:mm:ss. -
toString
-