Table of Contents

Class AssetLocation

Namespace
Vintagestory.API.Common
Assembly
VintagestoryAPI.dll

Defines a complete path to an assets, including it's domain.

[TypeConverter(typeof(StringAssetLocationConverter))]
[ProtoContract]
public class AssetLocation : IEquatable<AssetLocation>, IComparable<AssetLocation>
Inheritance
AssetLocation
Implements
Derived
Inherited Members
Extension Methods

Examples

In JSON assets, asset locations are represented as single strings in the form "domain:path". To access an asset in the vanilla game, use the domain 'game'.

"code": "game:vegetable-cookedcattailroot",

Constructors

AssetLocation()

public AssetLocation()

AssetLocation(string)

Create a new AssetLocation from a single string (e.g. when parsing an AssetLocation in a JSON file). If no domain is prefixed, the default 'game' domain is used. This ensures the domain and path in the created AssetLocation are lowercase (as the input string could have any case)

public AssetLocation(string domainAndPath)

Parameters

domainAndPath string

AssetLocation(string, string)

Create a new AssetLocation with given domain and path: for efficiency it is the responsibility of calling code to ensure these are lowercase

public AssetLocation(string domain, string path)

Parameters

domain string
path string

Fields

LocationSeparator

public const char LocationSeparator = ':'

Field Value

char

Properties

Category

Gets the category of the asset.

public AssetCategory Category { get; }

Property Value

AssetCategory

Domain

public string Domain { get; set; }

Property Value

string

EndsWithWildCard

public bool EndsWithWildCard { get; }

Property Value

bool

IsWildCard

public bool IsWildCard { get; }

Property Value

bool

Path

public string Path { get; set; }

Property Value

string

Valid

Returns true if this is a valid path. For an asset location to be valid it needs to have any string as domain, any string as path, the domain may not contain slashes, and the path may not contain 2 consecutive slashes

public bool Valid { get; }

Property Value

bool

Methods

BeginsWith(string, string)

public virtual bool BeginsWith(string domain, string partialPath)

Parameters

domain string
partialPath string

Returns

bool

Clone()

Clones this asset.

public virtual AssetLocation Clone()

Returns

AssetLocation

the cloned asset.

CloneWithoutPrefixAndEnding(int)

public virtual AssetLocation CloneWithoutPrefixAndEnding(int prefixLength)

Parameters

prefixLength int

Returns

AssetLocation

CodePartsAfterSecond()

public string CodePartsAfterSecond()

Returns

string

CompareTo(AssetLocation)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

public int CompareTo(AssetLocation other)

Parameters

other AssetLocation

An object to compare with this instance.

Returns

int

A value that indicates the relative order of the objects being compared. The return value has these meanings:

Value Meaning
Less than zero This instance precedes other in the sort order.
Zero This instance occurs in the same position in the sort order as other.
Greater than zero This instance follows other in the sort order.

CopyWithPath(string)

Makes a copy of the asset with a modified path.

public virtual AssetLocation CopyWithPath(string path)

Parameters

path string

Returns

AssetLocation

CopyWithPathPrefixAndAppendix(string, string)

public virtual AssetLocation CopyWithPathPrefixAndAppendix(string prefix, string appendix)

Parameters

prefix string
appendix string

Returns

AssetLocation

CopyWithPathPrefixAndAppendixOnce(string, string)

public virtual AssetLocation CopyWithPathPrefixAndAppendixOnce(string prefix, string appendix)

Parameters

prefix string
appendix string

Returns

AssetLocation

Create(string, string)

Create an Asset Location from a string which may optionally have no prefixed domain: - in which case the defaultDomain is used. This may be used to create an AssetLocation from any string (e.g. from custom Attributes in a JSON file). For safety and consistency it ensures the domainAndPath string is lowercase. BUT: the calling code has the responsibility to ensure the defaultDomain parameter is lowercase (normally the defaultDomain will be taken from another existing AssetLocation, in which case it should already be lowercase).

public static AssetLocation Create(string domainAndPath, string defaultDomain = "game")

Parameters

domainAndPath string
defaultDomain string

Returns

AssetLocation

EndVariant()

Returns the code of the last variant in the path, for example for a path of "water-still-7" it would return "7"

public string EndVariant()

Returns

string

Equals(object)

Determines whether the specified object is equal to the current object.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

Equals(AssetLocation)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(AssetLocation other)

Parameters

other AssetLocation

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

FirstCodePart()

public string FirstCodePart()

Returns

string

FirstPathPart(int)

Returns the n-th path part

public string FirstPathPart(int posFromLeft = 0)

Parameters

posFromLeft int

Returns

string

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

GetName()

Gets the name of the asset.

public virtual string GetName()

Returns

string

HasDomain()

Whether or not the Asset has a domain.

public virtual bool HasDomain()

Returns

bool

IsChild(AssetLocation)

public virtual bool IsChild(AssetLocation Location)

Parameters

Location AssetLocation

Returns

bool

PathOmittingPrefixAndSuffix(string, string)

public string PathOmittingPrefixAndSuffix(string prefix, string suffix)

Parameters

prefix string
suffix string

Returns

string

PathStartsWith(string)

public bool PathStartsWith(string partialPath)

Parameters

partialPath string

Returns

bool

RemoveEnding()

Removes the file ending from the asset path.

public virtual void RemoveEnding()

SecondCodePart()

public string SecondCodePart()

Returns

string

ShortDomain()

public string ShortDomain()

Returns

string

ToShortString()

public string ToShortString()

Returns

string

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

WildCardMatch(AssetLocation, string)

public bool WildCardMatch(AssetLocation other, string pathAsRegex)

Parameters

other AssetLocation
pathAsRegex string

Returns

bool

WithFilename(string)

Sets the last part after the last /

public virtual AssetLocation WithFilename(string filename)

Parameters

filename string

Returns

AssetLocation

WithLocationPrefixOnce(AssetLocation)

public AssetLocation WithLocationPrefixOnce(AssetLocation prefix)

Parameters

prefix AssetLocation

Returns

AssetLocation

WithPath(string)

Sets the path of the asset location

public virtual AssetLocation WithPath(string path)

Parameters

path string

the new path to set.

Returns

AssetLocation

The modified AssetLocation

WithPathAppendix(string)

public AssetLocation WithPathAppendix(string appendix)

Parameters

appendix string

Returns

AssetLocation

WithPathAppendixOnce(string)

public AssetLocation WithPathAppendixOnce(string appendix)

Parameters

appendix string

Returns

AssetLocation

WithPathPrefix(string)

public AssetLocation WithPathPrefix(string prefix)

Parameters

prefix string

Returns

AssetLocation

WithPathPrefixOnce(string)

public AssetLocation WithPathPrefixOnce(string prefix)

Parameters

prefix string

Returns

AssetLocation

WithoutPathAppendix(string)

public AssetLocation WithoutPathAppendix(string appendix)

Parameters

appendix string

Returns

AssetLocation

toLocations(string[])

Converts a collection of paths to AssetLocations.

public static AssetLocation[] toLocations(string[] names)

Parameters

names string[]

The names of all of the locations

Returns

AssetLocation[]

The AssetLocations for all the names given.

Operators

operator ==(AssetLocation, AssetLocation)

public static bool operator ==(AssetLocation left, AssetLocation right)

Parameters

left AssetLocation
right AssetLocation

Returns

bool

implicit operator AssetLocation(string)

public static implicit operator AssetLocation(string code)

Parameters

code string

Returns

AssetLocation

implicit operator string(AssetLocation)

public static implicit operator string(AssetLocation loc)

Parameters

loc AssetLocation

Returns

string

operator !=(AssetLocation, AssetLocation)

public static bool operator !=(AssetLocation left, AssetLocation right)

Parameters

left AssetLocation
right AssetLocation

Returns

bool