API 参考取自源码中的 Go 文档注释,以英文书写。
package farming
import "github.com/nsgo-dev/game/pkg/farming"概述
Package farming is experimental: its API and documented formats may change in a minor release. See the API stability policy. contains deterministic rules shared by farming and life-sim games. Calendar and crop records are deliberately independent of devices, rendering, and storage so games can drive them from a fixed-step loop.
索引
类型
type Calendar struct {
Seasons []Season
Day int
Season int
Hour float32
}Calendar is a repeating season calendar. Day is one-based and Hour is in [0, 24). Advancing past the end of a season starts the next season at day 1.
func (c *Calendar) Advance(elapsed time.Duration) (days int, err error)Advance moves the clock by elapsed wall/game time and returns the number of whole days crossed. It never uses time.Now, so replay and tests stay stable.
func (c Calendar) Validate() errorValidate reports whether the calendar's season, day and hour are valid.
type Crop struct {
Kind string
Stage int
Days int
}Crop is the persistent state of one planted crop.
func (c *Crop) WateredDay(k CropKind) (bool, error)WateredDay records one day's watering. It returns true when the crop became ripe on this day.
type CropKind struct {
ID string
Stages int
DaysPerStage int
}CropKind describes growth stages. A crop advances once for each watered day, and is ripe at the final stage.
func (k CropKind) Validate() errorValidate reports whether the crop kind has usable IDs and positive growth values.
type Season struct {
ID string
Days int
}Season describes one calendar season and its length in days.