1c2ce2d9a9
【调整singletion时间组件大小写】
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
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)
|
|
}
|
|
|
|
type Singleton struct {
|
|
}
|
|
|
|
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("不存在UidEntityIndex组件")
|
|
}
|
|
return EntityUidIndexType.Get(entry)
|
|
}
|