2023-12-28 16:49:28 +08:00
|
|
|
package singleton
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"joylink.club/ecs"
|
|
|
|
)
|
|
|
|
|
|
|
|
var WorldTimeType = ecs.NewComponentType[WorldTime]()
|
|
|
|
|
|
|
|
type WorldTime struct {
|
|
|
|
time int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *WorldTime) SetTime(t time.Time) {
|
|
|
|
w.time = t.UnixMilli()
|
|
|
|
}
|
|
|
|
|
|
|
|
// 增加时间
|
|
|
|
func (w *WorldTime) Run(ms int) {
|
|
|
|
w.time += int64(ms)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取时间
|
|
|
|
func (w *WorldTime) GetTime() time.Time {
|
|
|
|
return time.UnixMilli(w.time)
|
|
|
|
}
|
|
|
|
|
2023-12-29 17:48:57 +08:00
|
|
|
// 获取时间戳ms
|
2023-12-28 16:49:28 +08:00
|
|
|
func (w *WorldTime) GetMilli() int64 {
|
|
|
|
return w.time
|
|
|
|
}
|
|
|
|
|
2024-01-05 14:07:43 +08:00
|
|
|
func LoadWorldTime(w ecs.World) {
|
2023-12-28 16:49:28 +08:00
|
|
|
entry := w.Entry(w.Create(WorldTimeType))
|
|
|
|
WorldTimeType.Set(entry, &WorldTime{time: time.Now().UnixMilli()})
|
|
|
|
}
|