rts-sim-module/entity/singleton.go

35 lines
784 B
Go
Raw Normal View History

package entity
import (
"time"
2023-09-28 15:38:18 +08:00
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/repository"
)
// 初始化世界数据
func LoadWorldData(w ecs.World, repo *repository.Repository) {
2023-09-28 15:38:18 +08:00
if repo == nil {
panic("repo不能为nil")
}
entry := w.Create(component.WorldDataType)
component.WorldDataType.Set(entry, &component.WorldData{
Repo: repo,
Time: time.Now().UnixMilli(),
EntityMap: make(map[string]*ecs.Entry),
})
}
2023-09-28 15:38:18 +08:00
var query = ecs.NewQuery(filter.Contains(component.WorldDataType))
// 获取世界数据
func GetWorldData(w ecs.World) *component.WorldData {
2023-09-28 15:38:18 +08:00
entry, ok := query.First(w)
if ok {
return component.WorldDataType.Get(entry)
}
panic("世界数据不存在")
}