Add tags api

This commit is contained in:
Tnze
2024-07-28 00:02:55 +08:00
parent 31375289b0
commit 66b3b11049
2 changed files with 12 additions and 33 deletions

View File

@ -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
}
}

View File

@ -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 {