34 lines
684 B
Go
34 lines
684 B
Go
|
package ecs
|
||
|
|
||
|
import (
|
||
|
"github.com/yohamta/donburi"
|
||
|
"github.com/yohamta/donburi/filter"
|
||
|
)
|
||
|
|
||
|
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
|
||
|
}
|