API リファレンスはソースコード内の Go ドキュメントコメントから生成されており、英語で記述されています。
package tags
import "github.com/nsgo-dev/game/pkg/tags"概要
Package tags is experimental: its API and documented formats may change in a minor release. See the API stability policy. holds gameplay tags: dotted hierarchical names such as status.debuff.stun that abilities, AI, items and UI share as one vocabulary. A Registry declares the tags a game uses in a versioned YAML file read with Parse and written with Encode, a Container holds the tags an entity has with a reference count for each, and a Query matches a container against all, any and none lists.
目次
定数
const Version = 1Version is the version of the tag registry file schema this package reads and writes.
関数
func Encode(r *Registry) ([]byte, error)Encode validates r as Parse does and writes it as canonical YAML, two-space indented with the tags sorted by name, which Parse reads back unchanged.
型
type Container map[string]intContainer holds the tags one entity has, each with a reference count: the number of sources, such as effects or items, that added it.
func (c Container) Add(name string)Add adds one reference to the tag name. An invalid name is ignored.
func (c Container) Has(name string) boolHas reports whether c holds the tag name or a child of it: holding status.debuff.stun matches status.debuff and status, because a child tag implies its parents, while holding only status.debuff does not match status.debuff.stun.
func (c Container) HasExact(name string) boolHasExact reports whether c holds the tag name itself.
func (c Container) Remove(name string)Remove removes one reference to the tag name, and the tag itself with its last reference.
type Definition struct {
// Name is the tag: dot-separated segments, each a letter followed by letters, digits, '_' or '-'. Each segment names a child of the tag before it.
Name string `yaml:"name"`
// Description, optional, says what the tag means.
Description string `yaml:"description,omitempty"`
}Definition declares one tag of a registry.
type Query struct {
// All are the tags the container must all have.
All []string `yaml:"all,omitempty"`
// Any are the tags the container must have at least one of; an empty list puts no condition.
Any []string `yaml:"any,omitempty"`
// None are the tags the container must have none of.
None []string `yaml:"none,omitempty"`
}Query matches a Container against three lists of tags, each compared as Container.Has compares one.
func (q Query) Match(c Container) boolMatch reports whether c has every tag of q.All, at least one of q.Any when it is not empty, and none of q.None.
type Registry struct {
// Version is the schema version; it must equal Version.
Version int `yaml:"version"`
// Tags are the declared tags, each name once. Encode writes them sorted by name.
Tags []Definition `yaml:"tags"`
}Registry is the root of a versioned YAML tag registry file: the tags a game declares.
func Parse(data []byte) (*Registry, error)Parse decodes a YAML tag registry and validates it. Unknown fields, trailing YAML documents, a missing or unsupported version and invalid or duplicate tag names are refused with a *loaderr.Error that names the line and a fix.
func (r *Registry) Has(name string) boolHas reports whether r declares the tag name exactly. A nil registry declares none.