Skip to content

CookBookEdits

Namespace Nfty.Core.Editing in assembly Nfty.Core.

public static class CookBookEdits

Splices an edited ingredient back into a loaded cookbook. Returns a new graph that reuses the existing image objects plus the new ingredient's — it disposes nothing, so the caller manages the lifetime of whatever it replaces.

Methods

EditIdentity(LoadedCookBook, string, Collection, int?)

public static LoadedCookBook EditIdentity(LoadedCookBook book, string name, Collection collection, int? targetSupply);

Edits the book's identity: its own name, the marketplace-facing collection record, and the intended supply. Nothing else in the manifest moves.

Parameters

  • book (LoadedCookBook) - The book to edit.
  • name (string) - The book's display name (what the titlebar, tree and recents show).
  • collection (Collection) - What SetWriter publishes: the collection name that prefixes every asset, plus description and symbol.
  • targetSupply (int?) - How many assets the author intends to mint, or null for no commitment.

Returns. A NEW graph SHARING every image and recipe with the previous book. Nothing is disposed. Nothing is validated either: Validator is the one place that decides what a legal book is, and the caller runs it before writing.

Remarks

None of these fields is read by a roll, so this can never change what a seed produces.

EditRecipeManifest(LoadedCookBook, string, Func<RecipeManifest, RecipeManifest>)

public static LoadedCookBook EditRecipeManifest(LoadedCookBook book, string recipeId, Func<RecipeManifest, RecipeManifest> edit);

Applies an edit to one recipe's MANIFEST, leaving its ingredients and every image alone.

Parameters

  • book (LoadedCookBook) - The book to edit.
  • recipeId (string) - Which recipe.
  • edit (Func<RecipeManifest, RecipeManifest>) - The manifest edit — one of the RuleEdits methods, or anything else pure. Taking the function rather than the finished manifest is what keeps the caller from having to hand-splice a recipe back into a book, which is the step every one of these methods exists to stop being written twice.

Returns. A NEW graph SHARING every image the old one held, like the rest of this class — so a caller swaps it in rather than disposing the book it replaces.

Exceptions

  • KeyNotFoundException - No such recipe.

MoveLayer(LoadedCookBook, string, string, int)

public static LoadedCookBook MoveLayer(LoadedCookBook book, string recipeId, string ingredientId, int toDepth);

Moves one of a recipe's layers to a depth, shifting the layers it passes. Depth is the 1-based position in layerOrder, bottom-first — see LayerDepth, which does the reordering and whose clamping rules apply here unchanged.

Parameters

  • book (LoadedCookBook) - The book to edit.
  • recipeId (string) - Which recipe owns the layer.
  • ingredientId (string) - The layer to move.
  • toDepth (int) - The 1-based depth to move it to; clamped to the stack rather than rejected.

Returns. A NEW graph SHARING every image with the previous book — only one recipe's manifest differs, and only in the order of its layer ids. Nothing is disposed.

Exceptions

  • KeyNotFoundException - No such recipe, or no such ingredient in it.

MoveRecipe(LoadedCookBook, string, int)

public static LoadedCookBook MoveRecipe(LoadedCookBook book, string recipeId, int toIndex);

Moves one recipe to a position in the book's listing, shifting the recipes it passes.

Parameters

  • book (LoadedCookBook) - The book to edit.
  • recipeId (string) - The recipe to move.
  • toIndex (int) - Where to put it, 0-based; clamped to the list rather than rejected, so nudging the first or last recipe off the end is a no-op exactly as LayerDepth.MoveTo() makes it one for a layer.

Returns. A NEW graph SHARING every image with the previous book. Only the manifest's CookBookManifest.RecipeOrder and the order of Recipes differ. Nothing is disposed.

Exceptions

  • KeyNotFoundException - No such recipe.

Remarks

THIS CHANGES NOTHING ABOUT WHAT A COOK PRODUCES, and that is the whole difference between it and CookBookEdits.MoveLayer() one level down. WeightedRoller.Prepare sorts its keys ordinally before building the cumulative table, so which Recipe a random number lands on is decided by the ids and their weights and never by the listing; a layer move, by contrast, moves which RNG draw reaches which layer and produces a different collection from the same seed. A reader who knows the layer rule would reasonably assume this one reorders their assets too. It does not.

The order is written WHOLE rather than as a patch — every id in the book, in the new order — so the field never describes a partial listing that the reader has to merge with a fallback to interpret.

RemoveIngredient(LoadedCookBook, string, string)

public static LoadedCookBook RemoveIngredient(LoadedCookBook book, string recipeId, string ingredientId);

Removes an ingredient from a recipe (dropping it from the layer order, its absent chance and the rules that name it too). Reuses every surviving image; the caller owns the removed ingredient's images.

Parameters

  • book (LoadedCookBook) - The book to edit; not modified.
  • recipeId (string) - Id of the recipe that holds the ingredient.
  • ingredientId (string) - Id of the ingredient (layer) to remove.

Returns. A new book without the layer; every surviving image is shared with book.

Exceptions

  • KeyNotFoundException - No recipe has recipeId, or that recipe has no such ingredient.

RemoveRecipe(LoadedCookBook, string)

public static LoadedCookBook RemoveRecipe(LoadedCookBook book, string recipeId);

Removes a recipe from a cookbook (and its selection-weight entry). Reuses every surviving image; the caller owns the removed recipe's ingredient images.

Parameters

  • book (LoadedCookBook) - The book to edit; not modified.
  • recipeId (string) - Id of the recipe to remove.

Returns. A new book without the recipe or its weight entry.

Exceptions

  • KeyNotFoundException - No recipe has recipeId.

RemoveVariant(LoadedCookBook, string, string, string)

public static LoadedCookBook RemoveVariant(LoadedCookBook book, string recipeId, string ingredientId, string variantId);

Removes one variant from an ingredient.

Parameters

  • book (LoadedCookBook) - The book to edit.
  • recipeId (string) - The recipe holding the layer.
  • ingredientId (string) - The layer holding the variant.
  • variantId (string) - The variant to remove.

Returns. A book with that variant gone.

Exceptions

  • KeyNotFoundException - No such recipe, ingredient or variant.
  • InvalidOperationException - It is the ingredient's only variant.

Remarks

Reuses every surviving image; the caller owns the removed one, exactly as CookBookEdits.RemoveIngredient() hands back the subtree it dropped.

It REFUSES to empty an ingredient. A layer with no variants has nothing to roll, and Validator reports it as a problem - so a book saved that way is broken from then on, reported on a screen nowhere near the delete. A front-end is expected to gray the control as well; this is the backstop that makes the rule true of the operation rather than true of whichever caller remembered it.

SetPalette(LoadedCookBook, IReadOnlyList<string>)

public static LoadedCookBook SetPalette(LoadedCookBook book, IReadOnlyList<string> swatches);

Replaces the swatches the book carries.

Parameters

  • book (LoadedCookBook) - The book to edit.
  • swatches (IReadOnlyList<string>) - Prefixed color specs (hex:d6249f), in order. An empty list stores null ("the book has never saved a palette") rather than an empty array, so a book with no swatches is written the way every book before the field was.

Returns. A NEW graph SHARING every image. Nothing is disposed.

SetRecipeWeight(LoadedCookBook, string, double)

public static LoadedCookBook SetRecipeWeight(LoadedCookBook book, string recipeId, double weight);

Sets one recipe's selection weight in the book. Zero shelves the recipe: it stays in the book and the roll skips it.

Parameters

  • book (LoadedCookBook) - The book to edit.
  • recipeId (string) - Which recipe.
  • weight (double) - The new weight. Not validated here; Validator reports a negative one.

Returns. A NEW graph SHARING every image. Nothing is disposed.

Exceptions

  • KeyNotFoundException - No such recipe.

Remarks

UNLIKE an identity edit, this DOES change which assets a seed produces: the weight is part of the roll's cumulative table.

UpsertIngredient(LoadedCookBook, string, LoadedIngredient)

public static LoadedCookBook UpsertIngredient(LoadedCookBook book, string recipeId, LoadedIngredient ingredient);

Returns a book with one ingredient replaced or added.

Parameters

  • book (LoadedCookBook) - The book to edit.
  • recipeId (string) - Which recipe owns the layer.
  • ingredient (LoadedIngredient) - The replacement.

Returns. A NEW graph SHARING the previous book's images, which is why the session swaps it in with Replace rather than Open — disposing the old book would dispose images the new one still points at.

Exceptions

  • KeyNotFoundException - No recipe has recipeId.

UpsertRecipe(LoadedCookBook, LoadedRecipe, double)

public static LoadedCookBook UpsertRecipe(LoadedCookBook book, LoadedRecipe recipe, double weight);

Adds a recipe to a cookbook (or replaces one with the same id) and sets its selection weight. Reuses every other recipe/image by reference; disposes nothing.

Parameters

  • book (LoadedCookBook) - The book to edit; not modified.
  • recipe (LoadedRecipe) - The recipe to add, or to put in place of the one with the same id.
  • weight (double) - The recipe's selection weight in the book.

Returns. A new book holding recipe with weight; every other recipe is shared.

WithoutLayer(RecipeManifest, string)

public static RecipeManifest WithoutLayer(RecipeManifest manifest, string ingredientId);

A recipe manifest with one layer gone: out of layerOrder, its absent chance dropped, and every rule that names it (as trigger or target) dropped with it. Leaving either behind writes a book Validator refuses - a chance for a layer the recipe does not stack, a rule naming an unknown ingredient - so removal is one operation here rather than three for each caller.

Parameters

  • manifest (RecipeManifest) - The recipe manifest to edit.
  • ingredientId (string) - The layer to take out.

Returns. The edited manifest; the input is unchanged.