rts-sim-module/component/singleton/load.go

43 lines
1.0 KiB
Go
Raw Normal View History

package singleton
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/modelrepo"
)
// 加载并初始化单例组件
func LoadSingletons(w ecs.World, r modelrepo.Repo) {
loadWorldRepo(w, r)
LoadWorldTime(w)
loadUidEntityIndex(w)
}
var worldRepoQuery = ecs.NewQuery(filter.Contains(WorldRepoType))
var worldTimeQuery = ecs.NewQuery(filter.Contains(WorldTimeType))
var uidEntityIndexQuery = ecs.NewQuery(filter.Contains(EntityUidIndexType))
func GetWorldTime(w ecs.World) *WorldTime {
entry, _ := worldTimeQuery.First(w)
if entry == nil {
panic("不存在世界时间单例组件")
}
return WorldTimeType.Get(entry)
}
func GetWorldRepo(w ecs.World) *WorldRepo {
entry, _ := worldRepoQuery.First(w)
if entry == nil {
panic("不存在世界数据单例组件")
}
return WorldRepoType.Get(entry)
}
func GetEntityUidIndex(w ecs.World) *EntityUidIndex {
entry, _ := uidEntityIndexQuery.First(w)
if entry == nil {
panic("不存在实体Uid索引单例组件")
}
return EntityUidIndexType.Get(entry)
}