34 lines
728 B
Go
34 lines
728 B
Go
|
package system
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/yohamta/donburi/filter"
|
||
|
"joylink.club/ecs"
|
||
|
"joylink.club/rtsssimulation/components"
|
||
|
)
|
||
|
|
||
|
func FindEntityById(world ecs.World, id string) *ecs.Entry {
|
||
|
query := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent))
|
||
|
return QueryEntityById(world, query, id)
|
||
|
}
|
||
|
func QueryEntityById(world ecs.World, q *ecs.Query, id string) *ecs.Entry {
|
||
|
var entry *ecs.Entry = nil
|
||
|
func() {
|
||
|
defer simpleRecover()
|
||
|
q.Each(world, func(e *ecs.Entry) {
|
||
|
if id == components.DeviceIdentityComponent.Get(e).Id {
|
||
|
entry = e
|
||
|
panic(fmt.Sprintf("找到实体[%s],结束查找", id))
|
||
|
}
|
||
|
})
|
||
|
}()
|
||
|
//
|
||
|
return entry
|
||
|
}
|
||
|
|
||
|
// 捕获panic并恢复执行
|
||
|
func simpleRecover() {
|
||
|
recover()
|
||
|
}
|