rts-sim-module/entity/singleton.go

26 lines
603 B
Go
Raw Normal View History

package entity
import (
"time"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/repository"
)
// 初始化世界数据
func InitWorldData(w ecs.World, repo *repository.Repository) {
entry := w.Create(component.WorldDataType)
component.WorldDataType.Set(entry, &component.WorldData{
Repo: repo,
Time: time.Now().UnixMilli(),
EntityMap: make(map[string]*ecs.Entry),
})
}
// 获取世界数据
func GetWorldData(w ecs.World) *component.WorldData {
entry := component.WorldDataType.MustFirst(w)
return component.WorldDataType.Get(entry)
}