Table of Contents

Class Shape

Namespace
Vintagestory.API.Common
Assembly
VintagestoryAPI.dll

The base shape for all json objects.

[JsonObject(MemberSerialization.OptIn)]
public class Shape
Inheritance
Shape
Inherited Members

Fields

Animations

The animations for the shape.

[JsonProperty]
public Animation[] Animations

Field Value

Animation[]

AnimationsByCrc32

public Dictionary<uint, Animation> AnimationsByCrc32

Field Value

Dictionary<uint, Animation>

AttachmentPointsByCode

public Dictionary<string, AttachmentPoint> AttachmentPointsByCode

Field Value

Dictionary<string, AttachmentPoint>

Elements

The elements of the shape.

[JsonProperty]
public ShapeElement[] Elements

Field Value

ShapeElement[]

JointsById

public Dictionary<int, AnimationJoint> JointsById

Field Value

Dictionary<int, AnimationJoint>

TextureHeight

The height of the texture (default: 16)

[JsonProperty]
public int TextureHeight

Field Value

int

TextureSizes

[JsonProperty]
public Dictionary<string, int[]> TextureSizes

Field Value

Dictionary<string, int[]>

TextureWidth

The width of the texture. (default: 16)

[JsonProperty]
public int TextureWidth

Field Value

int

Textures

The collection of textures in the shape.

[JsonProperty]
public Dictionary<string, AssetLocation> Textures

Field Value

Dictionary<string, AssetLocation>

Methods

Clone()

Creates a deep copy of the shape

public Shape Clone()

Returns

Shape

CloneAnimations()

public Animation[] CloneAnimations()

Returns

Animation[]

CloneElements()

public ShapeElement[] CloneElements()

Returns

ShapeElement[]

CollectElements(ShapeElement[], Dictionary<string, ShapeElement>)

Collects all the elements in the shape recursively.

public void CollectElements(ShapeElement[] elements, Dictionary<string, ShapeElement> elementsByName)

Parameters

elements ShapeElement[]
elementsByName Dictionary<string, ShapeElement>

GetElementByName(string, StringComparison)

Recursively searches the element by name from the shape.

public ShapeElement GetElementByName(string name, StringComparison stringComparison = StringComparison.InvariantCultureIgnoreCase)

Parameters

name string

The name of the element to get.

stringComparison StringComparison

Returns

ShapeElement

The shape element or null if none was found

RemoveElementByName(string, StringComparison)

Removes all elements with given name

public bool RemoveElementByName(string name, StringComparison stringComparison = StringComparison.InvariantCultureIgnoreCase)

Parameters

name string
stringComparison StringComparison

Returns

bool

ResolveAndFindJoints(ILogger, string, params string[])

Resolves all joints and loads them.

public void ResolveAndFindJoints(ILogger errorLogger, string shapeName, params string[] requireJointsForElements)

Parameters

errorLogger ILogger
shapeName string
requireJointsForElements string[]

ResolveAndLoadJoints(params string[])

[Obsolete("Must call ResolveAndFindJoints(errorLogger, shapeName, joints) instead")]
public void ResolveAndLoadJoints(params string[] requireJointsForElements)

Parameters

requireJointsForElements string[]

ResolveReferences(ILogger, string)

Attempts to resolve all references within the shape. Logs missing references them to the errorLogger

public void ResolveReferences(ILogger errorLogger, string shapeNameForLogging)

Parameters

errorLogger ILogger
shapeNameForLogging string

StepParentShape(Shape, string, string, string, ILogger, Action<string, AssetLocation>, float)

Adds a step parented shape to this shape. If you plan to cache the childShape use the shorter argument method and call SubclassForStepParenting() only once on it

public bool StepParentShape(Shape childShape, string texturePrefixCode, string childLocationForLogging, string parentLocationForLogging, ILogger logger, Action<string, AssetLocation> onTexture, float damageEffect = 0)

Parameters

childShape Shape
texturePrefixCode string
childLocationForLogging string
parentLocationForLogging string
logger ILogger
onTexture Action<string, AssetLocation>
damageEffect float

Returns

bool

StepParentShape(Shape, string, string, ILogger, Action<string, AssetLocation>)

Adds a step parented shape to this shape, does not call the required pre-step SubclassForStepParenting()

public bool StepParentShape(Shape childShape, string childLocationForLogging, string parentLocationForLogging, ILogger logger, Action<string, AssetLocation> onTexture)

Parameters

childShape Shape
childLocationForLogging string
parentLocationForLogging string
logger ILogger
onTexture Action<string, AssetLocation>

Returns

bool

SubclassForStepParenting(string, float)

Prefixes texturePrefixCode to all textures in this shape. Required pre-step for stepparenting. The long arguments StepParentShape() calls this method.

public bool SubclassForStepParenting(string texturePrefixCode, float damageEffect = 0)

Parameters

texturePrefixCode string
damageEffect float

Returns

bool

TrimTextureNamesAndResolveFaces(StreamingContext)

[OnDeserialized]
public void TrimTextureNamesAndResolveFaces(StreamingContext context)

Parameters

context StreamingContext

TryGet(ICoreAPI, string)

Tries to load the shape from the specified JSON file, with error logging
Returns null if the file could not be found, or if there was an error

public static Shape TryGet(ICoreAPI api, string shapePath)

Parameters

api ICoreAPI
shapePath string

Returns

Shape

TryGet(ICoreAPI, AssetLocation)

Tries to load the shape from the specified JSON file, with error logging
Returns null if the file could not be found, or if there was an error

public static Shape TryGet(ICoreAPI api, AssetLocation shapePath)

Parameters

api ICoreAPI
shapePath AssetLocation

Returns

Shape

WalkElements(string, Action<ShapeElement>)

public void WalkElements(string wildcardpath, Action<ShapeElement> onElement)

Parameters

wildcardpath string
onElement Action<ShapeElement>