1c2ce2d9a9
【调整singletion时间组件大小写】
38 lines
615 B
Go
38 lines
615 B
Go
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)
|
|
}
|
|
|
|
// 获取时间戳ms
|
|
func (w *WorldTime) GetMilli() int64 {
|
|
return w.time
|
|
}
|
|
|
|
func LoadWorldTime(w ecs.World) {
|
|
entry := w.Entry(w.Create(WorldTimeType))
|
|
WorldTimeType.Set(entry, &WorldTime{time: time.Now().UnixMilli()})
|
|
}
|