asset

package
v0.0.0-...-20810c9 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoEmbeddedFileSystem = errors.New("no embedded files set via axe.SetEmbedAssetRoot")

Functions

func SetEmbedAssetRoot

func SetEmbedAssetRoot(root fs.FS)

Types

type Asset

type Asset struct {
	Ref            Ref
	Source         Source
	SourceReader   io.Reader
	Format         Format
	LoadStatus     Status
	Data           any
	ActivateStatus Status
	Dependent      []Ref
	Next           []Ref
}

func (*Asset) Activate

func (a *Asset) Activate() error

func (*Asset) AddNext

func (a *Asset) AddNext(relative string, dependent bool)

func (Asset) IsValid

func (a Asset) IsValid() bool

func (*Asset) Load

func (a *Asset) Load() error

func (*Asset) LoadData

func (a *Asset) LoadData() error

func (*Asset) LoadReader

func (a *Asset) LoadReader() error

func (*Asset) Relative

func (a *Asset) Relative(relative string) Ref

func (*Asset) Unload

func (a *Asset) Unload() error

type Assets

type Assets struct {
	FormatMap     map[Type]Format
	Formats       []Format
	Sources       []Source
	DefaultSource Source
	Assets        map[string]*Asset
	NamedAssets   map[string]*Asset
}

func NewAssets

func NewAssets() Assets

func (*Assets) Add

func (assets *Assets) Add(ref Ref) *Asset

func (*Assets) AddDefaults

func (assets *Assets) AddDefaults()

func (*Assets) AddFormat

func (assets *Assets) AddFormat(format Format)

func (*Assets) AddMany

func (assets *Assets) AddMany(refs []Ref) []*Asset

func (*Assets) AddManyMap

func (assets *Assets) AddManyMap(refs []Ref) map[string]*Asset

func (*Assets) AddSource

func (assets *Assets) AddSource(source Source)

func (*Assets) Destroy

func (assets *Assets) Destroy()

func (*Assets) Get

func (assets *Assets) Get(uri string) *Asset

func (*Assets) GetEither

func (assets *Assets) GetEither(nameOrURI string) *Asset

func (*Assets) GetNamed

func (assets *Assets) GetNamed(name string) *Asset

func (*Assets) GetRef

func (assets *Assets) GetRef(ref Ref) *Asset

type EmbedAssetSource

type EmbedAssetSource struct{}

func (EmbedAssetSource) Handles

func (local EmbedAssetSource) Handles(ref Ref) bool

func (EmbedAssetSource) Read

func (local EmbedAssetSource) Read(ref Ref) (io.Reader, error)

func (EmbedAssetSource) Relative

func (local EmbedAssetSource) Relative(uri string, relative string) string

type FileSystemAssetSource

type FileSystemAssetSource struct {
	Files          fs.FS
	HandlesPattern *regexp.Regexp
	CustomRelative func(uri string, relative string) string
}

func (FileSystemAssetSource) Handles

func (src FileSystemAssetSource) Handles(ref Ref) bool

func (FileSystemAssetSource) Read

func (src FileSystemAssetSource) Read(ref Ref) (io.Reader, error)

func (FileSystemAssetSource) Relative

func (src FileSystemAssetSource) Relative(uri string, relative string) string

type Format

type Format interface {
	// Does this format handle refs like this one.
	Handles(ref Ref) bool
	// Native types this format handles.
	Types() []Type
	// Load the asset from the source. This could be done in any thread.
	Load(asset *Asset) error
	// Unload the asset, we don't need it anymore. This could be done in any thread.
	Unload(asset *Asset) error
	// The asset is loaded by we need to use it now. This is done in the main thread.
	Activate(asset *Asset) error
	// The asset is not needed right now, but don't unload it yet. This is done in the main thread.
	Deactivate(asset *Asset) error
}

type JsonArray

type JsonArray []*JsonValue

type JsonGenericAssetFormat

type JsonGenericAssetFormat struct{}

func (*JsonGenericAssetFormat) Activate

func (format *JsonGenericAssetFormat) Activate(asset *Asset) error

func (*JsonGenericAssetFormat) Deactivate

func (format *JsonGenericAssetFormat) Deactivate(asset *Asset) error

func (*JsonGenericAssetFormat) Handles

func (format *JsonGenericAssetFormat) Handles(ref Ref) bool

func (*JsonGenericAssetFormat) Load

func (format *JsonGenericAssetFormat) Load(asset *Asset) error

func (*JsonGenericAssetFormat) Types

func (format *JsonGenericAssetFormat) Types() []Type

func (*JsonGenericAssetFormat) Unload

func (format *JsonGenericAssetFormat) Unload(asset *Asset) error

type JsonObject

type JsonObject map[string]*JsonValue

type JsonValue

type JsonValue struct {
	Kind   JsonValueKind
	Value  any
	Parent *JsonValue
}

type JsonValueKind

type JsonValueKind int
const (
	JsonValueKindUnknown JsonValueKind = iota
	JsonValueKindNull
	JsonValueKindNumber
	JsonValueKindString
	JsonValueKindBoolean
	JsonValueKindObject
	JsonValueKindArray
)

type LocalAssetSource

type LocalAssetSource struct{}

func (LocalAssetSource) Handles

func (local LocalAssetSource) Handles(ref Ref) bool

func (LocalAssetSource) Read

func (local LocalAssetSource) Read(ref Ref) (io.Reader, error)

func (LocalAssetSource) Relative

func (local LocalAssetSource) Relative(uri string, relative string) string

type Ref

type Ref struct {
	Name    string
	URI     string
	Type    Type
	Options any
}

func (Ref) String

func (ref Ref) String() string

func (Ref) UniqueName

func (ref Ref) UniqueName() string

type Source

type Source interface {
	Handles(ref Ref) bool
	Read(ref Ref) (io.Reader, error)
	Relative(uri string, relative string) string
}

type Status

type Status struct {
	Progress float32
	Started  bool
	Done     bool
	Error    error
}

func (*Status) Fail

func (status *Status) Fail(err error)

func (*Status) IsSuccess

func (status *Status) IsSuccess() bool

func (*Status) Reset

func (status *Status) Reset()

func (*Status) Start

func (status *Status) Start()

func (*Status) Success

func (status *Status) Success()

type Type

type Type string
const (
	TypeUnknown        Type = ""
	TypeTexture        Type = "texture"
	TypeAudio          Type = "audio"
	TypeVertexShader   Type = "vertex-shader"
	TypeFragmentShader Type = "fragment-shader"
	TypeXml            Type = "xml"
	TypeJson           Type = "json"
	TypeModel          Type = "model"
	TypeMaterials      Type = "materials"
	TypeMaterial       Type = "material"
	TypeFontBitmap     Type = "font-bitmap"
)

type WebAssetSource

type WebAssetSource struct{}

func (WebAssetSource) Handles

func (local WebAssetSource) Handles(ref Ref) bool

func (WebAssetSource) Read

func (local WebAssetSource) Read(ref Ref) (io.Reader, error)

func (WebAssetSource) Relative

func (local WebAssetSource) Relative(uri string, relative string) string

type XmlAssetFormat

type XmlAssetFormat[T any] struct {
	EmptyValue        T
	Suffix            string
	SuffixInsensitive bool
	Regex             *regexp.Regexp
	CustomTypes       []Type
}

func (*XmlAssetFormat[T]) Activate

func (format *XmlAssetFormat[T]) Activate(asset *Asset) error

func (*XmlAssetFormat[T]) Deactivate

func (format *XmlAssetFormat[T]) Deactivate(asset *Asset) error

func (*XmlAssetFormat[T]) Handles

func (format *XmlAssetFormat[T]) Handles(ref Ref) bool

func (*XmlAssetFormat[T]) Load

func (format *XmlAssetFormat[T]) Load(asset *Asset) error

func (*XmlAssetFormat[T]) Types

func (format *XmlAssetFormat[T]) Types() []Type

func (*XmlAssetFormat[T]) Unload

func (format *XmlAssetFormat[T]) Unload(asset *Asset) error

type XmlGenericAssetFormat

type XmlGenericAssetFormat struct{}

func (*XmlGenericAssetFormat) Activate

func (format *XmlGenericAssetFormat) Activate(asset *Asset) error

func (*XmlGenericAssetFormat) Deactivate

func (format *XmlGenericAssetFormat) Deactivate(asset *Asset) error

func (*XmlGenericAssetFormat) Handles

func (format *XmlGenericAssetFormat) Handles(ref Ref) bool

func (*XmlGenericAssetFormat) Load

func (format *XmlGenericAssetFormat) Load(asset *Asset) error

func (*XmlGenericAssetFormat) Types

func (format *XmlGenericAssetFormat) Types() []Type

func (*XmlGenericAssetFormat) Unload

func (format *XmlGenericAssetFormat) Unload(asset *Asset) error

type XmlNode

type XmlNode struct {
	Token    xml.Token
	Children []*XmlNode
}

Jump to

Keyboard shortcuts

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