Table of Contents

Interface IAssetManager

Namespace
Vintagestory.API.Common
Assembly
VintagestoryAPI.dll

Takes care loading, reloading and managing all files inside the assets folder. All asset names and paths are always converted to lower case.

public interface IAssetManager

Properties

AllAssets

All assets found in the assets folder

Dictionary<AssetLocation, IAsset> AllAssets { get; }

Property Value

Dictionary<AssetLocation, IAsset>

Origins

Returns all origins in the priority order. Highest (First) to Lowest (Last)

List<IAssetOrigin> Origins { get; }

Property Value

List<IAssetOrigin>

Methods

Add(AssetLocation, IAsset)

Adds a runtime asset to the game, curently used by ModCompatiblityUtil. Allows you do add an asset found at path but loaded from path asset.Path.

void Add(AssetLocation path, IAsset asset)

Parameters

path AssetLocation
asset IAsset

AddModOrigin(string, string)

void AddModOrigin(string domain, string fullPath)

Parameters

domain string
fullPath string

AddPathOrigin(string, string)

[Obsolete("Use AddModOrigin")]
void AddPathOrigin(string domain, string fullPath)

Parameters

domain string
fullPath string

Exists(AssetLocation)

Returns true if given asset exists in the list of loaded assets

bool Exists(AssetLocation location)

Parameters

location AssetLocation

Returns

bool

Get(string)

Retrieves an asset from given path within the assets folder. Throws an exception when the asset does not exist. Remember to use lower case paths.

IAsset Get(string path)

Parameters

path string

Returns

IAsset

Get(AssetLocation)

Retrieves an asset from given path within the assets folder. Throws an exception when the asset does not exist. Remember to use lower case paths.

IAsset Get(AssetLocation Location)

Parameters

Location AssetLocation

Returns

IAsset

GetLocations(string, string)

Returns all asset locations that begins with given path and domain. If no domain is specified, all domains will be searched. The returned list is considered unsorted.

List<AssetLocation> GetLocations(string pathBegins, string domain = null)

Parameters

pathBegins string
domain string

Returns

List<AssetLocation>

GetMany(string, string, bool)

Returns all assets inside given category with the given path. If no domain is specified, all domains will be searched. The returned list is considered unsorted.

List<IAsset> GetMany(string pathBegins, string domain = null, bool loadAsset = true)

Parameters

pathBegins string
domain string
loadAsset bool

Whether it should load the contents of this asset

Returns

List<IAsset>

GetManyInCategory(string, string, string, bool)

List<IAsset> GetManyInCategory(string categoryCode, string pathBegins, string domain = null, bool loadAsset = true)

Parameters

categoryCode string
pathBegins string
domain string
loadAsset bool

Returns

List<IAsset>

GetMany<T>(ILogger, string, string)

Searches for all assets in given basepath and uses JSON.NET to automatically turn them into objects. Will log an error to given ILogger if it can't parse the json file and continue with the next asset. Remember to use lower case paths. If no domain is specified, all domains will be searched. The returned list is considered unsorted.

Dictionary<AssetLocation, T> GetMany<T>(ILogger logger, string pathBegins, string domain = null)

Parameters

logger ILogger
pathBegins string
domain string

Returns

Dictionary<AssetLocation, T>

Type Parameters

T

Get<T>(AssetLocation)

Retrieves an asset from given path within the assets folder and uses JSON.NET to automatically turn them into objects. Throws an exception when the asset does not exist or the conversion failed. Remember to use lower case paths.

T Get<T>(AssetLocation location)

Parameters

location AssetLocation

Returns

T

Type Parameters

T

Reload(AssetCategory)

Reloads all assets in given base location path. It returns the amount of the found locations.

int Reload(AssetCategory category)

Parameters

category AssetCategory

Returns

int

Reload(AssetLocation)

Reloads all assets in given base location path. It returns the amount of the found locations.

int Reload(AssetLocation baseLocation)

Parameters

baseLocation AssetLocation

Returns

int

TryGet(string, bool)

Retrieves an asset from given path within the assets folder. Returns null when the asset does not exist. Remember to use lower case paths.

Mods must not call TryGet to get assets before AssetsLoaded stage in a ModSystem - do not load assets in the Start() method! In StartClientSide() is OK though. (Or if you absolutely have to load assets in Start(), use IAssetManager.Get(), but it will throw an exception for anything except a base asset.)

IAsset TryGet(string Path, bool loadAsset = true)

Parameters

Path string
loadAsset bool

Returns

IAsset

TryGet(AssetLocation, bool)

Retrieves an asset from given path within the assets folder. Returns null when the asset does not exist. Remember to use lower case paths.

Mods must not call TryGet to get assets before AssetsLoaded stage in a ModSystem - do not load assets in the Start() method! (Or if you absolutely have to load assets in Start(), use IAssetManager.Get(), but it will throw an exception for anything except a base asset.)

IAsset TryGet(AssetLocation Location, bool loadAsset = true)

Parameters

Location AssetLocation
loadAsset bool

Returns

IAsset