assets

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ASSET_KEY    = "assets-%s"
	ASSET_EXPIRY = time.Duration(1 * time.Hour)
)

Variables

View Source
var Missing = fmt.Errorf("asset missing")

Functions

func CleanSourcePath

func CleanSourcePath(indexURL string) string

func DownloadBytes

func DownloadBytes(url string) ([]byte, error)

func DownloadFile

func DownloadFile(url string, path string) error

func FileExists

func FileExists(path string) bool

func GetURLBase

func GetURLBase(url string) string

func NewRemoteReader

func NewRemoteReader(
	url string,
	cache Store,
	shouldCache bool,
) *remoteReader

func WriteBytes

func WriteBytes(data []byte, path string) error

Types

type Asset

type Asset struct {
	Id   string
	Path string
	// contains filtered or unexported fields
}

type AssetFetcher

type AssetFetcher struct {
	// contains filtered or unexported fields
}

func NewAssetFetcher

func NewAssetFetcher(ctx context.Context, cache Store, roots []string, onlyMaps bool) (*AssetFetcher, error)

func (*AssetFetcher) FetchMapBundle

func (m *AssetFetcher) FetchMapBundle(ctx context.Context, needle string) ([]byte, error)

func (*AssetFetcher) FetchMapBytes

func (m *AssetFetcher) FetchMapBytes(ctx context.Context, needle string) ([]byte, error)

func (*AssetFetcher) FindMap

func (m *AssetFetcher) FindMap(needle string) *FoundMap

func (*AssetFetcher) GetMaps

func (m *AssetFetcher) GetMaps(skipRoot string) []SlimMap

func (*AssetFetcher) PollDownloads

func (m *AssetFetcher) PollDownloads(ctx context.Context)

type AssetSource

type AssetSource struct {
	Index *Index
	Base  string
}

type Bundle

type Bundle struct {
	Id      string
	Desktop bool
	Web     bool
	Assets  []Asset
}

type FSRoot

type FSRoot string

An FSRoot is just an absolute path on the FS.

func (FSRoot) Exists

func (f FSRoot) Exists(ctx context.Context, path string) bool

func (FSRoot) ReadFile

func (f FSRoot) ReadFile(ctx context.Context, path string) ([]byte, error)

func (FSRoot) Reference

func (f FSRoot) Reference(ctx context.Context, path string) (string, error)

type FSStore

type FSStore string

func (FSStore) Get

func (f FSStore) Get(ctx context.Context, key string) ([]byte, error)

func (FSStore) Set

func (f FSStore) Set(ctx context.Context, key string, data []byte) error

type FetchResult

type FetchResult struct {
	Data []byte
	Err  error
}

type FoundMap

type FoundMap struct {
	Map  *SlimMap
	Root *PackagedRoot
	// contains filtered or unexported fields
}

func (*FoundMap) GetBundle

func (f *FoundMap) GetBundle(ctx context.Context) ([]byte, error)

func (*FoundMap) GetOGZ

func (f *FoundMap) GetOGZ(ctx context.Context) ([]byte, error)

type GameMap

type GameMap struct {
	Id          string
	Name        string
	Ogz         string
	Bundle      string
	Assets      []Asset
	Image       string
	Description string
}

type Index

type Index struct {
	Assets   []string
	Refs     []IndexAsset
	Textures []Asset
	Sounds   []Asset
	Bundles  []Bundle
	Maps     []GameMap
	Models   []Model
	Mods     []Mod
}

type IndexAsset

type IndexAsset struct {
	Id   int
	Path string
	// contains filtered or unexported fields
}

type Job

type Job struct {
	Id     string
	Result chan FetchResult
}

type Mod

type Mod struct {
	Id          string
	Name        string
	Image       string
	Description string
}

type Model

type Model struct {
	Id   string
	Name string
}

type PackagedRoot

type PackagedRoot struct {

	// FS path -> asset id
	FS map[string]int
	// contains filtered or unexported fields
}

func NewPackagedRoot

func NewPackagedRoot(
	ctx context.Context,
	reader packageReader,
	base string,
	skip bool,
) (*PackagedRoot, error)

func (*PackagedRoot) Exists

func (f *PackagedRoot) Exists(ctx context.Context, path string) bool

func (*PackagedRoot) GetID

func (f *PackagedRoot) GetID(index int) (string, error)

func (*PackagedRoot) IsFS added in v0.2.0

func (f *PackagedRoot) IsFS() bool

func (*PackagedRoot) ReadAsset

func (f *PackagedRoot) ReadAsset(ctx context.Context, id string) ([]byte, error)

func (*PackagedRoot) ReadFile

func (f *PackagedRoot) ReadFile(ctx context.Context, path string) ([]byte, error)

func (*PackagedRoot) Reference

func (f *PackagedRoot) Reference(ctx context.Context, path string) (string, error)

func (*PackagedRoot) Source added in v0.2.0

func (f *PackagedRoot) Source() string

type RedisCache

type RedisCache struct {
	*RedisStore
	// contains filtered or unexported fields
}

func NewRedisCache

func NewRedisCache(client *redis.Client, ttl time.Duration) *RedisCache

func (*RedisCache) Set

func (r *RedisCache) Set(ctx context.Context, id string, data []byte) error

type RedisStore

type RedisStore struct {
	// contains filtered or unexported fields
}

func NewRedisStore

func NewRedisStore(client *redis.Client) *RedisStore

func (*RedisStore) Get

func (r *RedisStore) Get(ctx context.Context, id string) ([]byte, error)

func (*RedisStore) Set

func (r *RedisStore) Set(ctx context.Context, id string, data []byte) error

type Root

type Root interface {
	Exists(ctx context.Context, path string) bool
	ReadFile(ctx context.Context, path string) ([]byte, error)
	Reference(ctx context.Context, path string) (string, error)
}

func LoadRoots

func LoadRoots(ctx context.Context, cache Store, targets []string, onlyMaps bool) ([]Root, error)

type SlimMap

type SlimMap struct {
	Id     string
	Name   string
	Ogz    string
	Bundle string
	HasCFG bool
}

type Store

type Store interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Set(ctx context.Context, key string, data []byte) error
}

Jump to

Keyboard shortcuts

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