Skip to content

MenuArchive

Namespace Nfty.Ticket in assembly Nfty.Ticket.

public sealed class MenuArchive : IDisposable

Reads a .mnu Menu: every weight, rule and colorization a rolled asset needs, plus its art, with no imaging library involved.

Remarks

This assembly decodes no pixels — that is the whole point of Nfty.Ticket being package-free. In atlas mode MenuArchive.ArtBytes() hands back the WHOLE atlas PNG's bytes and MenuArchive.Cell() the rect inside it; the caller crops. In loose mode the "rect" is simply the whole image, so a caller can treat both modes through one code path without ever asking which mode a Menu was written in.

Owns the open archive. MenuArchive.Open() opens the file and keeps it open for the life of this object — MenuArchive.ArtBytes() reads from it lazily rather than eagerly decoding everything up front, which is what lets a host page through a large Menu's art without holding it all in memory at once. Dispose frees the archive (and, for MenuArchive.Open(), the file it was opened from).

Properties

Book

public MenuBook Book { get; }

The Menu's manifest: every weight, rule, colorization and cell rect.

Methods

ArtBytes(string)

public byte[] ArtBytes(string cellKey);

One cell's art, as raw PNG bytes.

Parameters

Returns. In atlas mode, the whole atlas PNG's bytes — use MenuArchive.Cell() to find where this cell sits inside them. In loose mode, that one variant's own PNG bytes in full.

Exceptions

  • KeyNotFoundException - The Menu has no cell for cellKey.
  • InvalidDataException - The archive is missing the entry the manifest points at.

Cell(string)

public MenuCell Cell(string cellKey);

Where cellKey's art sits inside the bytes MenuArchive.ArtBytes() returns.

Parameters

Returns. The cell rect — the whole image in loose mode, so a caller can treat both modes with one code path.

Exceptions

  • KeyNotFoundException - The Menu has no cell for cellKey.

Depth(string)

public DepthMap? Depth(string cellKey);

One variant's depth map, when it has one.

Parameters

Returns. null when the variant carries no depth data — "paper" for the Rise feature — otherwise a DepthMap sized to that cell's MenuCell.Width and MenuCell.Height.

Exceptions

  • KeyNotFoundException - The Menu has no cell for cellKey — the same check, and the same message, MenuArchive.Cell() makes.
  • InvalidDataException - A stored depth entry's length disagrees with the cell's dimensions, naming the key.

Remarks

Read lazily, like MenuArchive.ArtBytes() — not eagerly at MenuArchive.Open() — for the same reason: most variants carry no depth data at all, and this assembly stays package-free, so nothing here decodes a pixel either way; a .dep entry is already raw bytes in the exact layout DepthMap.FromBytes() expects.

Dispose()

public void Dispose();

Closes the underlying archive, and the file it was opened from.

Layer(string, string)

public MenuLayer Layer(string recipeId, string ingredientId);

One layer's definition — kind, colorization and variants — as the recipe it belongs to records it.

Parameters

  • recipeId (string) - The recipe.
  • ingredientId (string) - The layer within that recipe.

Returns. The layer, exactly as the Menu manifest carries it.

Exceptions

  • KeyNotFoundException - The Menu has no recipe named recipeId, or that recipe has no layer named ingredientId. Both cases are reported by this single method — naming which of the two failed — so a caller (Plating.Plate, chiefly) never has to reach into MenuArchive.Book itself to answer the question, and never hits the BCL's unnamed default message for either.

Open(Stream)

public static MenuArchive Open(Stream stream);

Opens a .mnu from an already-open stream.

Parameters

  • stream (Stream) - A seekable stream over the archive's bytes. Ownership passes to the returned MenuArchive — it is closed when that object is disposed.

Returns. The open archive; the caller disposes it.

Exceptions

  • NotSupportedException - The manifest declares a schema newer than this build reads.
  • InvalidDataException - The stream is not a readable Menu.

Open(string)

public static MenuArchive Open(string path);

Opens a .mnu file for reading.

Parameters

  • path (string) - The Menu to open.

Returns. The open archive; the caller disposes it.

Exceptions

  • NotSupportedException - The manifest declares a schema newer than this build reads.
  • InvalidDataException - The file is not a readable Menu.