Documentation ¶
Index ¶
- Constants
- func Create[K Object](which string) K
- func GetConstructor(name string) func() any
- func Initialize(templatePath, listPath, variablesFilePath string, rng uo.RandomSource, ...) []error
- func RandomListMember(list string) string
- func RegisterConstructor(name string, fn func() any)
- type Object
- type Template
- func (t *Template) GetBool(name string, def bool) bool
- func (t *Template) GetBounds(name string, def uo.Bounds) uo.Bounds
- func (t *Template) GetFloat(name string, def float32) float32
- func (t *Template) GetHex(name string, def uint32) uint32
- func (t *Template) GetLocation(name string, def uo.Location) uo.Location
- func (t *Template) GetNumber(name string, def int) int
- func (t *Template) GetObjectReferences(name string) []uo.Serial
- func (t *Template) GetString(name, def string) string
- func (t *Template) GetULong(name string, def uint64) uint64
- type TemplateManager
Constants ¶
const (
MaxRecursion int = 16
)
Variables ¶
This section is empty.
Functions ¶
func Create ¶
Create returns a pointer to a newly constructed object that has been assigned a unique serial of the correct type and added to the data stores. It does not yet have a parent nor has it been placed on the map. One of these things must be done otherwise the data store will leak this object.
func GetConstructor ¶
GetConstructor returns the named constructor or nil.
func Initialize ¶
func Initialize(templatePath, listPath, variablesFilePath string, rng uo.RandomSource, fn func(Object)) []error
Initialize initializes the template package and must be called prior to all other package calls. The function parameter fn should add the game object to internal data stores when a new object is created by the template engine.
func RandomListMember ¶
func RegisterConstructor ¶
RegisterConstructor registers a constructor with the template package.
Types ¶
type Object ¶
type Object interface { // Serial returns the unique ID of the object. Serial() uo.Serial // Deserialize takes data from the template object and initializes the // object's data structures with it. Deserialize(*Template, bool) // RecalculateStats is called after Deserialize() and should be used to // recalculate any dynamic values of the data structures initialized by // Deserialize(). RecalculateStats() // InsertObject adds an object as a child of this object through an empty // interface. InsertObject(any) // SetAmount sets the stack amount for the object, if any. SetAmount(int) }
Object is the interface all Template objects must implement.
func GenerateObject ¶
GenerateObject returns a pointer to a newly constructed object as in Create() but the object is not added to the data stores.
type Template ¶
type Template struct { TypeName string // Name of the object constructor used to create the object. TemplateName string // Unique name of the template. BaseTemplate string // Name of the base template. The empty string means a root template. IsResolved bool // True if the template's inheritance chain has already been satisfied. // contains filtered or unexported fields }
Template contains all of the property lines of the template.
func FindTemplate ¶
FindTemplate returns a pointer to the named template or nil if not found.
func NewTemplate ¶
func NewTemplate(tfo *util.TagFileObject, tm *TemplateManager) (*Template, []error)
NewTemplate creates a new template.T object from the provided TagFileObject. The inheritance chain has not been resolved for this object and the text template has not been created or compiled.
func (*Template) GetBool ¶
GetBool returns the named property as a boolean value or the default if not found. This function may add errors to the internal error slice.
func (*Template) GetBounds ¶
GetBounds returns a uo.Bounds value. The default value is returned if the named tag is not found.
func (*Template) GetFloat ¶
GetFloat returns the named property as a float32 or the default if not found. This function may add errors to the internal error slice.
func (*Template) GetHex ¶
GetHex returns the named property as an unsigned number or the default if not found. This function may add errors to the internal error slice.
func (*Template) GetLocation ¶
GetLocation returns a uo.Location value. The default value is returned if the named tag is not found.
func (*Template) GetNumber ¶
GetNumber returns the named property as a number or the default if not found. This function may add errors to the internal error slice.
func (*Template) GetObjectReferences ¶
GetObjectReferences returns a slice of uo.Serial values. nil is the default value. This function may add errors to the internal error slice.
type TemplateManager ¶
type TemplateManager struct {
// contains filtered or unexported fields
}
TemplateManager manages a collection of templates
func (*TemplateManager) CurrentContext ¶
func (m *TemplateManager) CurrentContext() map[string]string
CurrentContext returns the current template execution context. This function panics if the context stack is empty.