GitHubComeçar

A referência da API é gerada a partir dos comentários de documentação Go no código-fonte e está escrita em inglês.

package gametime

import "github.com/nsgo-dev/game/pkg/gametime"

Visão geral

Package gametime is experimental: its API and documented formats may change in a minor release. See the API stability policy. provides deterministic in-game calendar clocks.

Índice

Tipos

type Clock struct {
	// DayLength is the real duration of one in-game day.
	DayLength time.Duration
	// DaysPerSeason is the number of days before Season advances. Zero disables rollover.
	DaysPerSeason int
	// Season is the zero-based current season.
	Season int
	// Day is the one-based current day within the season.
	Day int
	// Minute is the current minute within the day, in [0, 1440).
	Minute int
	// Partial is the progress toward the next in-game minute, as the fraction Partial/DayLength of a minute, in [0, DayLength). Step keeps it so that many short steps add up to the same time as one long step, and a saved and restored clock keeps stepping as one that was never saved.
	Partial time.Duration
}

Clock advances a deterministic in-game calendar without reading the device clock.

func (c Clock) Now() Date

Now returns the current in-game date and time.

func (c *Clock) SkipTo(hour int)

SkipTo advances to the next occurrence of hour, or to that hour today when it has not passed yet.

func (c *Clock) Step(dt time.Duration)

Step advances the clock by dt. Non-positive durations and clocks without a positive DayLength are ignored. Time shorter than an in-game minute is kept in Partial rather than dropped, so many short steps advance the clock as far as one step of their total length.

type Date struct {
	// Day is the one-based day within the current season.
	Day int
	// Hour is the in-game hour.
	Hour int
	// Minute is the in-game minute within the hour.
	Minute int
}

Date is the current in-game calendar date and time.