Skip to content
EvilEngine.Conversion

ConversionContext class

public sealed class ConversionContext

What a converter reads through, in Accepts and Convert: the content asked for, the namespace’s files, and the places to note what the result points at and what went wrong.

Every read is recorded with a hash of what it found, a missing file and a folder listing included. A cached result is used again only while every one of those still matches, so read through here and nowhere else. The pipeline makes the context. You never make one yourself.

Assembly
EvilEngine.Conversion
Commit
4ff877b1

Members

Kind property

public ContentKind Kind { get; }

The ContentKind being asked for, always the converter’s Produces.

Id property

public ContentId Id { get; }

The ContentId being asked for. Its namespace is the one the converter is bound to, and its name is what the converter turns into paths to read.

LastRead property

public VirtualPath? LastRead { get; }

The last path read, or null before anything is. A failed conversion is reported with it.

Exists method

public bool Exists(VirtualPath path)

Returns whether a file is at path in the namespace. A file that isn’t there is recorded too, so the result converts again if one appears.

List method

public IReadOnlyList<FileEntry> List(VirtualPath directory, bool recursive = false)

Lists the files under directory, sorted by path, directly in it or at any depth with recursive. The listing is recorded by its paths, sizes and the layers they come from, so adding, removing or moving a file between layers converts the result again.

LayerOf method

public FileLayer? LayerOf(VirtualPath path)

Returns which layer the file at path comes from, its name and role, or null when the namespace isn’t a layered mount. It records a listing of the file’s folder if nothing already covers it, so the result converts again if another layer’s copy takes over. The map converters tag a map’s origin by its layer’s role: community for an addon, download, workshop or mod, expansion for DLC, official otherwise.

TryRead method

public bool TryRead(VirtualPath path, out ReadOnlyMemory<byte> data)

Reads the whole file at path, or returns false if it isn’t there. The data is the file’s bytes from the layer that wins.

Copies method

public IReadOnlyList<string> Copies(VirtualPath path)

Names every layer that holds a file at path, the winning one first. Read one of them with TryReadCopy.

TryReadCopy method

public bool TryReadCopy(VirtualPath path, string layer, out ReadOnlyMemory<byte> data)

Reads the copy of path in the layer named layer, rather than the one that wins, or returns false if that layer has none. It’s recorded apart from the winning copy. It’s for when the winning copy can’t be used, as when a Garry’s Mod addon’s copy of a model is a stub its Lua fills in at runtime and the one beneath stands in.

TryOpen method

public bool TryOpen(VirtualPath path, out IRandomAccess? access)

Opens the file at path for reading at any offset, without reading it whole, or returns false if it isn’t there. It’s the one for a big archive inside the mount, like a map’s BSP, when you only need some of it.

Open method

public IRandomAccess Open(VirtualPath path)

TryOpen, throwing FileNotFoundException naming the content and the path when the file isn’t there.

Read method

public ReadOnlyMemory<byte> Read(VirtualPath path)

TryRead, throwing FileNotFoundException naming the content and the path when the file isn’t there.

Reference method

public ContentId Reference(ContentKind kind, string name)
public ContentId Reference(ContentKind kind, ContentId id)

Names a piece of content the result points at, by kind and id, and returns the id. Give a bare name for content in the same namespace, or a whole ContentId for another. Starting a map follows every reference out from its manifest, so everything the map reaches converts as it loads.

Warn method

public void Warn(string message)

Notes a problem that didn’t stop the conversion, kept with the result and shown with it. Say what was left out and why.

Shared method

public T Shared<T>(string key, Func<ConversionContext, T> build) where T : class

Parses something once for every conversion that needs it, under a key, and hands each the same object. A Source map’s BSP is read once for its manifest, cells, models and lightmaps this way. The parse runs on a context of its own, and everything it read, listed, referenced and warned about counts as this conversion’s too, so each result still converts again when the parse’s inputs change. The object is held in memory and parsed again once any of those inputs change.

Start the key with the converter’s own prefix and the path, as source.bsp:<path>. Throws InvalidOperationException if the key is already shared as a different type.