Add tags api
This commit is contained in:
@ -1,33 +0,0 @@
|
|||||||
# Registry System
|
|
||||||
|
|
||||||
instance {
|
|
||||||
ResourceLocation {
|
|
||||||
namespace: string
|
|
||||||
path: string
|
|
||||||
}
|
|
||||||
|
|
||||||
ResourceKey<T> {
|
|
||||||
registryName: ResourceLocation
|
|
||||||
location: ResourceLocation
|
|
||||||
}
|
|
||||||
|
|
||||||
registry<T> {
|
|
||||||
getId(T): int
|
|
||||||
byId(int): T
|
|
||||||
|
|
||||||
getKey(T): ResourceLocation
|
|
||||||
getResourceKey(T): ResourceKey<T>
|
|
||||||
get(ResourceKey<T>): T
|
|
||||||
get(ResourceLocation): T
|
|
||||||
|
|
||||||
getTags(TagKey<T>): (TagKey<T>, *T[])[]
|
|
||||||
getTagNames(): TagKey<T>[]
|
|
||||||
resetTags()
|
|
||||||
bindTags((TagKey<T>, *T[])[])
|
|
||||||
}[]
|
|
||||||
|
|
||||||
TagKey<T> {
|
|
||||||
*Registry<T>
|
|
||||||
ResourceLocation
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,7 @@
|
|||||||
package registry
|
package registry
|
||||||
|
|
||||||
|
import "slices"
|
||||||
|
|
||||||
type Registry[E any] struct {
|
type Registry[E any] struct {
|
||||||
keys map[string]int32
|
keys map[string]int32
|
||||||
values []E
|
values []E
|
||||||
@ -47,6 +49,16 @@ func (r *Registry[E]) Put(name string, data E) (id int32, val *E) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tags
|
||||||
|
|
||||||
|
func (r *Registry[E]) Tag(tag string) []*E {
|
||||||
|
return slices.Clone(r.tags[tag])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Registry[E]) ClearTags() {
|
||||||
|
r.tags = make(map[string][]*E)
|
||||||
|
}
|
||||||
|
|
||||||
// func (r *Registry[E]) BindTags(tag string, ids []int32) error {
|
// func (r *Registry[E]) BindTags(tag string, ids []int32) error {
|
||||||
// values := make([]*E, len(ids))
|
// values := make([]*E, len(ids))
|
||||||
// for i, id := range ids {
|
// for i, id := range ids {
|
||||||
|
Reference in New Issue
Block a user