Recipe module

For working with raw recipes.

Only usable in the mod data stage.

See also

Usage

local Data = require('stdlib/data/data')

Functions

format_items (recipes) Formats the recipes.
select (pattern) Selects all recipe values where the key matches the selector pattern.

Functions

# format_items (recipes)

Formats the recipes.

Parameters:
  • recipes : ({Recipe,...}) an array of recipes
Returns:
  • ({Recipe,...}) the formatted recipes
# select (pattern)

Selects all recipe values where the key matches the selector pattern.

The selector pattern is divided into groups. The pattern should have a colon character : to denote the selection for each group.

The first group is for the name of the recipe element.

The second group is for the name of keys inside of the recipe element, and is optional. If missing, all elements matching prior groups are returned.

The third group is for the name of values inside of the recipe element, and is optional. If missing, all elements matching prior groups are returned.

Selectors without a colon : separator are assumed to select all values in the first group.

Parameters:
  • pattern : (string) a pattern used for the search
Returns:
  • ({nil or Mixed,...}) an array containing the elements matching the selector pattern, or an empty array if there were no matches
Usage:
Recipe.select('.*') -- returns an array with all recipes, equivalent to Data.select('recipe:.*')
Recipe.select('steel.*') -- returns an array with all recipes whose name matches 'steel.*'
Recipe.select('steel.*:ingredients') -- returns an array with all ingredients from all recipes whose name matches 'steel.*'
Recipe.select('steel.*:ingredients:iron-plate') -- returns an array with all iron-plate ingredient objects, from all recipes whose name matches 'steel.*'