template

package
v0.0.0-...-b0deb01 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRecursion int = 16
)

Variables

This section is empty.

Functions

func Create

func Create[K Object](which string) K

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

func GetConstructor(name string) func() any

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 RandomListMember(list string) string

func RegisterConstructor

func RegisterConstructor(name string, fn func() any)

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

func GenerateObject(which string) Object

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

func FindTemplate(which string) *Template

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

func (t *Template) GetBool(name string, def bool) bool

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

func (t *Template) GetBounds(name string, def uo.Bounds) uo.Bounds

GetBounds returns a uo.Bounds value. The default value is returned if the named tag is not found.

func (*Template) GetFloat

func (t *Template) GetFloat(name string, def float32) float32

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

func (t *Template) GetHex(name string, def uint32) uint32

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

func (t *Template) GetLocation(name string, def uo.Location) uo.Location

GetLocation returns a uo.Location value. The default value is returned if the named tag is not found.

func (*Template) GetNumber

func (t *Template) GetNumber(name string, def int) int

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

func (t *Template) GetObjectReferences(name string) []uo.Serial

GetObjectReferences returns a slice of uo.Serial values. nil is the default value. This function may add errors to the internal error slice.

func (*Template) GetString

func (t *Template) GetString(name, def string) string

GetString returns the named property as a string or the default if not found. This function panics if no context is on the stack. See PushContext and PopContext.

func (*Template) GetULong

func (t *Template) GetULong(name string, def uint64) uint64

GetULong returns the named property as a uint64 or the default if not found. This function may add errors to the internal error slice. Only use this for actual 64-bit values, like uo.Time.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL