Skip to content

IngredientArchive

Namespace Nfty.Core.Formats in assembly Nfty.Core.

public static class IngredientArchive

Reads and writes .igt archives — a manifest plus one PNG per variant, plus an optional depth map per variant. The ZipArchive overloads exist so a Recipe can nest one without going through a file.

Methods

Read(ZipArchive, Parallelism?)

public static LoadedIngredient Read(ZipArchive zip, Parallelism? parallelism = null);

Reads an Ingredient from an already-open archive, decoding every variant PNG.

Parameters

  • zip (ZipArchive) - The open archive.
  • parallelism (Parallelism?) - How wide PNG encoding (or decoding) may run; null means Parallelism.Default. Never changes the bytes.

Returns. The loaded ingredient; the caller owns it. Its manifest's PartialAlpha is recomputed from the decoded images rather than trusting the stored value.

Exceptions

Read(string, Parallelism?)

public static LoadedIngredient Read(string path, Parallelism? parallelism = null);

Reads an Ingredient from a file, decoding every variant PNG.

Parameters

  • path (string) - Archive path.
  • parallelism (Parallelism?) - How wide PNG encoding (or decoding) may run; null means Parallelism.Default. Never changes the bytes.

Returns. The loaded ingredient; the caller owns it and must dispose it.

Exceptions

ReadAsync(ZipArchive, CancellationToken, Parallelism?)

public static Task<LoadedIngredient> ReadAsync(ZipArchive zip, CancellationToken ct = default, Parallelism? parallelism = null);

Reads an Ingredient from an already-open archive.

Parameters

  • zip (ZipArchive) - The open archive.
  • ct (CancellationToken) - Cancels the read; anything already decoded is disposed first.
  • parallelism (Parallelism?) - How wide PNG encoding (or decoding) may run; null means Parallelism.Default. Never changes the bytes.

Returns. The loaded ingredient; the caller owns it. Its manifest's PartialAlpha is recomputed from the decoded images rather than trusting the stored value.

Exceptions

ReadAsync(string, CancellationToken, Parallelism?)

public static Task<LoadedIngredient> ReadAsync(string path, CancellationToken ct = default, Parallelism? parallelism = null);

Reads an Ingredient from a file.

Parameters

  • path (string) - Archive path.
  • ct (CancellationToken) - Cancels the read; anything already decoded is disposed first.
  • parallelism (Parallelism?) - How wide decoding may run; null means Parallelism.Default.

Returns. The loaded ingredient; the caller owns it.

Exceptions

Write(ZipArchive, IngredientManifest, IReadOnlyDictionary<string, Image<Rgba32>>, IReadOnlyDictionary<string, DepthMap>, Parallelism?)

public static void Write(ZipArchive zip, IngredientManifest manifest, IReadOnlyDictionary<string, Image<Rgba32>> variantImages, IReadOnlyDictionary<string, DepthMap> depths, Parallelism? parallelism = null);

Writes an Ingredient into an already-open archive.

Parameters

  • zip (ZipArchive) - The open archive.
  • manifest (IngredientManifest) - The ingredient's manifest. Its PartialAlpha is ignored — the written value is recomputed from variantImages.
  • variantImages (IReadOnlyDictionary<string, Image<Rgba32>>) - One image per variant id.
  • depths (IReadOnlyDictionary<string, DepthMap>) - Depth maps by variant id. A variant with no entry, or whose entry is flat once zeroed over transparency, gets no depth/ entry at all. An entry whose key is not one of this manifest's variants is ignored.
  • parallelism (Parallelism?) - How wide PNG encoding (or decoding) may run; null means Parallelism.Default. Never changes the bytes.

Write(string, IngredientManifest, IReadOnlyDictionary<string, Image<Rgba32>>, IReadOnlyDictionary<string, DepthMap>, Parallelism?)

public static void Write(string path, IngredientManifest manifest, IReadOnlyDictionary<string, Image<Rgba32>> variantImages, IReadOnlyDictionary<string, DepthMap> depths, Parallelism? parallelism = null);

Writes an Ingredient to a file.

Parameters

  • path (string) - Destination path.
  • manifest (IngredientManifest) - The ingredient's manifest.
  • variantImages (IReadOnlyDictionary<string, Image<Rgba32>>) - One image per variant id.
  • depths (IReadOnlyDictionary<string, DepthMap>) - Depth maps by variant id.
  • parallelism (Parallelism?) - How wide PNG encoding (or decoding) may run; null means Parallelism.Default. Never changes the bytes.

WriteAsync(ZipArchive, IngredientManifest, IReadOnlyDictionary<string, Image<Rgba32>>, IReadOnlyDictionary<string, DepthMap>, CancellationToken, Parallelism?)

public static Task WriteAsync(ZipArchive zip, IngredientManifest manifest, IReadOnlyDictionary<string, Image<Rgba32>> variantImages, IReadOnlyDictionary<string, DepthMap> depths, CancellationToken ct = default, Parallelism? parallelism = null);

Writes an Ingredient into an already-open archive.

Parameters

  • zip (ZipArchive) - The open archive.
  • manifest (IngredientManifest) - The ingredient's manifest.
  • variantImages (IReadOnlyDictionary<string, Image<Rgba32>>) - One image per variant id.
  • depths (IReadOnlyDictionary<string, DepthMap>) - Depth maps by variant id. See the sync overload for the write rules.
  • ct (CancellationToken) - Cancels the write.
  • parallelism (Parallelism?) - How wide PNG encoding (or decoding) may run; null means Parallelism.Default. Never changes the bytes.

Returns. A task that completes when it is written.

WriteAsync(string, IngredientManifest, IReadOnlyDictionary<string, Image<Rgba32>>, IReadOnlyDictionary<string, DepthMap>, CancellationToken, Parallelism?)

public static Task WriteAsync(string path, IngredientManifest manifest, IReadOnlyDictionary<string, Image<Rgba32>> variantImages, IReadOnlyDictionary<string, DepthMap> depths, CancellationToken ct = default, Parallelism? parallelism = null);

Writes an Ingredient to a file.

Parameters

  • path (string) - Destination path.
  • manifest (IngredientManifest) - The ingredient's manifest.
  • variantImages (IReadOnlyDictionary<string, Image<Rgba32>>) - One image per variant id.
  • depths (IReadOnlyDictionary<string, DepthMap>) - Depth maps by variant id.
  • ct (CancellationToken) - Cancels the write.
  • parallelism (Parallelism?) - How wide PNG encoding (or decoding) may run; null means Parallelism.Default. Never changes the bytes.

Returns. A task that completes when it is written.