asset

package
v0.0.0-...-04212e3 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChildOverridesField

func ChildOverridesField(child Asset, pathToField string) bool

func FilterFilesByReflectType

func FilterFilesByReflectType(typ reflect.Type) ([]string, error)

func FilterFilesByType

func FilterFilesByType[T any]() ([]string, error)

func GetFlatTag

func GetFlatTag(sf *reflect.StructField, key string) (value string, exists bool)

func New

func New[T any]() *T

Create a new T and ensure that T and all it's public fields have their DefaultInitializers called.

func ObjectTypeName

func ObjectTypeName(obj any) (name string, fullname string)

func ReadFile

func ReadFile(assetPath Path) ([]byte, error)

func RegisterAsset

func RegisterAsset(zeroAsset any)

func RegisterAssetFactory

func RegisterAssetFactory(zeroAsset any, factoryFunction FactoryFunc)

func RegisterFileSystem

func RegisterFileSystem(filesystem fs.FS, priority int) error

func RegisterWritableFileSystem

func RegisterWritableFileSystem(filesystem WriteableFileSystem) error

func ResetForTest

func ResetForTest()

func Save

func Save(path Path, toSave Asset) error

func SetChildOverrideForField

func SetChildOverrideForField(child Asset, pathToField string, enable OverrideEnableType) error

func SetEditorMode

func SetEditorMode()

SetEditorMode informs the asset package that it is being used in an editor context. For example when enabled extra meta data about which fields a child asset overrides must be saved.

func SetParent

func SetParent(child Asset, parent Asset) error

SetParent is used to set the parent of an Asset. When an Asset is reparented, all values that are not overridden by the child are copied in from the parent. If there is no previous parent then the parent and the child are diffed and in places where they differ the child will override the parent.

func TypeName

func TypeName(t reflect.Type) (name string, fullname string)

func WalkFiles

func WalkFiles(fn fs.WalkDirFunc) error

WalkFiles is like fs.WalkDir, but it will walk all the readable file systems registered with asset.RegisterFileSystem

Types

type Asset

type Asset interface{}

Asset can be any type.

func GetParentAsset

func GetParentAsset(child Asset) Asset

func Load

func Load(assetPath Path) (Asset, error)

func LoadWithOptions

func LoadWithOptions(assetPath Path, options LoadOptions) (Asset, error)

func NewInstance

func NewInstance(a Asset) (Asset, error)

type AssetDescriptor

type AssetDescriptor struct {
	Name     string
	FullName string
	Create   FactoryFunc
	Type     reflect.Type
}

func FilterAssetDescriptorsByReflectType

func FilterAssetDescriptorsByReflectType(typ reflect.Type) []*AssetDescriptor

func FilterAssetDescriptorsByType

func FilterAssetDescriptorsByType[T any]() []*AssetDescriptor

func GetAssetDescriptors

func GetAssetDescriptors() []*AssetDescriptor

func GetDescriptorForAsset

func GetDescriptorForAsset(asset Asset) *AssetDescriptor

type DefaultInitializer

type DefaultInitializer interface {
	DefaultInitialize()
}

Any type that implements DefaultInitializer will have DefaultInitialize called when assets are created. Types do not need to be assets for this to work.

type FactoryFunc

type FactoryFunc func() (Asset, error)

type LoadOptions

type LoadOptions struct {
	// ForceReload will reload the asset from disk.  If the asset already
	// exists in memory that same object will be reused.
	ForceReload bool
	// contains filtered or unexported fields
}

type NamedAsset

type NamedAsset interface {
	Name() string
}

NamedAsset allows assets to provide a different Name The editor will use this Name instead of the struct name

type OverrideEnableType

type OverrideEnableType uint8
const (
	OverrideEnable OverrideEnableType = iota
	OverrideDisable
)

type Path

type Path string

Path is a distinct type from string so that the editor package can present an autocomplete window. The editor also understands the `filter` tag when used with Path, for example

struct {
  P Path `filter:"png,jpg"`
}

will only show files that contain the text 'png' or 'jpg'

func GetLoadPathForAsset

func GetLoadPathForAsset(a Asset) (Path, error)

func GetParent

func GetParent(child Asset) Path

type PostLoadingAsset

type PostLoadingAsset interface {
	PostLoad()
}

type PreSavingAsset

type PreSavingAsset interface {
	PreSave()
}

type WriteableFileSystem

type WriteableFileSystem interface {
	WriteFile(path Path, data []byte) error
}

func NewWritableFS

func NewWritableFS(basepath Path) WriteableFileSystem

Jump to

Keyboard shortcuts

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