diff --git a/entity/singleton.go b/entity/singleton.go index b5fb73b..79cde10 100644 --- a/entity/singleton.go +++ b/entity/singleton.go @@ -3,6 +3,7 @@ package entity import ( "time" + "github.com/yohamta/donburi/filter" "joylink.club/ecs" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/repository" @@ -10,6 +11,9 @@ import ( // 初始化世界数据 func LoadWorldData(w ecs.World, repo *repository.Repository) { + if repo == nil { + panic("repo不能为nil") + } entry := w.Create(component.WorldDataType) component.WorldDataType.Set(entry, &component.WorldData{ Repo: repo, @@ -18,8 +22,13 @@ func LoadWorldData(w ecs.World, repo *repository.Repository) { }) } +var query = ecs.NewQuery(filter.Contains(component.WorldDataType)) + // 获取世界数据 func GetWorldData(w ecs.World) *component.WorldData { - entry := component.WorldDataType.MustFirst(w) - return component.WorldDataType.Get(entry) + entry, ok := query.First(w) + if ok { + return component.WorldDataType.Get(entry) + } + panic("世界数据不存在") } diff --git a/examples/main.go b/examples/main.go new file mode 100644 index 0000000..f729447 --- /dev/null +++ b/examples/main.go @@ -0,0 +1,10 @@ +package main + +import ( + rtss_simulation "joylink.club/rtsssimulation" + "joylink.club/rtsssimulation/repository" +) + +func main() { + rtss_simulation.NewSimulation(&repository.Repository{}) +}