From 4d914eb66e923d1867398e776fce8afe6a83370f Mon Sep 17 00:00:00 2001 From: walker Date: Thu, 28 Sep 2023 15:38:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96WorldData?= =?UTF-8?q?=E5=8D=95=E4=BE=8B=E7=BB=84=E4=BB=B6bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entity/singleton.go | 13 +++++++++++-- examples/main.go | 10 ++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 examples/main.go 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{}) +}