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
Fields
LocationSeparator
public const char LocationSeparator = ':'
Field Value
Properties
Category
Gets the category of the asset.
public AssetCategory Category { get; }
Property Value
Domain
public string Domain { get; set; }
Property Value
EndsWithWildCard
public bool EndsWithWildCard { get; }
Property Value
IsWildCard
public bool IsWildCard { get; }
Property Value
Path
public string Path { get; set; }
Property Value
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
Methods
BeginsWith(string, string)
public virtual bool BeginsWith(string domain, string partialPath)
Parameters
Returns
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
CodePartsAfterSecond()
public string CodePartsAfterSecond()
Returns
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
AssetLocationAn 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
CopyWithPathPrefixAndAppendix(string, string)
public virtual AssetLocation CopyWithPathPrefixAndAppendix(string prefix, string appendix)
Parameters
Returns
CopyWithPathPrefixAndAppendixOnce(string, string)
public virtual AssetLocation CopyWithPathPrefixAndAppendixOnce(string prefix, string appendix)
Parameters
Returns
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
Returns
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
Equals(object)
Determines whether the specified object is equal to the current object.
public override bool Equals(object obj)
Parameters
obj
objectThe object to compare with the current object.
Returns
Equals(AssetLocation)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(AssetLocation other)
Parameters
other
AssetLocationAn object to compare with this object.
Returns
FirstCodePart()
public string FirstCodePart()
Returns
FirstPathPart(int)
Returns the n-th path part
public string FirstPathPart(int posFromLeft = 0)
Parameters
posFromLeft
int
Returns
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
HasDomain()
Whether or not the Asset has a domain.
public virtual bool HasDomain()
Returns
IsChild(AssetLocation)
public virtual bool IsChild(AssetLocation Location)
Parameters
Location
AssetLocation
Returns
PathOmittingPrefixAndSuffix(string, string)
public string PathOmittingPrefixAndSuffix(string prefix, string suffix)
Parameters
Returns
PathStartsWith(string)
public bool PathStartsWith(string partialPath)
Parameters
partialPath
string
Returns
RemoveEnding()
Removes the file ending from the asset path.
public virtual void RemoveEnding()
SecondCodePart()
public string SecondCodePart()
Returns
ShortDomain()
public string ShortDomain()
Returns
ToShortString()
public string ToShortString()
Returns
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
AssetLocationpathAsRegex
string
Returns
WithFilename(string)
Sets the last part after the last /
public virtual AssetLocation WithFilename(string filename)
Parameters
filename
string
Returns
WithLocationPrefixOnce(AssetLocation)
public AssetLocation WithLocationPrefixOnce(AssetLocation prefix)
Parameters
prefix
AssetLocation
Returns
WithPath(string)
Sets the path of the asset location
public virtual AssetLocation WithPath(string path)
Parameters
path
stringthe new path to set.
Returns
- AssetLocation
The modified AssetLocation
WithPathAppendix(string)
public AssetLocation WithPathAppendix(string appendix)
Parameters
appendix
string
Returns
WithPathAppendixOnce(string)
public AssetLocation WithPathAppendixOnce(string appendix)
Parameters
appendix
string
Returns
WithPathPrefix(string)
public AssetLocation WithPathPrefix(string prefix)
Parameters
prefix
string
Returns
WithPathPrefixOnce(string)
public AssetLocation WithPathPrefixOnce(string prefix)
Parameters
prefix
string
Returns
WithoutPathAppendix(string)
public AssetLocation WithoutPathAppendix(string appendix)
Parameters
appendix
string
Returns
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
AssetLocationright
AssetLocation
Returns
implicit operator AssetLocation(string)
public static implicit operator AssetLocation(string code)
Parameters
code
string
Returns
implicit operator string(AssetLocation)
public static implicit operator string(AssetLocation loc)
Parameters
loc
AssetLocation
Returns
operator !=(AssetLocation, AssetLocation)
public static bool operator !=(AssetLocation left, AssetLocation right)
Parameters
left
AssetLocationright
AssetLocation