2023-08-04 11:02:08 +08:00
|
|
|
package ecs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/yohamta/donburi"
|
2023-10-09 11:12:05 +08:00
|
|
|
"joylink.club/ecs/filter"
|
2023-08-04 11:02:08 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type Query struct {
|
|
|
|
*donburi.Query
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewQuery creates a new query.
|
|
|
|
// It receives arbitrary filters that are used to filter entities.
|
|
|
|
func NewQuery(filter filter.LayoutFilter) *Query {
|
|
|
|
return &Query{
|
|
|
|
donburi.NewQuery(filter),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Query) Each(w World, callback func(*Entry)) {
|
|
|
|
q.Query.Each(w.(*world).world, func(entry *donburi.Entry) {
|
|
|
|
callback(&Entry{entry})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Query) Count(w World) int {
|
|
|
|
return q.Query.Count(w.(*world).world)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Query) First(w World) (entry *Entry, ok bool) {
|
|
|
|
e, ok := q.Query.First(w.(*world).world)
|
|
|
|
return &Entry{e}, ok
|
|
|
|
}
|